Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
0a394fa671 | |||
f200ff6f96 | |||
fb4a54ab57 | |||
67d13c9354 | |||
6aa330c387 | |||
18772160cf | |||
361a361a50 | |||
d74b0835bf | |||
f85f6f0d3c | |||
63a2ec3ff9 | |||
f8cabf71b6 | |||
bbdc06b4c1 | |||
3bf5e3d4ab | |||
c27dbe9343 | |||
aa416c1950 |
41
.woodpecker.yml
Normal file
41
.woodpecker.yml
Normal file
@ -0,0 +1,41 @@
|
||||
clone:
|
||||
git:
|
||||
image: woodpeckerci/plugin-git
|
||||
debug: true
|
||||
|
||||
steps:
|
||||
build:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- apk add --no-cache bash zip
|
||||
- VERSION=${CI_COMMIT_TAG#v}
|
||||
- mkdir -p build/plugin-reference-cleaner
|
||||
- cp plugin-reference-cleaner.php build/plugin-reference-cleaner/
|
||||
- cp readme.txt build/plugin-reference-cleaner/
|
||||
- cp LICENSE build/plugin-reference-cleaner/
|
||||
- cp README.md build/plugin-reference-cleaner/
|
||||
- if [ -f CHANGELOG.md ]; then cp CHANGELOG.md build/plugin-reference-cleaner/; fi
|
||||
- cd build
|
||||
- zip -r ../plugin-reference-cleaner-$VERSION.zip plugin-reference-cleaner
|
||||
- cd ..
|
||||
- echo "Build completed - plugin-reference-cleaner-$VERSION.zip"
|
||||
- ls -la *.zip
|
||||
|
||||
release:
|
||||
image: plugins/gitea-release
|
||||
environment:
|
||||
PLUGIN_API_KEY:
|
||||
from_secret: gitea_token
|
||||
PLUGIN_BASE_URL: https://gitea.wpallstars.com
|
||||
PLUGIN_FILES: plugin-reference-cleaner-*.zip
|
||||
PLUGIN_TITLE: "Release ${CI_COMMIT_TAG}"
|
||||
PLUGIN_NOTE: "Plugin Reference Cleaner ${CI_COMMIT_TAG}\n\nSee [CHANGELOG.md](https://gitea.wpallstars.com/wpallstars/plugin-reference-cleaner/src/branch/main/CHANGELOG.md) for details."
|
||||
|
||||
test:
|
||||
image: alpine:latest
|
||||
commands:
|
||||
- echo "Hello from Woodpecker CI"
|
||||
- echo "Testing minimal configuration"
|
||||
|
||||
when:
|
||||
event: [push, tag, pull_request]
|
32
CHANGELOG.md
32
CHANGELOG.md
@ -2,14 +2,46 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [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
|
||||
- Added SQL reference for technical users
|
||||
- Suggested potential inclusion in WordPress core
|
||||
|
||||
## [1.1] - 2025-04-07
|
||||
### Added
|
||||
- Support for multisite WordPress installations
|
||||
- Network admin page integration
|
||||
- Woodpecker CI integration for automated releases
|
||||
|
||||
### Improved
|
||||
- Error handling
|
||||
- User experience with better confirmation messages
|
||||
- Security by adding proper capability checks
|
||||
|
||||
## [1.0] - 2025-03-15
|
||||
### Added
|
||||
|
56
README.md
56
README.md
@ -1,14 +1,28 @@
|
||||
# Plugin Reference Cleaner
|
||||
|
||||
A WordPress plugin that adds a "Remove Reference" button to plugin deactivation error notices, allowing users to clean up invalid plugin entries in the database.
|
||||
Author: Marcus Quinn
|
||||
Author URI: https://www.wpallstars.com
|
||||
Version: 1.2.3
|
||||
License: GPL-2.0+
|
||||
|
||||
## Description
|
||||
|
||||
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."
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
**Note:** This plugin only needs to be installed and active if you have an error notification showing like this:
|
||||
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
|
||||
|
||||
* Adds a "Remove Reference" button to plugin error notices
|
||||
@ -31,10 +45,36 @@ When WordPress detects a plugin file that no longer exists but is still referenc
|
||||
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.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
|
@ -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.1
|
||||
* Version: 1.2.3
|
||||
* 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;
|
||||
@ -58,21 +59,51 @@ 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');
|
||||
|
||||
// Try multiple selectors to find error notices
|
||||
var notices = document.querySelectorAll('.notice-error p, .error p, .notice p, .updated p, .update-nag p');
|
||||
|
||||
if (notices.length === 0) {
|
||||
// If no p elements found, try the parent elements
|
||||
notices = document.querySelectorAll('.notice-error, .error, .notice, .updated, .update-nag');
|
||||
}
|
||||
|
||||
if (notices.length === 0) {
|
||||
// Try a more generic approach - find any element containing the error text
|
||||
var allElements = document.querySelectorAll('*');
|
||||
var errorNotices = [];
|
||||
|
||||
for (var i = 0; i < allElements.length; i++) {
|
||||
var el = allElements[i];
|
||||
if (el.childNodes.length === 1 && el.childNodes[0].nodeType === 3) { // Text node
|
||||
if (el.textContent.includes('has been deactivated due to an error: Plugin file does not exist') ||
|
||||
el.textContent.includes('deactivated due to an error: Plugin file does not exist')) {
|
||||
errorNotices.push(el);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errorNotices.length > 0) {
|
||||
notices = errorNotices;
|
||||
}
|
||||
}
|
||||
|
||||
if (notices.length === 0) {
|
||||
console.log('Plugin Reference Cleaner: No notice elements found');
|
||||
return;
|
||||
}
|
||||
|
||||
notices.forEach(function(notice) {
|
||||
pluginFiles.forEach(function(pluginFile) {
|
||||
if (notice.textContent.includes('The plugin ' + pluginFile)) {
|
||||
if (notice.textContent.includes(pluginFile) ||
|
||||
notice.textContent.includes('Plugin file does not exist')) {
|
||||
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);
|
||||
console.log('Plugin Reference Cleaner: Added button for ' + pluginFile);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -117,11 +148,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();
|
||||
}
|
||||
|
39
readme.txt
39
readme.txt
@ -1,24 +1,36 @@
|
||||
=== Plugin Reference Cleaner ===
|
||||
Author: Marcus Quinn
|
||||
Author URI: https://wpallstars.com
|
||||
Version: 1.1
|
||||
Author URI: https://www.wpallstars.com
|
||||
Version: 1.2.3
|
||||
License: GPL-2.0+
|
||||
|
||||
== Description ==
|
||||
|
||||
Plugin Reference Cleaner adds a convenient "Remove Reference" button to plugin deactivation error notices in WordPress. This tool helps administrators clean up invalid plugin entries that can occur when plugins are improperly removed from the server.
|
||||
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."
|
||||
|
||||
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.
|
||||
|
||||
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 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 ==
|
||||
|
||||
* Adds a "Remove Reference" button to plugin error notices
|
||||
* Works for both single site and multisite WordPress installations
|
||||
* Confirms before removing any plugin references
|
||||
* Simple, lightweight solution with no settings page required
|
||||
* Secure implementation with proper permissions checking
|
||||
* Compatible with WordPress 5.0+
|
||||
|
||||
== Installation ==
|
||||
|
||||
@ -35,9 +47,30 @@ Note: This plugin only needs to be installed and active if you have an error not
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 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
|
||||
|
Reference in New Issue
Block a user