diff --git a/CHANGELOG.md b/CHANGELOG.md index 68f9b6d..7573a87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,18 @@ All notable changes to this project will be documented in this file. #### [2.1.1] - 2025-04-13 +#### Added +- New "Choose Update Source" feature allowing users to select their preferred update source (WordPress.org, GitHub, or Gitea) +- Modal dialog with detailed information about each update source option +- Visual indicator showing the currently selected update source + #### Fixed - Updated heading styles in CHANGELOG.md for better readability - Corrected dates in changelog to use 2025 instead of 2024 #### Improved - Documentation improvements for better clarity +- Enhanced Git Updater integration with user-selectable update sources #### [2.1.0] - 2025-04-13 #### Changed diff --git a/README.md b/README.md index 2106576..44482dd 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,21 @@ If you've installed this plugin from GitHub or Gitea, you'll need Git Updater to 3. Click the "Refresh Cache" button to ensure Git Updater recognizes the latest version 4. Updates will now appear in your WordPress dashboard when available +### Choosing Your Update Source + +This plugin allows you to choose where you want to receive updates from: + +1. In the Plugins list, find "Fix 'Plugin file does not exist' Notices" +2. Click the "Choose Update Source" link next to the plugin +3. Select your preferred update source: + - **Auto-detect** (default): Automatically determines the source based on installation origin + - **WordPress.org**: Updates from the official WordPress.org repository (may have delays due to approval process) + - **GitHub**: Updates directly from GitHub (usually has the latest version first) + - **Gitea**: Updates from Gitea (usually has the latest version first) +4. Click "Save" to apply your preference + +> **Note:** GitHub and Gitea options require the Git Updater plugin to be installed and activated. + ## Frequently Asked Questions ### Is it safe to remove plugin references? @@ -186,9 +201,13 @@ The plugin works by: ## Changelog ### 2.1.1 +* Added: New "Choose Update Source" feature allowing users to select their preferred update source (WordPress.org, GitHub, or Gitea) +* Added: Modal dialog with detailed information about each update source option +* Added: Visual indicator showing the currently selected update source * Fixed: Updated heading styles in CHANGELOG.md for better readability * Fixed: Corrected dates in changelog to use 2025 instead of 2024 * Improved: Documentation improvements for better clarity +* Improved: Enhanced Git Updater integration with user-selectable update sources ### 2.1.0 * Minor version bump for Git Updater compatibility diff --git a/assets/css/update-source-selector.css b/assets/css/update-source-selector.css new file mode 100644 index 0000000..7d38651 --- /dev/null +++ b/assets/css/update-source-selector.css @@ -0,0 +1,86 @@ +/** + * Update Source Selector Styles + */ +#fpden-update-source-modal { + display: none; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; +} + +#fpden-update-source-modal h2 { + margin-top: 0; + margin-bottom: 15px; + font-size: 1.3em; + font-weight: 600; +} + +#fpden-update-source-modal p { + margin-bottom: 20px; +} + +#fpden-update-source-form label { + display: block; + margin-bottom: 10px; + padding: 8px; + border-radius: 4px; + cursor: pointer; +} + +#fpden-update-source-form label:hover { + background-color: #f0f0f1; +} + +#fpden-update-source-form input[type="radio"] { + margin-right: 8px; +} + +.fpden-source-description { + display: block; + margin-left: 24px; + font-size: 0.9em; + color: #666; + margin-top: 3px; +} + +.fpden-submit-container { + margin-top: 20px; + text-align: right; +} + +.fpden-submit-container button { + margin-left: 10px; +} + +.fpden-update-source-toggle { + color: #2271b1; +} + +.fpden-update-source-toggle:hover { + color: #135e96; +} + +/* Source badges */ +.fpden-source-badge { + display: inline-block; + padding: 2px 6px; + border-radius: 3px; + font-size: 0.8em; + margin-left: 5px; + color: white; + font-weight: normal; +} + +.fpden-source-badge.wordpress { + background-color: #0073aa; +} + +.fpden-source-badge.github { + background-color: #24292e; +} + +.fpden-source-badge.gitea { + background-color: #609926; +} + +.fpden-source-badge.auto { + background-color: #666; +} diff --git a/assets/js/update-source-selector.js b/assets/js/update-source-selector.js new file mode 100644 index 0000000..4e38e37 --- /dev/null +++ b/assets/js/update-source-selector.js @@ -0,0 +1,119 @@ +/** + * 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('
'); + $('#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, .fpden-close-modal', function() { + $('#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) { + // Show success message + var message = $('
Update source saved successfully!
'); + 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 = $('
Error saving update source.
'); + 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); + } + }); + }); +}); diff --git a/includes/Updater.php b/includes/Updater.php index fecb915..819953e 100644 --- a/includes/Updater.php +++ b/includes/Updater.php @@ -61,7 +61,15 @@ class Updater { * @return string Installation source: 'github', 'gitea', or 'wordpress.org' */ private function determine_installation_source() { - // Default to WordPress.org + // Check for user preference first + $user_preference = \get_option('fpden_update_source', 'auto'); + + // If not set to auto, use the user preference + if ($user_preference !== 'auto') { + return $user_preference; + } + + // Otherwise, auto-detect as before $source = 'wordpress.org'; // Check if the plugin was installed from GitHub diff --git a/readme.txt b/readme.txt index 1d32ceb..b5be53a 100644 --- a/readme.txt +++ b/readme.txt @@ -93,6 +93,21 @@ If you've installed this plugin from GitHub or Gitea, you'll need Git Updater to 3. Click the "Refresh Cache" button to ensure Git Updater recognizes the latest version 4. Updates will now appear in your WordPress dashboard when available += Choosing Your Update Source = + +This plugin allows you to choose where you want to receive updates from: + +1. In the Plugins list, find "Fix 'Plugin file does not exist' Notices" +2. Click the "Choose Update Source" link next to the plugin +3. Select your preferred update source: + * **Auto-detect** (default): Automatically determines the source based on installation origin + * **WordPress.org**: Updates from the official WordPress.org repository (may have delays due to approval process) + * **GitHub**: Updates directly from GitHub (usually has the latest version first) + * **Gitea**: Updates from Gitea (usually has the latest version first) +4. Click "Save" to apply your preference + +**Note:** GitHub and Gitea options require the Git Updater plugin to be installed and activated. + == Frequently Asked Questions == = Is it safe to remove plugin references? = @@ -150,9 +165,13 @@ Manually editing the WordPress database is risky and requires technical knowledg == Changelog == = 2.1.1 = +* Added: New "Choose Update Source" feature allowing users to select their preferred update source (WordPress.org, GitHub, or Gitea) +* Added: Modal dialog with detailed information about each update source option +* Added: Visual indicator showing the currently selected update source * Fixed: Updated heading styles in CHANGELOG.md for better readability * Fixed: Corrected dates in changelog to use 2025 instead of 2024 -* Updated: Documentation improvements for better clarity +* Improved: Documentation improvements for better clarity +* Improved: Enhanced Git Updater integration with user-selectable update sources = 2.1.0 = * Minor version bump for Git Updater compatibility @@ -482,7 +501,7 @@ Manually editing the WordPress database is risky and requires technical knowledg == Upgrade Notice == = 2.1.1 = -Fixed dates in changelog and improved documentation formatting. +Added new "Choose Update Source" feature allowing you to select where to receive plugin updates from (WordPress.org, GitHub, or Gitea). = 2.1.0 = Minor version bump with improved Git Updater compatibility and error handling. diff --git a/wp-fix-plugin-does-not-exist-notices.php b/wp-fix-plugin-does-not-exist-notices.php index 2f33338..b45f033 100644 --- a/wp-fix-plugin-does-not-exist-notices.php +++ b/wp-fix-plugin-does-not-exist-notices.php @@ -40,6 +40,15 @@ add_action('plugins_loaded', 'fpden_init_git_updater_fixes'); * It uses named functions instead of anonymous functions for better compatibility */ function fpden_init_git_updater_fixes() { + // Add filter for plugin action links to add our update source selector + add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'fpden_add_update_source_link'); + + // Add AJAX handler for saving update source + add_action('wp_ajax_fpden_save_update_source', 'fpden_save_update_source'); + + // Add the update source modal to admin footer + add_action('admin_footer', 'fpden_add_update_source_modal'); + // Fix for Git Updater looking for 'master' branch instead of 'main' add_filter('gu_get_repo_branch', 'fpden_override_branch', 999, 3); @@ -876,6 +885,150 @@ class Fix_Plugin_Does_Not_Exist_Notices { // Initialize the plugin class. new Fix_Plugin_Does_Not_Exist_Notices(); +/** + * Add the "Choose Update Source" link to plugin action links + * + * @param array $links Array of plugin action links + * @return array Modified array of plugin action links + */ +function fpden_add_update_source_link($links) { + if (!current_user_can('manage_options')) { + return $links; + } + + // Get current update source + $current_source = get_option('fpden_update_source', 'auto'); + + // Add a badge to show the current source + $badge_class = 'fpden-source-badge ' . $current_source; + $badge_text = ucfirst($current_source); + if ($current_source === 'auto') { + $badge_text = 'Auto'; + } elseif ($current_source === 'wordpress.org') { + $badge_text = 'WP.org'; + } + + // Add the link with the badge + $update_source_link = 'Choose Update Source ' . $badge_text . ''; + $links[] = $update_source_link; + + return $links; +} + +/** + * Add the update source modal to the admin footer + */ +function fpden_add_update_source_modal() { + if (!is_admin() || !current_user_can('manage_options')) { + return; + } + + // Only show on plugins page + $screen = get_current_screen(); + if (!$screen || $screen->id !== 'plugins') { + return; + } + + // Get current source + $current_source = get_option('fpden_update_source', 'auto'); + + // Enqueue the CSS and JS + wp_enqueue_style( + 'fpden-update-source-selector', + FPDEN_PLUGIN_URL . 'assets/css/update-source-selector.css', + array(), + FPDEN_VERSION + ); + + wp_enqueue_script( + 'fpden-update-source-selector', + FPDEN_PLUGIN_URL . 'assets/js/update-source-selector.js', + array('jquery'), + FPDEN_VERSION, + true + ); + + // Add nonce to the existing fpdenData object or create it if it doesn't exist + $nonce = wp_create_nonce('fpden_update_source'); + wp_localize_script( + 'fpden-update-source-selector', + 'fpdenData', + array( + 'updateSourceNonce' => $nonce, + ) + ); + + // Modal HTML + ?> +
+ × +

Choose Update Source

+

Select where you want to receive plugin updates from:

+ +
+ + + + + + + + +
+ + +
+
+
+