我创建了一个插件,可以将当天X点之前下的所有订单发送到电子邮件Y。我在这里遵循了教程:https://scotch.io/tutorials/how-to-build-a-wordpress-plugin-part-1
在每次选项更新时,它会删除所有计划的事件并添加新的事件。出于某种原因,我不明白,只要有人以管理员身份登录主页,就会发送电子邮件。一旦我更改并保存设置,它就会停止。以下是我认为相关的代码:
public function options_update() {
register_setting($this->plugin_name, $this->plugin_name, array($this, \'validate\'));
wp_clear_scheduled_hook(\'send_woocommerce_daily_order_summary_email\');
$options = get_option($this->plugin_name);
$timestamp = strtotime($options[\'send_time\'] . ":00:00 " . get_option(\'timezone_string\'));
wp_schedule_event($timestamp, \'daily\', \'send_woocommerce_daily_order_summary_email\');
}
在添加操作的位置:`
private function define_admin_hooks() {
$plugin_admin = new Woocommerce_Daily_Order_Summary_Email_Admin( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( \'admin_enqueue_scripts\', $plugin_admin, \'enqueue_styles\' );
$this->loader->add_action( \'admin_enqueue_scripts\', $plugin_admin, \'enqueue_scripts\' );
// Add menu item
$this->loader->add_action( \'admin_menu\', $plugin_admin, \'add_plugin_admin_menu\' );
// Add Settings link to the plugin
$plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . \'.php\' );
$this->loader->add_filter( \'plugin_action_links_\' . $plugin_basename, $plugin_admin, \'add_action_links\' );
// Save/Update our plugin options
$this->loader->add_action(\'admin_init\', $plugin_admin, \'options_update\');
}
有人能帮我理解为什么会发生这种情况吗?