Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a scheduled event that runs twice daily in my plugin, the action is registered with

add_action('fhprw_action','fhprw_check_fetch'); 

function fhprw_check_fetch($args){
  $type=$args['type'];

//do stuff according to $type
}

if I manually call a do_action('fhprw_action',array('type'=>'uk')); when a widget is updated then the function receives $args as an array and I can get $type from $args['type'] no problem

but when I schedule an event with

wp_schedule_event(time() , 'twicedaily', 'fhprw_action',array('type'=>$instance['type'])); // ($instance['type'] will be 'uk')

then the function receives $args as a string

$args = 'uk' instead of array('type'=>'uk');

why is the function not receiving an array for $args when it is called by the cron?

[edit]

scheduled events call the callback function with a list of parameters, not an array of parameters so my callback function for the action would receive $arg1,$arg2 etc and wouldn't be able to accept an associative array

share|improve this question

1 Answer 1

It could be the phrasing of the array so try setting the array outside the wp_schedule_event call:

$args = array('type'=>$instance['type']);
wp_schedule_event(time() , 'twicedaily', 'fhprw_action',$args);
share|improve this answer
1  
turns out that a scheduled event will call the callback function with call_user_func_array which means the function is called with fhprw_check_fetch($arg1,$arg2,$arg3) and not fhprw_check_fetch($arrarg); –  CommentLuv Mar 19 '11 at 15:02
1  
In which case, if you really wanted args passed back as an associative array, you could schedule with $args = array( array( 'type' => $instance['type'] ) ); –  TheDeadMedic Mar 19 '11 at 15:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.