一段代码轻松解决wordpress定时发布失败的问题
- 时间:2020-05-17 12:16:18
- 分类:网络文摘
- 阅读:113 次
之前,本站写过一篇关于 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 ,定时发布有时会出现二分钟左右的延迟,之后会正常发布的。
推荐阅读:5 Habits Of Highly Successful Bloggers 5 Ways to Connect Your Blog Content Writers Google’s Perfect World: A New Technical SEO Framework Boost the Visibility of Your Blog With In-Person Events Are Top 20 Witnesses Voting Each Other? Introducing Witness-voti How to Design a Browser History using Double-ended Queue (deque) SteemJs: How Many Witnesses are Running on 23.1? Illustrating the Blockchain via SteemJs – Blocks are Chain DFS and BFS Algorithms to Find All the Lonely Nodes of a Binary Three ways of Running a continuous NodeJS Application on Your Se
- 评论列表
-
- 添加评论