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;
}
do_action()
does not use a returned value. It works more like theonload
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):