WordPress常规发布失败的解决方案(无插件实现方法)

Wordpress1年前 (2023)发布 SUYEONE
1.4K 0 0

WordPress users often report issues with scheduled posts not publishing on time, without any clear reason. It might be related to server sluggishness, although this issue isn’t consistently experienced. Here’s a log of potential solutions for your reference.

Two plugins are recommended to address the problem of fAIled scheduled posts: WP Missed Schedule Posts and My Missed Schedule.

– WP Missed Schedule Posts: Download from the official Website or via a download link.
– My Missed Schedule: Download from the official website or through a download link.

Alternatively, you can implement the following code snippet. This code is derived from an older version of the WP Missed Schedule Posts plugin. Add it to your current theme’s functions.php file:

“`php
if (!function_exists(‘add_Action’)) {
header(‘HTTP/1.0 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-&gt;get_col(“SELECT `ID` FROM {$wpdb->posts} WHERE ((`post_date` > 0 AND `post_date` 0 AND `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);
“`
After adding this code, scheduled posts may still initially show a Failure notice, but they should publish correctly within two to three minutes.

It's up to you to experiment and determine which solution best suits your needs.

© 版权声明

相关文章

暂无评论

暂无评论...
☺一键登录开启个人书签等功能!