@@ -348,12 +348,14 @@ protected function update_many( $args, $assoc_args ) {
348348 $ minor = (bool ) Utils \get_flag_value ( $ assoc_args , 'minor ' , false );
349349 $ patch = (bool ) Utils \get_flag_value ( $ assoc_args , 'patch ' , false );
350350
351- if ( 'plugin ' === $ this ->item_type
352- && ( $ minor || $ patch ) ) {
351+ if (
352+ in_array ( $ this ->item_type , [ 'plugin ' , 'theme ' ], true ) &&
353+ ( $ minor || $ patch )
354+ ) {
353355 $ type = $ minor ? 'minor ' : 'patch ' ;
354356 $ insecure = (bool ) Utils \get_flag_value ( $ assoc_args , 'insecure ' , false );
355357
356- $ items_to_update = self ::get_minor_or_patch_updates ( $ items_to_update , $ type , $ insecure , true );
358+ $ items_to_update = self ::get_minor_or_patch_updates ( $ items_to_update , $ type , $ insecure , true , $ this -> item_type );
357359 }
358360
359361 $ exclude = Utils \get_flag_value ( $ assoc_args , 'exclude ' );
@@ -368,11 +370,10 @@ protected function update_many( $args, $assoc_args ) {
368370 }
369371 unset( $ items_to_update [ $ plugin ->file ] );
370372 } elseif ( 'theme ' === $ this ->item_type ) {
371- $ theme_root = get_theme_root () . ' / ' . $ item ;
372- if ( ! is_dir ( $ theme_root ) ) {
373- continue ;
373+ $ theme = wp_get_theme ( $ item ) ;
374+ if ( $ theme -> exists ( ) ) {
375+ unset( $ items_to_update [ $ theme -> get_stylesheet () ] ) ;
374376 }
375- unset( $ items_to_update [ $ theme_root ] );
376377 }
377378 }
378379 }
@@ -429,8 +430,13 @@ protected function update_many( $args, $assoc_args ) {
429430 $ transient_filter = function ( $ transient ) use ( $ items_to_update ) {
430431 foreach ( $ items_to_update as $ name => $ item_data ) {
431432 if ( isset ( $ transient ->response [ $ name ] ) ) {
432- $ transient ->response [ $ name ]->new_version = $ item_data ['update_version ' ];
433- $ transient ->response [ $ name ]->package = $ item_data ['update_package ' ];
433+ if ( is_object ( $ transient ->response [ $ name ] ) ) {
434+ $ transient ->response [ $ name ]->new_version = $ item_data ['update_version ' ];
435+ $ transient ->response [ $ name ]->package = $ item_data ['update_package ' ];
436+ } else {
437+ $ transient ->response [ $ name ]['new_version ' ] = $ item_data ['update_version ' ];
438+ $ transient ->response [ $ name ]['package ' ] = $ item_data ['update_package ' ];
439+ }
434440 }
435441 }
436442 return $ transient ;
@@ -611,19 +617,27 @@ private function get_color( $status ) {
611617 }
612618
613619 /**
614- * Get the minor or patch version for plugins with available updates
620+ * Get the minor or patch version for plugins and themes with available updates
615621 *
616- * @param array $items Plugins with updates.
622+ * @param array $items Items with updates.
617623 * @param string $type Either 'minor' or 'patch'.
618624 * @param bool $insecure Whether to retry without certificate validation on TLS handshake failure.
619625 * @param bool $require_stable Whether to require stable version when comparing versions.
626+ * @param string $item_type Item type, either 'plugin' or 'theme'.
620627 * @return array
621628 */
622- private function get_minor_or_patch_updates ( $ items , $ type , $ insecure , $ require_stable ) {
629+ private function get_minor_or_patch_updates ( $ items , $ type , $ insecure , $ require_stable, $ item_type ) {
623630 $ wp_org_api = new WpOrgApi ( [ 'insecure ' => $ insecure ] );
624631 foreach ( $ items as $ i => $ item ) {
625632 try {
626- $ data = $ wp_org_api ->get_plugin_info ( $ item ['name ' ] );
633+ $ data = call_user_func (
634+ [ $ wp_org_api , "get_ {$ item_type }_info " ],
635+ $ item ['name ' ],
636+ // The default.
637+ 'en_US ' ,
638+ // We are only interested in the versions field.
639+ [ 'versions ' => true ]
640+ );
627641 } catch ( Exception $ exception ) {
628642 unset( $ items [ $ i ] );
629643 continue ;
0 commit comments