如何定义wp-cron



我想每小时制作一个wp-cron到add_option(),但它不起作用!(实际上它添加到了_get_cron_array(),但我认为该功能不起作用。(

我的WordPress插件代码:

<?php
/*
Plugin Name: A1
*/
function test_activation()
{
add_action('test_cron', 'test_cron_func');
wp_next_scheduled('test_cron');
wp_schedule_event(time(), 'hourly', 'test_cron');
if (!wp_next_scheduled('test_cron')) {
wp_schedule_event(time(), 'hourly', 'test_cron');
}
}
function test_deactivation()
{
$timestamp = wp_next_scheduled('test_cron');
wp_unschedule_event($timestamp, 'test_cron');
}

function test_cron_func()
{
add_option('Bookzisto1234', '1234');
}
register_activation_hook(FILE, 'test_activation');
register_deactivation_hook(FILE, 'test_deactivation');

我认为问题出在函数挂钩和text_activation逻辑上,请尝试:

<?php
/*
Plugin Name: A1
*/
function test_activation()
{
if (! wp_next_scheduled ( 'test_cron' )) {
wp_schedule_event( time(), 'hourly', 'test_cron' );
}
}
add_action('test_cron', 'test_cron_func');
function test_cron_func()
{
add_option('Bookzisto1234', '1234');
// $log = get_option( 'Bookzisto1234' );
// error_log($log);
}
function test_deactivation()
{
$timestamp = wp_next_scheduled('test_cron');
wp_unschedule_event($timestamp, 'test_cron');
}
register_activation_hook( __FILE__ , 'test_activation');
register_deactivation_hook( __FILE__ , 'test_deactivation');

最新更新