一段代码轻松解决wordpress定时发布失败的问题
- 时间:2020-05-17 12:16:18
- 分类:网络文摘
- 阅读:137 次
之前,本站写过一篇关于 wordpress 文章发布出现“定时发布失败”的原因及解决方法 的文章。其中介绍了定时发布失败的原因和通过插件或更改 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 );
说明:此段代码应该是提取自老版本的wordpress插件 WP Missed Schedule Posts ,定时发布有时会出现二分钟左右的延迟,之后会正常发布的。
推荐阅读:How To Successfully Fine-tune Your Overall Social Media Strategy What It Really Takes To Make Money As a Blogger How Do You Increase Website Domain Authority? Bitcoin Expert Regrets Blogging About Rumored Bitcoin Creator WordPress Theme Seller, Templatic, Warns Users Of Hacking Samsung Utilizes Virtual Reality Stories For Children’s Bedtimes 6 Things You Need to Do Before Writing a Single Word on Your Blo Verge Introduces Innovative Gadget Blog, ‘Circuit Breaker’ 5 Tools That Will Grow Your Online Retail Business #PlaylistsForLife: Doctors Without Borders Launches Awareness Ca
- 评论列表
-
- 添加评论