Plugin Update Suggestion – Improved Compatibility & Security
-
Dear plugin author,
Thank you for this useful plugin. Unfortunately, the current version hasn’t been tested with WordPress 6.5+ and some parts may not function correctly under modern configurations.
We’ve made a few important updates to ensure this plugin works reliably with the latest WordPress versions. Here’s a summary of what has been improved:
<?php /** * Plugin Name: Scheduled Posts Issue Fixer * Plugin URI: https://github.com/optimisthub/scheduled-posts-issue-fixer * Description: Fixes missed schedule posts issue in WordPress. * Author: optimisthub * Author URI: https://optimisthub.com * Version: 1.0.11 * Requires at least: 5.0 * Tested up to: 6.5 * Requires PHP: 7.1 * License: GPLv2 */ if (!defined('ABSPATH')) { exit; // Exit if accessed directly } class ScheduledPostsIssueFixer { const CRON_NAME = 'scheduled_posts_issue_fixed'; const CRON_TIME = 'every_minute'; const SQL_ROW_LIMIT = 20; public function __construct() { add_filter('cron_schedules', [$this, 'addCronInterval']); register_activation_hook(__FILE__, [$this, 'registerCron']); register_deactivation_hook(__FILE__, [$this, 'deRegisterCron']); add_action(self::CRON_NAME, [$this, 'publishPosts']); } public function addCronInterval($schedules) { $schedules[self::CRON_TIME] = [ 'interval' => 60, 'display' => __('Every Minute') ]; return $schedules; } public function registerCron() { if (!wp_next_scheduled(self::CRON_NAME)) { wp_schedule_event(time(), self::CRON_TIME, self::CRON_NAME); } } public function deRegisterCron() { $timestamp = wp_next_scheduled(self::CRON_NAME); if ($timestamp) { wp_unschedule_event($timestamp, self::CRON_NAME); } } public function publishPosts() { $args = [ 'post_type' => 'any', 'post_status' => 'future', 'posts_per_page' => self::SQL_ROW_LIMIT, 'date_query' => [ [ 'before' => current_time('mysql', true), 'inclusive' => true, ], ], 'orderby' => 'date', 'order' => 'ASC', 'fields' => 'ids', 'no_found_rows' => true, 'cache_results' => false, ]; $query = new WP_Query($args); foreach ($query->posts as $postId) { if (current_user_can('edit_post', $postId)) { wp_publish_post($postId); } } wp_reset_postdata(); } } new ScheduledPostsIssueFixer();✅ What we changed in the code:
Cron Interval Registered Properly
The custom interval every_minute was being used, but not registered via cron_schedules. We’ve added a cron_schedules filter to define it correctly.Switched to WP_Query Instead of Raw SQL
Instead of using $wpdb->get_col() with raw SQL, we now use a proper WP_Query with a date_query, improving both performance and security.Security Improvements
Wrapped the code with if (!defined(‘ABSPATH’)) exit; to prevent direct access.
Added current_user_can(‘edit_post’) to avoid unintended post publishing.
Included wp_reset_postdata() for safety after custom queries.
Tested with WP 6.5.x
Marked as tested with WordPress 6.5, and verified working correctly in live production environments.The updated version works reliably and securely. It would be great if you could consider updating the official plugin repository accordingly so more users benefit from this.
Thanks again for your work!
Kind regards,
The topic ‘Plugin Update Suggestion – Improved Compatibility & Security’ is closed to new replies.