From 74c46749cb6a9d6614f00e1f32e254e50d222aa3 Mon Sep 17 00:00:00 2001 From: markjaquith Date: Wed, 6 Aug 2008 20:31:54 +0000 Subject: [PATCH] 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 --- wp-includes/capabilities.php | 6 ++--- wp-includes/category-template.php | 4 +-- wp-includes/category.php | 2 +- wp-includes/classes.php | 18 ++++++------- wp-includes/comment.php | 4 +-- wp-includes/cron.php | 6 ++--- wp-includes/feed.php | 10 +++---- wp-includes/functions.php | 14 +++++----- wp-includes/general-template.php | 18 ++++++------- wp-includes/kses.php | 4 +-- wp-includes/locale.php | 2 +- wp-includes/pluggable.php | 10 +++---- wp-includes/plugin.php | 2 +- wp-includes/post-template.php | 2 +- wp-includes/post.php | 16 ++++++------ wp-includes/query.php | 6 ++--- wp-includes/rewrite.php | 16 ++++++------ wp-includes/rss.php | 10 +++---- wp-includes/taxonomy.php | 43 ++++++++++++++++--------------- wp-includes/user.php | 4 +-- wp-includes/widgets.php | 42 +++++++++++++++--------------- wp-includes/wp-db.php | 10 +++---- 22 files changed, 125 insertions(+), 124 deletions(-) diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index 875173d63b..3a931bee2d 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -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
"; if(empty($capabilities[$cap]) || !$capabilities[$cap]) return false; diff --git a/wp-includes/category-template.php b/wp-includes/category-template.php index d4df694758..bd692144ab 100644 --- a/wp-includes/category-template.php +++ b/wp-includes/category-template.php @@ -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]); } diff --git a/wp-includes/category.php b/wp-includes/category.php index d97b72d2a6..e7bf932354 100644 --- a/wp-includes/category.php +++ b/wp-includes/category.php @@ -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]); diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 9b46ba35dd..2b5d9bb53b 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -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 .= "get_error_message($code) . "]]>"; 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>"; $s = "$s"; @@ -800,7 +800,7 @@ class WP_Ajax_Response { function send() { header('Content-Type: text/xml'); echo ""; - foreach ( $this->responses as $response ) + foreach ( (array) $this->responses as $response ) echo $response; echo ''; die(); diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 30d9a1b920..87a728bb3e 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -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 - 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); diff --git a/wp-includes/cron.php b/wp-includes/cron.php index 7925a2c7f7..65c5d8573a 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -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; } diff --git a/wp-includes/feed.php b/wp-includes/feed.php index 11ff42bc23..bf133ae9c6 100644 --- a/wp-includes/feed.php +++ b/wp-includes/feed.php @@ -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', '' . "\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', '' . "\n"); } @@ -501,4 +501,4 @@ function self_link() { . wp_specialchars(stripslashes($_SERVER['REQUEST_URI']), 1); } -?> \ No newline at end of file +?> diff --git a/wp-includes/functions.php b/wp-includes/functions.php index fb3aaf0f00..0a5eae6af9 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -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; } -?> \ No newline at end of file +?> diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 0b6b4b415c..865569af8e 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -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('"', '"', 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; diff --git a/wp-includes/kses.php b/wp-includes/kses.php index 2a9cd729a7..af5892b959 100644 --- a/wp-includes/kses.php +++ b/wp-includes/kses.php @@ -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 diff --git a/wp-includes/locale.php b/wp-includes/locale.php index 5f24c54357..27a35d1344 100644 --- a/wp-includes/locale.php +++ b/wp-includes/locale.php @@ -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]; } diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index 9407f1a986..b9409669a0 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -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); diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php index 83b53580e5..7e205d4ead 100644 --- a/wp-includes/plugin.php +++ b/wp-includes/plugin.php @@ -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; } diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index 7b56ab03be..fa415fadb2 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -255,7 +255,7 @@ function post_custom( $key = '' ) { function the_meta() { if ( $keys = get_post_custom_keys() ) { echo "