WordPress.org

Ready to get started?Download WordPress

Forums

Plugins
Basic Schedule Not Working (3 posts)

  1. J7mbo
    Member
    Posted 2 years ago #

    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/

  2. J7mbo
    Member
    Posted 2 years ago #

    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.

  3. J7mbo
    Member
    Posted 2 years ago #

    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...

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic