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

WordPress Trac noreply at wordpress.org
Fri Sep 11 11:36:20 UTC 2020


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

 * keywords:  reporter-feedback 2nd-opinion => needs-patch
 * milestone:  Awaiting Review => 5.6


Comment:

 Previously: #13905, #23377, #30821, #48415.

 [34113] / #13905 added some sanity checks, but they're not preventing the
 notice.

 As noted in comment:2:ticket:48415:
 > If you're checking whether the current user can publish posts in
 general, `current_user_can( 'publish_posts' )` should be used (note the
 plural `posts`), which does not require a post ID.
 >
 > If you're checking whether they can publish a particular post,
 `current_user_can( 'publish_post', $post_id )` should be used, which does
 require a post ID.
 >
 > Checking `current_user_can( 'publish_post' )` without passing in a post
 ID seems like a developer error, so the notice is legitimate.

 Replying to [comment:3 mattheweppelsheimer]:
 > I would argue, however, that this is an area where Core could be made
 friendlier to plugin/theme developers by going ahead and adding those
 guards.
 >
 > One might also argue against adding these guards because they might
 obscure underlying issues. So I would propose to use `_doing_it_wrong()`
 and `WP_Error` where appropriate.

 Yes, I think a `_doing_it_wrong()` notice similar to the ones added in
 [34091] or [47178] would be a better experience here. Let's add that :)

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


More information about the wp-trac mailing list