Repository navigation
Description
Description
When a connected site deactivates Optimole, the hourly optml_pull_image_data cron event is left behind. Optml_Main::deactivate() still clears optml_pull_image_data_init, which was the hourly hook's name before 4.0.0. Since 4.0.0 the plugin schedules optml_pull_image_data instead, and nothing clears it on deactivation. The plugin has no uninstall routine, so the event also stays after the plugin is deleted. WordPress keeps rescheduling it every hour, but no callback runs because the plugin is no longer loaded.
This is the same leftover-cron problem that #659 reported and #687 fixed. It came back when #889 renamed the hook.
Expected: deactivation removes every recurring event Optimole scheduled, optml_pull_image_data included.
Step-by-step reproduction instructions
- On a test site, install and activate Optimole 4.2.17, then connect it:
wp optimole setting connect <api-key>. - Run
wp cron event list --fields=hook,recurrence | grep optml. You seeoptml_pull_image_data(1 hour) andoptml_daily_sync(12 hours). - Run
wp plugin deactivate optimole-wp. - Run
wp cron event list --fields=hook,recurrence | grep optmlagain.- Actual:
optml_pull_image_data(1 hour) is still listed. - Expected: no
optml_events are listed.
- Actual:
- Optional: run
wp plugin delete optimole-wp. The event is still listed.
WP Crontrol (Tools > Cron Events) shows the same result if you use the UI. I also checked the logic with a standalone PHP script that copies how core stores and clears events. It shows that deactivate() clears optml_daily_sync (1 event) and optml_pull_image_data_init (0 events), and leaves optml_pull_image_data scheduled.
Screenshots, screen recording, code snippet or Help Scout ticket
Hourly event scheduled under the new name, https://github.com/Codeinwp/optimole-wp/blob/v4.2.17/inc/admin.php#L48-L49 and https://github.com/Codeinwp/optimole-wp/blob/v4.2.17/inc/admin.php#L89-L91:
const ENRICH_CRON = 'optml_pull_image_data';
...
if ( ! wp_next_scheduled( self::ENRICH_CRON ) ) {
wp_schedule_event( time() + 10, 'hourly', self::ENRICH_CRON );
}Deactivation clears the old name, https://github.com/Codeinwp/optimole-wp/blob/v4.2.17/inc/main.php#L277-L281:
public function deactivate() {
// Clear registered cron events.
wp_clear_scheduled_hook( 'optml_daily_sync' );
wp_clear_scheduled_hook( 'optml_pull_image_data_init' );
}wp_clear_scheduled_hook() only matches the exact hook name, so the second call removes nothing on 4.x sites (https://github.com/WordPress/WordPress/blob/7.1.3/wp-includes/cron.php#L638-L644). Optml_Settings::reset() already clears both constants on disconnect (https://github.com/Codeinwp/optimole-wp/blob/v4.2.17/inc/settings.php#L774-L775). A likely fix is to also call wp_clear_scheduled_hook( Optml_Admin::ENRICH_CRON ) in deactivate(), and to keep the _init line for sites upgraded from 3.x.
Environment info
- Optimole 4.2.17 (same code on
masteranddevelopmenttoday), on a site connected to an Optimole account - WordPress 5.5 to 7.1 (core cron behaviour is the same across these versions)
- PHP 7.4 and later
Is the issue you are reporting a regression
Yes. In 3.11.0 to 3.14.1, the hourly event was optml_pull_image_data_init (https://github.com/Codeinwp/optimole-wp/blob/v3.14.1/inc/admin.php#L198-L199), and deactivate() cleared it. In 4.0.0, #889 (commit 8640f6d) renamed the hourly event to optml_pull_image_data but did not update deactivate(). This conclusion comes from comparing the source code at both tags. I did not run 3.14.1 to confirm it.
Found while writing the WordPress compatibility checks for Optimole.
Activity
girishpanchal30 commentedon Oct 28, 2026
I have fixed it with PR #1207
kushh23 commentedon Oct 28, 2026
🧪 QA steps and test links
When Optimole is deactivated on a connected site, its hourly image data sync stays scheduled in WP-Cron. WordPress keeps rescheduling it every hour with nothing to run it, and it stays even after the plugin is deleted.
Requires: an Optimole account to connect the test site (the links fake the connection instead).
optml_pull_image_datawas still listed (Once Hourly, Action: None)d071db4optmlshowed "No matching cron events"In the links:
optml.debug.log. The "Undefined array key whitelist" warnings there come from the fake connection.Reproduce on Optimole 4.2.17:
optml. You seeoptml_pull_image_data(Once Hourly) andoptml_daily_sync(Twice Daily).optmlagain.optml_pull_image_datais still listed, now with Action "None".optmlevents are listed.Edge cases
optmlevents remain.optml_pull_image_data_initstill scheduled: deactivating removes it too.Fix: #1207 (open)
pirate-bot commentedon Oct 28, 2026
QA agent — 🟢 Passing checks · Deactivation clears Optimole’s current and legacy recurring cron events.
The hourly cron leak reproduced on the base build and did not reproduce on the PR build using the same Plugins-screen deactivation flow. The connected-site fixture used a mocked account response, and the legacy upgrade fixture used the exact old hook. Current and legacy events were removed, while an unrelated event remained. Repeated deactivation, multiple timestamps, reactivation, disconnect, deletion, and the added regression test all passed.
Checks (2 passed)
Full report, evidence and session trail
pirate-bot commentedon Nov 2, 2026
🎉 This issue has been resolved in version 4.2.18 🎉
The release is available on GitHub release
Your semantic-release bot 📦🚀