[wp-trac] [WordPress Trac] #48415: Calling current_user_can( 'publish_post' ) results in Notice on 5.3-RC2-46574

WordPress Trac noreply at wordpress.org
Wed Oct 23 23:50:22 UTC 2019


#48415: Calling current_user_can( 'publish_post' ) results in Notice on
5.3-RC2-46574
----------------------------+---------------------
 Reporter:  johnstonphilip  |       Owner:  (none)
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  5.3
Component:  Users           |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  close           |     Focuses:
----------------------------+---------------------
Changes (by SergeyBiryukov):

 * keywords:  needs-patch => close


Comment:

 Hi there, thanks for the ticket!

 The spread operator was added in [45622], however it seems unrelated to
 the issue, I can reproduce it on 5.2.4 as well.

 If you need to check 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 need to check 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.

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


More information about the wp-trac mailing list