Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed:The recovery_mode_clean_expired_keys cron event is orphaned after converting to Multisite #6835

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/wp-includes/class-wp-recovery-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function initialize() {
add_action( 'wp_logout', array( $this, 'exit_recovery_mode' ) );
add_action( 'login_form_' . self::EXIT_ACTION, array( $this, 'handle_exit_recovery_mode' ) );
add_action( 'recovery_mode_clean_expired_keys', array( $this, 'clean_expired_keys' ) );
add_action( 'wp_install', array( $this, 'remove_orphaned_recovery_mode_cron_event' ), 10, 1 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function don't have argument 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my bad 😞 Fixed now.


if ( ! wp_next_scheduled( 'recovery_mode_clean_expired_keys' ) && ! wp_installing() ) {
wp_schedule_event( time(), 'daily', 'recovery_mode_clean_expired_keys' );
Expand Down Expand Up @@ -262,6 +263,21 @@ public function clean_expired_keys() {
$this->key_service->clean_expired_keys( $this->get_link_ttl() );
}

/**
* Unschedule the recovery_mode_clean_expired_keys Event.
*/
public function remove_orphaned_recovery_mode_cron_event() {
// Check if we are in a Multisite installation.
if ( is_multisite() ) {
// Check if the cron event is scheduled.
$timestamp = wp_next_scheduled( 'recovery_mode_clean_expired_keys' );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @narenin,

I think it is better to use the wp_clear_scheduled_hook function instead of the wp_unschedule_event.

@mukeshpanchal27 Please share your opinions as well.

Thanks

if ( $timestamp ) {
// Unschedule the event.
wp_unschedule_event( $timestamp, 'recovery_mode_clean_expired_keys' );
}
}
}

/**
* Handles checking for the recovery mode cookie and validating it.
*
Expand Down
Loading