[wp-trac] [WordPress Trac] #45197: Introduce `user_can_for_blog()`

WordPress Trac noreply at wordpress.org
Mon Jul 8 21:27:06 UTC 2024


#45197: Introduce `user_can_for_blog()`
-------------------------------------------------+-------------------------
 Reporter:  johnbillion                          |       Owner:
                                                 |  johnbillion
     Type:  enhancement                          |      Status:  reviewing
 Priority:  normal                               |   Milestone:  6.7
Component:  Role/Capability                      |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:  multisite
  testing has-testing-info                       |
-------------------------------------------------+-------------------------
Changes (by rajinsharwar):

 * keywords:  has-patch has-unit-tests needs-testing needs-testing-info =>
     has-patch has-unit-tests needs-testing has-testing-info


Comment:

 Yeah, maybe some code testing info might be helpful!

 So this is a new function, especially useful for multisites. Used to check
 if a current user can a particular capability in a particular site in the
 network.

 Testing instructions:
 1. Make sure you are in a multisite environment and have more than one
 subsite. Let's say, you have a editor user with an ID of 2 in your subsite
 1. And another subscriber user with an ID of 3, in your subsite 2.
 2. In the functions.php of your active theme on your main site, add this
 code:
 {{{#!php

 error_log('User Capability for Editor User ID 2, in subsite ID 1: ' .
 user_can_for_blog( 2, 1, 'delete_pages' ) );
 error_log('User Capability for Subscriber User ID 3, in subsite ID 1: ' .
 user_can_for_blog( 3, 1, 'delete_pages' ) );

 error_log('User Capability for False cap User ID 2, in subsite ID 1: ' .
 user_can_for_blog( 2, 1, 'foo_bar' ) );
 error_log('Read User Capability for Subscriber User ID 3, in subsite ID 1:
 ' . user_can_for_blog( 3, 1, 'read' ) );

 }}}

 Here the:
 "User Capability for Editor User ID 2, in subsite ID 1" should be
 **true**.
 "User Capability for Subscriber User ID 3, in subsite ID 1" should be
 **false**.
 "User Capability for False cap User ID 2, in subsite ID 1" should be
 **false**.
 "Read User Capability for Subscriber User ID 3" should be **true**.

 Feel free to add/edit this @oglekler or anyone working on this ticket if
 you feel. 🙂

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


More information about the wp-trac mailing list