From 4c9e8d5a7bd1ef7ae1b460ff5a4002e13e5578b2 Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Sun, 13 Apr 2025 02:33:39 +0100 Subject: [PATCH] Add JavaScript-based fix for plugin details popup version display --- assets/js/plugin-details-fix.js | 74 ++++++++++++++++++++++++ wp-fix-plugin-does-not-exist-notices.php | 12 +++- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 assets/js/plugin-details-fix.js diff --git a/assets/js/plugin-details-fix.js b/assets/js/plugin-details-fix.js new file mode 100644 index 0000000..a523684 --- /dev/null +++ b/assets/js/plugin-details-fix.js @@ -0,0 +1,74 @@ +/** + * Fix Plugin Details Popup + * + * This script directly modifies the plugin details popup to show the correct version + * when the popup is opened for our plugin. + */ +(function($) { + 'use strict'; + + // Current plugin version - this should match the version in the main plugin file + const CURRENT_VERSION = '2.0.9'; + + // Plugin slugs to check for + const OUR_SLUGS = ['wp-fix-plugin-does-not-exist-notices', 'fix-plugin-does-not-exist-notices']; + + // Wait for the document to be ready + $(document).ready(function() { + // Listen for the thickbox to open (WordPress uses thickbox for plugin details) + $(document).on('tb_init', function() { + // Check if we're on the plugins page + if (window.location.href.indexOf('plugins.php') === -1) { + return; + } + + // Set a timeout to allow the thickbox content to load + setTimeout(function() { + // Get the thickbox content + const $thickbox = $('#TB_window'); + if (!$thickbox.length) return; + + // Get the plugin slug from the URL + const tbUrl = $('#TB_iframeContent').attr('src'); + if (!tbUrl) return; + + // Extract the plugin slug from the URL + const slugMatch = tbUrl.match(/plugin=([^&]+)/); + if (!slugMatch || !slugMatch[1]) return; + + const pluginSlug = decodeURIComponent(slugMatch[1]); + + // Check if this is our plugin + if (OUR_SLUGS.indexOf(pluginSlug) !== -1) { + console.log('Fixing plugin details for: ' + pluginSlug); + + // Find the version element in the thickbox + const $iframe = $('#TB_iframeContent'); + if (!$iframe.length) return; + + // Wait for iframe to load + $iframe.on('load', function() { + const iframeDoc = this.contentDocument || this.contentWindow.document; + + // Find the version element + const $versionElement = $(iframeDoc).find('.plugin-version-author-uri'); + if (!$versionElement.length) return; + + // Update the version text + const versionText = $versionElement.text(); + const newVersionText = versionText.replace(/Version: [0-9.]+/, 'Version: ' + CURRENT_VERSION); + $versionElement.text(newVersionText); + + // Also update the version in the header if it exists + const $versionHeader = $(iframeDoc).find('h2:contains("Version:")'); + if ($versionHeader.length) { + $versionHeader.text('Version: ' + CURRENT_VERSION); + } + + console.log('Plugin details updated to version: ' + CURRENT_VERSION); + }); + } + }, 500); // Wait 500ms for the thickbox to load + }); + }); +})(jQuery); diff --git a/wp-fix-plugin-does-not-exist-notices.php b/wp-fix-plugin-does-not-exist-notices.php index 705b761..bc56753 100644 --- a/wp-fix-plugin-does-not-exist-notices.php +++ b/wp-fix-plugin-does-not-exist-notices.php @@ -88,7 +88,16 @@ class Fix_Plugin_Does_Not_Exist_Notices { return; } - // Get invalid plugins to decide if assets are needed. + // Always load the plugin details fix script on the plugins page + wp_enqueue_script( + 'fpden-plugin-details-fix', + FPDEN_PLUGIN_URL . 'assets/js/plugin-details-fix.js', + array( 'jquery', 'thickbox' ), // Add thickbox dependency + FPDEN_VERSION . '.' . time(), // Add timestamp to force cache busting + true // Load in footer. + ); + + // Get invalid plugins to decide if other assets are needed. $invalid_plugins = $this->get_invalid_plugins(); if ( empty( $invalid_plugins ) ) { return; // No missing plugins, no need for the special notice JS/CSS. @@ -119,6 +128,7 @@ class Fix_Plugin_Does_Not_Exist_Notices { 'pluginMissing' => esc_html__( 'File Missing', 'wp-fix-plugin-does-not-exist-notices' ), 'removeNotice' => esc_html__( 'Remove Notice', 'wp-fix-plugin-does-not-exist-notices' ), ), + 'version' => FPDEN_VERSION, // Add version for the plugin details fix script ) ); }