For clarity, initialize some arrays that previously were only assigned via short circuit in loops.

See #30799.

Built from https://develop.svn.wordpress.org/trunk@30982


git-svn-id: http://core.svn.wordpress.org/trunk@30968 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-12-20 22:47:22 +00:00
parent 2dbd0d0a8f
commit 5eb5afac34
15 changed files with 56 additions and 25 deletions

View File

@ -1252,7 +1252,7 @@ add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items');
*/ */
function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) { function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) {
$unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish' ) ); $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish' ) );
$messages = array();
$menu_items = array(); $menu_items = array();
// Index menu items by db ID // Index menu items by db ID
foreach ( $unsorted_menu_items as $_item ) foreach ( $unsorted_menu_items as $_item )

View File

@ -301,11 +301,14 @@ function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $ech
function wp_link_category_checklist( $link_id = 0 ) { function wp_link_category_checklist( $link_id = 0 ) {
$default = 1; $default = 1;
$checked_categories = array();
if ( $link_id ) { if ( $link_id ) {
$checked_categories = wp_get_link_cats( $link_id ); $checked_categories = wp_get_link_cats( $link_id );
// No selected categories, strange // No selected categories, strange
if ( ! count( $checked_categories ) ) if ( ! count( $checked_categories ) ) {
$checked_categories[] = $default; $checked_categories[] = $default;
}
} else { } else {
$checked_categories[] = $default; $checked_categories[] = $default;
} }

View File

@ -430,6 +430,9 @@ function wp_prepare_themes_for_js( $themes = null ) {
} }
WP_Theme::sort_by_name( $themes ); WP_Theme::sort_by_name( $themes );
$parents = array();
foreach ( $themes as $theme ) { foreach ( $themes as $theme ) {
$slug = $theme->get_stylesheet(); $slug = $theme->get_stylesheet();
$encoded_slug = urlencode( $slug ); $encoded_slug = urlencode( $slug );
@ -469,7 +472,7 @@ function wp_prepare_themes_for_js( $themes = null ) {
} }
// Remove 'delete' action if theme has an active child // Remove 'delete' action if theme has an active child
if ( isset( $parents ) && array_key_exists( $current_theme, $parents ) ) { if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) {
unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] ); unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] );
} }

View File

@ -1786,7 +1786,7 @@ function dbDelta( $queries = '', $execute = true ) {
if ($tableindices) { if ($tableindices) {
// Clear the index array. // Clear the index array.
unset($index_ary); $index_ary = array();
// For every index in the table. // For every index in the table.
foreach ($tableindices as $tableindex) { foreach ($tableindices as $tableindex) {

View File

@ -1289,11 +1289,14 @@ function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = ''
if ( empty( $terms ) ) if ( empty( $terms ) )
return false; return false;
$links = array();
foreach ( $terms as $term ) { foreach ( $terms as $term ) {
$link = get_term_link( $term, $taxonomy ); $link = get_term_link( $term, $taxonomy );
if ( is_wp_error( $link ) ) if ( is_wp_error( $link ) ) {
return $link; return $link;
$term_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; }
$links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
} }
/** /**
@ -1304,9 +1307,9 @@ function get_the_term_list( $id, $taxonomy, $before = '', $sep = '', $after = ''
* *
* @since 2.5.0 * @since 2.5.0
* *
* @param array $term_links An array of term links. * @param array $links An array of term links.
*/ */
$term_links = apply_filters( "term_links-$taxonomy", $term_links ); $term_links = apply_filters( "term_links-$taxonomy", $links );
return $before . join( $sep, $term_links ) . $after; return $before . join( $sep, $term_links ) . $after;
} }

View File

@ -1266,6 +1266,7 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
} }
public function update( $new_instance, $old_instance ) { public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['title'] = strip_tags(stripslashes($new_instance['title']));
$instance['taxonomy'] = stripslashes($new_instance['taxonomy']); $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
return $instance; return $instance;

View File

@ -1022,6 +1022,7 @@ function remove_accents($string) {
$string = strtr($string, $chars); $string = strtr($string, $chars);
} else { } else {
$chars = array();
// Assume ISO-8859-1 if not UTF-8 // Assume ISO-8859-1 if not UTF-8
$chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158) $chars['in'] = chr(128).chr(131).chr(138).chr(142).chr(154).chr(158)
.chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194) .chr(159).chr(162).chr(165).chr(181).chr(192).chr(193).chr(194)
@ -1037,6 +1038,7 @@ function remove_accents($string) {
$chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy"; $chars['out'] = "EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy";
$string = strtr($string, $chars['in'], $chars['out']); $string = strtr($string, $chars['in'], $chars['out']);
$double_chars = array();
$double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254)); $double_chars['in'] = array(chr(140), chr(156), chr(198), chr(208), chr(222), chr(223), chr(230), chr(240), chr(254));
$double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th'); $double_chars['out'] = array('OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th');
$string = str_replace($double_chars['in'], $double_chars['out'], $string); $string = str_replace($double_chars['in'], $double_chars['out'], $string);

