@@ -33,48 +33,47 @@ function auto_update( $update, $item ) {
3333 * Fetch the first non pre-release zip from GitHub releases and store the response for later use.
3434 */
3535 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 ' ) ) ) {
3737 $ request_uri = 'https://api.github.com/repos/woocommerce/wc-api-dev/releases ' ;
3838 $ response = json_decode ( wp_remote_retrieve_body ( wp_remote_get ( $ request_uri ) ), true );
3939 if ( is_array ( $ response ) ) {
4040 foreach ( $ response as $ entry ) {
4141 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 );
4344 break ;
4445 }
4546 }
4647 }
4748 }
49+ $ this ->github_response = $ gh_response ;
4850 }
4951
5052 /**
5153 * Add our plugin to the list of plugins to update, if we find the version is out of date.
5254 */
5355 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 ();
5757
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+ }
6564
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 ;
7775 }
76+
7877 return $ transient ;
7978 }
8079
@@ -128,6 +127,10 @@ public function after_install( $response, $hook_extra, $result ) {
128127 $ wp_filesystem ->move ( $ result ['destination ' ], $ install_directory );
129128 $ result ['destination ' ] = $ install_directory ;
130129 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+
131134 return $ result ;
132135 }
133136}
0 commit comments