Fix GU Branch Fix plugin to use named functions and proper WordPress hooks

This commit is contained in:
2025-04-13 04:10:18 +01:00
parent 75da5357a9
commit 7a2f123278

View File

@ -15,37 +15,73 @@ if (!defined('WPINC')) {
die; 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 * Fix Git Updater branch issues
* *
* This simple plugin adds a filter to change the branch from 'master' to 'main' * This simple plugin adds a filter to change the branch from 'master' to 'main'
* for the wp-fix-plugin-does-not-exist-notices plugin. * 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
*/ */
add_filter('gu_get_repo_branch', function($branch, $git, $repo) { function gu_branch_fix_branch($branch, $git, $repo) {
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)) {
return 'main'; return 'main';
} }
return $branch; return $branch;
}, 999, 3); }
// Fix for Git Updater API URLs /**
add_filter('gu_get_repo_api', function($api_url, $git, $repo) { * 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) && 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)) {
return str_replace('/master/', '/main/', $api_url); return str_replace('/master/', '/main/', $api_url);
} }
return $api_url; return $api_url;
}, 999, 3); }
// Fix for Git Updater download URLs /**
add_filter('gu_download_link', function($download_link, $git, $repo) { * 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) && 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)) {
return str_replace('/master.zip', '/main.zip', $download_link); return str_replace('/master.zip', '/main.zip', $download_link);
} }
return $download_link; return $download_link;
}, 999, 3); }
// Hook into WordPress
add_action('plugins_loaded', 'gu_branch_fix_init');