Fix plugin details popup to show correct version and handle old plugin slug
This commit is contained in:
@ -20,7 +20,7 @@ if ( ! defined( 'WPINC' ) ) {
|
||||
}
|
||||
|
||||
// Define plugin constants.
|
||||
define( 'FPDEN_VERSION', '2.0.8' );
|
||||
define( 'FPDEN_VERSION', '2.0.9' );
|
||||
define( 'FPDEN_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||
define( 'FPDEN_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
@ -402,19 +402,21 @@ class Fix_Plugin_Does_Not_Exist_Notices {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Debug: Log the requested slug
|
||||
error_log('Plugin API request for slug: ' . $args->slug);
|
||||
|
||||
// Check if this is our own plugin (either old or new slug)
|
||||
$our_plugin = false;
|
||||
if ($args->slug === 'wp-fix-plugin-does-not-exist-notices' || $args->slug === 'fix-plugin-does-not-exist-notices') {
|
||||
$our_plugin = true;
|
||||
error_log('Detected request for our own plugin: ' . $args->slug);
|
||||
}
|
||||
|
||||
// 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
|
||||
if ( $args->slug === $plugin_slug ) {
|
||||
// Check if the requested plugin is one of our missing plugins or our own plugin
|
||||
if ($our_plugin || $this->is_missing_plugin($args->slug, $invalid_plugins)) {
|
||||
// If we don't have a result yet, create one
|
||||
if ( ! $result ) {
|
||||
$result = new stdClass();
|
||||
@ -424,9 +426,9 @@ class Fix_Plugin_Does_Not_Exist_Notices {
|
||||
$new_result = new stdClass();
|
||||
|
||||
// Set all the properties we need
|
||||
$new_result->name = isset($result->name) ? $result->name : basename( $plugin_file );
|
||||
$new_result->name = $our_plugin ? 'Fix \'Plugin file does not exist\' Notices' : (isset($result->name) ? $result->name : $args->slug);
|
||||
$new_result->slug = $args->slug;
|
||||
$new_result->version = FPDEN_VERSION . ' (' . date('Y-m-d') . ')';
|
||||
$new_result->version = FPDEN_VERSION;
|
||||
$new_result->author = '<a href="https://www.wpallstars.com">Marcus Quinn & WP ALLSTARS</a>';
|
||||
$new_result->author_profile = 'https://www.wpallstars.com';
|
||||
$new_result->requires = '5.0';
|
||||
@ -446,11 +448,15 @@ class Fix_Plugin_Does_Not_Exist_Notices {
|
||||
}
|
||||
}
|
||||
|
||||
$new_result->sections = array(
|
||||
'description' => sprintf(
|
||||
$description = $our_plugin
|
||||
? 'Adds missing plugins to your plugins list with a "Remove Notice" action link, allowing you to safely clean up invalid plugin references.'
|
||||
: sprintf(
|
||||
__( 'This plugin is still marked as "Active" in your database — but its folder and files can\'t be found in %s. Use the "Remove Notice" link on the plugins page to permanently remove it from your active plugins list and eliminate the error notice.', 'wp-fix-plugin-does-not-exist-notices' ),
|
||||
'<code>/wp-content/plugins/</code>'
|
||||
),
|
||||
);
|
||||
|
||||
$new_result->sections = array(
|
||||
'description' => $description,
|
||||
'changelog' => $changelog,
|
||||
'faq' => '<h3>Is it safe to remove plugin references?</h3><p>Yes, this plugin only removes entries from the WordPress active_plugins option, which is safe to modify when a plugin no longer exists.</p>'
|
||||
);
|
||||
@ -492,11 +498,32 @@ class Fix_Plugin_Does_Not_Exist_Notices {
|
||||
// Return our completely new result object
|
||||
return $new_result;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a slug matches one of our missing plugins.
|
||||
*
|
||||
* @param string $slug The plugin slug to check.
|
||||
* @param array $invalid_plugins List of invalid plugin paths.
|
||||
* @return bool True if the slug matches a missing plugin.
|
||||
*/
|
||||
private function is_missing_plugin($slug, $invalid_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 ($slug === $plugin_slug) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent WordPress from caching our plugin API responses.
|
||||
*
|
||||
@ -608,16 +635,30 @@ class Fix_Plugin_Does_Not_Exist_Notices {
|
||||
* @return void
|
||||
*/
|
||||
private function clear_own_plugin_cache() {
|
||||
// Clear our own plugin's cache
|
||||
$our_slug = 'wp-fix-plugin-does-not-exist-notices';
|
||||
delete_transient( 'plugins_api_' . $our_slug );
|
||||
delete_site_transient( 'plugins_api_' . $our_slug );
|
||||
delete_transient( 'plugin_information_' . $our_slug );
|
||||
delete_site_transient( 'plugin_information_' . $our_slug );
|
||||
// Clear our own plugin's cache (both old and new slugs)
|
||||
$our_slugs = array('wp-fix-plugin-does-not-exist-notices', 'fix-plugin-does-not-exist-notices');
|
||||
|
||||
// Force refresh of plugin update information
|
||||
foreach ($our_slugs as $slug) {
|
||||
delete_transient( 'plugins_api_' . $slug );
|
||||
delete_site_transient( 'plugins_api_' . $slug );
|
||||
delete_transient( 'plugin_information_' . $slug );
|
||||
delete_site_transient( 'plugin_information_' . $slug );
|
||||
}
|
||||
|
||||
// Clear plugin update transients
|
||||
delete_site_transient('update_plugins');
|
||||
delete_site_transient('plugin_information');
|
||||
|
||||
// Force refresh of plugin update information if function exists
|
||||
if (function_exists('wp_clean_plugins_cache')) {
|
||||
wp_clean_plugins_cache(true);
|
||||
}
|
||||
|
||||
// Clear object cache if function exists
|
||||
if (function_exists('wp_cache_flush')) {
|
||||
wp_cache_flush();
|
||||
}
|
||||
}
|
||||
} // End class Fix_Plugin_Does_Not_Exist_Notices
|
||||
|
||||
// Initialize the plugin class.
|
||||
|
Reference in New Issue
Block a user