Coding Standards: Use strict comparison in `wp-includes/capabilities.php`.

Follow-up to [2703], [3297], [3513], [6697], [14189], [25177], [27390], [38378], [38698], [39588], [48356], [48664].

Props aristath, poena, afercia, SergeyBiryukov.
See #61607.
Built from https://develop.svn.wordpress.org/trunk@58998


git-svn-id: http://core.svn.wordpress.org/trunk@58394 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2024-09-08 19:18:17 +00:00
parent 35b7340af9
commit 11f8d8ec2b
2 changed files with 11 additions and 9 deletions

View File

@ -47,7 +47,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
switch ( $cap ) { switch ( $cap ) {
case 'remove_user': case 'remove_user':
// In multisite the user must be a super admin to remove themselves. // In multisite the user must be a super admin to remove themselves.
if ( isset( $args[0] ) && $user_id == $args[0] && ! is_super_admin( $user_id ) ) { if ( isset( $args[0] ) && $user_id === (int) $args[0] && ! is_super_admin( $user_id ) ) {
$caps[] = 'do_not_allow'; $caps[] = 'do_not_allow';
} else { } else {
$caps[] = 'remove_users'; $caps[] = 'remove_users';
@ -60,7 +60,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
case 'edit_user': case 'edit_user':
case 'edit_users': case 'edit_users':
// Allow user to edit themselves. // Allow user to edit themselves.
if ( 'edit_user' === $cap && isset( $args[0] ) && $user_id == $args[0] ) { if ( 'edit_user' === $cap && isset( $args[0] ) && $user_id === (int) $args[0] ) {
break; break;
} }
@ -103,7 +103,9 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
break; break;
} }
if ( ( get_option( 'page_for_posts' ) == $post->ID ) || ( get_option( 'page_on_front' ) == $post->ID ) ) { if ( (int) get_option( 'page_for_posts' ) === $post->ID
|| (int) get_option( 'page_on_front' ) === $post->ID
) {
$caps[] = 'manage_options'; $caps[] = 'manage_options';
break; break;
} }
@ -137,7 +139,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
} }
// If the post author is set and the user is the author... // If the post author is set and the user is the author...
if ( $post->post_author && $user_id == $post->post_author ) { if ( $post->post_author && $user_id === (int) $post->post_author ) {
// If the post is published or scheduled... // If the post is published or scheduled...
if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) {
$caps[] = $post_type->cap->delete_published_posts; $caps[] = $post_type->cap->delete_published_posts;
@ -240,7 +242,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
} }
// If the post author is set and the user is the author... // If the post author is set and the user is the author...
if ( $post->post_author && $user_id == $post->post_author ) { if ( $post->post_author && $user_id === (int) $post->post_author ) {
// If the post is published or scheduled... // If the post is published or scheduled...
if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) { if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) {
$caps[] = $post_type->cap->edit_published_posts; $caps[] = $post_type->cap->edit_published_posts;
@ -362,7 +364,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
break; break;
} }
if ( $post->post_author && $user_id == $post->post_author ) { if ( $post->post_author && $user_id === (int) $post->post_author ) {
$caps[] = $post_type->cap->read; $caps[] = $post_type->cap->read;
} elseif ( $status_obj->private ) { } elseif ( $status_obj->private ) {
$caps[] = $post_type->cap->read_private_posts; $caps[] = $post_type->cap->read_private_posts;
@ -730,8 +732,8 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
} }
if ( 'delete_term' === $cap if ( 'delete_term' === $cap
&& ( get_option( 'default_' . $term->taxonomy ) == $term->term_id && ( (int) get_option( 'default_' . $term->taxonomy ) === $term->term_id
|| get_option( 'default_term_' . $term->taxonomy ) == $term->term_id ) || (int) get_option( 'default_term_' . $term->taxonomy ) === $term->term_id )
) { ) {
$caps[] = 'do_not_allow'; $caps[] = 'do_not_allow';
break; break;

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.7-alpha-58997'; $wp_version = '6.7-alpha-58998';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.