how can I detect that option value has changed?

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

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

Read More

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

I hope I have posted my question clearly.

thanks for help

Related posts

Leave a Reply

1 comment

  1. I just came across your question while trying to do a similar thing. I figured out what I needed so I thought I would post an answer here in case someone else finds it useful.

    In short I used this filter:

    And it looks something like this:

    function set_admin_notice_options( $new_value, $old_value ) {
        // Check test mode
        if ( $new_value !== $old_value && ! empty( $new_value ) ) {
            update_option( 'some_option_changed', $new_value );
        return $new_value;
    add_filter( 'pre_update_option_my_option_name', 'set_admin_notice_options', 10, 2 );

    With this method you will then have an option saved if a change is found. Then you can check that option anywhere else and perform any action with it and remove the option afterwards or whatever you wish to do.

    Hope you find this helpful.