Update file paths to use admin directory for JS and CSS files
This commit is contained in:
131
admin/js/admin-scripts.js
Normal file
131
admin/js/admin-scripts.js
Normal file
@ -0,0 +1,131 @@
|
||||
(function() {
|
||||
// Track if we've already added our notice
|
||||
var noticeAdded = false;
|
||||
|
||||
// Function to inject our notice
|
||||
function injectNotice() {
|
||||
// If we've already added a notice, don't add another one
|
||||
if (noticeAdded) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find all notification containers first
|
||||
var noticeContainers = document.querySelectorAll('.notice, .error, .updated, div.error');
|
||||
var targetNotice = null;
|
||||
|
||||
// Find all error notifications about missing plugins
|
||||
noticeContainers.forEach(function(notice) {
|
||||
if ((notice.textContent.includes('Plugin file does not exist') ||
|
||||
notice.textContent.includes('has been deactivated due to an error')) &&
|
||||
(notice.classList.contains('error') || notice.classList.contains('notice-error'))) {
|
||||
// We'll use the last matching notice as our target
|
||||
targetNotice = notice;
|
||||
console.log('Found WordPress error notice:', notice.textContent);
|
||||
}
|
||||
});
|
||||
|
||||
// If we didn't find a specific error notice, look for the general WordPress error at the top
|
||||
if (!targetNotice) {
|
||||
// Try to find the WordPress error message at the top of the page
|
||||
var wpError = document.querySelector('.error:not(.below-h2), div.error:not(.below-h2), .notice-error:not(.below-h2)');
|
||||
if (wpError) {
|
||||
targetNotice = wpError;
|
||||
console.log('Found general WordPress error notice');
|
||||
}
|
||||
}
|
||||
|
||||
// If we found a target notice, add our custom notice after it
|
||||
if (targetNotice) {
|
||||
// Check if we already added our notice
|
||||
if (targetNotice.nextElementSibling && targetNotice.nextElementSibling.classList.contains('prc-notice')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create our custom notice
|
||||
var ourNotice = document.createElement('div');
|
||||
ourNotice.className = 'prc-notice';
|
||||
|
||||
// Add content using localized strings passed via wp_localize_script
|
||||
var pluginMissingText = typeof fpdenData !== 'undefined' && fpdenData.i18n && fpdenData.i18n.pluginMissing ?
|
||||
fpdenData.i18n.pluginMissing : 'File Missing';
|
||||
var removeNoticeText = typeof fpdenData !== 'undefined' && fpdenData.i18n && fpdenData.i18n.removeNotice ?
|
||||
fpdenData.i18n.removeNotice : 'Remove Notice';
|
||||
var clickToScrollText = typeof fpdenData !== 'undefined' && fpdenData.i18n && fpdenData.i18n.clickToScroll ?
|
||||
fpdenData.i18n.clickToScroll : 'Click here to scroll to and highlight missing plugins';
|
||||
|
||||
ourNotice.innerHTML = '<h3 style="margin-top:0;color:#826200;">Fix Plugin Does Not Exist Notices 👆</h3>' +
|
||||
'<p>To remove these notices, scroll down to each plugin\'s row showing: plugin-name.php "<strong style="color:red">(' + pluginMissingText + ')</strong>". Then, click the "<strong>' + removeNoticeText + '</strong>" link for that plugin.</p>' +
|
||||
'<p>This safely removes the missing active plugin reference from your database, using the standard WordPress function to update your active plugin options table, to leave the remaining plugins installed and active.</p>' +
|
||||
'<p><a href="#" id="prc-scroll-to-plugin" style="font-weight:bold;text-decoration:underline;color:#826200;">' + clickToScrollText + '</a></p>';
|
||||
|
||||
// Insert our notice right after the error
|
||||
targetNotice.parentNode.insertBefore(ourNotice, targetNotice.nextSibling);
|
||||
|
||||
// Make sure our notice has the same width as the WordPress error notice
|
||||
ourNotice.style.width = targetNotice.offsetWidth + 'px';
|
||||
ourNotice.style.maxWidth = '100%';
|
||||
ourNotice.style.boxSizing = 'border-box';
|
||||
|
||||
// Mark that we've added our notice
|
||||
noticeAdded = true;
|
||||
|
||||
// Add scroll behavior
|
||||
var scrollLink = document.getElementById('prc-scroll-to-plugin');
|
||||
if (scrollLink) {
|
||||
scrollLink.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
// Look for all plugin rows, not just inactive ones
|
||||
var allPluginRows = document.querySelectorAll('tr.active, tr.inactive');
|
||||
for (var i = 0; i < allPluginRows.length; i++) {
|
||||
if (allPluginRows[i].textContent.includes('(File Missing)')) {
|
||||
// Add a class for highlighting instead of direct style manipulation
|
||||
allPluginRows[i].classList.add('prc-highlight-missing');
|
||||
allPluginRows[i].scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
// Optional: Remove highlight after a delay
|
||||
(function(row) {
|
||||
setTimeout(function() {
|
||||
row.classList.remove('prc-highlight-missing');
|
||||
}, 3000); // Remove highlight after 3 seconds
|
||||
})(allPluginRows[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to inject notices on multiple events to ensure it works
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Delay the initial injection to ensure WordPress has fully loaded its notices
|
||||
setTimeout(injectNotice, 100);
|
||||
|
||||
// Also set up a MutationObserver to watch for dynamically added notices
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
mutations.forEach(function(mutation) {
|
||||
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
|
||||
// Check if added nodes are notices or contain notices
|
||||
mutation.addedNodes.forEach(function(node) {
|
||||
if (node.nodeType === 1 && (node.matches('.notice, .error, .updated, div.error') || node.querySelector('.notice, .error, .updated, div.error'))) {
|
||||
setTimeout(injectNotice, 50); // Small delay to ensure the DOM is updated
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Start observing the body for changes in children
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
});
|
||||
|
||||
// Backup attempt with window.onload (less reliable than DOMContentLoaded but good fallback)
|
||||
window.addEventListener('load', function() {
|
||||
setTimeout(injectNotice, 500); // Delay slightly to ensure dynamic content is loaded
|
||||
});
|
||||
|
||||
// Additional attempt after a longer delay to catch late-loading notices
|
||||
window.addEventListener('load', function() {
|
||||
setTimeout(injectNotice, 1000); // Longer delay as final attempt
|
||||
});
|
||||
|
||||
})();
|
138
admin/js/update-source-selector.js
Normal file
138
admin/js/update-source-selector.js
Normal file
@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Update Source Selector
|
||||
*
|
||||
* Handles the UI for selecting which source to use for plugin updates.
|
||||
*/
|
||||
jQuery(document).ready(function($) {
|
||||
// Open modal when toggle is clicked
|
||||
$(document).on('click', '.fpden-update-source-toggle', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Add overlay
|
||||
$('body').append('<div id="fpden-modal-overlay"></div>');
|
||||
$('#fpden-modal-overlay').css({
|
||||
'position': 'fixed',
|
||||
'top': 0,
|
||||
'left': 0,
|
||||
'width': '100%',
|
||||
'height': '100%',
|
||||
'background-color': 'rgba(0,0,0,0.5)',
|
||||
'z-index': 100000
|
||||
});
|
||||
|
||||
// Position and show modal
|
||||
var modal = $('#fpden-update-source-modal');
|
||||
modal.css({
|
||||
'position': 'fixed',
|
||||
'top': '50%',
|
||||
'left': '50%',
|
||||
'transform': 'translate(-50%, -50%)',
|
||||
'background-color': '#fff',
|
||||
'padding': '20px',
|
||||
'border-radius': '5px',
|
||||
'box-shadow': '0 0 10px rgba(0,0,0,0.5)',
|
||||
'z-index': 100001,
|
||||
'width': '400px',
|
||||
'max-width': '90%'
|
||||
}).show();
|
||||
|
||||
// Add close button styles
|
||||
$('.fpden-close-modal').css({
|
||||
'position': 'absolute',
|
||||
'top': '10px',
|
||||
'right': '10px',
|
||||
'cursor': 'pointer',
|
||||
'font-size': '20px',
|
||||
'color': '#666'
|
||||
});
|
||||
});
|
||||
|
||||
// Close modal when clicking overlay or close button
|
||||
$(document).on('click', '#fpden-modal-overlay', function() {
|
||||
$('#fpden-update-source-modal').hide();
|
||||
$('#fpden-modal-overlay').remove();
|
||||
});
|
||||
|
||||
// Separate handler for close button to ensure it works
|
||||
$(document).on('click', '.fpden-close-modal', function(e) {
|
||||
e.preventDefault();
|
||||
$('#fpden-update-source-modal').hide();
|
||||
$('#fpden-modal-overlay').remove();
|
||||
});
|
||||
|
||||
// Prevent clicks inside modal from closing it
|
||||
$('#fpden-update-source-modal').on('click', function(e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
// Handle form submission
|
||||
$('#fpden-update-source-form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var source = $('input[name="update_source"]:checked').val();
|
||||
|
||||
// Show loading state
|
||||
var submitButton = $(this).find('button[type="submit"]');
|
||||
var originalText = submitButton.text();
|
||||
submitButton.text('Saving...').prop('disabled', true);
|
||||
|
||||
// Save via AJAX
|
||||
$.post(ajaxurl, {
|
||||
action: 'fpden_save_update_source',
|
||||
source: source,
|
||||
nonce: fpdenData.updateSourceNonce
|
||||
}, function(response) {
|
||||
submitButton.text(originalText).prop('disabled', false);
|
||||
|
||||
if (response.success) {
|
||||
// Update the badge
|
||||
var badgeText = source.charAt(0).toUpperCase() + source.slice(1);
|
||||
if (source === 'wordpress.org') {
|
||||
badgeText = 'WP.org';
|
||||
}
|
||||
|
||||
// Remove all badge classes and add the new one
|
||||
var badge = $('.fpden-update-source-toggle .fpden-source-badge');
|
||||
badge.removeClass('auto wordpress github gitea')
|
||||
.addClass(source)
|
||||
.text(badgeText);
|
||||
|
||||
// Show success message
|
||||
var message = $('<div class="fpden-success-message">Update source saved successfully!</div>');
|
||||
message.css({
|
||||
'color': 'green',
|
||||
'margin-top': '10px',
|
||||
'text-align': 'center'
|
||||
});
|
||||
|
||||
$('#fpden-update-source-form').append(message);
|
||||
|
||||
// Hide message and modal after delay
|
||||
setTimeout(function() {
|
||||
message.fadeOut(function() {
|
||||
$(this).remove();
|
||||
$('#fpden-update-source-modal').hide();
|
||||
$('#fpden-modal-overlay').remove();
|
||||
});
|
||||
}, 1500);
|
||||
} else {
|
||||
// Show error message
|
||||
var message = $('<div class="fpden-error-message">Error saving update source.</div>');
|
||||
message.css({
|
||||
'color': 'red',
|
||||
'margin-top': '10px',
|
||||
'text-align': 'center'
|
||||
});
|
||||
|
||||
$('#fpden-update-source-form').append(message);
|
||||
|
||||
// Hide message after delay
|
||||
setTimeout(function() {
|
||||
message.fadeOut(function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
75
admin/js/version-fix.js
Normal file
75
admin/js/version-fix.js
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Fix Plugin Version Display
|
||||
*
|
||||
* 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.1.1';
|
||||
|
||||
// Plugin slugs to check for
|
||||
const OUR_SLUGS = ['wp-fix-plugin-does-not-exist-notices', 'fix-plugin-does-not-exist-notices'];
|
||||
|
||||
// Function to fix the version in the plugin details popup
|
||||
function fixPluginDetailsVersion() {
|
||||
// Check if we're on the plugins page
|
||||
if (window.location.href.indexOf('plugins.php') === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Wait for the thickbox to be initialized
|
||||
$(document).on('tb_init', function() {
|
||||
// Set a timeout to allow the thickbox content to load
|
||||
setTimeout(function() {
|
||||
// Get the thickbox iframe
|
||||
const $iframe = $('#TB_iframeContent');
|
||||
if (!$iframe.length) return;
|
||||
|
||||
// Wait for iframe to load
|
||||
$iframe.on('load', function() {
|
||||
try {
|
||||
const iframeDoc = this.contentDocument || this.contentWindow.document;
|
||||
|
||||
// Get the plugin title from the iframe
|
||||
const $title = $(iframeDoc).find('h2.plugin-title');
|
||||
if (!$title.length) return;
|
||||
|
||||
// Check if this is our plugin
|
||||
const titleText = $title.text();
|
||||
if (titleText.indexOf('Fix \'Plugin file does not exist\' Notices') !== -1) {
|
||||
console.log('Found our plugin in the details popup, fixing version...');
|
||||
|
||||
// Find the version element
|
||||
const $version = $(iframeDoc).find('.plugin-version-author-uri');
|
||||
if ($version.length) {
|
||||
// Update the version text
|
||||
const versionText = $version.text();
|
||||
const newVersionText = versionText.replace(/Version: [0-9.]+|Version: 0\.0\.0/, 'Version: ' + CURRENT_VERSION);
|
||||
$version.text(newVersionText);
|
||||
console.log('Updated version to: ' + CURRENT_VERSION);
|
||||
}
|
||||
|
||||
// Also update the version in the header if it exists
|
||||
const $versionHeader = $(iframeDoc).find('.wrap h2:contains("Version:")');
|
||||
if ($versionHeader.length) {
|
||||
$versionHeader.text('Version: ' + CURRENT_VERSION);
|
||||
console.log('Updated version header to: ' + CURRENT_VERSION);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error updating plugin version:', e);
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize when the document is ready
|
||||
$(document).ready(function() {
|
||||
fixPluginDetailsVersion();
|
||||
});
|
||||
|
||||
})(jQuery);
|
Reference in New Issue
Block a user