From 22d13ef8aa21ac3876416da67fcf1968fa1c7164 Mon Sep 17 00:00:00 2001 From: Marcus Quinn <6428977+marcusquinn@users.noreply.github.com> Date: Sat, 12 Apr 2025 00:03:10 +0100 Subject: [PATCH] Add Git Updater support with smart source detection --- .gitignore | 6 +- CHANGELOG.md | 2 + build.sh | 18 ++- composer.json | 21 ++++ fix-plugin-does-not-exist-notices.php | 16 +++ includes/Updater.php | 152 ++++++++++++++++++++++++++ readme.txt | 4 +- 7 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 composer.json create mode 100644 includes/Updater.php diff --git a/.gitignore b/.gitignore index d95bd35..1d64fdb 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,10 @@ bower_components/ composer.lock package-lock.json +# Composer +vendor/ +composer.phar + # Build files build/ dist/ @@ -76,4 +80,4 @@ codecov.yml webpack.config.js gulpfile.js Gruntfile.js -*.zip \ No newline at end of file +*.zip \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dccf6a..d85e798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,12 @@ All notable changes to this project will be documented in this file. - Full translation support with POT file - JavaScript localization for better multilingual support - Plugin constants for improved code organization +- Git Updater support for updates from GitHub and Gitea ### Changed - Updated code to follow WordPress internationalization best practices - Improved asset loading with version constants +- Smart update detection based on installation source ## [1.5.0] - 2024-05-15 ### Added diff --git a/build.sh b/build.sh index 3f21f78..34fd1b0 100755 --- a/build.sh +++ b/build.sh @@ -18,6 +18,10 @@ ZIP_FILE="${PLUGIN_SLUG}-${VERSION}.zip" echo "Creating build directory..." mkdir -p $BUILD_DIR +# Install composer dependencies +echo "Installing composer dependencies..." +composer install --no-dev --optimize-autoloader + # Copy required files echo "Copying plugin files..." cp fix-plugin-does-not-exist-notices.php $BUILD_DIR/ @@ -25,6 +29,18 @@ cp readme.txt $BUILD_DIR/ cp LICENSE $BUILD_DIR/ cp README.md $BUILD_DIR/ cp CHANGELOG.md $BUILD_DIR/ +cp composer.json $BUILD_DIR/ + +# Copy directories +echo "Copying directories..." +mkdir -p $BUILD_DIR/includes +cp -r includes/* $BUILD_DIR/includes/ +mkdir -p $BUILD_DIR/languages +cp -r languages/* $BUILD_DIR/languages/ +mkdir -p $BUILD_DIR/assets +cp -r assets/* $BUILD_DIR/assets/ +mkdir -p $BUILD_DIR/vendor +cp -r vendor/* $BUILD_DIR/vendor/ # Create ZIP file echo "Creating ZIP file..." @@ -39,4 +55,4 @@ if [ -f "$ZIP_FILE" ]; then else echo "❌ Build failed: ZIP file was not created" exit 1 -fi \ No newline at end of file +fi \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a37e57f --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "wpallstars/fix-plugin-does-not-exist-notices", + "description": "Adds missing plugins to the plugins list with a 'Remove Reference' link so you can permanently clean up invalid plugin entries and remove error notices.", + "type": "wordpress-plugin", + "license": "GPL-2.0-or-later", + "authors": [ + { + "name": "Marcus Quinn", + "email": "6428977+marcusquinn@users.noreply.github.com" + } + ], + "require": { + "php": ">=7.0", + "afragen/git-updater-lite": "^1" + }, + "autoload": { + "psr-4": { + "WPAllStars\\FixPluginDoesNotExistNotices\\": "includes/" + } + } +} diff --git a/fix-plugin-does-not-exist-notices.php b/fix-plugin-does-not-exist-notices.php index 2253e7f..7c68295 100644 --- a/fix-plugin-does-not-exist-notices.php +++ b/fix-plugin-does-not-exist-notices.php @@ -9,6 +9,7 @@ * * @wordpress-plugin * Plugin Name: Fix 'Plugin file does not exist.' Notices + * Plugin URI: https://wordpress.org/plugins/fix-plugin-does-not-exist-notices/ * Description: Adds missing plugins to the plugins list with a "Remove Reference" link so you can permanently clean up invalid plugin entries and remove error notices. * Version: 1.6.0 * Author: Marcus Quinn @@ -19,6 +20,10 @@ * Domain Path: /languages * Requires at least: 5.0 * Requires PHP: 7.0 + * GitHub Plugin URI: wpallstars/fix-plugin-does-not-exist-notices + * GitHub Branch: main + * Gitea Plugin URI: wpallstars/fix-plugin-does-not-exist-notices + * Gitea Branch: main * * This plugin is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -395,3 +400,14 @@ class Fix_Plugin_Does_Not_Exist_Notices { // Initialize the plugin class. new Fix_Plugin_Does_Not_Exist_Notices(); + +// Initialize the updater if composer autoload exists +$autoloader = __DIR__ . '/vendor/autoload.php'; +if (file_exists($autoloader)) { + require_once $autoloader; + + // Initialize the updater if the class exists + if (class_exists('\WPAllStars\FixPluginDoesNotExistNotices\Updater')) { + new \WPAllStars\FixPluginDoesNotExistNotices\Updater(__FILE__); + } +} diff --git a/includes/Updater.php b/includes/Updater.php new file mode 100644 index 0000000..655ac51 --- /dev/null +++ b/includes/Updater.php @@ -0,0 +1,152 @@ +plugin_file = $plugin_file; + $this->source = $this->determine_installation_source(); + $this->init(); + } + + /** + * Initialize the updater based on the installation source + * + * @return void + */ + public function init() { + // Only initialize Git Updater if not installed from WordPress.org + if ($this->source !== 'wordpress.org') { + $this->init_git_updater(); + } + } + + /** + * Determine the installation source of the plugin + * + * @return string Installation source: 'github', 'gitea', or 'wordpress.org' + */ + private function determine_installation_source() { + // Default to WordPress.org + $source = 'wordpress.org'; + + // Check if the plugin was installed from GitHub + if ($this->is_github_installation()) { + $source = 'github'; + } + // Check if the plugin was installed from Gitea + elseif ($this->is_gitea_installation()) { + $source = 'gitea'; + } + + return $source; + } + + /** + * Check if the plugin was installed from GitHub + * + * @return bool + */ + private function is_github_installation() { + // Check for GitHub-specific markers in the plugin directory + $plugin_dir = plugin_dir_path($this->plugin_file); + + // Look for .git directory with GitHub remote + if (file_exists($plugin_dir . '.git')) { + $git_config = @file_get_contents($plugin_dir . '.git/config'); + if ($git_config && strpos($git_config, 'github.com') !== false) { + return true; + } + } + + // Check for GitHub-specific files that might indicate it was downloaded from GitHub + if (file_exists($plugin_dir . '.github')) { + return true; + } + + return false; + } + + /** + * Check if the plugin was installed from Gitea + * + * @return bool + */ + private function is_gitea_installation() { + // Check for Gitea-specific markers in the plugin directory + $plugin_dir = plugin_dir_path($this->plugin_file); + + // Look for .git directory with Gitea remote + if (file_exists($plugin_dir . '.git')) { + $git_config = @file_get_contents($plugin_dir . '.git/config'); + if ($git_config && strpos($git_config, 'gitea.wpallstars.com') !== false) { + return true; + } + } + + return false; + } + + /** + * Initialize Git Updater Lite + * + * @return void + */ + private function init_git_updater() { + // Check if the Git Updater Lite class exists (composer autoload) + if (!class_exists('\\Fragen\\Git_Updater\\Lite')) { + // Try to include the autoloader + $autoloader = dirname($this->plugin_file) . '/vendor/autoload.php'; + if (file_exists($autoloader)) { + require_once $autoloader; + } else { + return; // Can't load Git Updater Lite + } + } + + // Set the update server based on the installation source + add_filter('gul_update_server', function() { + if ($this->source === 'github') { + return 'https://wpallstars.com'; // GitHub update server + } elseif ($this->source === 'gitea') { + return 'https://wpallstars.com'; // Gitea update server + } + return ''; + }); + + // Initialize Git Updater Lite + if (class_exists('\\Fragen\\Git_Updater\\Lite')) { + (new \Fragen\Git_Updater\Lite($this->plugin_file))->run(); + } + } +} diff --git a/readme.txt b/readme.txt index 6f162e9..c46860b 100644 --- a/readme.txt +++ b/readme.txt @@ -93,8 +93,10 @@ Although this plugin consumes minimal disk space, and doesn't run unless you are * Added full translation support with POT file * Added JavaScript localization for better multilingual support * Added plugin constants for improved code organization +* Added Git Updater support for updates from GitHub and Gitea * Updated code to follow WordPress internationalization best practices * Improved asset loading with version constants +* Added smart update detection based on installation source = 1.5.0 = * Improved compatibility with WordPress 6.4 @@ -169,7 +171,7 @@ Although this plugin consumes minimal disk space, and doesn't run unless you are == Upgrade Notice == = 1.6.0 = -Added full translation support! The plugin can now be translated into any language. +Added full translation support and Git Updater compatibility for direct updates from GitHub and Gitea! = 1.5.0 = Improved compatibility with WordPress 6.4 and accessibility enhancements for screen readers!