From 7ae1da37751fb31f8442323ed865aba95fd6d9d7 Mon Sep 17 00:00:00 2001 From: Marcus Quinn <6428977+marcusquinn@users.noreply.github.com> Date: Thu, 10 Apr 2025 01:03:23 +0100 Subject: [PATCH] Rename plugin to 'Fix Plugin file does not exist. Notices' for better SEO --- .github/workflows/assets.yml | 24 ++ .github/workflows/release.yml | 20 +- README.md | 10 +- fix-plugin-does-not-exist-notices.php | 343 ++++++++++++++++++++++++++ readme.txt | 6 +- rename-migration.md | 63 +++++ 6 files changed, 448 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/assets.yml create mode 100644 fix-plugin-does-not-exist-notices.php create mode 100644 rename-migration.md diff --git a/.github/workflows/assets.yml b/.github/workflows/assets.yml new file mode 100644 index 0000000..ce0b410 --- /dev/null +++ b/.github/workflows/assets.yml @@ -0,0 +1,24 @@ +name: Plugin Asset Update + +on: + push: + branches: + - main + paths: + - '.wordpress-org/**' + - 'assets/**' + +jobs: + assets: + name: Push assets to WordPress.org + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: WordPress.org plugin asset/readme update + uses: 10up/action-wordpress-plugin-asset-update@stable + env: + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + SLUG: fix-plugin-does-not-exist-notices \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6e5188..fb813f1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,19 +20,19 @@ jobs: run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT - name: Create build directory - run: mkdir -p build/plugin-reference-cleaner + run: mkdir -p build/fix-plugin-does-not-exist-notices - name: Copy plugin files run: | - 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/ + cp fix-plugin-does-not-exist-notices.php build/fix-plugin-does-not-exist-notices/ + cp readme.txt build/fix-plugin-does-not-exist-notices/ + cp LICENSE build/fix-plugin-does-not-exist-notices/ + cp README.md build/fix-plugin-does-not-exist-notices/ - name: Create ZIP file run: | cd build - zip -r ../plugin-reference-cleaner-${{ steps.get_version.outputs.VERSION }}.zip plugin-reference-cleaner + zip -r ../fix-plugin-does-not-exist-notices-${{ steps.get_version.outputs.VERSION }}.zip fix-plugin-does-not-exist-notices - name: Create Release id: create_release @@ -42,11 +42,11 @@ jobs: draft: false prerelease: false files: | - plugin-reference-cleaner-${{ steps.get_version.outputs.VERSION }}.zip + fix-plugin-does-not-exist-notices-${{ steps.get_version.outputs.VERSION }}.zip body: | - Plugin Reference Cleaner v${{ steps.get_version.outputs.VERSION }} + Fix 'Plugin file does not exist.' Notices v${{ steps.get_version.outputs.VERSION }} - See [CHANGELOG.md](https://github.com/wpallstars/plugin-reference-cleaner/blob/main/CHANGELOG.md) for details. + See [CHANGELOG.md](https://github.com/wpallstars/fix-plugin-does-not-exist-notices/blob/main/CHANGELOG.md) for details. # Deploy to WordPress.org wordpress: @@ -65,4 +65,4 @@ jobs: env: SVN_USERNAME: ${{ secrets.SVN_USERNAME }} SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SLUG: plugin-reference-cleaner \ No newline at end of file + SLUG: fix-plugin-does-not-exist-notices \ No newline at end of file diff --git a/README.md b/README.md index 86010d3..d78405b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Plugin Reference Cleaner +# Fix 'Plugin file does not exist.' Notices -[](https://wordpress.org/plugins/plugin-reference-cleaner/) -[](https://wordpress.org/plugins/plugin-reference-cleaner/) -[](https://wordpress.org/plugins/plugin-reference-cleaner/) +[](https://wordpress.org/plugins/fix-plugin-does-not-exist-notices/) +[](https://wordpress.org/plugins/fix-plugin-does-not-exist-notices/) +[](https://wordpress.org/plugins/fix-plugin-does-not-exist-notices/) [](https://www.gnu.org/licenses/gpl-2.0.html) Easily remove references to deleted plugins that cause "Plugin file does not exist" errors in your WordPress admin. @@ -45,7 +45,7 @@ When WordPress detects a plugin file that no longer exists but is still referenc ### From WordPress.org: 1. Visit Plugins > Add New in your WordPress admin -2. Search for "Plugin Reference Cleaner" +2. Search for "Fix 'Plugin file does not exist.' Notices" 3. Click "Install Now" and then "Activate" ### Manual Installation: diff --git a/fix-plugin-does-not-exist-notices.php b/fix-plugin-does-not-exist-notices.php new file mode 100644 index 0000000..cd577f4 --- /dev/null +++ b/fix-plugin-does-not-exist-notices.php @@ -0,0 +1,343 @@ +is_plugins_page()) { + return $plugins; + } + + // Get active plugins that don't exist + $invalid_plugins = $this->get_invalid_plugins(); + + // Add each invalid plugin to the plugin list + foreach ($invalid_plugins as $plugin_path) { + if (!isset($plugins[$plugin_path])) { + $plugin_name = basename($plugin_path); + $plugins[$plugin_path] = array( + 'Name' => $plugin_name . ' (File Missing)', + 'Description' => 'This plugin file does not exist. You can safely remove this reference.', + 'Version' => 'N/A', + 'Author' => '', + 'PluginURI' => '', + 'AuthorURI' => '', + 'Title' => $plugin_name . ' (Missing)', + 'AuthorName' => '' + ); + } + } + + return $plugins; + } + + /** + * Add the Remove Reference action link to invalid plugins + */ + public function add_remove_reference_action($actions, $plugin_file, $plugin_data, $context) { + // Only run on the plugins page + if (!$this->is_plugins_page()) { + return $actions; + } + + // Check if this is a missing plugin + if (isset($plugin_data['Name']) && strpos($plugin_data['Name'], '(File Missing)') !== false) { + // Clear existing actions + $actions = array(); + + // Add our action + $nonce = wp_create_nonce('remove_plugin_reference_' . $plugin_file); + $remove_url = admin_url('plugins.php?action=remove_reference&plugin=' . urlencode($plugin_file) . '&_wpnonce=' . $nonce); + $actions['remove_reference'] = 'Remove Reference'; + } + + return $actions; + } + + /** + * Handle the remove reference action + */ + public function handle_remove_reference() { + // Check if we're removing a reference + if (!isset($_GET['action']) || $_GET['action'] !== 'remove_reference' || !isset($_GET['plugin'])) { + return; + } + + // Verify permissions + if (!current_user_can('activate_plugins')) { + wp_die(__('You do not have sufficient permissions to perform this action.', 'plugin-reference-cleaner')); + } + + // Get the plugin file + $plugin_file = isset($_GET['plugin']) ? $_GET['plugin'] : ''; + + // Verify nonce + check_admin_referer('remove_plugin_reference_' . $plugin_file); + + // Remove the plugin reference + $success = $this->remove_plugin_reference($plugin_file); + + // Redirect back to plugins page with a message + $redirect = admin_url('plugins.php'); + $redirect = add_query_arg($success ? 'reference_removed' : 'reference_removal_failed', '1', $redirect); + wp_redirect($redirect); + exit; + } + + /** + * Remove a plugin reference from the active plugins + */ + public function remove_plugin_reference($plugin_file) { + $success = false; + + // Handle multisite network admin + if (is_multisite() && is_network_admin()) { + $active_plugins = get_site_option('active_sitewide_plugins', array()); + if (isset($active_plugins[$plugin_file])) { + unset($active_plugins[$plugin_file]); + $success = update_site_option('active_sitewide_plugins', $active_plugins); + } + } + // Handle single site or multisite subsite + else { + $active_plugins = get_option('active_plugins', array()); + $key = array_search($plugin_file, $active_plugins); + if ($key !== false) { + unset($active_plugins[$key]); + $active_plugins = array_values($active_plugins); // Re-index array + $success = update_option('active_plugins', $active_plugins); + } + } + + return $success; + } + + /** + * Display admin notices + */ + public function admin_notices() { + // Only run on the plugins page + if (!$this->is_plugins_page()) { + return; + } + + // Get invalid plugins + $invalid_plugins = $this->get_invalid_plugins(); + + // Create a highlighted notice immediately after WordPress error messages + if (!empty($invalid_plugins)) { + // Add a notice specifically targeting the WordPress error notification + // Use admin_head to ensure it runs early in the page load process + add_action('admin_head', function() use ($invalid_plugins) { + ?> + + + '; + echo '
Missing plugin files detected: The plugins listed below with (File Missing) tag no longer exist but are still referenced in your database.
'; + echo 'How to fix: Click the "Remove Reference" link next to each missing plugin to safely remove it from your active plugins list.
'; + echo 'This will clean up your database and remove the error notifications.
'; + echo ''; + } + + // Show success message + if (isset($_GET['reference_removed']) && $_GET['reference_removed'] === '1') { + echo 'Plugin reference removed successfully.
Failed to remove plugin reference. The plugin may already have been removed.