mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-09-03 23:50:20 +00:00
Coding Standards: Use strict type check for in_array() and array_search() where strings are involved.
This reduces the number of `WordPress.PHP.StrictInArray.MissingTrueStrict` issues from 486 to 50. Includes minor code layout fixes for better readability. See #49542. git-svn-id: https://develop.svn.wordpress.org/trunk@47550 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -493,7 +493,7 @@ function twentyeleven_layout_classes( $existing_classes ) {
|
||||
$options = twentyeleven_get_theme_options();
|
||||
$current_layout = $options['theme_layout'];
|
||||
|
||||
if ( in_array( $current_layout, array( 'content-sidebar', 'sidebar-content' ) ) ) {
|
||||
if ( in_array( $current_layout, array( 'content-sidebar', 'sidebar-content' ), true ) ) {
|
||||
$classes = array( 'two-column' );
|
||||
} else {
|
||||
$classes = array( 'one-column' );
|
||||
|
||||
@@ -61,7 +61,7 @@ if ( ! function_exists( 'twentyfifteen_entry_meta' ) ) :
|
||||
);
|
||||
}
|
||||
|
||||
if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
|
||||
if ( in_array( get_post_type(), array( 'post', 'attachment' ), true ) ) {
|
||||
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
|
||||
|
||||
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</a>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div><!-- .entry-meta -->
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<?php twentyfourteen_post_thumbnail(); ?>
|
||||
|
||||
<header class="entry-header">
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ) ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<?php if ( in_array( 'category', get_object_taxonomies( get_post_type() ), true ) && twentyfourteen_categorized_blog() ) : ?>
|
||||
<div class="entry-meta">
|
||||
<span class="cat-links"><?php echo get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfourteen' ) ); ?></span>
|
||||
</div>
|
||||
|
||||
@@ -544,7 +544,7 @@ function twentyfourteen_body_classes( $classes ) {
|
||||
|
||||
if ( get_header_image() ) {
|
||||
$classes[] = 'header-image';
|
||||
} elseif ( ! in_array( $GLOBALS['pagenow'], array( 'wp-activate.php', 'wp-signup.php' ) ) ) {
|
||||
} elseif ( ! in_array( $GLOBALS['pagenow'], array( 'wp-activate.php', 'wp-signup.php' ), true ) ) {
|
||||
$classes[] = 'masthead-fixed';
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ function twentyfourteen_customize_partial_blogdescription() {
|
||||
* @return string Filtered layout type (grid|slider).
|
||||
*/
|
||||
function twentyfourteen_sanitize_layout( $layout ) {
|
||||
if ( ! in_array( $layout, array( 'grid', 'slider' ) ) ) {
|
||||
if ( ! in_array( $layout, array( 'grid', 'slider' ), true ) ) {
|
||||
$layout = 'grid';
|
||||
}
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ class Featured_Content {
|
||||
}
|
||||
|
||||
// We only want to hide the featured tag.
|
||||
if ( ! in_array( 'post_tag', $taxonomies ) ) {
|
||||
if ( ! in_array( 'post_tag', $taxonomies, true ) ) {
|
||||
return $terms;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,11 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
|
||||
* @param array $instance An array of settings for this widget instance.
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
$format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside';
|
||||
$format = isset( $instance['format'] ) ? $instance['format'] : '';
|
||||
|
||||
if ( ! $format || ! in_array( $format, $this->formats, true ) ) {
|
||||
$format = 'aside';
|
||||
}
|
||||
|
||||
switch ( $format ) {
|
||||
case 'image':
|
||||
@@ -105,8 +109,9 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
|
||||
break;
|
||||
}
|
||||
|
||||
$number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] );
|
||||
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? $format_string : $instance['title'], $instance, $this->id_base );
|
||||
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 2;
|
||||
$title = ! empty( $instance['title'] ) ? $instance['title'] : $format_string;
|
||||
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
|
||||
|
||||
$ephemera = new WP_Query(
|
||||
array(
|
||||
@@ -265,7 +270,8 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
|
||||
function update( $new_instance, $instance ) {
|
||||
$instance['title'] = strip_tags( $new_instance['title'] );
|
||||
$instance['number'] = empty( $new_instance['number'] ) ? 2 : absint( $new_instance['number'] );
|
||||
if ( in_array( $new_instance['format'], $this->formats ) ) {
|
||||
|
||||
if ( in_array( $new_instance['format'], $this->formats, true ) ) {
|
||||
$instance['format'] = $new_instance['format'];
|
||||
}
|
||||
|
||||
@@ -280,9 +286,13 @@ class Twenty_Fourteen_Ephemera_Widget extends WP_Widget {
|
||||
* @param array $instance
|
||||
*/
|
||||
function form( $instance ) {
|
||||
$title = empty( $instance['title'] ) ? '' : esc_attr( $instance['title'] );
|
||||
$number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] );
|
||||
$format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside';
|
||||
$title = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
|
||||
$number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 2;
|
||||
$format = isset( $instance['format'] ) ? $instance['format'] : '';
|
||||
|
||||
if ( ! $format || ! in_array( $format, $this->formats, true ) ) {
|
||||
$format = 'aside';
|
||||
}
|
||||
?>
|
||||
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'twentyfourteen' ); ?></label>
|
||||
<input id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>"></p>
|
||||
|
||||
@@ -165,7 +165,7 @@ add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
|
||||
function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
|
||||
|
||||
// Add [aria-haspopup] and [aria-expanded] to menu items that have children.
|
||||
$item_has_children = in_array( 'menu-item-has-children', $item->classes );
|
||||
$item_has_children = in_array( 'menu-item-has-children', $item->classes, true );
|
||||
if ( $item_has_children ) {
|
||||
$atts['aria-haspopup'] = 'true';
|
||||
$atts['aria-expanded'] = 'false';
|
||||
|
||||
@@ -29,7 +29,7 @@ if ( ! function_exists( 'twentysixteen_entry_meta' ) ) :
|
||||
);
|
||||
}
|
||||
|
||||
if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) {
|
||||
if ( in_array( get_post_type(), array( 'post', 'attachment' ), true ) ) {
|
||||
twentysixteen_entry_date();
|
||||
}
|
||||
|
||||
|
||||
@@ -578,7 +578,7 @@ function twentytwelve_body_class( $classes ) {
|
||||
if ( empty( $background_image ) ) {
|
||||
if ( empty( $background_color ) ) {
|
||||
$classes[] = 'custom-background-empty';
|
||||
} elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) {
|
||||
} elseif ( in_array( $background_color, array( 'fff', 'ffffff' ), true ) ) {
|
||||
$classes[] = 'custom-background-white';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user