Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
    else
    $options['excerpt_enable'] = 1;

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

    return $options;
}
share|improve this question

1 Answer 1

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

 
discard

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.