Skip to content

Commit

Permalink
Coding Standards: Use strict comparison for count() calls.
Browse files Browse the repository at this point in the history
See #49542.

git-svn-id: https://develop.svn.wordpress.org/trunk@47848 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed May 23, 2020
1 parent a5baf8b commit 772a11b
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/wp-admin/includes/bookmark.php
Expand Up @@ -198,7 +198,7 @@ function wp_insert_link( $linkdata, $wp_error = false ) {
$link_category = ( ! empty( $parsed_args['link_category'] ) ) ? $parsed_args['link_category'] : array();

// Make sure we set a valid category.
if ( ! is_array( $link_category ) || 0 == count( $link_category ) ) {
if ( ! is_array( $link_category ) || 0 === count( $link_category ) ) {
$link_category = array( get_option( 'default_link_category' ) );
}

Expand Down Expand Up @@ -257,7 +257,7 @@ function wp_insert_link( $linkdata, $wp_error = false ) {
*/
function wp_set_link_cats( $link_id = 0, $link_categories = array() ) {
// If $link_categories isn't already an array, make it one:
if ( ! is_array( $link_categories ) || 0 == count( $link_categories ) ) {
if ( ! is_array( $link_categories ) || 0 === count( $link_categories ) ) {
$link_categories = array( get_option( 'default_link_category' ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/class-wp-upgrader.php
Expand Up @@ -498,7 +498,7 @@ public function install_package( $args = array() ) {
$remote_destination = $wp_filesystem->find_folder( $local_destination );

// Locate which directory to copy to the new folder. This is based on the actual folder holding the files.
if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) {
if ( 1 === count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) {
// Only one folder? Then we want its contents.
$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
} elseif ( count( $source_files ) == 0 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/deprecated.php
Expand Up @@ -1339,7 +1339,7 @@ function wp_dashboard_plugins_output( $rss, $args = array() ) {
// Pick a random, non-installed plugin.
while ( true ) {
// Abort this foreach loop iteration if there's no plugins left of this type.
if ( 0 == count($items) )
if ( 0 === count($items) )
continue 2;

$item_key = array_rand($items);
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/file.php
Expand Up @@ -1627,7 +1627,7 @@ function _unzip_file_pclzip( $file, $to, $needed_dirs = array() ) {
return new WP_Error( 'incompatible_archive', __( 'Incompatible Archive.' ), $archive->errorInfo( true ) );
}

if ( 0 == count( $archive_files ) ) {
if ( 0 === count( $archive_files ) ) {
return new WP_Error( 'empty_archive_pclzip', __( 'Empty archive.' ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/includes/menu.php
Expand Up @@ -168,7 +168,7 @@
* If there is only one submenu and it is has same destination as the parent,
* remove the submenu.
*/
if ( ! empty( $submenu[ $data[2] ] ) && 1 == count( $submenu[ $data[2] ] ) ) {
if ( ! empty( $submenu[ $data[2] ] ) && 1 === count( $submenu[ $data[2] ] ) ) {
$subs = $submenu[ $data[2] ];
$first_sub = reset( $subs );
if ( $data[2] == $first_sub[2] ) {
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/includes/ms.php
Expand Up @@ -856,7 +856,7 @@ function confirm_delete_users( $users ) {
?>
<h1><?php esc_html_e( 'Users' ); ?></h1>

<?php if ( 1 == count( $users ) ) : ?>
<?php if ( 1 === count( $users ) ) : ?>
<p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
<?php else : ?>
<p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
Expand Down Expand Up @@ -974,7 +974,7 @@ function confirm_delete_users( $users ) {
/** This action is documented in wp-admin/users.php */
do_action( 'delete_user_form', $current_user, $allusers );

if ( 1 == count( $users ) ) :
if ( 1 === count( $users ) ) :
?>
<p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
<?php else : ?>
Expand Down
13 changes: 10 additions & 3 deletions src/wp-admin/nav-menus.php
Expand Up @@ -423,12 +423,19 @@

$locations_screen = ( isset( $_GET['action'] ) && 'locations' === $_GET['action'] ) ? true : false;

$page_count = wp_count_posts( 'page' );

/*
* If we have one theme location, and zero menus, we take them right
* into editing their first menu.
*/
$page_count = wp_count_posts( 'page' );
$one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false;
if ( 1 === count( get_registered_nav_menus() ) && ! $add_new_screen
&& empty( $nav_menus ) && ! empty( $page_count->publish )
) {
$one_theme_location_no_menus = true;
} else {
$one_theme_location_no_menus = false;
}

$nav_menus_l10n = array(
'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
Expand Down Expand Up @@ -928,7 +935,7 @@ function wp_nav_menu_max_depth( $classes ) {

<?php
$hide_style = '';
if ( isset( $menu_items ) && 0 == count( $menu_items ) ) {
if ( isset( $menu_items ) && 0 === count( $menu_items ) ) {
$hide_style = 'style="display: none;"';
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/network.php
Expand Up @@ -99,7 +99,7 @@
if ( ! network_domain_check() ) {
$result = populate_network( 1, get_clean_basedomain(), sanitize_email( $_POST['email'] ), wp_unslash( $_POST['sitename'] ), $base, $subdomain_install );
if ( is_wp_error( $result ) ) {
if ( 1 == count( $result->get_error_codes() ) && 'no_wildcard_dns' === $result->get_error_code() ) {
if ( 1 === count( $result->get_error_codes() ) && 'no_wildcard_dns' === $result->get_error_code() ) {
network_step2( $result );
} else {
network_step1( $result );
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/themes.php
Expand Up @@ -285,7 +285,7 @@

/*
// Certain error codes are less fatal than others. We can still display theme information in most cases.
if ( ! $ct->errors() || ( 1 == count( $ct->errors()->get_error_codes() )
if ( ! $ct->errors() || ( 1 === count( $ct->errors()->get_error_codes() )
&& in_array( $ct->errors()->get_error_code(), array( 'theme_no_parent', 'theme_parent_invalid', 'theme_no_index' ) ) ) ) : ?>
*/

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/update-core.php
Expand Up @@ -46,7 +46,7 @@ function list_core_update( $update ) {
$version_string = $update->current;
} elseif ( 'en_US' === $update->locale && $update->packages->partial && $wp_version == $update->partial_version ) {
$updates = get_core_updates();
if ( $updates && 1 == count( $updates ) ) {
if ( $updates && 1 === count( $updates ) ) {
// If the only available update is a partial builds, it doesn't need a language-specific version string.
$version_string = $update->current;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wp-admin/users.php
Expand Up @@ -278,7 +278,7 @@
</div>
<?php endif; ?>

<?php if ( 1 == count( $all_userids ) ) : ?>
<?php if ( 1 === count( $all_userids ) ) : ?>
<p><?php _e( 'You have specified this user for deletion:' ); ?></p>
<?php else : ?>
<p><?php _e( 'You have specified these users for deletion:' ); ?></p>
Expand Down Expand Up @@ -415,7 +415,7 @@
<div class="wrap">
<h1><?php _e( 'Remove Users from Site' ); ?></h1>

<?php if ( 1 == count( $userids ) ) : ?>
<?php if ( 1 === count( $userids ) ) : ?>
<p><?php _e( 'You have specified this user for removal:' ); ?></p>
<?php else : ?>
<p><?php _e( 'You have specified these users for removal:' ); ?></p>
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-user.php
Expand Up @@ -590,7 +590,7 @@ public function remove_role( $role ) {
* @param string $role Role name.
*/
public function set_role( $role ) {
if ( 1 == count( $this->roles ) && current( $this->roles ) == $role ) {
if ( 1 === count( $this->roles ) && current( $this->roles ) == $role ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/formatting.php
Expand Up @@ -406,7 +406,7 @@ function _wptexturize_pushpop_element( $text, &$stack, $disabled_elements ) {
if ( isset( $text[1] ) && '/' !== $text[1] ) {
$opening_tag = true;
$name_offset = 1;
} elseif ( 0 == count( $stack ) ) {
} elseif ( 0 === count( $stack ) ) {
// Stack is empty. Just stop.
return;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/post-template.php
Expand Up @@ -1072,7 +1072,7 @@ function post_custom( $key = '' ) {

if ( ! isset( $custom[ $key ] ) ) {
return false;
} elseif ( 1 == count( $custom[ $key ] ) ) {
} elseif ( 1 === count( $custom[ $key ] ) ) {
return $custom[ $key ][0];
} else {
return $custom[ $key ];
Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/post.php
Expand Up @@ -3709,7 +3709,7 @@ function wp_insert_post( $postarr, $wp_error = false ) {
}

// Make sure we set a valid category.
if ( empty( $post_category ) || 0 == count( $post_category ) || ! is_array( $post_category ) ) {
if ( empty( $post_category ) || 0 === count( $post_category ) || ! is_array( $post_category ) ) {
// 'post' requires at least one category.
if ( 'post' === $post_type && 'auto-draft' !== $post_status ) {
$post_category = array( get_option( 'default_category' ) );
Expand Down Expand Up @@ -4684,7 +4684,7 @@ function wp_set_post_categories( $post_ID = 0, $post_categories = array(), $appe
} else {
$post_categories = array();
}
} elseif ( 1 == count( $post_categories ) && '' === reset( $post_categories ) ) {
} elseif ( 1 === count( $post_categories ) && '' === reset( $post_categories ) ) {
return true;
}

Expand Down Expand Up @@ -5439,7 +5439,7 @@ function get_pages( $args = array() ) {
$where .= $wpdb->prepare( ' AND post_parent = %d ', $parent );
}

if ( 1 == count( $post_status ) ) {
if ( 1 === count( $post_status ) ) {
$where_post_type = $wpdb->prepare( 'post_type = %s AND post_status = %s', $parsed_args['post_type'], reset( $post_status ) );
} else {
$post_status = implode( "', '", $post_status );
Expand Down

0 comments on commit 772a11b

Please sign in to comment.