Skip to content

Commit 42d8807

Browse files
committed
Merge branch 'develop'
2 parents 29b975e + 8680947 commit 42d8807

File tree

17 files changed

+117
-103
lines changed

17 files changed

+117
-103
lines changed

CHANGES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
#### [unreleased]
22

3+
#### 12.18.0 / 2025-08-04
4+
* update cache delete and don't use `wp_cache_flush`
5+
* always show download link in REST endpoint
6+
* improved reverse sort for branch/tag versions
7+
* get all release assets from GitHub API and pick release asset download from release assets array, other APIs get latest release asset only
8+
* update `parse_tag()` and `sort_tags()`
9+
* update branch switching tags
10+
311
#### 12.17.3 / 2025-07-31
412
* add new `Security` header with value of email or URI
513

composer.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-updater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Plugin ID: did:plc:afjf7gsjzsqmgc7dlhb553mv
1414
* Plugin URI: https://git-updater.com
1515
* Description: A plugin to automatically update GitHub hosted plugins, themes, and language packs. Additional API plugins available for Bitbucket, GitLab, Gitea, and Gist.
16-
* Version: 12.17.3
16+
* Version: 12.18.0
1717
* Author: Andy Fragen
1818
* Author URI: https://thefragens.com
1919
* Security: [email protected]

gu-uninstall.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,14 @@
3434
}
3535

3636
global $wpdb;
37-
$table = is_multisite() ? $wpdb->base_prefix . 'sitemeta' : $wpdb->base_prefix . 'options';
38-
$column = is_multisite() ? 'meta_key' : 'option_name';
39-
$delete_string = 'DELETE FROM ' . $table . ' WHERE ' . $column . ' LIKE %s LIMIT 1000';
37+
$table = is_multisite() ? $wpdb->base_prefix . 'sitemeta' : $wpdb->base_prefix . 'options';
38+
$column = is_multisite() ? 'meta_key' : 'option_name';
39+
$delete_string = 'DELETE FROM ' . $table . ' WHERE ' . $column . ' LIKE %s LIMIT 1000';
40+
$get_options_string = 'SELECT * FROM ' . $table . ' WHERE ' . $column . ' LIKE %s';
41+
42+
$ghu_options = $wpdb->get_results( $wpdb->prepare( $get_options_string, [ '%ghu-%' ] ) ); // phpcs:ignore
43+
foreach ( $ghu_options as $option ) {
44+
delete_site_option( $option->option_name );
45+
}
4046

4147
$wpdb->query( $wpdb->prepare( $delete_string, [ '%ghu-%' ] ) ); // phpcs:ignore

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<!-- Only check PHP files. -->
1111
<arg name="extensions" value="php"/>
12-
12+
1313
<file>.</file>
1414

1515
<!-- Exclude these -->

