因此,我想到了以下似乎有效的方法:
此函数将按用户id搜索并找到相应的cron作业
function search_user_cron( $hook, $user_id ) {
$crons = _get_cron_array();
foreach( $crons as $timestamp => $cron )
if( isset( $cron[$hook] ) )
foreach( $cron as $jobs )
foreach( $jobs as $key => $job )
if( $job[\'args\'][0][\'customer\'][\'user_id\'] == $user_id )
return array( \'id\' => $user_id, \'timestamp\' => $timestamp, \'key\' => $key );
}
然后,我使用此函数使用新参数完成并创建一个新作业,并取消设置旧作业
function replace_cron_args( $hook, $user_id ) {
// lets find the cron job corresponding to the user id
$user = search_user_cron( $hook, $user_id );
// get all the current cron jobs
$crons = _get_cron_array();
// get the most recent updated arguments
$stored_args = get_user_meta( $user[\'id\'], \'oe_customer_details\', true );
// get the current user key
$key = $user[\'key\'];
// get the current user timestamp
$timestamp = $user[\'timestamp\'];
// serialize the new arguments
$newkey = md5( serialize( $stored_args ) );
// update the stored arguments
$crons[$timestamp][$hook][$key][\'args\'][0] = $stored_args;
// replace the key with the new serialized key
$crons[$timestamp][$hook][$newkey] = $crons[$timestamp][$hook][$key];
// unset the old array
unset( $crons[$timestamp][$hook][$key] );
// set the new cron jobs
_set_cron_array( $crons );
}
如果有人能想出更有效的方法,请告诉我。