Wordpress 这段代码中的WP Cron有什么问题
我有这个代码,它应该每1小时运行一次代码,但它似乎有什么不对劲。。。如果我运行/?mnd import,它可以正常工作,但它不是每一小时工作一次。。。请帮忙 有没有一种方法可以让它每一分钟测试一次它是否工作Wordpress 这段代码中的WP Cron有什么问题,wordpress,cron,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 s
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' ) );
wordpress cron作业在PHP级别运行。如果没有人访问您的站点,那么就不会运行wpcron作业,因为不会执行任何php代码。是的,我测试了该站点,并在前端和管理中打开它,如何让它每分钟运行一次,以测试它是否工作….?在linux机器上创建一个cron作业,每x分钟加载一次您的网站。。。如果你经常这样做,可能会损害你的网站性能。