Coding Standards: Replace alias PHP functions with the canonical names.

Using the canonical function name for PHP functions is strongly recommended, as aliases may be deprecated or removed without (much) warning.

This replaces all uses of the following:
* `join()` with `implode()`
* `sizeof()` with `count()`
* `is_writeable()` with `is_writable()`
* `doubleval()` with a `(float)` cast

In part, this is a follow-up to #47746.

Props jrf.
See #50767.

git-svn-id: https://develop.svn.wordpress.org/trunk@49193 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-10-18 17:25:10 +00:00
parent f124a650ba
commit 97b2f07d2e
61 changed files with 115 additions and 115 deletions

View File

@@ -120,7 +120,7 @@ if ( $doaction ) {
$redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
}
if ( $trashed || $spammed ) {
$redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
$redirect_to = add_query_arg( 'ids', implode( ',', $comment_ids ), $redirect_to );
}
wp_safe_redirect( $redirect_to );

View File

@@ -126,7 +126,7 @@ if ( $doaction ) {
$sendback = add_query_arg(
array(
'trashed' => $trashed,
'ids' => join( ',', $post_ids ),
'ids' => implode( ',', $post_ids ),
'locked' => $locked,
),
$sendback
@@ -442,7 +442,7 @@ foreach ( $bulk_counts as $message => $count ) {
}
if ( $messages ) {
echo '<div id="message" class="updated notice is-dismissible"><p>' . join( ' ', $messages ) . '</p></div>';
echo '<div id="message" class="updated notice is-dismissible"><p>' . implode( ' ', $messages ) . '</p></div>';
}
unset( $messages );

View File

@@ -162,7 +162,7 @@ function wp_ajax_ajax_tag_search() {
)
);
echo join( "\n", $results );
echo implode( "\n", $results );
wp_die();
}

View File

