admin管理员组文章数量:1130349
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?
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 asked Mar 4, 2013 at 4:01 urok93urok93 4,05412 gold badges67 silver badges104 bronze badges 2- it sounds like you are looking for callbacks? – Jesse Commented Mar 4, 2013 at 4:58
- @Jesse I think it's a hook I need. – urok93 Commented Mar 4, 2013 at 5:01
2 Answers
Reset to default 1I'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.
The correct answer is to add_action after an option as been updated.
See this answer: Hook if somebody saves plugin options?
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?
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 asked Mar 4, 2013 at 4:01 urok93urok93 4,05412 gold badges67 silver badges104 bronze badges 2- it sounds like you are looking for callbacks? – Jesse Commented Mar 4, 2013 at 4:58
- @Jesse I think it's a hook I need. – urok93 Commented Mar 4, 2013 at 5:01
2 Answers
Reset to default 1I'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.
The correct answer is to add_action after an option as been updated.
See this answer: Hook if somebody saves plugin options?
本文标签: optionsRun function on settings save
版权声明:本文标题:options - Run function on settings save 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749024337a2304865.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论