Changeset 60364 for trunk/src/wp-includes/class-wp-roles.php
- Timestamp:
- 06/29/2025 09:45:30 PM (10 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-roles.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-roles.php
r58975 r60364 144 144 * Updates the list of roles, if the role doesn't already exist. 145 145 * 146 * The capabilities are defined in the following format: `array( 'read' => true )`. 147 * To explicitly deny the role a capability, set the value for that capability to false. 148 * 149 * @since 2.0.0 150 * 151 * @param string $role Role name. 152 * @param string $display_name Role display name. 153 * @param bool[] $capabilities Optional. List of capabilities keyed by the capability name, 154 * e.g. `array( 'edit_posts' => true, 'delete_posts' => false )`. 155 * Default empty array. 146 * The list of capabilities can be passed either as a numerically indexed array of capability names, or an 147 * associative array of boolean values keyed by the capability name. To explicitly deny the role a capability, set 148 * the value for that capability to false. 149 * 150 * Examples: 151 * 152 * // Add a role that can edit posts. 153 * wp_roles()->add_role( 'custom_role', 'Custom Role', array( 154 * 'read', 155 * 'edit_posts', 156 * ) ); 157 * 158 * Or, using an associative array: 159 * 160 * // Add a role that can edit posts but explicitly cannot not delete them. 161 * wp_roles()->add_role( 'custom_role', 'Custom Role', array( 162 * 'read' => true, 163 * 'edit_posts' => true, 164 * 'delete_posts' => false, 165 * ) ); 166 * 167 * @since 2.0.0 168 * @since x.y.z Support was added for a numerically indexed array of strings for the capabilities array. 169 * 170 * @param string $role Role name. 171 * @param string $display_name Role display name. 172 * @param array<string,bool>|array<int,string> $capabilities Capabilities to be added to the role. 173 * Default empty array. 156 174 * @return WP_Role|void WP_Role object, if the role is added. 157 175 */ … … 159 177 if ( empty( $role ) || isset( $this->roles[ $role ] ) ) { 160 178 return; 179 } 180 181 if ( wp_is_numeric_array( $capabilities ) ) { 182 $capabilities = array_fill_keys( $capabilities, true ); 161 183 } 162 184
Note: See TracChangeset
for help on using the changeset viewer.