WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I am implementing a core plugin plus add ons. There is a settings page and I would like to hook some validation routines for the addon plugin into the core plugin's validation function. However it's not working. Can you point me in the right direction?

Here's an excerpt of what I have:

    register_setting( 'myp_settings', 'myp_settings', 'myp_settings_validate' );

    function myp_settings_validate( $input ) {
      $options = get_option( 'myp_settings' );
      do_action( 'myp_settings_validate', $input, $options );
      return $options;

The above is in the core plugin's code, while the below is in the addon plugin:

add_action( 'myp_settings_validate', 'myp_settings_et_validate', '', 2 );

function myp_settings_et_validate( $input, $options ) {

    if ( ! isset( $input['excerpt_enable'] ) || $input['excerpt_enable'] != '1' )
    $options['excerpt_enable'] = 0;
    $options['excerpt_enable'] = 1;

    if ( ! isset( $input['thumbnail_enable'] ) || $input['thumbnail_enable'] != '1' )
    $options['thumbnail_enable'] = 0;
    $options['thumbnail_enable'] = 1;

    return $options;
share|improve this question
up vote 1 down vote accepted

do_action() does not use a returned value. It works more like the onload event in JavaScript: You cannot undo the load. To change a value you need filters.

If you want to change the option content, hook into pre_update_option_{$option_name} very late (with a high priority parameter):

add_filter( 'pre_update_option_myp_settings', 'myp_settings_et_validate', 100, 3 );

function myp_settings_et_validate( $option, $newvalue, $oldvalue )
    # do something awesome and return a value
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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