Compare commits

..

4 Commits
v1.2 ... v1.2.4

Author SHA1 Message Date
7ac72fd3c0 Fix compatibility with more WordPress admin themes (v1.2.4)
Some checks failed
ci/woodpecker/push/woodpecker Pipeline is pending
Build Release / Build and Create Release (push) Has been cancelled
ci/woodpecker/tag/woodpecker Pipeline failed
2025-04-10 00:01:20 +01:00
0a394fa671 Fix button not appearing in some WP admin themes (v1.2.3)
Some checks failed
ci/woodpecker/push/woodpecker Pipeline is pending
Build Release / Build and Create Release (push) Has been cancelled
ci/woodpecker/tag/woodpecker Pipeline failed
2025-04-09 23:56:47 +01:00
f200ff6f96 Fix timeout issue during plugin activation (v1.2.2)
Some checks failed
ci/woodpecker/push/woodpecker Pipeline is pending
Build Release / Build and Create Release (push) Has been cancelled
ci/woodpecker/tag/woodpecker Pipeline failed
2025-04-09 23:46:06 +01:00
fb4a54ab57 Version 1.2.1: Fix typos and improve text clarity
Some checks failed
ci/woodpecker/push/woodpecker Pipeline is pending
Build Release / Build and Create Release (push) Has been cancelled
ci/woodpecker/tag/woodpecker Pipeline failed
2025-04-07 14:35:48 +01:00
4 changed files with 247 additions and 52 deletions

View File

@ -2,6 +2,40 @@
All notable changes to this project will be documented in this file.
## [1.2.4] - 2023-10-05
### Fixed
- Compatibility with more WordPress admin UI variations
- Specific targeting for admin notices in various themes
### Added
- Advanced DOM traversal using TreeWalker API
- Multiple fallback approaches to ensure button appears
- Enhanced console logging for troubleshooting
## [1.2.3] - 2023-10-05
### Fixed
- Button not appearing in some WordPress admin themes
- Error message detection for greater theme compatibility
### Improved
- DOM traversal to find notification elements in various themes
- Added console logging for troubleshooting
## [1.2.2] - 2023-10-05
### Fixed
- Timeout issue during plugin activation
- Potential infinite recursion in admin notices handling
### Improved
- Hook management to prevent performance issues
- Optimized by only loading on plugins page
## [1.2.1] - 2025-04-07
### Improved
- Fixed typos in documentation
- Improved text clarity
- Added question mark to first sentence for better readability
## [1.2] - 2025-04-07
### Added
- Improved documentation with detailed explanation

View File

