[wp-trac] [WordPress Trac] #60065: Update Icons Retrieval in update-core.php for Plugin Updates

WordPress Trac noreply at wordpress.org
Thu Dec 14 00:49:57 UTC 2023


#60065: Update Icons Retrieval in update-core.php for Plugin Updates
-------------------------+-------------------------------------------------
 Reporter:  tomsnunes    |      Owner:  tomsnunes
     Type:  defect       |     Status:  assigned
  (bug)                  |
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  6.4.2
 Severity:  major        |   Keywords:  has-patch has-dev-note needs-
  Focuses:               |  testing
-------------------------+-------------------------------------------------
 WordPress version 6.4.2 seems to have a bug that is not allowing plugins
 to be listed on wp-admin/update-core.php page.

 Apache Error Log

 {{{
 [proxy_fcgi:error] [pid 470:tid 140131151341120] [client
 2804:90:4000:f275:4145:c03f:530:4536:0] AH01071: Got error 'PHP message:
 PHP Fatal error:  Uncaught Error: Cannot use object of type stdClass as
 array in /var/www/site/wordpress/wp-admin/update-core.php:520\nStack
 trace:\n#0 /var/www/site/wordpress/wp-admin/update-core.php(1118):
 list_plugin_updates()\n#1 {main}\n  thrown in /var/www/site/wordpress/wp-
 admin/update-core.php on line 520', referer: https://site/wp-admin/update-
 core.php
 }}}


 The error message indicates that there is an issue in the update-core.php
 file at line 520. The specific error is "Cannot use object of type
 stdClass as array." This suggests that there is an attempt to use an
 object as if it were an array on that line.

 Looking at the provided code snippet, the relevant part is:
 {{{#!php
 <?php
 $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file,
 (array) $plugin_data, false, true );
 }}}


 Here, $plugin_data is being cast to an object using (object).

 Later in the code, you are trying to access properties of $plugin_data as
 if it were an array:
 {{{#!php
 <?php
 $icon = '<img src="' . esc_url( $plugin_data->update->icons[
 $preferred_icon ] ) . '" alt="" />';
 }}}


 If update is supposed to be an array and not an object, you might want to
 adjust how $plugin_data is handled.

 Here's a modified version that assumes $plugin_data->update is an array:
 {{{#!php
 <?php
 $plugin_data = (object) _get_plugin_data_markup_translate( $plugin_file,
 (array) $plugin_data, false, true );

 $icon            = '<span class="dashicons dashicons-admin-
 plugins"></span>';
 $preferred_icons = array( 'svg', '2x', '1x', 'default' );

 // Assuming $plugin_data->update is an array
 $update_icons = (array) $plugin_data->update;

 foreach ( $preferred_icons as $preferred_icon ) {
     if ( ! empty( $update_icons[ $preferred_icon ] ) ) {
         $icon = '<img src="' . esc_url( $update_icons[ $preferred_icon ] )
 . '" alt="" />';
         break;
     }
 }
 }}}

 This modification ensures that $plugin_data->update is cast to an array
 before trying to access its elements.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60065>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list