wordpress常规设置预保存挂钩

时间:2017-02-13 11:00:14

标签: wordpress

有没有办法检测wp常规设置是否更新(wp-admin / options-general.php页面)并在保存更改后执行一些人员?

1 个答案:

答案 0 :(得分:0)

我在2020年9月24日时遇到了完全相同的问题。

这是我找到的解决方案,但我只想注册对站点语言的更改:

add_filter( 'pre_update_option_WPLANG', function( $new_value, $old_value ) {
  global $current_user;
  get_currentuserinfo();
$msg = 'oldvalue: ' . $old_value . "\n\n new value: " . $new_value . "\n\n user: " . (string) $current_user->user_email ;
  wp_mail( 'myemail@myemail.com', 'SOMEONE CHANGED LANGUAGE OF [domainname]', $msg );

  return $new_value;

}, 10, 2);

因此基本上使用 pre_update_option _ {$ option} 过滤器。 https://developer.wordpress.org/reference/hooks/pre_update_option_option/