侧边栏壁纸
  • 累计撰写 82 篇文章
  • 累计创建 56 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

WordPress定时发布失败-解决

修仙大佬
2020-02-03 / 0 评论 / 0 点赞 / 9 阅读 / 1,152 字 / 正在检测是否收录...

将此代码加入到function.php就能解决,感谢知更鸟

    if (!function_exists( 'add_action' ) ) {
    	header( 'Status 403 Forbidden' );
    	header( 'HTTP/1.0 403 Forbidden' );
    	header( 'HTTP/1.1 403 Forbidden' );
    	exit();
    }
     
    function wpms_log() {
    	echo"\n";
    }
    add_action( 'wp_head', 'wpms_log' );
    add_action( 'wp_footer', 'wpms_log' );
     
    define( 'WPMS_DELAY', 5 );
    define( 'WPMS_OPTION', 'wp_missed_schedule' );
     
    function wpms_replace() {
    	delete_option(WPMS_OPTION);
    }
     
    register_deactivation_hook(__FILE__,'wpms_replace');
    function wpms_init() {
    	remove_action('publish_future_post','check_and_publish_future_post');
    	$last=get_option(WPMS_OPTION,false);
    	if (($last!==false)&&($last>(time()-(WPMS_DELAY*60))))return;
    	update_option(WPMS_OPTION,time());
    	global$wpdb;
    	$scheduledIDs=$wpdb->get_col("SELECT`ID`FROM`{$wpdb->posts}`"."WHERE("."((`post_date`>0)&&(`post_date`<=CURRENT_TIMESTAMP()))OR"."((`post_date_gmt`>0)&&(`post_date_gmt`<=UTC_TIMESTAMP()))".")AND`post_status`='future'LIMIT 0,5");
    	if (!count($scheduledIDs))return;
    	foreach($scheduledIDs as$scheduledID) {
    		if (!$scheduledID)continue;
    		wp_publish_post($scheduledID);
    	}
    }
    add_action( 'init', 'wpms_init', 0 );
0

评论区