最近浏览wp的博客站长群的消息,发现有个伙计提到自己在用WordPress定时发布文章的时候,发布失败,不知道如何解决,在群里求问,其实大多数定时发布文章失败的原因是主机访问速度慢,发布超时影响的,下面推荐几种方法解决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-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定时发布文章失败的方法,个人推荐第一种方法。