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.

I am using the Settings API for a plugin's settings page. One of the settings allows the user to change the cron job interval for the cron job created by this plugin.

Therefore I'd like to run a function on saving of the settings page, which checks the value in the database and compares it to the value the existing cron job has. If they are different, the cron job should be recreated.

Is my logic right, and if so how can I run such a function after the plugin settings have been saved?

share|improve this question
    
it sounds like you are looking for callbacks? –  Jesse Mar 4 '13 at 4:58
    
@Jesse I think it's a hook I need. –  drtanz Mar 4 '13 at 5:01
add comment

1 Answer

up vote 2 down vote accepted

I'm not familiar with wordpress settings api but I know those options generated by settings api are handled/saved in wp-admin/options.php

Unfortunately,

if ( isset( $_POST[ $option ] ) ) {
        $value = $_POST[ $option ];
    if ( ! is_array( $value ) )
        $value = trim( $value );
    $value = stripslashes_deep( $value );
}
update_option( $option, $value );

as you can see, no hook before update_option.

But there is a workaround:

add_settings_field('..','..','callback');

function callback(){
   if($_GET['settings-updated']=='true'){
        //do your cron update stuff here.
   }
   echo 'output <input or something';
}

Not very elegant though.

share|improve this answer
    
In that case I don't even need the extra function and blank settings field I think, I can put the code inside the callback of one of the existing sections. –  drtanz Mar 4 '13 at 13:57
    
yes, you can do that in the callback of register_setting and add_settings_section too –  Jesse Mar 5 '13 at 0:14
add comment

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.