how can I detect that option value has changed in wordpress?

I am working on a WordPress plugin and I want to fire a different action based on each option value change. so how can I do that ?

Example:

Read More
$options = get_option('ACP_settings'); if $options['acp-select'] has changed from previous value than I want to fire different action based on selection

Please note that $option['acp-select'] is retrieved from select/option html form and has following values for selection:'book','air','SW','HW' and etc….

I hope I have posted my question clearly.

thanks for help

Related posts

Leave a Reply

1 comment

  1. You can use wordpress hooks in the update_option() function.

    In your case you can use updated_option or update_option_{$option} hooks.

    The code for ACP_settings option would look like:

    add_action( 'update_option_ACP_settings', function($old_value, $value, $option){
    
        if( $old_value !== $value ){
            // Your option was updated
            // Run your code here       
        }
    
    }, 10, 3 );