Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
0a394fa671 | |||
f200ff6f96 |
18
CHANGELOG.md
18
CHANGELOG.md
@ -2,6 +2,24 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
## [1.2.1] - 2025-04-07
|
||||||
### Improved
|
### Improved
|
||||||
- Fixed typos in documentation
|
- Fixed typos in documentation
|
||||||
|
14
README.md
14
README.md
@ -1,7 +1,7 @@
|
|||||||
# Plugin Reference Cleaner
|
# Plugin Reference Cleaner
|
||||||
Author: Marcus Quinn
|
Author: Marcus Quinn
|
||||||
Author URI: https://wpallstars.com
|
Author URI: https://www.wpallstars.com
|
||||||
Version: 1.2.1
|
Version: 1.2.3
|
||||||
License: GPL-2.0+
|
License: GPL-2.0+
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
@ -47,6 +47,16 @@ If you don't have this notification perpetually showing on your /wp-admin/plugin
|
|||||||
|
|
||||||
## Changelog
|
## 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
|
### 1.2.1
|
||||||
* Fixed typos in documentation
|
* Fixed typos in documentation
|
||||||
* Improved text clarity
|
* Improved text clarity
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
/*
|
/*
|
||||||
* Plugin Name: Plugin Reference Cleaner
|
* Plugin Name: Plugin Reference Cleaner
|
||||||
* Description: Adds a "Remove Reference" button to plugin deactivation error notices, allowing users to clean up invalid plugin entries.
|
* Description: Adds a "Remove Reference" button to plugin deactivation error notices, allowing users to clean up invalid plugin entries.
|
||||||
* Version: 1.2.1
|
* Version: 1.2.3
|
||||||
* Author: Marcus Quinn
|
* Author: Marcus Quinn
|
||||||
* Author URI: https://wpallstars.com
|
* Author URI: https://www.wpallstars.com
|
||||||
* License: GPL-2.0+
|
* License: GPL-2.0+
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -15,22 +15,21 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
class Plugin_Reference_Cleaner {
|
class Plugin_Reference_Cleaner {
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
// 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
|
// Hook into admin notices to modify plugin error messages
|
||||||
add_action('admin_notices', array($this, 'inject_remove_button'), 100);
|
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
|
add_action('network_admin_notices', array($this, 'inject_remove_button'), 100);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Handle the AJAX request to remove the plugin reference
|
// Handle the AJAX request to remove the plugin reference
|
||||||
add_action('wp_ajax_remove_plugin_reference', array($this, 'remove_plugin_reference'));
|
add_action('wp_ajax_remove_plugin_reference', array($this, 'remove_plugin_reference'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject "Remove Reference" button only if a relevant notice exists
|
// Inject "Remove Reference" button only if a relevant notice exists
|
||||||
public function inject_remove_button() {
|
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
|
// Check if a "Plugin file does not exist" notice exists
|
||||||
$notices = $this->get_admin_notices();
|
$notices = $this->get_admin_notices();
|
||||||
$has_error_notice = false;
|
$has_error_notice = false;
|
||||||
@ -38,8 +37,10 @@ class Plugin_Reference_Cleaner {
|
|||||||
|
|
||||||
if (!empty($notices)) {
|
if (!empty($notices)) {
|
||||||
foreach ($notices as $notice) {
|
foreach ($notices as $notice) {
|
||||||
if (strpos($notice, 'has been deactivated due to an error: Plugin file does not exist') !== false) {
|
// Look for both variations of the error message
|
||||||
// Extract plugin file from notice
|
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)) {
|
if (preg_match('/The plugin ([^ ]+)/', $notice, $match)) {
|
||||||
$plugin_files[] = $match[1];
|
$plugin_files[] = $match[1];
|
||||||
$has_error_notice = true;
|
$has_error_notice = true;
|
||||||
@ -58,21 +59,51 @@ class Plugin_Reference_Cleaner {
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var pluginFiles = <?php echo wp_json_encode($plugin_files); ?>;
|
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 (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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
notices.forEach(function(notice) {
|
notices.forEach(function(notice) {
|
||||||
pluginFiles.forEach(function(pluginFile) {
|
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');
|
var button = document.createElement('button');
|
||||||
button.textContent = 'Remove Reference';
|
button.textContent = 'Remove Reference';
|
||||||
button.className = 'button button-secondary remove-plugin-ref';
|
button.className = 'button button-secondary remove-plugin-ref';
|
||||||
button.dataset.plugin = pluginFile;
|
button.dataset.plugin = pluginFile;
|
||||||
button.style.marginLeft = '10px';
|
button.style.marginLeft = '10px';
|
||||||
notice.appendChild(button);
|
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
|
// Helper function to capture admin notices
|
||||||
private function get_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();
|
ob_start();
|
||||||
do_action('admin_notices');
|
do_action('admin_notices');
|
||||||
do_action('network_admin_notices');
|
do_action('network_admin_notices');
|
||||||
$output = ob_get_clean();
|
$output = ob_get_clean();
|
||||||
|
|
||||||
|
$is_capturing = false;
|
||||||
|
|
||||||
if (empty($output)) {
|
if (empty($output)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
14
readme.txt
14
readme.txt
@ -1,7 +1,7 @@
|
|||||||
=== Plugin Reference Cleaner ===
|
=== Plugin Reference Cleaner ===
|
||||||
Author: Marcus Quinn
|
Author: Marcus Quinn
|
||||||
Author URI: https://wpallstars.com
|
Author URI: https://www.wpallstars.com
|
||||||
Version: 1.2.1
|
Version: 1.2.3
|
||||||
License: GPL-2.0+
|
License: GPL-2.0+
|
||||||
|
|
||||||
== Description ==
|
== Description ==
|
||||||
@ -47,6 +47,16 @@ If you don't have this notification perpetually showing on your /wp-admin/plugin
|
|||||||
|
|
||||||
== Changelog ==
|
== 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 =
|
= 1.2.1 =
|
||||||
* Fixed typos in documentation
|
* Fixed typos in documentation
|
||||||
* Improved text clarity
|
* Improved text clarity
|
||||||
|
Reference in New Issue
Block a user