[wp-trac] [WordPress Trac] #44304: API will create PHP warning and thus break code on empty category

WordPress Trac noreply at wordpress.org
Tue Jun 5 08:35:45 UTC 2018


#44304: API will create PHP warning and thus break code on empty category
--------------------------+-----------------------------
 Reporter:  apermo        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.9.6
 Severity:  minor         |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Example Request


 {{{
 array (size=3)
   'headers' =>
     array (size=)
       'Authorization' => string 'Basic randomstring==' (length=34)
   'body' =>
     array (size=15)
       'title' => string 'Test' (length=4)
       'status' => string 'publish' (length=7)
       'content' => string '' (length=0)
       'date' => string '2018-06-04 17:11:32' (length=19)
       'date_gmt' => string '2018-06-04 15:11:32' (length=19)
       'modified' => string '2018-06-05 10:24:01' (length=19)
       'modified_gmt' => string '2018-06-05 08:24:01' (length=19)
       'excerpt' => string '' (length=0)
       'slug' => string 'test' (length=4)
       'type' => string 'post' (length=4)
       'comment_status' => string 'closed' (length=6)
       'ping_status' => string 'closed' (length=6)
       'sticky' => boolean false
       'categories' => string '' (length=0)
       'tags' => string '' (length=0)
   'method' => string 'POST' (length=4)
 }}}


 This will lead to warnings when Debug is active on the remote node.

 Warning: Invalid argument supplied for foreach() in /path/to/public_html
 /wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php on line
 1256

 I suggest to replace (1251-1253):
 {{{#!php
 <?php
 if ( ! isset( $request[ $base ] ) ) {
         continue;
 }
 }}}

 With:
 {{{#!php
 <?php
 if ( ! isset( $request[ $base ] ) || ! is_array( $request[ $base ] ) ) {
         continue;
 }
 }}}

 This will avoid entering the loop and the warning

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


More information about the wp-trac mailing list