@@ -615,7 +615,7 @@ class WP_Comments_List_Table extends WP_List_Table {
if ( ! $the_comment_class ) {
$the_comment_class = '';
}
$the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) );
$the_comment_class = implode( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) );
if ( $comment->comment_post_ID > 0 ) {
$post = get_post( $comment->comment_post_ID );

View File

@@ -291,7 +291,7 @@ function get_cli_args( $param, $required = false ) {
$last_arg = null;
$return = null;
$il = sizeof( $args );
$il = count( $args );
for ( $i = 1, $il; $i < $il; $i++ ) {
if ( (bool) preg_match( '/^--(.+)/', $args[ $i ], $match ) ) {

View File

@@ -976,7 +976,7 @@ class WP_List_Table {
if ( ! empty( $infinite_scroll ) ) {
$pagination_links_class .= ' hide-if-js';
}
$output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
$output .= "\n<span class='$pagination_links_class'>" . implode( "\n", $page_links ) . '</span>';
if ( $total_pages ) {
$page_class = $total_pages < 2 ? ' one-page' : '';
@@ -1242,7 +1242,7 @@ class WP_List_Table {
$id = $with_id ? "id='$column_key'" : '';
if ( ! empty( $class ) ) {
$class = "class='" . join( ' ', $class ) . "'";
$class = "class='" . implode( ' ', $class ) . "'";
}
echo "<$tag $scope $id $class>$column_display_name</$tag>";

View File

@@ -614,7 +614,7 @@ class WP_Media_List_Table extends WP_List_Table {
);
}
/* translators: Used between list items, there is a space after the comma. */
echo join( __( ', ' ), $out );
echo implode( __( ', ' ), $out );
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . get_taxonomy( $taxonomy )->labels->no_terms . '</span>';
}

View File

@@ -1219,7 +1219,7 @@ class WP_Posts_List_Table extends WP_List_Table {
$term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );
/* translators: Used between list items, there is a space after the comma. */
echo join( __( ', ' ), $term_links );
echo implode( __( ', ' ), $term_links );
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
}

View File

@@ -1855,7 +1855,7 @@ class WP_Site_Health {
$hosts = explode( ',', WP_ACCESSIBLE_HOSTS );
}
if ( $blocked && 0 === sizeof( $hosts ) ) {
if ( $blocked && 0 === count( $hosts ) ) {
$result['status'] = 'critical';
$result['label'] = __( 'HTTP requests are blocked' );
@@ -1870,7 +1870,7 @@ class WP_Site_Health {
);
}
if ( $blocked && 0 < sizeof( $hosts ) ) {
if ( $blocked && 0 < count( $hosts ) ) {
$result['status'] = 'recommended';
$result['label'] = __( 'HTTP requests are partially blocked' );

View File

@@ -534,7 +534,7 @@ function export_wp( $args = array() ) {
// Fetch 20 posts at a time rather than loading the entire table into memory.
while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
$where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
$where = 'WHERE ID IN (' . implode( ',', $next_posts ) . ')';
$posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
// Begin Loop.

View File

@@ -489,7 +489,7 @@ function wp_edit_theme_plugin_file( $args ) {
$previous_content = file_get_contents( $real_file );
if ( ! is_writeable( $real_file ) ) {
if ( ! is_writable( $real_file ) ) {
return new WP_Error( 'file_not_writable' );
}

View File

@@ -1118,7 +1118,7 @@ function image_align_input_fields( $post, $checked = '' ) {
" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
}
return join( "\n", $out );
return implode( "\n", $out );
}
/**
@@ -1195,7 +1195,7 @@ function image_size_input_fields( $post, $check = '' ) {
return array(
'label' => __( 'Size' ),
'input' => 'html',
'html' => join( "\n", $out ),
'html' => implode( "\n", $out ),
);
}
@@ -1424,7 +1424,7 @@ function get_attachment_fields_to_edit( $post, $errors = null ) {
$values[] = $term->slug;
}
$t['value'] = join( ', ', $values );
$t['value'] = implode( ', ', $values );
$form_fields[ $taxonomy ] = $t;
}
@@ -1784,7 +1784,7 @@ function get_media_item( $attachment_id, $args = null ) {
}
if ( ! empty( $field['helps'] ) ) {
$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
}
$item .= "</td>\n\t\t</tr>\n";
@@ -1883,7 +1883,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
$values[] = $term->slug;
}
$t['value'] = join( ', ', $values );
$t['value'] = implode( ', ', $values );
$t['taxonomy'] = true;
$form_fields[ $taxonomy ] = $t;
@@ -1976,7 +1976,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
}
if ( ! empty( $field['helps'] ) ) {
$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
}
$item .= "</td>\n\t\t</tr>\n";

View File

@@ -121,7 +121,7 @@ function insert_with_markers( $filename, $marker, $insertion ) {
if ( $perms ) {
chmod( $filename, $perms | 0644 );
}
} elseif ( ! is_writeable( $filename ) ) {
} elseif ( ! is_writable( $filename ) ) {
return false;
}

View File

@@ -275,7 +275,7 @@ function wp_prepare_revisions_for_js( $post, $selected_revision_id, $from = null
* If we only have one revision, the initial revision is missing; This happens
* when we have an autsosave and the user has clicked 'View the Autosave'
*/
if ( 1 === sizeof( $revisions ) ) {
if ( 1 === count( $revisions ) ) {
$revisions[ $post->ID ] = array(
'id' => $post->ID,
'title' => get_the_title( $post->ID ),

View File

@@ -278,7 +278,7 @@ function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$term_names[] = $term->name;
}
$terms_to_edit = esc_attr( join( ',', $term_names ) );
$terms_to_edit = esc_attr( implode( ',', $term_names ) );
/**
* Filters the comma-separated list of terms available to edit.

View File

@@ -1112,7 +1112,7 @@ function upgrade_130() {
$limit = $option->dupes - 1;
$dupe_ids = $wpdb->get_col( $wpdb->prepare( "SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit ) );
if ( $dupe_ids ) {
$dupe_ids = join( ',', $dupe_ids );
$dupe_ids = implode( ',', $dupe_ids );
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)" );
}
}

View File

@@ -60,7 +60,7 @@ switch ( $action ) {
wp_redirect( $this_file );
exit;
}
$all_links = join( ',', $linkcheck );
$all_links = implode( ',', $linkcheck );
/*
* Should now have an array of links we can change:
* $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");

View File

@@ -106,7 +106,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
$class[] = esc_attr( $item[4] );
}
$class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
$class = $class ? ' class="' . implode( ' ', $class ) . '"' : '';
$id = ! empty( $item[5] ) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : '';
$img = '';
$img_style = '';
@@ -240,7 +240,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
$class[] = esc_attr( $sub_item[4] );
}
$class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
$class = $class ? ' class="' . implode( ' ', $class ) . '"' : '';
$menu_hook = get_plugin_page_hook( $sub_item[2], $item[2] );
$sub_file = $sub_item[2];

View File

@@ -89,7 +89,7 @@ if ( $action ) {
echo '<div class="wrap">';
echo '<h1>' . esc_html( $title ) . '</h1>';
$url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( join( ',', $themes ) ) );
$url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( implode( ',', $themes ) ) );
$url = wp_nonce_url( $url, 'bulk-update-themes' );
echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";

View File

@@ -195,7 +195,7 @@ $content = esc_textarea( $content );
<h2>
<?php
if ( is_plugin_active( $plugin ) ) {
if ( is_writeable( $real_file ) ) {
if ( is_writable( $real_file ) ) {
/* translators: %s: Plugin file name. */
printf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
} else {
@@ -203,7 +203,7 @@ $content = esc_textarea( $content );
printf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
}
} else {
if ( is_writeable( $real_file ) ) {
if ( is_writable( $real_file ) ) {
/* translators: %s: Plugin file name. */
printf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
} else {
@@ -275,7 +275,7 @@ $content = esc_textarea( $content );
</div>
<?php endif; ?>
<?php if ( is_writeable( $real_file ) ) : ?>
<?php if ( is_writable( $real_file ) ) : ?>
<div class="editor-notices">
<?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) ) { ?>
<div class="notice notice-warning inline active-plugin-edit-warning">

View File

@@ -162,7 +162,7 @@ if ( $action ) {
echo '<div class="wrap">';
echo '<h1>' . esc_html( $title ) . '</h1>';
$url = self_admin_url( 'update.php?action=update-selected&amp;plugins=' . urlencode( join( ',', $plugins ) ) );
$url = self_admin_url( 'update.php?action=update-selected&amp;plugins=' . urlencode( implode( ',', $plugins ) ) );
$url = wp_nonce_url( $url, 'bulk-update-plugins' );
echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";

View File

@@ -301,7 +301,7 @@ else :
<?php if ( is_child_theme() && $theme->get_stylesheet() === get_template() ) : ?>
<div class="notice notice-warning inline">
<p>
<?php if ( is_writeable( $file ) ) : ?>
<?php if ( is_writable( $file ) ) : ?>
<strong><?php _e( 'Caution:' ); ?></strong>
<?php endif; ?>
<?php _e( 'This is a file in your current parent theme.' ); ?>
@@ -309,7 +309,7 @@ else :
</div>
<?php endif; ?>
</div>
<?php if ( is_writeable( $file ) ) : ?>
<?php if ( is_writable( $file ) ) : ?>
<p class="submit">
<?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?>
<span class="spinner"></span>

View File

@@ -162,7 +162,7 @@ if ( $doaction ) {
$location = add_query_arg(
array(
'trashed' => count( $post_ids ),
'ids' => join( ',', $post_ids ),
'ids' => implode( ',', $post_ids ),
),
$location
);