Support » Plugin: Plugins » [Plugin: Plugins] Basic Schedule Not Working

  • Hi, I’m a newbie to wordpress plugins (but not PHP). I’ve followed a couple of tutorials and I simply can’t get a schedule working. I basically want to create the equivalent of a cronjob to send today’s posts out to every user of the system.

    First thing’s first, I can’t even get the most basic schedule working. Please advise?

    <?php
    /*
      Plugin Name: testschedule
      Version: 0.1
      Description: A simple plugin to test schedules are working
      Plugin URI: lololol
      Author: Moi
      Author URI: http://www.j7mbo.co.uk
     */
    
    $plugin_dir = plugin_basename(__FILE__);
    $plugin_dir = str_replace(basename($plugin_dir), '', $plugin_dir);
    define('TESTSCHEDULE_DIR', WP_PLUGIN_DIR . '/' . $plugin_dir);
    define('TESTSCHEDULE_URL', WP_PLUGIN_URL . '/' . $plugin_dir);
    define('TESTSCHEDULE_VERSION', 0.1);
    
    class testschedule {
    	private static $instance;
    
    	public static function forge() {
            if (!isset(self::$instance)) {
                $className = __CLASS__;
                self::$instance = new $className;
            }
            return self::$instance;
        }
    
    	private function __construct() {
    		add_action('daily_schedule', array($this, 'main') );
    	}
    
    	private function main() {
    
    		// Do something
    		echo '<br><br><br>OMG';
    		die;
    	}
    
    }
    
    global $testschedule;
    $testschedule = testschedule::forge();
    
    register_activation_hook(__FILE__, 'activate');
    register_deactivation_hook(__FILE__, 'deactivate');
    
    function activate() {
    	if ( !wp_next_scheduled( 'daily_schedule' ) ) {
    		wp_schedule_event( '1342021600', 'daily', 'daily_schedule');
    		// Daily at 4:50pm = 1342025400
    	}
    }
    
    function deactivate() {
    	wp_clear_scheduled_hook('activate');
    }

    http://wordpress.org/extend/plugins/plugins/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter J7mbo

    (@j7mbo)

    I thought I’d add that to get the ‘cronjob’ going, I’ll ping / wget the page to simulate a visitor visiting at the time I need the e-mail sent out.

    Thread Starter J7mbo

    (@j7mbo)

    2 days on, has nobody got experience with this scheduling? Please could somebody who has lend a quick hand – it’s not for profit, just for learning. I’ve tried repeated clean wordpress installs…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Plugins] Basic Schedule Not Working’ is closed to new replies.