src/Git_Updater/API/API.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,26 +453,20 @@ protected function local_file_exists( $filename ) {
453453
/**
454454
* Sort tags and set object data.
455455
*
456-
* @param array $parsed_tags Array of tags.
456+
* @param array $tags Associative array of tags[ tag ].
457457
*
458458
* @return bool
459459
*/
460-
protected function sort_tags( $parsed_tags ) {
461-
if ( empty( $parsed_tags ) ) {
460+
protected function sort_tags( $tags ) {
461+
if ( empty( $tags ) ) {
462462
return false;
463463
}
464464

465-
list($tags, $rollback) = $parsed_tags;
466-
usort( $tags, 'version_compare' );
467-
uksort( $rollback, 'version_compare' );
465+
uksort( $tags, fn ( $a, $b ) => version_compare( trim( $b, 'v' ), trim( $a, 'v' ) ) );
468466

469-
$newest_tag = array_slice( $tags, -1, 1, true );
470-
$newest_tag_key = key( $newest_tag );
471-
$newest_tag = $tags[ $newest_tag_key ];
472-
473-
$this->type->newest_tag = $newest_tag;
467+
$tag_keys = array_keys( $tags );
468+
$this->type->newest_tag = reset( $tag_keys );
474469
$this->type->tags = $tags;
475-
$this->type->rollback = $rollback;
476470

477471
return true;
478472
}

src/Git_Updater/API/GitHub_API.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public function get_remote_branches() {
103103
/**
104104
* Return the latest GitHub release asset URL.
105105
*
106-
* @return string|bool
106+
* @return string|bool|void
107107
*/
108108
public function get_release_asset() {
109-
return $this->get_api_release_asset( 'github', '/repos/:owner/:repo/releases/latest' );
109+
// return $this->get_api_release_asset( 'github', '/repos/:owner/:repo/releases/latest' );
110110
}
111111

112112
/**
@@ -152,12 +152,11 @@ public function construct_download_link( $branch_switch = false ) {
152152

153153
// Release asset.
154154
if ( $this->use_release_asset( $branch_switch ) ) {
155-
$this->get_release_assets();
156-
$release_asset = $this->get_release_asset();
155+
$release_assets = $this->get_release_assets();
156+
$release_asset = reset( $release_assets );
157157

158158
if ( empty( $this->response['release_asset_download'] ) ) {
159-
$response = $this->api( $release_asset );
160-
$this->parse_release_asset_response( $response );
159+
$this->set_repo_cache( 'release_asset_download', $release_asset );
161160
}
162161
if ( ! empty( $this->response['release_asset_download'] ) ) {
163162
return $this->response['release_asset_download'];
@@ -375,11 +374,10 @@ public function parse_release_asset_response( $response ) {
375374
* @return array
376375
*/
377376
protected function parse_tags( $response, $repo_type ) {
378-
$tags = [];
379-
$rollback = [];
377+
$tags = [];
380378

381379
foreach ( (array) $response as $tag ) {
382-
$download_base = implode(
380+
$download_base = implode(
383381
'/',
384382
[
385383
$repo_type['base_uri'],
@@ -389,11 +387,15 @@ protected function parse_tags( $response, $repo_type ) {
389387
'zipball/',
390388
]
391389
);
392-
$tags[] = $tag;
393-
$rollback[ $tag ] = $download_base . $tag;
390+
391+
// Ignore leading 'v' and skip anything with dash or words.
392+
if ( ! preg_match( '/[^v]+[-a-z]+/', $tag ) ) {
393+
$tags[ $tag ] = $download_base . $tag;
394+
}
395+
uksort( $tags, fn ( $a, $b ) => version_compare( ltrim( $b, 'v' ), ltrim( $a, 'v' ) ) );
394396
}
395397

396-
return [ $tags, $rollback ];
398+
return $tags;
397399
}
398400

399401
/**

src/Git_Updater/Base.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ protected function set_defaults( $type ) {
367367
$this->$type->newest_tag = '0.0.0';
368368
$this->$type->download_link = '';
369369
$this->$type->tags = [];
370-
$this->$type->rollback = [];
371370
$this->$type->branches = [];
372371
$this->$type->requires = '';
373372
$this->$type->tested = '';

src/Git_Updater/Branch.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,8 @@ public function single_install_switcher( $theme ) {
329329
echo '<option>' . esc_attr( $branch ) . '</option>';
330330
}
331331
}
332-
if ( ! empty( $theme->rollback ) ) {
333-
$rollback = array_keys( $theme->rollback );
334-
usort( $rollback, 'version_compare' );
335-
krsort( $rollback );
332+
if ( ! empty( $theme->tags ) ) {
333+
uksort( $theme->tags, fn ( $a, $b ) => version_compare( ltrim( $b, 'v' ), trim( $a, 'v' ) ) );
336334

337335
/**
338336
* Filter to return the number of tagged releases (rollbacks) in branch switching.
@@ -342,16 +340,16 @@ public function single_install_switcher( $theme ) {
342340
*/
343341
$num_rollbacks = absint( apply_filters( 'gu_number_rollbacks', 0 ) );
344342

345-
// Still only return last tag if using release assets.
346-
$rollback = 0 === $num_rollbacks || $theme->release_asset
347-
? array_slice( $rollback, 0, 1 )
348-
: array_splice( $rollback, 0, $num_rollbacks, true );
343+
$tag_keys = array_keys( $theme->tags );
344+
$rollback = 0 === $num_rollbacks
345+
? array_slice( $tag_keys, 0, 1 )
346+
: array_splice( $tag_keys, 0, $num_rollbacks );
349347

350348
foreach ( $rollback as $tag ) {
351349
echo '<option>' . esc_attr( $tag ) . '</option>';
352350
}
353351
}
354-
if ( empty( $theme->rollback ) ) {
352+
if ( empty( $theme->tags ) ) {
355353
echo '<option>' . esc_html__( 'No previous tags to rollback to.', 'git-updater' ) . '</option></select></label>';
356354
}
357355
?>
@@ -373,7 +371,7 @@ public function single_install_switcher( $theme ) {
373371
* @return void
374372
*/
375373
public function make_branch_switch_row( $data, $config ) {
376-
$rollback = empty( $config[ $data['slug'] ]->rollback ) ? [] : $config[ $data['slug'] ]->rollback;
374+
$rollback = empty( $config[ $data['slug'] ]->tags ) ? [] : $config[ $data['slug'] ]->tags;
377375

378376
// Make the branch switch row visually appear as if it is contained with the plugin/theme's row.
379377
// We have to use JS for this because of the way:
@@ -441,9 +439,7 @@ public function make_branch_switch_row( $data, $config ) {
441439
}
442440

443441
if ( ! empty( $rollback ) ) {
444-
$rollback = array_keys( $rollback );
445-
usort( $rollback, 'version_compare' );
446-
krsort( $rollback );
442+
uksort( $rollback, fn ( $a, $b ) => version_compare( trim( $b, 'v' ), trim( $a, 'v' ) ) );
447443

448444
/**
449445
* Filter to return the number of tagged releases (rollbacks) in branch switching.
@@ -453,10 +449,10 @@ public function make_branch_switch_row( $data, $config ) {
453449
*/
454450
$num_rollbacks = absint( apply_filters( 'gu_number_rollbacks', 0 ) );
455451

456-
// Still only return last tag if using release assets.
457-
$rollback = 0 === $num_rollbacks || $data['release_asset']
458-
? array_slice( $rollback, 0, 1 )
459-
: array_splice( $rollback, 0, $num_rollbacks, true );
452+
$rollback_keys = array_keys( $rollback );
453+
$rollback = 0 === $num_rollbacks
454+
? array_slice( $rollback_keys, 0, 1 )
455+
: array_splice( $rollback_keys, 0, $num_rollbacks );
460456

461457
if ( $data['release_asset'] ) {
462458
/**

src/Git_Updater/GU_Upgrade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ private function save_db_version( $options ) {
7474
* Flush caches and delete cached options.
7575
*/
7676
private function delete_flush_cache() {
77-
wp_cache_flush();
7877
$this->delete_all_cached_data();
7978
}
8079

0 commit comments

Comments
 (0)