@@ -33,48 +33,47 @@ function auto_update( $update, $item ) {
33
33
* Fetch the first non pre-release zip from GitHub releases and store the response for later use.
34
34
*/
35
35
private function maybe_fetch_github_response () {
36
- if ( is_null ( $ this -> github_response ) ) {
36
+ if ( false === ( $ gh_response = get_transient ( ' wc_api_dev_gh_response ' ) ) ) {
37
37
$ request_uri = 'https://api.github.com/repos/woocommerce/wc-api-dev/releases ' ;
38
38
$ response = json_decode ( wp_remote_retrieve_body ( wp_remote_get ( $ request_uri ) ), true );
39
39
if ( is_array ( $ response ) ) {
40
40
foreach ( $ response as $ entry ) {
41
41
if ( false === ( bool ) $ entry ['prerelease ' ] ) {
42
- $ this ->github_response = $ entry ;
42
+ $ gh_response = $ entry ;
43
+ set_transient ( 'wc_api_dev_gh_response ' , $ entry , 2 * HOUR_IN_SECONDS );
43
44
break ;
44
45
}
45
46
}
46
47
}
47
48
}
49
+ $ this ->github_response = $ gh_response ;
48
50
}
49
51
50
52
/**
51
53
* Add our plugin to the list of plugins to update, if we find the version is out of date.
52
54
*/
53
55
public function modify_transient ( $ transient ) {
54
- if ( property_exists ( $ transient , 'checked ' ) && $ transient ->checked ) {
55
- $ checked = $ transient ->checked ;
56
- $ this ->maybe_fetch_github_response ();
56
+ $ this ->maybe_fetch_github_response ();
57
57
58
- if (
59
- empty ( $ this ->github_response ['tag_name ' ] ) ||
60
- empty ( $ checked [ $ this ->file ] ) ||
61
- empty ( $ this ->github_response ['zipball_url ' ] )
62
- ) {
63
- return $ transient ;
64
- }
58
+ if (
59
+ empty ( $ this ->github_response ['tag_name ' ] ) ||
60
+ empty ( $ this ->github_response ['zipball_url ' ] )
61
+ ) {
62
+ return $ transient ;
63
+ }
65
64
66
- $ out_of_date = version_compare ( $ this ->github_response ['tag_name ' ], $ checked [ $ this ->file ], '> ' );
67
- if ( $ out_of_date ) {
68
- $ plugin = array (
69
- 'url ' => 'https://github.com/woocommerce/wc-api-dev ' ,
70
- 'plugin ' => $ this ->file ,
71
- 'slug ' => 'wc-api-dev ' ,
72
- 'package ' => $ this ->github_response ['zipball_url ' ],
73
- 'new_version ' => $ this ->github_response ['tag_name ' ]
74
- );
75
- $ transient ->response [ $ this ->file ] = (object ) $ plugin ;
76
- }
65
+ $ out_of_date = version_compare ( $ this ->github_response ['tag_name ' ], WC_API_Dev::CURRENT_VERSION , '> ' );
66
+ if ( $ out_of_date ) {
67
+ $ plugin = array (
68
+ 'url ' => 'https://github.com/woocommerce/wc-api-dev ' ,
69
+ 'plugin ' => $ this ->file ,
70
+ 'slug ' => 'wc-api-dev ' ,
71
+ 'package ' => $ this ->github_response ['zipball_url ' ],
72
+ 'new_version ' => $ this ->github_response ['tag_name ' ]
73
+ );
74
+ $ transient ->response [ $ this ->file ] = (object ) $ plugin ;
77
75
}
76
+
78
77
return $ transient ;
79
78
}
80
79
@@ -128,6 +127,10 @@ public function after_install( $response, $hook_extra, $result ) {
128
127
$ wp_filesystem ->move ( $ result ['destination ' ], $ install_directory );
129
128
$ result ['destination ' ] = $ install_directory ;
130
129
activate_plugin ( $ this ->file );
130
+
131
+ // Prevent double notice being displayed. At this point we don't need the plugin injected.
132
+ remove_filter ( 'pre_set_site_transient_update_plugins ' , array ( $ this , 'modify_transient ' ), 10 );
133
+
131
134
return $ result ;
132
135
}
133
136
}
0 commit comments