WP Cron在这段代码中有什么问题

时间:2015-02-19 15:14:17

标签: wordpress cron

我有这个代码,它假设每1小时运行一次代码,但它似乎有问题...如果我运行/?mnd-import它可以正常运行但是它每隔一小时就不起作用..请任何帮助。

有没有办法每隔一分钟做一次,只是为了测试它是否正常工作。

class MND_Importer
{
  // Name of WP cron job
  const CRON_NAME = 'mnd-import-api';
  // Meta key where posts feed id will be stored
  protected static $instance = null;
  /**
   * Access to the working instance of this class
   *
   * @wp-hook plugins_loaded
   * @return Ngn_Pr_Importer
   */
  public static function get_instance()
  {
    null === self::$instance and self::$instance = new self;
    return self::$instance;
  }
  /**
   * Constructor. Intentionally left empty and public.
   *
   * @see plugin_setup()
   */
  public function __construct() {}
  /**
   * Initalizes the plugin
   * @wp-hook plugins_loaded
   */
  public function plugin_setup()
  {
    $this->_schedule_import();
    add_action( self::CRON_NAME, array( $this, 'add_new_entries' ) );   
    // If you add '/?mnd-import' to the url you force the import of news
    if ( isset( $_GET['mnd-import'] ) ) {
        add_and_update_entries_news();
        add_and_update_entries_press();
      add_and_update_entries_event();
        exit();
    }
  }
  /**
   * Schedule the import hook to be run hourly
   */
  private function _schedule_import()
  {
    // If the schedule isn't set
    if ( !wp_next_scheduled( self::CRON_NAME ) )
    {
      // Use the built in function wp_schedule event to run the function every hour
      wp_schedule_event( time(), 'hourly', self::CRON_NAME );
    }
  }
}
include( plugin_dir_path( __FILE__ ) . 'news.php');
include( plugin_dir_path( __FILE__ ) . 'press.php');
include( plugin_dir_path( __FILE__ ) . 'event.php');
add_action('after_setup_theme',array( MND_Importer::get_instance(), 'plugin_setup' ) );

0 个答案:

没有答案