Cast to array when using foreach(). Props santosj (and thanks for your perseverance!). fixes #2784

git-svn-id: http://svn.automattic.com/wordpress/trunk@8572 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2008-08-06 20:31:54 +00:00
parent 064b19958f
commit 74c46749cb
22 changed files with 125 additions and 124 deletions

View File

@ -28,7 +28,7 @@ class WP_Roles {
$this->role_objects = array();
$this->role_names = array();
foreach ($this->roles as $role => $data) {
foreach ( (array) $this->roles as $role => $data) {
$this->role_objects[$role] = new WP_Role($role, $this->roles[$role]['capabilities']);
$this->role_names[$role] = $this->roles[$role]['name'];
}
@ -207,7 +207,7 @@ class WP_User {
}
function set_role($role) {
foreach($this->roles as $oldrole)
foreach( (array) $this->roles as $oldrole)
unset($this->caps[$oldrole]);
if ( !empty($role) ) {
$this->caps[$role] = true;
@ -265,7 +265,7 @@ class WP_User {
$caps = call_user_func_array('map_meta_cap', $args);
// Must have ALL requested caps
$capabilities = apply_filters('user_has_cap', $this->allcaps, $caps, $args);
foreach ($caps as $cap) {
foreach ( (array) $caps as $cap) {
//echo "Checking cap $cap<br />";
if(empty($capabilities[$cap]) || !$capabilities[$cap])
return false;

View File

@ -7,7 +7,7 @@ function get_category_children($id, $before = '/', $after = '', $visited=array()
$chain = '';
// TODO: consult hierarchy
$cat_ids = get_all_category_ids();
foreach ( $cat_ids as $cat_id ) {
foreach ( (array) $cat_ids as $cat_id ) {
if ( $cat_id == $id )
continue;
@ -84,7 +84,7 @@ function get_the_category($id = false) {
else
$categories = array();
foreach(array_keys($categories) as $key) {
foreach( (array) array_keys($categories) as $key) {
_make_cat_compat($categories[$key]);
}

View File

@ -43,7 +43,7 @@ function &get_categories($args = '') {
$taxonomy = 'category';
if ( 'link' == $args['type'] )
$taxonomy = 'link_category';
$categories = get_terms($taxonomy, $args);
$categories = (array) get_terms($taxonomy, $args);
foreach ( array_keys($categories) as $k )
_make_cat_compat($categories[$k]);

View File

@ -90,7 +90,7 @@ class WP {
// Look for matches.
$request_match = $request;
foreach ($rewrite as $match => $query) {
foreach ( (array) $rewrite as $match => $query) {
// Don't try to match against AtomPub calls
if ( $req_uri == 'wp-app.php' )
break;
@ -171,7 +171,7 @@ class WP {
}
}
foreach ($this->private_query_vars as $var) {
foreach ( (array) $this->private_query_vars as $var) {
if (isset($this->extra_query_vars[$var]))
$this->query_vars[$var] = $this->extra_query_vars[$var];
elseif (isset($GLOBALS[$var]) && '' != $GLOBALS[$var])
@ -242,7 +242,7 @@ class WP {
function build_query_string() {
$this->query_string = '';
foreach (array_keys($this->query_vars) as $wpvar) {
foreach ( (array) array_keys($this->query_vars) as $wpvar) {
if ( '' != $this->query_vars[$wpvar] ) {
$this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
@ -261,7 +261,7 @@ class WP {
function register_globals() {
global $wp_query;
// Extract updated query vars back into global namespace.
foreach ($wp_query->query_vars as $key => $value) {
foreach ( (array) $wp_query->query_vars as $key => $value) {
$GLOBALS[$key] = $value;
}
@ -350,7 +350,7 @@ class WP_Error {
// Return all messages if no code specified.
if ( empty($code) ) {
$all_messages = array();
foreach ( $this->errors as $code => $messages )
foreach ( (array) $this->errors as $code => $messages )
$all_messages = array_merge($all_messages, $messages);
return $all_messages;
@ -527,7 +527,7 @@ class Walker {
* if we are displaying all levels, and remaining children_elements is not empty,
* then we got orphans, which should be displayed regardless
*/
if ( ( $max_depth == 0 ) && sizeof( $children_elements ) > 0 ) {
if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
$empty_array = array();
foreach ( $children_elements as $orphans )
foreach( $orphans as $op )
@ -750,7 +750,7 @@ class WP_Ajax_Response {
$response = '';
if ( is_wp_error($data) ) {
foreach ( $data->get_error_codes() as $code ) {
foreach ( (array) $data->get_error_codes() as $code ) {
$response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
if ( !$error_data = $data->get_error_data($code) )
continue;
@ -776,7 +776,7 @@ class WP_Ajax_Response {
}
$s = '';
if ( (array) $supplemental ) {
if ( is_array($supplemental) ) {
foreach ( $supplemental as $k => $v )
$s .= "<$k><![CDATA[$v]]></$k>";
$s = "<supplemental>$s</supplemental>";
@ -800,7 +800,7 @@ class WP_Ajax_Response {
function send() {
header('Content-Type: text/xml');
echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
foreach ( $this->responses as $response )
foreach ( (array) $this->responses as $response )
echo $response;
echo '</wp_ajax>';
die();

View File

@ -52,7 +52,7 @@ function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $
if ( !empty($mod_keys) ) {
$words = explode("\n", $mod_keys );
foreach ($words as $word) {
foreach ( (array) $words as $word) {
$word = trim($word);
// Skip empty lines
@ -1235,7 +1235,7 @@ function pingback($content, $post_ID) {
// http://dummy-weblog.org/post.php
// We don't wanna ping first and second types, even if they have a valid <link/>
foreach ( $post_links_temp[0] as $link_test ) :
foreach ( (array) $post_links_temp[0] as $link_test ) :
if ( !in_array($link_test, $pung) && (url_to_postid($link_test) != $post_ID) // If we haven't pung it already and it isn't a link to itself
&& !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
$test = parse_url($link_test);

View File

@ -110,7 +110,7 @@ function wp_cron() {
$schedules = wp_get_schedules();
foreach ( $crons as $timestamp => $cronhooks ) {
if ( $timestamp > time() ) break;
foreach ( $cronhooks as $hook => $args ) {
foreach ( (array) $cronhooks as $hook => $args ) {
if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) )
continue;
spawn_cron();
@ -168,8 +168,8 @@ function _upgrade_cron_array($cron) {
$new_cron = array();
foreach ($cron as $timestamp => $hooks) {
foreach ( $hooks as $hook => $args ) {
foreach ( (array) $cron as $timestamp => $hooks) {
foreach ( (array) $hooks as $hook => $args ) {
$key = md5(serialize($args['args']));
$new_cron[$timestamp][$hook][$key] = $args;
}

View File

@ -398,9 +398,9 @@ function rss_enclosure() {
if ( !empty($post->post_password) && (!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
return;
foreach (get_post_custom() as $key => $val) {
foreach ( (array) get_post_custom() as $key => $val) {
if ($key == 'enclosure') {
foreach ((array)$val as $enc) {
foreach ( (array) $val as $enc ) {
$enclosure = split("\n", $enc);
echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
}
@ -430,9 +430,9 @@ function atom_enclosure() {
if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
return;
foreach (get_post_custom() as $key => $val) {
foreach ( (array) get_post_custom() as $key => $val ) {
if ($key == 'enclosure') {
foreach ((array)$val as $enc) {
foreach ( (array) $val as $enc ) {
$enclosure = split("\n", $enc);
echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
}
@ -501,4 +501,4 @@ function self_link() {
. wp_specialchars(stripslashes($_SERVER['REQUEST_URI']), 1);
}
?>
?>

View File

@ -421,7 +421,7 @@ function get_alloptions() {
$options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
$wpdb->show_errors($show);
foreach ( $options as $option ) {
foreach ( (array) $options as $option ) {
// "When trying to design a foolproof system,
// never underestimate the ingenuity of the fools :)" -- Dougal
if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
@ -777,7 +777,7 @@ function do_enclose( $content, $post_ID ) {
debug_fwrite( $log, 'Post contents:' );
debug_fwrite( $log, $content . "\n" );
foreach ( $post_links_temp[0] as $link_test ) {
foreach ( (array) $post_links_temp[0] as $link_test ) {
if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
$test = parse_url( $link_test );
if ( isset( $test['query'] ) )
@ -787,7 +787,7 @@ function do_enclose( $content, $post_ID ) {
}
}
foreach ( $post_links as $url ) {
foreach ( (array) $post_links as $url ) {
if ( $url != '' && !$wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $url . '%' ) ) ) {
if ( $headers = wp_get_http_headers( $url) ) {
$len = (int) $headers['content-length'];
@ -1007,7 +1007,7 @@ function add_query_arg() {
$qs[func_get_arg( 0 )] = func_get_arg( 1 );
}
foreach ( $qs as $k => $v ) {
foreach ( (array) $qs as $k => $v ) {
if ( $v === false )
unset( $qs[$k] );
}
@ -1031,7 +1031,7 @@ function add_query_arg() {
*/
function remove_query_arg( $key, $query=false ) {
if ( is_array( $key ) ) { // removing multiple keys
foreach ( (array) $key as $k )
foreach ( $key as $k )
$query = add_query_arg( $k, false, $query );
return $query;
}
@ -1049,7 +1049,7 @@ function remove_query_arg( $key, $query=false ) {
function add_magic_quotes( $array ) {
global $wpdb;
foreach ( $array as $k => $v ) {
foreach ( (array) $array as $k => $v ) {
if ( is_array( $v ) ) {
$array[$k] = add_magic_quotes( $v );
} else {
@ -2329,4 +2329,4 @@ function wp_guess_url() {
return $url;
}
?>
?>

View File

@ -434,7 +434,7 @@ function wp_get_archives($args = '') {
}
if ( $arcresults ) {
$afterafter = $after;
foreach ( $arcresults as $arcresult ) {
foreach ( (array) $arcresults as $arcresult ) {
$url = get_month_link($arcresult->year, $arcresult->month);
$text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
if ( $show_post_count )
@ -455,7 +455,7 @@ function wp_get_archives($args = '') {
}
if ($arcresults) {
$afterafter = $after;
foreach ($arcresults as $arcresult) {
foreach ( (array) $arcresults as $arcresult) {
$url = get_year_link($arcresult->year);
$text = sprintf('%d', $arcresult->year);
if ($show_post_count)
@ -476,7 +476,7 @@ function wp_get_archives($args = '') {
}
if ( $arcresults ) {
$afterafter = $after;
foreach ( $arcresults as $arcresult ) {
foreach ( (array) $arcresults as $arcresult ) {
$url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
$date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
$text = mysql2date($archive_day_date_format, $date);
@ -500,7 +500,7 @@ function wp_get_archives($args = '') {
$arc_w_last = '';
$afterafter = $after;
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
foreach ( (array) $arcresults as $arcresult ) {
if ( $arcresult->week != $arc_w_last ) {
$arc_year = $arcresult->yr;
$arc_w_last = $arcresult->week;
@ -528,7 +528,7 @@ function wp_get_archives($args = '') {
$arcresults = $cache[ $key ];
}
if ( $arcresults ) {
foreach ( $arcresults as $arcresult ) {
foreach ( (array) $arcresults as $arcresult ) {
if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
$url = get_permalink($arcresult);
$arc_title = $arcresult->post_title;
@ -668,7 +668,7 @@ function get_calendar($initial = true) {
AND post_type = 'post' AND post_status = 'publish'
AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
if ( $dayswithposts ) {
foreach ( $dayswithposts as $daywith ) {
foreach ( (array) $dayswithposts as $daywith ) {
$daywithpost[] = $daywith[0];
}
} else {
@ -689,7 +689,7 @@ function get_calendar($initial = true) {
."AND post_type = 'post' AND post_status = 'publish'"
);
if ( $ak_post_titles ) {
foreach ( $ak_post_titles as $ak_post_title ) {
foreach ( (array) $ak_post_titles as $ak_post_title ) {
$post_title = apply_filters( "the_title", $ak_post_title->post_title );
$post_title = str_replace('"', '&quot;', wptexturize( $post_title ));
@ -756,7 +756,7 @@ add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
function allowed_tags() {
global $allowedtags;
$allowed = '';
foreach ( $allowedtags as $tag => $attributes ) {
foreach ( (array) $allowedtags as $tag => $attributes ) {
$allowed .= '<'.$tag;
if ( 0 < count($attributes) ) {
foreach ( $attributes as $attribute => $limits ) {
@ -1066,7 +1066,7 @@ function paginate_links( $args = '' ) {
extract($args, EXTR_SKIP);
// Who knows what else people pass in $args
$total = (int) $total;
$total = (int) $total;
if ( $total < 2 )
return;
$current = (int) $current;

View File

@ -793,11 +793,11 @@ function wp_kses_stripslashes($string) {
function wp_kses_array_lc($inarray) {
$outarray = array ();
foreach ($inarray as $inkey => $inval) {
foreach ( (array) $inarray as $inkey => $inval) {
$outkey = strtolower($inkey);
$outarray[$outkey] = array ();
foreach ($inval as $inkey2 => $inval2) {
foreach ( (array) $inval as $inkey2 => $inval2) {
$outkey2 = strtolower($inkey2);
$outarray[$outkey][$outkey2] = $inval2;
} # foreach $inval

View File

@ -190,7 +190,7 @@ class WP_Locale {
$this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
// Import global locale vars set during inclusion of $locale.php.
foreach ( $this->locale_vars as $var ) {
foreach ( (array) $this->locale_vars as $var ) {
if ( isset($GLOBALS[$var]) )
$this->$var = $GLOBALS[$var];
}

View File

@ -280,7 +280,7 @@ function wp_mail( $to, $subject, $message, $headers = '' ) {
// If it's actually got contents
if ( !empty( $tempheaders ) ) {
// Iterate through the raw headers
foreach ( $tempheaders as $header ) {
foreach ( (array) $tempheaders as $header ) {
if ( strpos($header, ':') === false )
continue;
// Explode them out
@ -363,12 +363,12 @@ function wp_mail( $to, $subject, $message, $headers = '' ) {
// Add any CC and BCC recipients
if ( !empty($cc) ) {
foreach ($cc as $recipient) {
foreach ( (array) $cc as $recipient ) {
$phpmailer->AddCc( trim($recipient) );
}
}
if ( !empty($bcc) ) {
foreach ($bcc as $recipient) {
foreach ( (array) $bcc as $recipient) {
$phpmailer->AddBcc( trim($recipient) );
}
}
@ -401,7 +401,7 @@ function wp_mail( $to, $subject, $message, $headers = '' ) {
// Set custom headers
if ( !empty( $headers ) ) {
foreach ( $headers as $name => $content ) {
foreach( (array) $headers as $name => $content ) {
$phpmailer->AddCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
}
}
@ -789,7 +789,7 @@ function wp_sanitize_redirect($location) {
$found = true;
while($found) {
$found = false;
foreach($strip as $val) {
foreach( (array) $strip as $val ) {
while(strpos($location, $val) !== false) {
$found = true;
$location = str_replace($val, '', $location);

View File

@ -90,7 +90,7 @@ function has_filter($tag, $function_to_check = false) {
if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) )
return false;
foreach ( array_keys($wp_filter[$tag]) as $priority ) {
foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) {
if ( isset($wp_filter[$tag][$priority][$idx]) )
return $priority;
}

View File

@ -255,7 +255,7 @@ function post_custom( $key = '' ) {
function the_meta() {
if ( $keys = get_post_custom_keys() ) {
echo "<ul class='post-meta'>\n";
foreach ( $keys as $key ) {
foreach ( (array) $keys as $key ) {
$keyt = trim($key);
if ( '_' == $keyt{0} )
continue;

View File

@ -143,11 +143,11 @@ function &get_children($args = '', $output = OBJECT) {
if ( $output == OBJECT ) {
return $kids;
} elseif ( $output == ARRAY_A ) {
foreach ( $kids as $kid )
foreach ( (array) $kids as $kid )
$weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
return $weeuns;
} elseif ( $output == ARRAY_N ) {
foreach ( $kids as $kid )
foreach ( (array) $kids as $kid )
$babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
return $babes;
} else {
@ -1579,7 +1579,7 @@ function wp_publish_post($post_id) {
wp_transition_post_status('publish', $old_status, $post);
// Update counts for the post's terms.
foreach ( get_object_taxonomies('post') as $taxonomy ) {
foreach ( (array) get_object_taxonomies('post') as $taxonomy ) {
$terms = wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');
wp_update_term_count($terms, $taxonomy);
}
@ -1845,7 +1845,7 @@ function trackback_url_list($tb_list, $post_id) {
}
$trackback_urls = explode(',', $tb_list);
foreach($trackback_urls as $tb_url) {
foreach( (array) $trackback_urls as $tb_url) {
$tb_url = trim($tb_url);
trackback($tb_url, stripslashes($post_title), $excerpt, $post_id);
}
@ -1926,7 +1926,7 @@ function get_page_by_path($page_path, $output = OBJECT) {
$page_paths = '/' . trim($page_path, '/');
$leaf_path = sanitize_title(basename($page_paths));
$page_paths = explode('/', $page_paths);
foreach($page_paths as $pathdir)
foreach( (array) $page_paths as $pathdir)
$full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
$pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = 'page' OR post_type = 'attachment')", $leaf_path ));
@ -1987,7 +1987,7 @@ function get_page_by_title($page_title, $output = OBJECT) {
*/
function &get_page_children($page_id, $pages) {
$page_list = array();
foreach ( $pages as $page ) {
foreach ( (array) $pages as $page ) {
if ( $page->post_parent == $page_id ) {
$page_list[] = $page;
if ( $children = get_page_children($page->ID, $pages) )
@ -2013,7 +2013,7 @@ function &get_page_children($page_id, $pages) {
*/
function get_page_hierarchy($posts, $parent = 0) {
$result = array ( );
if ($posts) { foreach ($posts as $post) {
if ($posts) { foreach ( (array) $posts as $post) {
if ($post->post_parent == $parent) {
$result[$post->ID] = $post->post_name;
$children = get_page_hierarchy($posts, $post->ID);
@ -3028,7 +3028,7 @@ function update_postmeta_cache($post_ids) {
$cache[$id] = array();
}
foreach ( array_keys($cache) as $post)
foreach ( (array) array_keys($cache) as $post)
wp_cache_set($post, $cache[$post], 'post_meta');
return $cache;

View File

@ -214,7 +214,7 @@ function is_page ($page = '') {
$page = (array) $page;
if ( in_array( $page_obj->ID, $page ) )
if ( in_array( $page_obj->ID, $page ) )
return true;
elseif ( in_array( $page_obj->post_title, $page ) )
return true;
@ -990,7 +990,7 @@ class WP_Query {
}
$n = ($q['exact']) ? '' : '%';
$searchand = '';
foreach((array)$q['search_terms'] as $term) {
foreach( (array) $q['search_terms'] as $term) {
$term = addslashes_gpc($term);
$search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
$searchand = ' AND ';
@ -1015,7 +1015,7 @@ class WP_Query {
$cat_array = preg_split('/[,\s]+/', $q['cat']);
$q['cat'] = '';
$req_cats = array();
foreach ( $cat_array as $cat ) {
foreach ( (array) $cat_array as $cat ) {
$cat = intval($cat);
$req_cats[] = $cat;
$in = ($cat > 0);

View File

@ -157,7 +157,7 @@ function url_to_postid($url) {
global $wp;
parse_str($query, $query_vars);
$query = array();
foreach ( $query_vars as $key => $value ) {
foreach ( (array) $query_vars as $key => $value ) {
if ( in_array($key, $wp->public_query_vars) )
$query[$key] = $value;
}
@ -390,7 +390,7 @@ class WP_Rewrite {
$front = $this->front;
preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
$tok_index = 1;
foreach ($tokens[0] as $token) {
foreach ( (array) $tokens[0] as $token) {
if ( ($token == '%post_id%') && ($tok_index <= 3) ) {
$front = $front . 'date/';
break;
@ -574,7 +574,7 @@ class WP_Rewrite {
function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
//build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
$feedregex2 = '';
foreach ($this->feeds as $feed_name) {
foreach ( (array) $this->feeds as $feed_name) {
$feedregex2 .= $feed_name . '|';
}
$feedregex2 = '(' . trim($feedregex2, '|') . ')/?$';
@ -589,7 +589,7 @@ class WP_Rewrite {
//build up an array of endpoint regexes to append => queries to append
if ($endpoints) {
$ep_query_append = array ();
foreach ($this->endpoints as $endpoint) {
foreach ( (array) $this->endpoints as $endpoint) {
//match everything after the endpoint name, but allow for nothing to appear there
$epmatch = $endpoint[1] . '(/(.*))?/?$';
//this will be appended on to the rest of the query for each dir
@ -688,7 +688,7 @@ class WP_Rewrite {
//do endpoints
if ($endpoints) {
foreach ($ep_query_append as $regex => $ep) {
foreach ( (array) $ep_query_append as $regex => $ep) {
//add the endpoints on if the mask fits
if ($ep[0] & $ep_mask || $ep[0] & $ep_mask_specific) {
$rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
@ -745,7 +745,7 @@ class WP_Rewrite {
$subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
//do endpoints for attachments
if (! empty($endpoint) ) { foreach ($ep_query_append as $regex => $ep) {
if ( !empty($endpoint) ) { foreach ( (array) $ep_query_append as $regex => $ep ) {
if ($ep[0] & EP_ATTACHMENT) {
$rewrite[$sub1 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
$rewrite[$sub2 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
@ -893,7 +893,7 @@ class WP_Rewrite {
$rules .= "RewriteBase $home_root\n";
//add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
foreach ($this->non_wp_rules as $match => $query) {
foreach ( (array) $this->non_wp_rules as $match => $query) {
// Apache 1.3 does not support the reluctant (non-greedy) modifier.
$match = str_replace('.+?', '.+', $match);
@ -914,7 +914,7 @@ class WP_Rewrite {
"RewriteCond %{REQUEST_FILENAME} -d\n" .
"RewriteRule ^.*$ - [S=$num_rules]\n";
foreach ($rewrite as $match => $query) {
foreach ( (array) $rewrite as $match => $query) {
// Apache 1.3 does not support the reluctant (non-greedy) modifier.
$match = str_replace('.+?', '.+', $match);

View File

@ -534,10 +534,10 @@ function _response_to_rss ($resp) {
$rss = new MagpieRSS( $resp->results );
// if RSS parsed successfully
if ( $rss and !$rss->ERROR) {
if ( $rss && !$rss->ERROR) {
// find Etag, and Last-Modified
foreach($resp->headers as $h) {
foreach( (array) $resp->headers as $h) {
// 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1"
if (strpos($h, ": ")) {
list($field, $val) = explode(": ", $h, 2);
@ -843,7 +843,7 @@ function wp_rss( $url, $num_items = -1 ) {
$rss->items = array_slice( $rss->items, 0, $num_items );
}
foreach ( $rss->items as $item ) {
foreach ( (array) $rss->items as $item ) {
printf(
'<li><a href="%1$s" title="%2$s">%3$s</a></li>',
clean_url( $item['link'] ),
@ -864,7 +864,7 @@ function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS
$rss = fetch_rss($url);
if ( $rss ) {
$rss->items = array_slice($rss->items, 0, $num_items);
foreach ($rss->items as $item ) {
foreach ( (array) $rss->items as $item ) {
echo "<li>\n";
echo "<a href='$item[link]' title='$item[description]'>";
echo htmlentities($item['title']);
@ -877,4 +877,4 @@ function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS
}
endif;
?>
?>

View File

@ -49,7 +49,7 @@ function get_object_taxonomies($object) {
$object = (array) $object;
$taxonomies = array();
foreach ( $wp_taxonomies as $taxonomy ) {
foreach ( (array) $wp_taxonomies as $taxonomy ) {
if ( array_intersect($object, (array) $taxonomy->object_type) )
$taxonomies[] = $taxonomy->name;
}
@ -230,7 +230,7 @@ function get_objects_in_term( $terms, $taxonomies, $args = array() ) {
if ( !is_array($taxonomies) )
$taxonomies = array($taxonomies);
foreach ( $taxonomies as $taxonomy ) {
foreach ( (array) $taxonomies as $taxonomy ) {
if ( ! is_taxonomy($taxonomy) )
return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
}
@ -425,7 +425,7 @@ function get_term_children( $term, $taxonomy ) {
$children = $terms[$term];
foreach ( $terms[$term] as $child ) {
foreach ( (array) $terms[$term] as $child ) {
if ( isset($terms[$child]) )
$children = array_merge($children, get_term_children($child, $taxonomy));
}
@ -558,7 +558,7 @@ function &get_terms($taxonomies, $args = '') {
$taxonomies = array($taxonomies);
}
foreach ( $taxonomies as $taxonomy ) {
foreach ( (array) $taxonomies as $taxonomy ) {
if ( ! is_taxonomy($taxonomy) )
return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
}
@ -626,7 +626,7 @@ function &get_terms($taxonomies, $args = '') {
$exclude = '';
$interms = preg_split('/[\s,]+/',$include);
if ( count($interms) ) {
foreach ( $interms as $interm ) {
foreach ( (array) $interms as $interm ) {
if (empty($inclusions))
$inclusions = ' AND ( t.term_id = ' . intval($interm) . ' ';
else
@ -643,7 +643,7 @@ function &get_terms($taxonomies, $args = '') {
if ( !empty($exclude) ) {
$exterms = preg_split('/[\s,]+/',$exclude);
if ( count($exterms) ) {
foreach ( $exterms as $exterm ) {
foreach ( (array) $exterms as $exterm ) {
if (empty($exclusions))
$exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
else
@ -721,13 +721,14 @@ function &get_terms($taxonomies, $args = '') {
_pad_term_counts($terms, $taxonomies[0]);
// Make sure we show empty categories that have children.
if ( $hierarchical && $hide_empty ) {
if ( $hierarchical && $hide_empty && is_array($terms) ) {
foreach ( $terms as $k => $term ) {
if ( ! $term->count ) {
$children = _get_term_children($term->term_id, $terms, $taxonomies[0]);
foreach ( $children as $child )
if ( $child->count )
continue 2;
if( is_array($children) )
foreach ( $children as $child )
if ( $child->count )
continue 2;
// It really is empty
unset($terms[$k]);
@ -824,7 +825,7 @@ function sanitize_term($term, $taxonomy, $context = 'display') {
if ( is_object($term) )
$do_object = true;
foreach ( $fields as $field ) {
foreach ( (array) $fields as $field ) {
if ( $do_object )
$term->$field = sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context);
else
@ -955,7 +956,7 @@ function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
if ( !is_array($taxonomies) )
$taxonomies = array($taxonomies);
foreach ( $taxonomies as $taxonomy ) {
foreach ( (array) $taxonomies as $taxonomy ) {
$terms = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
$in_terms = "'" . implode("', '", $terms) . "'";
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_terms)", $object_id) );
@ -1082,7 +1083,7 @@ function wp_get_object_terms($object_ids, $taxonomies, $args = array()) {
if ( !is_array($taxonomies) )
$taxonomies = array($taxonomies);
foreach ( $taxonomies as $taxonomy ) {
foreach ( (array) $taxonomies as $taxonomy ) {
if ( ! is_taxonomy($taxonomy) )
return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
}
@ -1323,7 +1324,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
$tt_ids = array();
$term_ids = array();
foreach ($terms as $term) {
foreach ( (array) $terms as $term) {
if ( !strlen(trim($term)) )
continue;
@ -1587,7 +1588,7 @@ function wp_update_term_count( $terms, $taxonomy, $do_deferred=false ) {
static $_deferred = array();
if ( $do_deferred ) {
foreach ( array_keys($_deferred) as $tax ) {
foreach ( (array) array_keys($_deferred) as $tax ) {
wp_update_term_count_now( $_deferred[$tax], $tax );
unset( $_deferred[$tax] );
}
@ -1628,7 +1629,7 @@ function wp_update_term_count_now( $terms, $taxonomy ) {
call_user_func($taxonomy->update_count_callback, $terms);
} else {
// Default count updater
foreach ($terms as $term) {
foreach ( (array) $terms as $term) {
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
}
@ -1821,7 +1822,7 @@ function update_object_term_cache($object_ids, $object_type) {
* @param string $taxonomy Optional. Update Term to this taxonomy in cache
*/
function update_term_cache($terms, $taxonomy = '') {
foreach ( $terms as $term ) {
foreach ( (array) $terms as $term ) {
$term_taxonomy = $taxonomy;
if ( empty($term_taxonomy) )
$term_taxonomy = $term->taxonomy;
@ -1896,7 +1897,7 @@ function &_get_term_children($term_id, $terms, $taxonomy) {
if ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) )
return $empty_array;
foreach ( $terms as $term ) {
foreach ( (array) $terms as $term ) {
$use_id = false;
if ( !is_object($term) ) {
$term = get_term($term, $taxonomy);
@ -1956,7 +1957,7 @@ function _pad_term_counts(&$terms, $taxonomy) {
$term_items = array();
foreach ( $terms as $key => $term ) {
foreach ( (array) $terms as $key => $term ) {
$terms_by_id[$term->term_id] = & $terms[$key];
$term_ids[$term->term_taxonomy_id] = $term->term_id;
}
@ -2006,7 +2007,7 @@ function _pad_term_counts(&$terms, $taxonomy) {
function _update_post_term_count( $terms ) {
global $wpdb;
foreach ( $terms as $term ) {
foreach ( (array) $terms as $term ) {
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term ) );
$wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
}
@ -2154,4 +2155,4 @@ function get_post_taxonomies($post = 0) {
return get_object_taxonomies($post);
}
?>
?>

View File

@ -286,7 +286,7 @@ function wp_dropdown_users( $args = '' ) {
if ( $show_option_none )
$output .= "\t<option value='-1'>$show_option_none</option>\n";
foreach ( $users as $user ) {
foreach ( (array) $users as $user ) {
$user->ID = (int) $user->ID;
$_selected = $user->ID == $selected ? " selected='selected'" : '';
$output .= "\t<option value='$user->ID'$_selected>" . wp_specialchars($user->$show) . "</option>\n";
@ -311,7 +311,7 @@ function _fill_user( &$user ) {
$wpdb->show_errors($show);
if ( $metavalues ) {
foreach ( $metavalues as $meta ) {
foreach ( (array) $metavalues as $meta ) {
$value = maybe_unserialize($meta->meta_value);
$user->{$meta->meta_key} = $value;
}

View File

@ -208,7 +208,7 @@ function dynamic_sidebar($index = 1) {
$index = "sidebar-$index";
} else {
$index = sanitize_title($index);
foreach ( $wp_registered_sidebars as $key => $value ) {
foreach ( (array) $wp_registered_sidebars as $key => $value ) {
if ( sanitize_title($value['name']) == $index ) {
$index = $key;
break;
@ -224,7 +224,7 @@ function dynamic_sidebar($index = 1) {
$sidebar = $wp_registered_sidebars[$index];
$did_one = false;
foreach ( $sidebars_widgets[$index] as $id ) {
foreach ( (array) $sidebars_widgets[$index] as $id ) {
$params = array_merge(
array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
(array) $wp_registered_widgets[$id]['params']
@ -274,9 +274,9 @@ function is_active_widget($callback, $widget_id = false) {
function is_dynamic_sidebar() {
global $wp_registered_widgets, $wp_registered_sidebars;
$sidebars_widgets = get_option('sidebars_widgets');
foreach ( $wp_registered_sidebars as $index => $sidebar ) {
foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
if ( count($sidebars_widgets[$index]) ) {
foreach ( $sidebars_widgets[$index] as $widget )
foreach ( (array) $sidebars_widgets[$index] as $widget )
if ( array_key_exists($widget, $wp_registered_widgets) )
return true;
}
@ -297,9 +297,9 @@ function wp_get_sidebars_widgets($update = true) {
switch ( $sidebars_widgets['array_version'] ) {
case 1 :
foreach ( $sidebars_widgets as $index => $sidebar )
foreach ( (array) $sidebars_widgets as $index => $sidebar )
if ( is_array($sidebar) )
foreach ( $sidebar as $i => $name ) {
foreach ( (array) $sidebar as $i => $name ) {
$id = strtolower($name);
if ( isset($wp_registered_widgets[$id]) ) {
$_sidebars_widgets[$index][$i] = $id;
@ -338,7 +338,7 @@ function wp_get_sidebars_widgets($update = true) {
$sidebars = array_keys( $wp_registered_sidebars );
if ( !empty( $sidebars ) ) {
// Move the known-good ones first
foreach ( $sidebars as $id ) {
foreach ( (array) $sidebars as $id ) {
if ( array_key_exists( $id, $sidebars_widgets ) ) {
$_sidebars_widgets[$id] = $sidebars_widgets[$id];
unset($sidebars_widgets[$id], $sidebars[$id]);
@ -373,7 +373,7 @@ function wp_get_widget_defaults() {
$defaults = array();
foreach ( $wp_registered_sidebars as $index => $sidebar )
foreach ( (array) $wp_registered_sidebars as $index => $sidebar )
$defaults[$index] = array();
return $defaults;
@ -635,7 +635,7 @@ function wp_widget_text_control($widget_args) {
else
$this_sidebar = array();
foreach ( $this_sidebar as $_widget_id ) {
foreach ( (array) $this_sidebar as $_widget_id ) {
if ( 'wp_widget_text' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
if ( !in_array( "text-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
@ -683,7 +683,7 @@ function wp_widget_text_register() {
$name = __('Text');
$id = false;
foreach ( array_keys($options) as $o ) {
foreach ( (array) array_keys($options) as $o ) {
// Old widgets can have null values for some reason
if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) )
continue;
@ -729,13 +729,13 @@ function wp_widget_categories($args, $widget_args = 1) {
<script type='text/javascript'>
/* <![CDATA[ */
var dropdown = document.getElementById("cat");
function onCatChange() {
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
}
dropdown.onchange = onCatChange;
/* ]]> */
</script>
@ -777,7 +777,7 @@ function wp_widget_categories_control( $widget_args ) {
else
$this_sidebar = array();
foreach ( $this_sidebar as $_widget_id ) {
foreach ( (array) $this_sidebar as $_widget_id ) {
if ( 'wp_widget_categories' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
if ( !in_array( "categories-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
@ -852,7 +852,7 @@ function wp_widget_categories_register() {
$name = __( 'Categories' );
$id = false;
foreach ( array_keys($options) as $o ) {
foreach ( (array) array_keys($options) as $o ) {
// Old widgets can have null values for some reason
if ( !isset($options[$o]['title']) )
continue;
@ -986,7 +986,7 @@ function wp_widget_recent_comments($args) {
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title; ?>
<ul id="recentcomments"><?php
if ( $comments ) : foreach ($comments as $comment) :
if ( $comments ) : foreach ( (array) $comments as $comment) :
echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
endforeach; endif;?></ul>
<?php echo $after_widget; ?>
@ -1117,7 +1117,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
if ( is_array( $rss->items ) && !empty( $rss->items ) ) {
$rss->items = array_slice($rss->items, 0, $items);
echo '<ul>';
foreach ($rss->items as $item ) {
foreach ( (array) $rss->items as $item ) {
while ( strstr($item['link'], 'http') != $item['link'] )
$item['link'] = substr($item['link'], 1);
$link = clean_url(strip_tags($item['link']));
@ -1184,7 +1184,7 @@ function wp_widget_rss_control($widget_args) {
$options = array();
$urls = array();
foreach ( $options as $option )
foreach ( (array) $options as $option )
if ( isset($option['url']) )
$urls[$option['url']] = true;
@ -1197,7 +1197,7 @@ function wp_widget_rss_control($widget_args) {
else
$this_sidebar = array();
foreach ( $this_sidebar as $_widget_id ) {
foreach ( (array) $this_sidebar as $_widget_id ) {
if ( 'wp_widget_rss' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
$widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
if ( !in_array( "rss-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
@ -1342,7 +1342,7 @@ function wp_widget_rss_register() {
$name = __('RSS');
$id = false;
foreach ( array_keys($options) as $o ) {
foreach ( (array) array_keys($options) as $o ) {
// Old widgets can have null values for some reason
if ( !isset($options[$o]['url']) || !isset($options[$o]['title']) || !isset($options[$o]['items']) )
continue;

View File

@ -378,7 +378,7 @@ class wpdb {
$old_prefix = $this->prefix;
$this->prefix = $prefix;
foreach ( $this->tables as $table )
foreach ( (array) $this->tables as $table )
$this->$table = $this->prefix . $table;
if ( defined('CUSTOM_USER_TABLE') )
@ -677,7 +677,7 @@ class wpdb {
function update($table, $data, $where){
$data = add_magic_quotes($data);
$bits = $wheres = array();
foreach ( array_keys($data) as $k )
foreach ( (array) array_keys($data) as $k )
$bits[] = "`$k` = '$data[$k]'";
if ( is_array( $where ) )
@ -805,7 +805,7 @@ class wpdb {
// Return an integer-keyed array of...
if ( $this->last_result ) {
$i = 0;
foreach( $this->last_result as $row ) {
foreach( (array) $this->last_result as $row ) {
if ( $output == ARRAY_N ) {
// ...integer-keyed row arrays
$new_array[$i] = array_values( get_object_vars( $row ) );
@ -833,7 +833,7 @@ class wpdb {
if ( $this->col_info ) {
if ( $col_offset == -1 ) {
$i = 0;
foreach($this->col_info as $col ) {
foreach( (array) $this->col_info as $col ) {
$new_array[$i] = $col->{$info_type};
$i++;
}
@ -941,7 +941,7 @@ class wpdb {
$bt = debug_backtrace();
$caller = '';
foreach ( $bt as $trace ) {
foreach ( (array) $bt as $trace ) {
if ( @$trace['class'] == __CLASS__ )
continue;
elseif ( strtolower(@$trace['function']) == 'call_user_func_array' )