@ -1,30 +1,27 @@
# Plugin Reference Cleaner
Have you ever deleted a plugin some other way than on the `/wp-admin/plugins.php` page, you'll probabaly have been stuck with this annoying notifications that can't be cleared:
> "The plugin folder-name/file-name.php has been deactivated due to an error: Plugin file does not exist."
This small WordPress utility plugin adds a "Remove Reference" button to these plugin deactivation error notices, allowing you to clean up the invalid plugin entries in the database.
Author: Marcus Quinn
Author URI: https://www.wpallstars.com
Version: 1.2.4
License: GPL-2.0+
## Description
When WordPress detects a plugin file that no longer exists but is still referenced in the database as active, it displays an error notice. This plugin enhances those notices with a button that allows you to safely remove the invalid reference with a single click.
Have you ever deleted a plugin some other way than through the /wp-admin/plugins.php page? If so, you've probably been stuck with this annoying notification that can't be cleared:
You can find these with `SELECT * FROM wp_options WHERE option_name = 'active_plugins';` — but, the cleanup involved removing the rogue entry, and renumbering the others. This plugin can simply do that for you at the click of a button added to that WP standard notification.
It's probabaly something that should be added to WP core. If anyone from the core team wants to adopt this solution, it's GPL, so feel free.
**Note:** This plugin only needs to be installed and active if you have an error notification showing like this:
"The plugin folder-name/file-name.php has been deactivated due to an error: Plugin file does not exist."
If you don't have this notification perpetually showing on your `/wp-admin/plugins.php` page, then you don't need this, but you might like to save or bookmark it for if ever you do.
This small WordPress utility plugin adds a "Remove Reference" button to these plugin deactivation error notices, allowing you to clean up the invalid plugin entries in the database.
**Testing:** Just delete any plugin (that you can replace) from your `/wp-content/plugins` directory, via ftp or however you manage your WordPress files, then revisit your `/wp-admin/plugins.php` page with this plugin active to show the "Remove Reference" button.
When WordPress detects a plugin file that no longer exists but is still referenced in the database as active, it displays an error notice. This plugin enhances those notices with a button that allows you to safely remove the invalid reference with a single click.
The only ways I know to clear this missing plugin notification are:
1. Reinstall it and delete on the `/wp-admin/plugins.php` page.
2. Run `SELECT * FROM wp_options WHERE option_name = 'active_plugins';` (or `wp_1_options`, `wp_2_options`, `wp_3_options`, etc on a multisite network, using the side id of the site affected) via phpMyAdmin or Adminer, etc, or via mysql via your server commandline. Then edit the record, copying the json into an AI LLM and asking it to update without the reference to the missing plugin.
3. Use this plugin.
You can find these with `SELECT * FROM wp_options WHERE option_name = 'active_plugins';` — but the cleanup involves removing the rogue entry, and renumbering all others. This plugin can simply do that for you at the click of a button added to that WP standard notification.
It's probably something that should be added to WP core. If anyone from the core team wants to adopt this solution, it's GPL, so feel free.
Note: This plugin only needs to be installed and active if you have an error notification showing at /wp-admin/plugins.php, like this:
"The plugin folder-name/file-name.php has been deactivated due to an error: Plugin file does not exist."
If you don't have this notification perpetually showing on your /wp-admin/plugins.php page, then you don't need this, but you might like to save or bookmark it for if ever you do.
## Features
@ -48,10 +45,42 @@ The only ways I know to clear this missing plugin notification are:
3. Click the button and confirm to remove the invalid plugin reference
4. The page will refresh with the error notice removed
## Changelog
### 1.2.4
* Fixed compatibility with more WordPress admin themes
* Added advanced DOM traversal to find error messages
* Implemented fallback mechanisms to ensure button appears
* Added detailed console logging for troubleshooting
### 1.2.3
* Fixed button not appearing in some WordPress admin themes
* Improved error message detection for greater compatibility
* Enhanced DOM traversal to find notification elements
### 1.2.2
* Fixed timeout issue during plugin activation
* Improved hook management to prevent potential infinite recursion
* Optimized performance by only loading on plugins page
### 1.2.1
* Fixed typos in documentation
* Improved text clarity
* Added question mark to first sentence for better readability
### 1.2
* Improved documentation with detailed explanation
* Added SQL reference for technical users
* Suggested potential inclusion in WordPress core
### 1.1
* Improved error handling
* Added support for multisite installations
* Enhanced security with proper capability checks
### 1.0
* Initial release
## Support
For support, please visit [WP ALLSTARS](https://wpallstars.com)
## License
This plugin is licensed under the [GPL v2 or later](https://www.gnu.org/licenses/gpl-2.0.html).
For support, please visit https://wpallstars.com

View File

@ -2,9 +2,9 @@
/*
* Plugin Name: Plugin Reference Cleaner
* Description: Adds a "Remove Reference" button to plugin deactivation error notices, allowing users to clean up invalid plugin entries.
* Version: 1.2
* Version: 1.2.4
* Author: Marcus Quinn
* Author URI: https://wpallstars.com
* Author URI: https://www.wpallstars.com
* License: GPL-2.0+
*/
@ -15,22 +15,21 @@ if (!defined('ABSPATH')) {
class Plugin_Reference_Cleaner {
public function __construct() {
// Hook into admin notices to modify plugin error messages
add_action('admin_notices', array($this, 'inject_remove_button'), 100);
add_action('network_admin_notices', array($this, 'inject_remove_button'), 100); // Ensure notices in network admin
// Only hook into admin actions when on the plugins page
add_action('current_screen', function($screen) {
if (isset($screen->id) && ($screen->id === 'plugins' || $screen->id === 'plugins-network')) {
// Hook into admin notices to modify plugin error messages
add_action('admin_notices', array($this, 'inject_remove_button'), 100);
add_action('network_admin_notices', array($this, 'inject_remove_button'), 100);
}
});
// Handle the AJAX request to remove the plugin reference
add_action('wp_ajax_remove_plugin_reference', array($this, 'remove_plugin_reference'));
}
// Inject "Remove Reference" button only if a relevant notice exists
public function inject_remove_button() {
global $pagenow;
// Only run on plugins.php or network admin plugins page
if (!in_array($pagenow, array('plugins.php', 'plugins.php'))) {
return;
}
// Check if a "Plugin file does not exist" notice exists
$notices = $this->get_admin_notices();
$has_error_notice = false;
@ -38,8 +37,10 @@ class Plugin_Reference_Cleaner {
if (!empty($notices)) {
foreach ($notices as $notice) {
if (strpos($notice, 'has been deactivated due to an error: Plugin file does not exist') !== false) {
// Extract plugin file from notice
// Look for both variations of the error message
if (strpos($notice, 'has been deactivated due to an error: Plugin file does not exist') !== false ||
strpos($notice, 'deactivated due to an error: Plugin file does not exist') !== false) {
// Extract plugin file from notice using various patterns
if (preg_match('/The plugin ([^ ]+)/', $notice, $match)) {
$plugin_files[] = $match[1];
$has_error_notice = true;
@ -47,7 +48,7 @@ class Plugin_Reference_Cleaner {
}
}
}
// Only proceed if a relevant notice was found
if (!$has_error_notice || empty($plugin_files)) {
return;
@ -58,25 +59,123 @@ class Plugin_Reference_Cleaner {
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var pluginFiles = <?php echo wp_json_encode($plugin_files); ?>;
var notices = document.querySelectorAll('.notice-error p');
console.log('Plugin Reference Cleaner: Detected plugin files:', pluginFiles);
if (notices.length === 0) {
// Get all notifications directly in the plugins page
var pluginsPage = document.querySelector('.wrap');
if (!pluginsPage) {
console.log('Plugin Reference Cleaner: Could not find the plugins page wrapper');
return;
}
notices.forEach(function(notice) {
// Look specifically for elements containing the error message
// Use direct DOM traversal to find all text nodes
function findTextNodesWithText(element, searchText) {
var result = [];
var walk = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null, false);
var node;
while (node = walk.nextNode()) {
if (node.nodeValue.indexOf(searchText) > -1) {
result.push(node);
}
}
return result;
}
// Find paragraphs containing error messages
var errorTexts = findTextNodesWithText(pluginsPage, 'Plugin file does not exist');
console.log('Plugin Reference Cleaner: Found error nodes:', errorTexts.length);
if (errorTexts.length === 0) {
// Try another approach - find direct error messages
var allElements = pluginsPage.querySelectorAll('*');
for (var i = 0; i < allElements.length; i++) {
var el = allElements[i];
var text = el.textContent;
if (text && text.includes('has been deactivated due to an error: Plugin file does not exist')) {
errorTexts.push(el);
}
}
}
// Handle each error message
errorTexts.forEach(function(textNode) {
console.log('Plugin Reference Cleaner: Processing error node:', textNode);
// Get the parent element of the text node
var errorElement = textNode.parentNode || textNode;
// Check if a button already exists to avoid duplicates
if (errorElement.querySelector('.remove-plugin-ref')) {
console.log('Plugin Reference Cleaner: Button already exists for this element');
return;
}
// Find which plugin file this error refers to
var matchingPluginFile = null;
pluginFiles.forEach(function(pluginFile) {
if (notice.textContent.includes('The plugin ' + pluginFile)) {
var button = document.createElement('button');
button.textContent = 'Remove Reference';
button.className = 'button button-secondary remove-plugin-ref';
button.dataset.plugin = pluginFile;
button.style.marginLeft = '10px';
notice.appendChild(button);
if (textNode.nodeValue && textNode.nodeValue.includes(pluginFile) ||
(textNode.textContent && textNode.textContent.includes(pluginFile))) {
matchingPluginFile = pluginFile;
}
});
// If we couldn't match a specific plugin, use the first one as fallback
if (!matchingPluginFile && pluginFiles.length > 0) {
matchingPluginFile = pluginFiles[0];
console.log('Plugin Reference Cleaner: Using fallback plugin file:', matchingPluginFile);
}
if (matchingPluginFile) {
// Create button
var button = document.createElement('button');
button.textContent = 'Remove Reference';
button.className = 'button button-secondary remove-plugin-ref';
button.dataset.plugin = matchingPluginFile;
button.style.marginLeft = '10px';
// Append the button to the error message
errorElement.appendChild(button);
console.log('Plugin Reference Cleaner: Added button for ' + matchingPluginFile + ' to', errorElement);
} else {
console.log('Plugin Reference Cleaner: Could not determine plugin file for this error');
}
});
// Inject a more direct approach if the above fails
if (errorTexts.length === 0) {
// Target the specific format in the screenshot
var errorMessages = document.querySelectorAll('.wrap > .notice, .wrap > div > .notice');
console.log('Plugin Reference Cleaner: Trying direct approach, found notices:', errorMessages.length);
errorMessages.forEach(function(notice) {
var text = notice.textContent;
if (text && text.includes('Plugin file does not exist')) {
// Extract the plugin path
var pluginMatch = /The plugin ([^ ]+) has been deactivated/.exec(text);
var pluginFile = pluginMatch ? pluginMatch[1] : (pluginFiles.length > 0 ? pluginFiles[0] : null);
if (pluginFile) {
// Get container to add button
var container = notice.querySelector('p') || notice;
if (!container.querySelector('.remove-plugin-ref')) {
var button = document.createElement('button');
button.textContent = 'Remove Reference';
button.className = 'button button-secondary remove-plugin-ref';
button.dataset.plugin = pluginFile;
button.style.marginLeft = '10px';
container.appendChild(button);
console.log('Plugin Reference Cleaner: Direct approach - added button for ' + pluginFile);
}
}
}
});
}
// Add click event listeners to all created buttons
document.querySelectorAll('.remove-plugin-ref').forEach(function(button) {
button.addEventListener('click', function(e) {
e.preventDefault();
@ -117,11 +216,23 @@ class Plugin_Reference_Cleaner {
// Helper function to capture admin notices
private function get_admin_notices() {
// Static flag to prevent infinite recursion
static $is_capturing = false;
// If already capturing, return empty to break potential loops
if ($is_capturing) {
return array();
}
$is_capturing = true;
ob_start();
do_action('admin_notices');
do_action('network_admin_notices');
$output = ob_get_clean();
$is_capturing = false;
if (empty($output)) {
return array();
}

View File

@ -1,12 +1,12 @@
=== Plugin Reference Cleaner ===
Author: Marcus Quinn
Author URI: https://wpallstars.com
Version: 1.2
Author URI: https://www.wpallstars.com
Version: 1.2.4
License: GPL-2.0+
== Description ==
Have you ever deleted a plugin some other way than on the /wp-admin/plugins.php page, you'll probably have been stuck with this annoying notification that can't be cleared:
Have you ever deleted a plugin some other way than through the /wp-admin/plugins.php page? If so, you've probably been stuck with this annoying notification that can't be cleared:
"The plugin folder-name/file-name.php has been deactivated due to an error: Plugin file does not exist."
@ -14,7 +14,7 @@ This small WordPress utility plugin adds a "Remove Reference" button to these pl
When WordPress detects a plugin file that no longer exists but is still referenced in the database as active, it displays an error notice. This plugin enhances those notices with a button that allows you to safely remove the invalid reference with a single click.
You can find these with `SELECT * FROM wp_options WHERE option_name = 'active_plugins';` — but, the cleanup involved removing the rogue entry, and renumbering the others. This plugin can simply do that for you at the click of a button added to that WP standard notification.
You can find these with `SELECT * FROM wp_options WHERE option_name = 'active_plugins';` — but the cleanup involves removing the rogue entry, and renumbering all others. This plugin can simply do that for you at the click of a button added to that WP standard notification.
It's probably something that should be added to WP core. If anyone from the core team wants to adopt this solution, it's GPL, so feel free.
@ -47,6 +47,27 @@ If you don't have this notification perpetually showing on your /wp-admin/plugin
== Changelog ==
= 1.2.4 =
* Fixed compatibility with more WordPress admin themes
* Added advanced DOM traversal to find error messages
* Implemented fallback mechanisms to ensure button appears
* Added detailed console logging for troubleshooting
= 1.2.3 =
* Fixed button not appearing in some WordPress admin themes
* Improved error message detection for greater compatibility
* Enhanced DOM traversal to find notification elements
= 1.2.2 =
* Fixed timeout issue during plugin activation
* Improved hook management to prevent potential infinite recursion
* Optimized performance by only loading on plugins page
= 1.2.1 =
* Fixed typos in documentation
* Improved text clarity
* Added question mark to first sentence for better readability
= 1.2 =
* Improved documentation with detailed explanation
* Added SQL reference for technical users