• Resolved Dankicity

    (@dankicity)


    I can place the code to schedule an event in the header and “Cron GUI” shows that it is registered but when I place it like below I get nothing. I put a die(‘YAY’); in each step and they’re getting hit but still no scheduled event. The plugin is initialized on init.

    class MyPlugin {
    	function __construct() {
    		$this->init(); // loads the courses class and inits
    		register_activation_hook( __FILE__, array(&$this, 'activation') );
    	}
    	function activation() { do_action( 'myplugin_activation' ); }
    }
    
    class Courses {
    	function Courses() {
    		add_action( 'myplugin_activation', array($this, 'activation') );
    		add_action( 'session_expiry_event', array($this, 'session_expiry') );
    	}
    	function activation() { wp_schedule_event(time(), 'daily', 'session_expiry_event'); }
    	function session_expiry() {/* blah blah */}
    }

    Any thoughts?

Viewing 1 replies (of 1 total)
  • Thread Starter Dankicity

    (@dankicity)

    Ahh figured it out. It was being assigned too late. I missed the bit in the codex

    Registering the hook inside your plugins_loaded hook is too late and it won’t run! (Even when it seems to work for register_deactivation_hook until the wp_loaded hook.)

    and the wp_schedule_event had me confused because of:

    function my_activation() {
    	if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
    		wp_schedule_event(time(), 'hourly', 'my_hourly_event');
    	}
    }
    add_action('wp', 'my_activation');

    Made me think wp was the point in which activation was triggered.

Viewing 1 replies (of 1 total)
  • The topic ‘logic in getting wp_schedule_event to register in plugin’ is closed to new replies.