Improve Choose Update Source feature based on feedback
Some checks failed
ci/woodpecker/push/woodpecker Pipeline is pending
ci/woodpecker/tag/woodpecker Pipeline is pending
Plugin Asset Update / Push assets to WordPress.org (push) Has been cancelled
Build Release / Build and Create Release (push) Has been cancelled
Build Release / Deploy to WordPress.org (push) Has been cancelled

This commit is contained in:
2025-04-13 13:48:13 +01:00
parent 3ebcaccf98
commit 5e8da5d87b
4 changed files with 70 additions and 23 deletions

View File

@ -50,12 +50,14 @@
margin-left: 10px;
}
/* Remove explicit color to inherit from theme */
.fpden-update-source-toggle {
color: #2271b1;
/* color is now inherited from theme */
}
.fpden-update-source-toggle:hover {
color: #135e96;
/* hover color is now inherited from theme */
text-decoration: underline;
}
/* Source badges */
@ -69,7 +71,7 @@
font-weight: normal;
}
.fpden-source-badge.wordpress {
.fpden-source-badge.wordpress, .fpden-source-badge.wordpress\.org {
background-color: #0073aa;
}

View File

@ -78,6 +78,20 @@ jQuery(document).ready(function($) {
submitButton.text(originalText).prop('disabled', false);
if (response.success) {
// Update the badge
var badgeText = source.charAt(0).toUpperCase() + source.slice(1);
if (source === 'auto') {
badgeText = 'Auto';
} else 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({

View File

@ -160,6 +160,38 @@ class Updater {
return '';
});
// Add filter to trigger Git Updater cache refresh when a version update is detected
\add_filter('site_transient_update_plugins', function($transient) {
// Check if our plugin has an update
$plugin_basename = \plugin_basename($this->plugin_file);
if (isset($transient->response) && isset($transient->response[$plugin_basename])) {
// Check if Git Updater is active by looking for its functions
if (function_exists('\\Fragen\\Git_Updater\\flush_git_updater_cache') ||
class_exists('\\Fragen\\Git_Updater\\API\\API')) {
// Try to call the flush cache function if it exists
if (function_exists('\\Fragen\\Git_Updater\\flush_git_updater_cache')) {
\Fragen\Git_Updater\flush_git_updater_cache();
} elseif (class_exists('\\Fragen\\Git_Updater\\API\\API')) {
// Try to use the API class if available
try {
$api = new \Fragen\Git_Updater\API\API();
if (method_exists($api, 'flush_cache_site_transient')) {
$api->flush_cache_site_transient();
}
} catch (\Exception $e) {
// Silently fail if API class can't be instantiated
}
}
// Also delete the update plugins transient to force a refresh
\delete_site_transient('update_plugins');
}
}
return $transient;
});
// Initialize Git Updater Lite
if (class_exists('\\Fragen\\Git_Updater\\Lite')) {
(new \Fragen\Git_Updater\Lite($this->plugin_file))->run();

View File

@ -961,7 +961,7 @@ function fpden_add_update_source_modal() {
// Modal HTML
?>
<div id="fpden-update-source-modal">
<a href="#" class="fpden-close-modal">×</a>
<a href="#" class="fpden-close-modal" aria-label="Close modal">×</a>
<h2>Choose Update Source</h2>
<p>Select where you want to receive plugin updates from:</p>
@ -975,23 +975,22 @@ function fpden_add_update_source_modal() {
<label>
<input type="radio" name="update_source" value="wordpress.org" <?php checked($current_source, 'wordpress.org'); ?>>
WordPress.org
<span class="fpden-source-description">Updates from the official WordPress.org plugin repository. May have a delay due to approval process.</span>
<span class="fpden-source-description">Updates from the official WordPress.org plugin repository. Will have a version update delay due to allow for the WP.org policy review and approval process. Best for unmonitored auto-updates.</span>
</label>
<label>
<input type="radio" name="update_source" value="github" <?php checked($current_source, 'github'); ?>>
GitHub
<span class="fpden-source-description">Updates directly from GitHub. Requires Git Updater plugin. Usually has the latest version first.</span>
<span class="fpden-source-description">Update directly from the GitHub repo main branch for the latest stable release. Git Updater plugin must be installed & active. Best for monitored updates, where the latest features and fixes are required as soon as they are merged into the main branch.</span>
</label>
<label>
<input type="radio" name="update_source" value="gitea" <?php checked($current_source, 'gitea'); ?>>
Gitea
<span class="fpden-source-description">Updates from Gitea. Requires Git Updater plugin. Usually has the latest version first.</span>
<span class="fpden-source-description">Update directly from the Gitea repo main branch for the latest stable release. Git Updater plugin must be installed & active. Best for monitored updates, where the latest features and fixes are required as soon as they are merged into the main branch, and independence from big-tech.</span>
</label>
<div class="fpden-submit-container">
<button type="button" class="button fpden-close-modal">Cancel</button>
<button type="submit" class="button button-primary">Save</button>
</div>
</form>