[wp-trac] [WordPress Trac] #51018: PHP Notice thrown when searching for certain terms via the Gutenberg block directory

WordPress Trac noreply at wordpress.org
Wed Aug 19 04:36:36 UTC 2020


#51018: PHP Notice thrown when searching for certain terms via the Gutenberg block
directory
-------------------------------+---------------------
 Reporter:  TwentyZeroTwo      |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  5.5.1
Component:  Editor             |     Version:  5.5
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+---------------------

Comment (by khag7):

 When a call is made to the WordPress.org Plugins API, the response is a
 list of plugins. Each plugin in that array has a property "blocks" which
 includes a 'name' and a 'title' for any blocks. In the offending plugin
 mentioned in this issue, no name and no title are returned. WordPress (the
 software here, not the API) can handle a missing title. But a missing name
 causes errors. **In my opinion this is an issue with the response returned
 from the WordPress.org Plugins API and should be fixed there. If the API
 can't find any registered block names then should it really be returning
 the plugin in the response list?**

 To handle the case where the API returns a block without a name we need to
 handle a poor response:


 {{{

 // First, if blocks doesn't exist or is empty, let's skip it.
 if( ! isset( $plugin['blocks'] ) || empty( $plugin['blocks'] ) ) continue;

 // Second, we can do our reset here to get the first block only.
 $plugin['block'] = reset( $plugin['blocks'] );

 // Last, if the block doesn't have a name or name is empty, we can't show
 this plugin.
 if( ! isset( $plugin['block']['name'] ) || empty( $plugin['block']['name']
 ) ) continue;

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51018#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list