diff --git a/wp-fix-plugin-does-not-exist-notices.php b/wp-fix-plugin-does-not-exist-notices.php index 17baee5..8fb96f6 100644 --- a/wp-fix-plugin-does-not-exist-notices.php +++ b/wp-fix-plugin-does-not-exist-notices.php @@ -1,82 +1,42 @@ slug ) ) { + return $result; + } + + // Get our list of invalid plugins + $invalid_plugins = $this->get_invalid_plugins(); + + // Check if the requested plugin is one of our missing plugins + foreach ( $invalid_plugins as $plugin_file ) { + // Extract the plugin slug from the plugin file path + $plugin_slug = dirname( $plugin_file ); + if ( '.' === $plugin_slug ) { + $plugin_slug = basename( $plugin_file, '.php' ); + } + + // If this is one of our missing plugins, prevent caching + if ( $args->slug === $plugin_slug ) { + // Add a filter to prevent caching of this response + add_filter( 'plugins_api_result_' . $args->slug, '__return_false' ); + + // Add a timestamp to force cache busting + if ( is_object( $result ) ) { + $result->last_updated = current_time( 'mysql' ); + $result->cache_time = 0; + } + } + } + + return $result; + } + + /** + * Clear plugin API cache when viewing the plugins page. + * + * @return void + */ + public function maybe_clear_plugin_api_cache() { + // Only run on the plugins page + if ( ! $this->is_plugins_page() ) { + return; + } + + // Get our list of invalid plugins + $invalid_plugins = $this->get_invalid_plugins(); + + // Clear transients for each invalid plugin + foreach ( $invalid_plugins as $plugin_file ) { + // Extract the plugin slug from the plugin file path + $plugin_slug = dirname( $plugin_file ); + if ( '.' === $plugin_slug ) { + $plugin_slug = basename( $plugin_file, '.php' ); + } + + // Delete the transient for this plugin + delete_transient( 'plugins_api_' . $plugin_slug ); + delete_site_transient( 'plugins_api_' . $plugin_slug ); + + // Also delete the update transient which might cache plugin info + delete_site_transient( 'update_plugins' ); + } + } } // End class Fix_Plugin_Does_Not_Exist_Notices // Initialize the plugin class.