Add JavaScript-based fix for plugin details popup version display
This commit is contained in:
74
assets/js/plugin-details-fix.js
Normal file
74
assets/js/plugin-details-fix.js
Normal file
@ -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);
|
@ -88,7 +88,16 @@ class Fix_Plugin_Does_Not_Exist_Notices {
|
|||||||
return;
|
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();
|
$invalid_plugins = $this->get_invalid_plugins();
|
||||||
if ( empty( $invalid_plugins ) ) {
|
if ( empty( $invalid_plugins ) ) {
|
||||||
return; // No missing plugins, no need for the special notice JS/CSS.
|
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' ),
|
'pluginMissing' => esc_html__( 'File Missing', 'wp-fix-plugin-does-not-exist-notices' ),
|
||||||
'removeNotice' => esc_html__( 'Remove Notice', '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
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user