2

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 ? example:

$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' etc....

I hope I have posted my question clearly.

thanks for help

3
  • When do you want to fire that action? When option is being saved? Some time after that?
    – Rarst
    Apr 12 '14 at 21:58
  • after option has been saved and changed. ie if user selects previous value and saves it then I do not want to fire that action Apr 13 '14 at 6:32
  • Still looking for solution, any help is appreciated. Apr 13 '14 at 18:57
4

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: https://codex.wordpress.org/Plugin_API/Filter_Reference/pre_update_option_(option_name)

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.