最近不是要过年了吗?寻思着可以定时发布一些文章,结果,今天在测试Wordpress定时发表文章时,出现如下错误提示:
定时发布失败
第一种方法:
将代码添加到当前主题 - functions.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 );
第二种方法:
推荐两款解决定时发布失败的插件:WP Missed Schedule Posts 和 MY Missed Schedule;
WP Missed Schedule官方下载地址:http://wordpress.org/extend/plugins/wp-missed-schedule/
MY Missed Schedule官方下载地址:https://cn.wordpress.org/plugins/my-missed-schedule/advanced/
第三种方法:
修改 /wp-includes/cron.php 系统文件;
打开wp-includes目录下面的cron.php文件,找到“timeout”代码:
wp_remote_post( $cron_url, array( 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ) ) );
将代码后面的数值0.01修改为比0.01大就可以了,也可以修改为10.00。
博主不是很推荐这种方法,因为WordPress版本更新后,你需要再次修改这个文件。这样很麻烦!