Skip to content

Commit

Permalink
add some invalidations
Browse files Browse the repository at this point in the history
  • Loading branch information
mreishus committed Sep 11, 2024
1 parent 0fc5fad commit 2489d39
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions projects/packages/connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,17 @@ public static function configure() {
add_action( 'deleted_user', array( $manager, 'disconnect_user_force' ), 9, 1 );
add_action( 'remove_user_from_blog', array( $manager, 'disconnect_user_force' ), 9, 1 );

// Force is_connected() to recompute after important actions.
add_action( 'jetpack_site_registered', array( $manager, 'reset_connection_status' ) );
add_action( 'jetpack_site_disconnected', array( $manager, 'reset_connection_status' ) );
add_action( 'jetpack_sync_register_user', array( $manager, 'reset_connection_status' ) );
add_action( 'pre_update_jetpack_option_id', array( $manager, 'reset_connection_status' ) );
add_action( 'pre_update_jetpack_blog_token', array( $manager, 'reset_connection_status' ) );
add_action( 'pre_update_jetpack_user_token', array( $manager, 'reset_connection_status' ) );
add_action( 'pre_update_jetpack_user_tokens', array( $manager, 'reset_connection_status' ) );
add_action( 'update_option', array( $manager, 'maybe_reset_connection_status' ), 10, 1 );
add_action( 'add_option', array( $manager, 'maybe_reset_connection_status' ), 10, 1 );
add_action( 'delete_option', array( $manager, 'maybe_reset_connection_status' ), 10, 1 );

// Set up package version hook.
add_filter( 'jetpack_package_versions', __NAMESPACE__ . '\Package_Version::send_package_version_to_tracker' );
Expand Down Expand Up @@ -629,6 +638,22 @@ public function reset_connection_status() {
self::$is_connected = null;
}

/**
* Resets the memoized connection status if jetpack_private_options is updated.
*
* Ideally, we would only do this on certain "sub" options stored inside
* jetpack_private_options, but delete_option() -> delete_grouped_option()
* provides us no hook to detect which options are being deleted.
*
* @param string $option The option name.
*/
public function maybe_reset_connection_status( $option ) {
$reset_options = array( 'jetpack_private_options' );
if ( in_array( $option, $reset_options, true ) ) {
self::$is_connected = null;
}
}

/**
* Returns true if the site has at least one connected administrator.
*
Expand Down

0 comments on commit 2489d39

Please sign in to comment.