[wp-trac] [WordPress Trac] #44591: PHP notice if optional argument isn't passed to map_meta_cap()

WordPress Trac noreply at wordpress.org
Sat Oct 10 18:25:28 UTC 2020


#44591: PHP notice if optional argument isn't passed to map_meta_cap()
--------------------------+-----------------------------
 Reporter:  henry.wright  |       Owner:  SergeyBiryukov
     Type:  defect (bug)  |      Status:  accepted
 Priority:  normal        |   Milestone:  5.6
Component:  Users         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+-----------------------------

Comment (by SergeyBiryukov):

 Replying to [comment:9 henry.wright]:
 > I disagree with `_doing_it_wrong`. My reasoning is the argument is
 **optional**. Optional indicates the function should be callable without
 passing a third argument

 Although the `$args` parameter is optional for the `map_meta_cap()`
 function, it's not really optional for some particular checks that do
 require an object ID (as noted in comment:23:ticket:50913):

 * `current_user_can( 'delete_post', $post_id )`
 * `current_user_can( 'edit_post', $post_id )`
 * `current_user_can( 'read_post', $post_id )`
 * `current_user_can( 'publish_post', $post_id )`
 * `current_user_can( 'edit_comment', $comment_id )`
 * etc.

 These all require a post ID to check, and will cause a PHP notice if the
 ID is not provided. Performing these checks without passing in a post ID
 (or a comment ID, in case of `edit_comment`) is a developer error, so I
 think a `_doing_it_wrong()` notice here would be the most appropriate way
 to notify the developer or site owner that something is wrong and doesn't
 work as expected.

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


More information about the wp-trac mailing list