View File

@ -1438,7 +1438,6 @@ function wp_get_archives( $args = '' ) {
$key = "wp_get_archives:$key:$last_changed"; $key = "wp_get_archives:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) { if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query ); $results = $wpdb->get_results( $query );
$cache[ $key ] = $results;
wp_cache_set( $key, $results, 'posts' ); wp_cache_set( $key, $results, 'posts' );
} }
if ( $results ) { if ( $results ) {
@ -1657,6 +1656,8 @@ function get_calendar($initial = true, $echo = true) {
<tbody> <tbody>
<tr>'; <tr>';
$daywithpost = array();
// Get days with posts // Get days with posts
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
@ -1666,8 +1667,6 @@ function get_calendar($initial = true, $echo = true) {
foreach ( (array) $dayswithposts as $daywith ) { foreach ( (array) $dayswithposts as $daywith ) {
$daywithpost[] = $daywith[0]; $daywithpost[] = $daywith[0];
} }
} else {
$daywithpost = array();
} }
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false) if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)

View File

@ -586,6 +586,8 @@ function image_get_intermediate_size($post_id, $size='thumbnail') {
// get the best one for a specified set of dimensions // get the best one for a specified set of dimensions
if ( is_array($size) && !empty($imagedata['sizes']) ) { if ( is_array($size) && !empty($imagedata['sizes']) ) {
$areas = array();
foreach ( $imagedata['sizes'] as $_size => $data ) { foreach ( $imagedata['sizes'] as $_size => $data ) {
// already cropped to width or height; so use this size // already cropped to width or height; so use this size
if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) { if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {

View File

@ -166,20 +166,21 @@ function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
global $wpdb; global $wpdb;
$blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A ); $blogs = $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A );
$blog_list = array();
foreach ( (array) $blogs as $details ) { foreach ( (array) $blogs as $details ) {
$blog_list[ $details['blog_id'] ] = $details; $blog_list[ $details['blog_id'] ] = $details;
$blog_list[ $details['blog_id'] ]['postcount'] = $wpdb->get_var( "SELECT COUNT(ID) FROM " . $wpdb->get_blog_prefix( $details['blog_id'] ). "posts WHERE post_status='publish' AND post_type='post'" ); $blog_list[ $details['blog_id'] ]['postcount'] = $wpdb->get_var( "SELECT COUNT(ID) FROM " . $wpdb->get_blog_prefix( $details['blog_id'] ). "posts WHERE post_status='publish' AND post_type='post'" );
} }
unset( $blogs );
$blogs = $blog_list;
if ( false == is_array( $blogs ) ) if ( ! $blog_list ) {
return array(); return array();
}
if ( $num == 'all' ) if ( $num == 'all' ) {
return array_slice( $blogs, $start, count( $blogs ) ); return array_slice( $blog_list, $start, count( $blog_list ) );
else } else {
return array_slice( $blogs, $start, $num ); return array_slice( $blog_list, $start, $num );
}
} }
/** /**

View File

@ -308,6 +308,8 @@ function get_site_by_path( $domain, $path, $segments = null ) {
$path_segments = array_slice( $path_segments, 0, $segments ); $path_segments = array_slice( $path_segments, 0, $segments );
} }
$paths = array();
while ( count( $path_segments ) ) { while ( count( $path_segments ) ) {
$paths[] = '/' . implode( '/', $path_segments ) . '/'; $paths[] = '/' . implode( '/', $path_segments ) . '/';
array_pop( $path_segments ); array_pop( $path_segments );

View File

@ -352,12 +352,16 @@ function get_children( $args = '', $output = OBJECT ) {
if ( $output == OBJECT ) { if ( $output == OBJECT ) {
return $kids; return $kids;
} elseif ( $output == ARRAY_A ) { } elseif ( $output == ARRAY_A ) {
foreach ( (array) $kids as $kid ) $weeuns = array();
foreach ( (array) $kids as $kid ) {
$weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]); $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
}
return $weeuns; return $weeuns;
} elseif ( $output == ARRAY_N ) { } elseif ( $output == ARRAY_N ) {
foreach ( (array) $kids as $kid ) $babes = array();
foreach ( (array) $kids as $kid ) {
$babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID])); $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
}
return $babes; return $babes;
} else { } else {
return $kids; return $kids;
@ -1681,9 +1685,10 @@ function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) ) if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) )
$object->labels['all_items'] = $object->labels['menu_name']; $object->labels['all_items'] = $object->labels['menu_name'];
foreach ( $nohier_vs_hier_defaults as $key => $value ) $defaults = array();
$defaults[$key] = $object->hierarchical ? $value[1] : $value[0]; foreach ( $nohier_vs_hier_defaults as $key => $value ) {
$defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
}
$labels = array_merge( $defaults, $object->labels ); $labels = array_merge( $defaults, $object->labels );
return (object)$labels; return (object)$labels;
} }
@ -2510,6 +2515,9 @@ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) {
$wildcards = array('', '%', '%/%'); $wildcards = array('', '%', '%/%');
if ( is_string($post_mime_types) ) if ( is_string($post_mime_types) )
$post_mime_types = array_map('trim', explode(',', $post_mime_types)); $post_mime_types = array_map('trim', explode(',', $post_mime_types));
$wheres = array();
foreach ( (array) $post_mime_types as $mime_type ) { foreach ( (array) $post_mime_types as $mime_type ) {
$mime_type = preg_replace('/\s/', '', $mime_type); $mime_type = preg_replace('/\s/', '', $mime_type);
$slashpos = strpos($mime_type, '/'); $slashpos = strpos($mime_type, '/');
@ -5140,6 +5148,7 @@ function wp_mime_type_icon( $mime = 0 ) {
wp_cache_add( 'icon_files', $icon_files, 'default', 600 ); wp_cache_add( 'icon_files', $icon_files, 'default', 600 );
} }
$types = array();
// Icon basename - extension = MIME wildcard. // Icon basename - extension = MIME wildcard.
foreach ( $icon_files as $file => $uri ) foreach ( $icon_files as $file => $uri )
$types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file]; $types[ preg_replace('/^([^.]*).*$/', '$1', basename($file)) ] =& $icon_files[$file];
@ -5513,9 +5522,11 @@ function update_post_caches( &$posts, $post_type = 'post', $update_term_cache =
if ( is_array($post_type) ) { if ( is_array($post_type) ) {
$ptypes = $post_type; $ptypes = $post_type;
} elseif ( 'any' == $post_type ) { } elseif ( 'any' == $post_type ) {
$ptypes = array();
// Just use the post_types in the supplied posts. // Just use the post_types in the supplied posts.
foreach ( $posts as $post ) foreach ( $posts as $post ) {
$ptypes[] = $post->post_type; $ptypes[] = $post->post_type;
}
$ptypes = array_unique($ptypes); $ptypes = array_unique($ptypes);
} else { } else {
$ptypes = array($post_type); $ptypes = array($post_type);

View File

@ -1288,6 +1288,7 @@ class WP_Rewrite {
$trackbackindex = $index; $trackbackindex = $index;
//build a list from the rewritecode and queryreplace arrays, that will look something like //build a list from the rewritecode and queryreplace arrays, that will look something like
//tagname=$matches[i] where i is the current $i //tagname=$matches[i] where i is the current $i
$queries = array();
for ( $i = 0; $i < $num_tokens; ++$i ) { for ( $i = 0; $i < $num_tokens; ++$i ) {
if ( 0 < $i ) if ( 0 < $i )
$queries[$i] = $queries[$i - 1] . '&'; $queries[$i] = $queries[$i - 1] . '&';
@ -1328,7 +1329,7 @@ class WP_Rewrite {
$num_toks = preg_match_all('/%.+?%/', $struct, $toks); $num_toks = preg_match_all('/%.+?%/', $struct, $toks);
//get the 'tagname=$matches[i]' //get the 'tagname=$matches[i]'
$query = ( isset($queries) && is_array($queries) && !empty($num_toks) ) ? $queries[$num_toks - 1] : ''; $query = ( ! empty( $num_toks ) && isset( $queries[$num_toks - 1] ) ) ? $queries[$num_toks - 1] : '';
//set up $ep_mask_specific which is used to match more specific URL types //set up $ep_mask_specific which is used to match more specific URL types
switch ( $dirs[$j] ) { switch ( $dirs[$j] ) {

View File

@ -3889,6 +3889,8 @@ function _pad_term_counts(&$terms, $taxonomy) {
return; return;
$term_items = array(); $term_items = array();
$terms_by_id = array();
$term_ids = array();
foreach ( (array) $terms as $key => $term ) { foreach ( (array) $terms as $key => $term ) {
$terms_by_id[$term->term_id] = & $terms[$key]; $terms_by_id[$term->term_id] = & $terms[$key];

View File

@ -406,6 +406,7 @@ function search_theme_directories( $force = false ) {
$found_themes = array(); $found_themes = array();
$wp_theme_directories = (array) $wp_theme_directories; $wp_theme_directories = (array) $wp_theme_directories;
$relative_theme_roots = array();
// Set up maybe-relative, maybe-absolute array of theme directories. // Set up maybe-relative, maybe-absolute array of theme directories.
// We always want to return absolute, but we need to cache relative // We always want to return absolute, but we need to cache relative