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() { // Check if a "Plugin file does not exist" notice exists $notices = $this->get_admin_notices(); $has_error_notice = false; $plugin_files = array(); 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 if (preg_match('/The plugin ([^ ]+)/', $notice, $match)) { $plugin_files[] = $match[1]; $has_error_notice = true; } } } } // Only proceed if a relevant notice was found if (!$has_error_notice || empty($plugin_files)) { return; } // Inject JavaScript with the specific plugin files ?>