Skip to content

Hourly optml_pull_image_data cron event stays scheduled after Optimole is deactivated #1198

Closed

Description

@kushh23

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

  1. On a test site, install and activate Optimole 4.2.17, then connect it: wp optimole setting connect <api-key>.
  2. Run wp cron event list --fields=hook,recurrence | grep optml. You see optml_pull_image_data (1 hour) and optml_daily_sync (12 hours).
  3. Run wp plugin deactivate optimole-wp.
  4. Run wp cron event list --fields=hook,recurrence | grep optml again.
    • Actual: optml_pull_image_data (1 hour) is still listed.
    • Expected: no optml_ events are listed.
  5. 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 master and development today), 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

  1. added
    bugThis label could be used to identify issues that are caused by a defect in the product.
    on Oct 28, 2026
  2. added theissue type on Oct 28, 2026
  3. girishpanchal30 commented on Oct 28, 2026

    @girishpanchal30
    Contributor

    I have fixed it with PR #1207

  4. kushh23 commented on Oct 28, 2026

    @kushh23
    ContributorAuthor

    🧪 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).

    Link Build Bot check
    Reproduce the bug Optimole 4.2.17 (released) ✅ Reproduced: after deactivating, optml_pull_image_data was still listed (Once Hourly, Action: None)
    Verify the fix PR #1207 build d071db4 ✅ Fixed: after deactivating, searching optml showed "No matching cron events"

    In the links:

    • Steps 1 to 3 are already done, and the links open on Cron → Cron Events filtered to optml.
    • Optimole is connected with fake keys, so nothing reaches the Optimole service. That is enough for it to schedule its events.
    • Tools → QA Logs shows debug.log. The "Undefined array key whitelist" warnings there come from the fake connection.

    Reproduce on Optimole 4.2.17:

    1. Install and activate Optimole 4.2.17 and WP Crontrol.
    2. Connect Optimole to your account (Optimole → enter your API key).
    3. Go to Cron → Cron Events and search for optml. You see optml_pull_image_data (Once Hourly) and optml_daily_sync (Twice Daily).
    4. Go to Plugins, click Deactivate under Optimole, then Skip & Deactivate.
    5. Go back to Cron → Cron Events and search for optml again.
    • Bug: optml_pull_image_data is still listed, now with Action "None".
    • Fixed: no optml events are listed.
    Edge cases
    • Delete Optimole after deactivating it: no optml events remain.
    • Reactivate Optimole on the connected site: both events are scheduled again once a front-end page loads.
    • Disconnect Optimole (keep it active): both events are removed, as before.
    • Site upgraded from Optimole 3.x with optml_pull_image_data_init still scheduled: deactivating removes it too.

    Fix: #1207 (open)

  5. pirate-bot commented on Oct 28, 2026

    @pirate-bot
    Collaborator

    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)
    • ✅ Deactivating Optimole on a connected site removes its hourly optml_pull_image_data and twice-daily optml_daily_sync recurring events from WP-Cron.
    • ✅ Deactivating Optimole also removes the legacy optml_pull_image_data_init recurring event retained by a site upgraded from version 3.x.

    Full report, evidence and session trail

  6. pirate-bot commented on Nov 2, 2026

    @pirate-bot
    Collaborator

    🎉 This issue has been resolved in version 4.2.18 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

  7. added
    releasedIndicate that an issue has been resolved and released in a particular version of the product.
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugThis label could be used to identify issues that are caused by a defect in the product.releasedIndicate that an issue has been resolved and released in a particular version of the product.

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions