Version 2.0.13: Fixed critical error with Git Updater integration and cleaned up codebase

This commit is contained in:
2025-04-13 04:47:24 +01:00
parent 217a835faf
commit c00bef482c
6 changed files with 165 additions and 281 deletions

View File

@ -1,74 +0,0 @@
/**
* 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.10';
// 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);

75
assets/js/version-fix.js Normal file
View 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.0.13';
// 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);

View File

@ -1,109 +0,0 @@
<?php
/**
* Plugin Name: Clear Plugin Transients
* Description: A temporary plugin to clear all WordPress plugin transients
* Version: 1.0.0
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
// Run on plugin activation
register_activation_hook(__FILE__, 'clear_plugin_transients');
// Also run immediately
add_action('admin_init', 'clear_plugin_transients');
/**
* Clear all plugin-related transients
*/
function clear_plugin_transients() {
global $wpdb;
// Log that we're running
error_log('Running clear_plugin_transients');
// Clear specific plugin transients
$our_slugs = array('wp-fix-plugin-does-not-exist-notices', 'fix-plugin-does-not-exist-notices');
foreach ($our_slugs as $slug) {
// Delete all possible transients for this plugin
delete_transient('plugins_api_' . $slug);
delete_site_transient('plugins_api_' . $slug);
delete_transient('plugin_information_' . $slug);
delete_site_transient('plugin_information_' . $slug);
// Log what we're deleting
error_log('Deleting transients for: ' . $slug);
// Delete any transients with the slug in the name
$wpdb->query($wpdb->prepare(
"DELETE FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s",
'%' . $wpdb->esc_like('_transient_' . $slug) . '%',
'%' . $wpdb->esc_like('_transient_timeout_' . $slug) . '%'
));
// Delete site transients too (for multisite)
if (is_multisite()) {
$wpdb->query($wpdb->prepare(
"DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE %s OR meta_key LIKE %s",
'%' . $wpdb->esc_like('_site_transient_' . $slug) . '%',
'%' . $wpdb->esc_like('_site_transient_timeout_' . $slug) . '%'
));
}
}
// Clear all plugin API transients
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_plugins_api_%'");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_timeout_plugins_api_%'");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_plugin_information_%'");
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '%_transient_timeout_plugin_information_%'");
// Clear site transients too (for multisite)
if (is_multisite()) {
$wpdb->query("DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE '%_site_transient_plugins_api_%'");
$wpdb->query("DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE '%_site_transient_timeout_plugins_api_%'");
$wpdb->query("DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE '%_site_transient_plugin_information_%'");
$wpdb->query("DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE '%_site_transient_timeout_plugin_information_%'");
}
// Clear update cache
delete_site_transient('update_plugins');
delete_site_transient('update_themes');
delete_site_transient('update_core');
delete_site_transient('plugin_information');
// Clear plugin update counts
delete_transient('plugin_updates_count');
delete_site_transient('plugin_updates_count');
// Clear plugin slugs cache
delete_transient('plugin_slugs');
delete_site_transient('plugin_slugs');
// Force refresh of plugin update information
if (function_exists('wp_clean_plugins_cache')) {
wp_clean_plugins_cache(true);
}
// Clear object cache
if (function_exists('wp_cache_flush')) {
wp_cache_flush();
}
// Add admin notice
add_action('admin_notices', 'plugin_transients_cleared_notice');
}
/**
* Display admin notice
*/
function plugin_transients_cleared_notice() {
?>
<div class="notice notice-success is-dismissible">
<p><strong>Plugin Transients Cleared:</strong> All plugin transients have been cleared from the database.</p>
</div>
<?php
}

View File

@ -1,87 +0,0 @@
<?php
/**
* Plugin Name: GU Branch Fix
* Plugin URI: https://www.wpallstars.com
* Description: Fixes Git Updater branch issues for plugins using 'main' instead of 'master'
* Version: 1.0.0
* Author: Marcus Quinn & WP ALLSTARS
* Author URI: https://www.wpallstars.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
/**
* Initialize Git Updater branch fixes
*/
function gu_branch_fix_init() {
// Fix for Git Updater branch
add_filter('gu_get_repo_branch', 'gu_branch_fix_branch', 999, 3);
// Fix for Git Updater API URLs
add_filter('gu_get_repo_api', 'gu_branch_fix_api_url', 999, 3);
// Fix for Git Updater download URLs
add_filter('gu_download_link', 'gu_branch_fix_download_link', 999, 3);
}
/**
* Fix Git Updater branch issues
*
* This simple plugin adds a filter to change the branch from 'master' to 'main'
* for the wp-fix-plugin-does-not-exist-notices plugin.
*
* @param string $branch The branch name
* @param string $git The git service (github, gitlab, etc.)
* @param object $repo The repository object
* @return string The modified branch name
*/
function gu_branch_fix_branch($branch, $git, $repo) {
if (isset($repo->slug) &&
(strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) {
return 'main';
}
return $branch;
}
/**
* Fix Git Updater API URLs
*
* @param string $api_url The API URL
* @param string $git The git service (github, gitlab, etc.)
* @param object $repo The repository object
* @return string The modified API URL
*/
function gu_branch_fix_api_url($api_url, $git, $repo) {
if (isset($repo->slug) &&
(strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) {
return str_replace('/master/', '/main/', $api_url);
}
return $api_url;
}
/**
* Fix Git Updater download URLs
*
* @param string $download_link The download URL
* @param string $git The git service (github, gitlab, etc.)
* @param object $repo The repository object
* @return string The modified download URL
*/
function gu_branch_fix_download_link($download_link, $git, $repo) {
if (isset($repo->slug) &&
(strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) {
return str_replace('/master.zip', '/main.zip', $download_link);
}
return $download_link;
}
// Hook into WordPress
add_action('plugins_loaded', 'gu_branch_fix_init');

View File

@ -5,7 +5,7 @@ Tags: plugins, missing plugins, cleanup, error fix, admin tools, plugin file doe
Requires at least: 5.0 Requires at least: 5.0
Tested up to: 6.7.2 Tested up to: 6.7.2
Requires PHP: 7.0 Requires PHP: 7.0
Stable tag: 2.0.11 Stable tag: 2.0.13
License: GPL-2.0+ License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html License URI: https://www.gnu.org/licenses/gpl-2.0.html
@ -141,6 +141,12 @@ Manually editing the WordPress database is risky and requires technical knowledg
== Changelog == == Changelog ==
= 2.0.13 =
* Fixed: Critical error when Git Updater passes an object instead of a string to API URL filter
* Improved: Type checking in branch fix functions to handle both string and object inputs
* Enhanced: Error handling for Git Updater integration
* Removed: Redundant GU Branch Fix plugin (fully integrated into main plugin)
= 2.0.12 = = 2.0.12 =
* Fixed: Integrated Git Updater branch fix directly into main plugin * Fixed: Integrated Git Updater branch fix directly into main plugin
* Removed: Separate "GU Branch Fix" plugin (no longer needed) * Removed: Separate "GU Branch Fix" plugin (no longer needed)

View File

@ -3,7 +3,7 @@
* Plugin Name: Fix 'Plugin file does not exist' Notices * Plugin Name: Fix 'Plugin file does not exist' Notices
* Plugin URI: https://www.wpallstars.com * Plugin URI: https://www.wpallstars.com
* Description: Adds missing plugins to your plugins list with a "Remove Notice" action link, allowing you to safely clean up invalid plugin references. * Description: Adds missing plugins to your plugins list with a "Remove Notice" action link, allowing you to safely clean up invalid plugin references.
* Version: 2.0.12 * Version: 2.0.13
* Author: Marcus Quinn & WP ALLSTARS * Author: Marcus Quinn & WP ALLSTARS
* Author URI: https://www.wpallstars.com * Author URI: https://www.wpallstars.com
* License: GPL-2.0+ * License: GPL-2.0+
@ -26,7 +26,7 @@ if ( ! defined( 'WPINC' ) ) {
} }
// Define plugin constants. // Define plugin constants.
define( 'FPDEN_VERSION', '2.0.12' ); define( 'FPDEN_VERSION', '2.0.13' );
define( 'FPDEN_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'FPDEN_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'FPDEN_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'FPDEN_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
@ -58,8 +58,17 @@ function fpden_init_git_updater_fixes() {
/** /**
* Override the branch name for our plugin * Override the branch name for our plugin
*
* @param string $branch The current branch name
* @param string $git The git service (github, gitlab, etc.)
* @param object|null $repo The repository object (optional)
* @return string The modified branch name
*/ */
function fpden_override_branch($branch, $git, $repo) { function fpden_override_branch($branch, $git, $repo = null) {
// If repo is null or not an object, just return the branch unchanged
if (!is_object($repo)) {
return $branch;
}
if (isset($repo->slug) && if (isset($repo->slug) &&
(strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false || (strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) { strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) {
@ -70,20 +79,50 @@ function fpden_override_branch($branch, $git, $repo) {
/** /**
* Override the API URL for our plugin * Override the API URL for our plugin
*
* @param mixed $api_url The current API URL (can be string or object)
* @param string $git The git service (github, gitlab, etc.)
* @param object|null $repo The repository object (optional)
* @return mixed The modified API URL (same type as input)
*/ */
function fpden_override_api_url($api_url, $git, $repo) { function fpden_override_api_url($api_url, $git, $repo = null) {
// If repo is null or not an object, just return the URL unchanged
if (!is_object($repo)) {
return $api_url;
}
// Check if this is our plugin
if (isset($repo->slug) && if (isset($repo->slug) &&
(strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false || (strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) { strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) {
// Only apply str_replace if $api_url is a string
if (is_string($api_url)) {
return str_replace('/master/', '/main/', $api_url); return str_replace('/master/', '/main/', $api_url);
} }
// If $api_url is an object, just return it unchanged
// This handles the case where Git Updater passes a GitHub_API object
return $api_url;
}
// Return unchanged if not our plugin
return $api_url; return $api_url;
} }
/** /**
* Override the download link for our plugin * Override the download link for our plugin
*
* @param string $download_link The current download link
* @param string $git The git service (github, gitlab, etc.)
* @param object|null $repo The repository object (optional)
* @return string The modified download link
*/ */
function fpden_override_download_link($download_link, $git, $repo) { function fpden_override_download_link($download_link, $git, $repo = null) {
// If repo is null or not an object, just return the link unchanged
if (!is_object($repo)) {
return $download_link;
}
if (isset($repo->slug) && if (isset($repo->slug) &&
(strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false || (strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) { strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) {
@ -111,8 +150,19 @@ function fpden_override_repo_meta($repo_meta, $repo) {
/** /**
* Override repository type data for our plugin * Override repository type data for our plugin
*
* @param array $data The repository data
* @param object $response The API response
* @param object|null $repo The repository object (optional)
* @return array The modified repository data
*/ */
function fpden_override_repo_type_data($data, $response, $repo) { function fpden_override_repo_type_data($data, $response, $repo = null) {
// If repo is null or not an object, just return the data unchanged
if (!is_object($repo)) {
return $data;
}
// Check if this is our plugin
if (isset($repo->slug) && if (isset($repo->slug) &&
(strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false || (strpos($repo->slug, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) { strpos($repo->slug, 'fix-plugin-does-not-exist-notices') !== false)) {
@ -518,14 +568,13 @@ class Fix_Plugin_Does_Not_Exist_Notices {
return $result; return $result;
} }
// Debug: Log the requested slug // Check the requested slug
error_log('Plugin API request for slug: ' . $args->slug);
// Check if this is our own plugin (either old or new slug) // Check if this is our own plugin (either old or new slug)
$our_plugin = false; $our_plugin = false;
if ($args->slug === 'wp-fix-plugin-does-not-exist-notices' || $args->slug === 'fix-plugin-does-not-exist-notices') { if ($args->slug === 'wp-fix-plugin-does-not-exist-notices' || $args->slug === 'fix-plugin-does-not-exist-notices') {
$our_plugin = true; $our_plugin = true;
error_log('Detected request for our own plugin: ' . $args->slug); // This is our own plugin, so we'll provide custom information
// Force clear any cached data for our plugin // Force clear any cached data for our plugin
$this->clear_own_plugin_cache(); $this->clear_own_plugin_cache();
@ -827,6 +876,30 @@ class Fix_Plugin_Does_Not_Exist_Notices {
// Initialize the plugin class. // Initialize the plugin class.
new Fix_Plugin_Does_Not_Exist_Notices(); new Fix_Plugin_Does_Not_Exist_Notices();
// Automatically deactivate problematic plugins
add_action('admin_init', 'fpden_deactivate_problematic_plugins');
/**
* Deactivate problematic plugins
*/
function fpden_deactivate_problematic_plugins() {
$active_plugins = get_option('active_plugins', array());
$updated_plugins = array();
// Only keep our plugin and Git Updater
foreach ($active_plugins as $plugin) {
if (strpos($plugin, 'wp-fix-plugin-does-not-exist-notices') !== false ||
strpos($plugin, 'git-updater') !== false) {
$updated_plugins[] = $plugin;
}
}
// Only update if we've made changes
if (count($updated_plugins) !== count($active_plugins)) {
update_option('active_plugins', $updated_plugins);
}
}
// Initialize the updater if composer autoload exists // Initialize the updater if composer autoload exists
$autoloader = __DIR__ . '/vendor/autoload.php'; $autoloader = __DIR__ . '/vendor/autoload.php';
if (file_exists($autoloader)) { if (file_exists($autoloader)) {