WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a widget

class Xwidget extends WP_Widget{
function cron_addB(){}


I want to run a cron job that calls that function from outside the class

function xxx_cron_activation() {   ;
    if ( !wp_next_scheduled( 'xxx_followers' ) ) {
    wp_schedule_event(time(), 'hourly', 'xxx_followers');
add_action('wp', 'xxx_cron_activation');


Cron is being triggered but the function is not being executed

share|improve this question
up vote 1 down vote accepted

Try this instead:

$gloabl $myxclass;
$myxclass = new Xwidget();
add_action( 'xxx_followers', array(&$myxclass, "cron_addB" ) );


add_action('xxx_followers', "init_xclass_and_cron");
function init_xclass_and_cron() {
    $myxclass = new Xwidget();
share|improve this answer
that won't work; the $myxclass object won't be initialized inside the cron request... – onetrickpony Jul 14 '11 at 17:10
How about setting $myxclass globally? – Brady Jul 14 '11 at 17:15
see update for another method – Brady Jul 14 '11 at 17:19
The 2nd one should work. The functions that cron executes are stored as simple strings in the db, so they should be static. The OP's code should also work if the method is really static... Another way is add_action('xxx_followers', 'Xwidget::cron_addB'); – onetrickpony Jul 14 '11 at 19:19
the second one works like charm! Thanx guys – Freeman Jul 17 '11 at 1:00

Your Answer


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.