Skip to content

Commit

Permalink
Added new logic to see if a new plugin has been installed, if yes del…
Browse files Browse the repository at this point in the history
…ete the caching transient to recreate it.
  • Loading branch information
redscar committed Dec 19, 2024
1 parent 31c4e4c commit 6a25c11
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Tribe/PUE/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,35 @@ public function __construct( $pue_update_url, $slug = '', $options = [], $plugin
$this->set_options( $options );
$this->hooks();
$this->set_key_status_name();
$this->init( $slug );
// So we can reference our "registered" instances later.
self::$instances[ $slug ] ??= $this;
}

/**
* Initializes the PUE checker and fires the appropriate action if not already initialized.
*
* This method ensures that the `tec_pue_checker_init` action is fired only once per unique slug.
*
* @since TBD
*
* @param string $slug The unique slug for the plugin being initialized.
*/
public function init( $slug ) {
if ( isset( self::$instances[ $slug ] ) ) {
return;
}

/**
* Fires when initializing the PUE checker.
*
* @since TBD
*
* @param Tribe__PUE__Checker $checker An instance of the PUE Checker being initialized.
*/
do_action( 'tec_pue_checker_init', $this );
}

/**
* Gets whether the license key is valid or not.
*
Expand Down Expand Up @@ -447,6 +472,7 @@ public function hooks() {
add_filter( 'upgrader_pre_download', [ Tribe__PUE__Package_Handler::instance(), 'filter_upgrader_pre_download' ], 5, 3 );

add_action( 'admin_init', [ $this, 'monitor_uplink_actions' ], 1000 );
add_action( 'tec_pue_checker_init', [ __CLASS__, 'monitor_active_plugins' ] );
}


Expand Down Expand Up @@ -2158,5 +2184,28 @@ function ( $plugin ) {
},
);
}

/**
* Monitor active plugins and validate the transient for the given slug.
*
* @param Tribe__PUE__Checker $checker An instance of the PUE Checker.
*/
public static function monitor_active_plugins( Tribe__PUE__Checker $checker ) {
$slug = $checker->get_slug();

if ( empty( $slug ) ) {
return;
}

$transient_data = get_transient( self::IS_ANY_LICENSE_VALID_TRANSIENT_KEY );

$plugins = $transient_data['plugins'] ?? null;

if ( ! is_array( $plugins ) || array_key_exists( $slug, $plugins ) ) {
return;
}

delete_transient( self::IS_ANY_LICENSE_VALID_TRANSIENT_KEY );
}
}
}

0 comments on commit 6a25c11

Please sign in to comment.