[wp-trac] [WordPress Trac] #45197: Introduce `user_can_for_blog()`
WordPress Trac
noreply at wordpress.org
Wed Sep 18 00:02:00 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 |
-------------------------------------------------+-------------------------
Comment (by n8finch):
Just tested this patch manually, and things look good, as expected 👍.
== Testing Instructions and Steps to Test
1. I applied the patch to a local WordPress multisite installation.
2. I created 2 subsites and a user for each of of those subsites, one with
Editor permissions and one with Author permissions.
3. Then I added the following code to the active theme's functions.php
file and refreshed the page:
{{{#!php
<?php
echo 'Super Admin User:</br>';
echo 'manage_sites Capability for Super Admin User ID 1, in subsite ID 1:
' . var_export( user_can_for_blog( 1, 1, 'manage_sites' ), true ) .
'<br>';
echo 'delete_posts Capability for Super Admin User ID 1, in subsite ID 2:
' . var_export( user_can_for_blog( 1, 2, 'delete_posts' ), true ) .
'<br>';
echo 'edit_posts Capability for Super Admin User ID 1, in subsite ID 3: '
. var_export( user_can_for_blog( 1, 3, 'edit_posts' ), true ) . '<br>';
echo '</br>';
echo 'Editor on subsite 2:</br>';
echo 'manage_sites Capability for Editor User ID 4, in subsite ID 1: ' .
var_export( user_can_for_blog( 4, 1, 'manage_sites' ), true ) . '<br>';
echo 'delete_others_pages Capability for Editor User ID 4, in subsite ID
2: ' . var_export( user_can_for_blog( 5, 2, 'delete_others_pages' ), true
) . '<br>';
echo 'edit_posts Capability for Editor User ID 5, in subsite ID 2: ' .
var_export( user_can_for_blog( 5, 2, 'edit_posts' ), true ) . '<br>';
echo 'edit_posts Capability for Editor User ID 5, in subsite ID 3: ' .
var_export( user_can_for_blog( 5, 3, 'edit_posts' ), true ) . '<br>';
echo '</br>';
echo 'Author on subsite 3:</br>';
echo 'delete_posts Capability for False cap User ID 4, in subsite ID 2: '
. var_export( user_can_for_blog( 4, 2, 'delete_posts' ), true ) . '<br>';
echo 'edit_posts Capability for Subscriber User ID 4, in subsite ID 3: ' .
var_export( user_can_for_blog( 4, 3, 'edit_posts' ), true ) . '<br>';
wp_die();
}}}
=== ✅ Results are as expected!:
{{{
Super Admin User:
manage_sites Capability for Super Admin User ID 1, in subsite ID 1: true
delete_posts Capability for Super Admin User ID 1, in subsite ID 2: true
edit_posts Capability for Super Admin User ID 1, in subsite ID 3: true
Editor on subsite 2:
manage_sites Capability for Editor User ID 4, in subsite ID 1: false
delete_others_pages Capability for Editor User ID 4, in subsite ID 2: true
edit_posts Capability for Editor User ID 5, in subsite ID 2: true
edit_posts Capability for Editor User ID 5, in subsite ID 3: false
Author on subsite 3:
delete_posts Capability for False cap User ID 4, in subsite ID 2: false
edit_posts Capability for Subscriber User ID 4, in subsite ID 3: true
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45197#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list