经常有用户说定时发布文章是提示失败,造成失败原因不太清楚,应该是主机慢有关吧,我自己从没遇到过,这里记录一下解决办法,供大家参考。
可以先用代码修复一下:在你workpress主题下面将代码添加到当前主题 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
如果上面按钮下载链接失效,可以在本页页面下面点击下载。(有两个插件打包在一起)根据自己喜好任选即可。
评论前必须登录!
立即登录 注册