Make WordPress Core

Ticket #2784: 2784.diff

File 2784.diff, 39.4 KB (added by jacobsantos, 18 years ago)

type casting for foreach in wp-includes.

  • capabilities.php

     
    2828
    2929                $this->role_objects = array();
    3030                $this->role_names =  array();
    31                 foreach ($this->roles as $role => $data) {
     31                foreach ( (array) $this->roles as $role => $data) {
    3232                        $this->role_objects[$role] = new WP_Role($role, $this->roles[$role]['capabilities']);
    3333                        $this->role_names[$role] = $this->roles[$role]['name'];
    3434                }
     
    207207        }
    208208
    209209        function set_role($role) {
    210                 foreach($this->roles as $oldrole)
     210                foreach( (array) $this->roles as $oldrole)
    211211                        unset($this->caps[$oldrole]);
    212212                if ( !empty($role) ) {
    213213                        $this->caps[$role] = true;
     
    265265                $caps = call_user_func_array('map_meta_cap', $args);
    266266                // Must have ALL requested caps
    267267                $capabilities = apply_filters('user_has_cap', $this->allcaps, $caps, $args);
    268                 foreach ($caps as $cap) {
     268                foreach ( (array) $caps as $cap) {
    269269                        //echo "Checking cap $cap<br />";
    270270                        if(empty($capabilities[$cap]) || !$capabilities[$cap])
    271271                                return false;
  • category-template.php

     
    77        $chain = '';
    88        // TODO: consult hierarchy
    99        $cat_ids = get_all_category_ids();
    10         foreach ( $cat_ids as $cat_id ) {
     10        foreach ( (array) $cat_ids as $cat_id ) {
    1111                if ( $cat_id == $id )
    1212                        continue;
    1313
     
    8484        else
    8585                $categories = array();
    8686
    87         foreach(array_keys($categories) as $key) {
     87        foreach( (array) array_keys($categories) as $key) {
    8888                _make_cat_compat($categories[$key]);
    8989        }
    9090
  • category.php

     
    4343        $taxonomy = 'category';
    4444        if ( 'link' == $args['type'] )
    4545                $taxonomy = 'link_category';
    46         $categories = get_terms($taxonomy, $args);
     46        $categories = (array) get_terms($taxonomy, $args);
    4747
    4848        foreach ( array_keys($categories) as $k )
    4949                _make_cat_compat($categories[$k]);
  • classes.php

     
    9090
    9191                        // Look for matches.
    9292                        $request_match = $request;
    93                         foreach ($rewrite as $match => $query) {
     93                        foreach ( (array) $rewrite as $match => $query) {
    9494                                // Don't try to match against AtomPub calls
    9595                                if ( $req_uri == 'wp-app.php' )
    9696                                        break;
     
    171171                        }
    172172                }
    173173
    174                 foreach ($this->private_query_vars as $var) {
     174                foreach ( (array) $this->private_query_vars as $var) {
    175175                        if (isset($this->extra_query_vars[$var]))
    176176                                $this->query_vars[$var] = $this->extra_query_vars[$var];
    177177                        elseif (isset($GLOBALS[$var]) && '' != $GLOBALS[$var])
     
    242242
    243243        function build_query_string() {
    244244                $this->query_string = '';
    245                 foreach (array_keys($this->query_vars) as $wpvar) {
     245                foreach ( (array) array_keys($this->query_vars) as $wpvar) {
    246246                        if ( '' != $this->query_vars[$wpvar] ) {
    247247                                $this->query_string .= (strlen($this->query_string) < 1) ? '' : '&';
    248248                                if ( !is_scalar($this->query_vars[$wpvar]) ) // Discard non-scalars.
     
    261261        function register_globals() {
    262262                global $wp_query;
    263263                // Extract updated query vars back into global namespace.
    264                 foreach ($wp_query->query_vars as $key => $value) {
     264                foreach ( (array) $wp_query->query_vars as $key => $value) {
    265265                        $GLOBALS[$key] = $value;
    266266                }
    267267
     
    350350                // Return all messages if no code specified.
    351351                if ( empty($code) ) {
    352352                        $all_messages = array();
    353                         foreach ( $this->errors as $code => $messages )
     353                        foreach ( (array) $this->errors as $code => $messages )
    354354                                $all_messages = array_merge($all_messages, $messages);
    355355
    356356                        return $all_messages;
     
    534534                * if we are displaying all levels, and remaining children_elements is not empty,
    535535                * then we got orphans, which should be displayed regardless
    536536                */
    537                 if ( ( $max_depth == 0 ) && sizeof( $children_elements ) > 0 ) {
     537                if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
    538538                        $empty_array = array();
    539539                        foreach ( $children_elements as $orphan_e )
    540540                                $this->display_element( $orphan_e, $empty_array, 1, 0, $args, $output );
     
    755755
    756756                $response = '';
    757757                if ( is_wp_error($data) ) {
    758                         foreach ( $data->get_error_codes() as $code ) {
     758                        foreach ( (array) $data->get_error_codes() as $code ) {
    759759                                $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>";
    760760                                if ( !$error_data = $data->get_error_data($code) )
    761761                                        continue;
     
    781781                }
    782782
    783783                $s = '';
    784                 if ( (array) $supplemental ) {
     784                if ( is_array($supplemental) ) {
    785785                        foreach ( $supplemental as $k => $v )
    786786                                $s .= "<$k><![CDATA[$v]]></$k>";
    787787                        $s = "<supplemental>$s</supplemental>";
     
    805805        function send() {
    806806                header('Content-Type: text/xml');
    807807                echo "<?xml version='1.0' standalone='yes'?><wp_ajax>";
    808                 foreach ( $this->responses as $response )
     808                foreach ( (array) $this->responses as $response )
    809809                        echo $response;
    810810                echo '</wp_ajax>';
    811811                die();
  • comment-template.php

     
    107107 */
    108108function get_comment_author_link() {
    109109        /** @todo Only call these functions when they are needed. Include in if... else blocks */
    110         $url    = get_comment_author_url();
     110        $url    = get_comment_author_url();
    111111        $author = get_comment_author();
    112112
    113113        if ( empty( $url ) || 'http://' == $url )
     
    769769        echo '</a>';
    770770}
    771771
    772 ?>
    773  No newline at end of file
     772?>
  • comment.php

     
    5151        if ( !empty($mod_keys) ) {
    5252                $words = explode("\n", $mod_keys );
    5353
    54                 foreach ($words as $word) {
     54                foreach ( (array) $words as $word) {
    5555                        $word = trim($word);
    5656
    5757                        // Skip empty lines
     
    11901190        // http://dummy-weblog.org/post.php
    11911191        // We don't wanna ping first and second types, even if they have a valid <link/>
    11921192
    1193         foreach ( $post_links_temp[0] as $link_test ) :
     1193        foreach ( (array) $post_links_temp[0] as $link_test ) :
    11941194                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
    11951195                                && !is_local_attachment($link_test) ) : // Also, let's never ping local attachments.
    11961196                        $test = parse_url($link_test);
  • cron.php

     
    121121        $schedules = wp_get_schedules();
    122122        foreach ( $crons as $timestamp => $cronhooks ) {
    123123                if ( $timestamp > time() ) break;
    124                 foreach ( $cronhooks as $hook => $args ) {
     124                foreach ( (array) $cronhooks as $hook => $args ) {
    125125                        if ( isset($schedules[$hook]['callback']) && !call_user_func( $schedules[$hook]['callback'] ) )
    126126                                continue;
    127127                        spawn_cron();
     
    178178
    179179        $new_cron = array();
    180180
    181         foreach ($cron as $timestamp => $hooks) {
    182                 foreach ( $hooks as $hook => $args ) {
     181        foreach ( (array) $cron as $timestamp => $hooks) {
     182                foreach ( (array) $hooks as $hook => $args ) {
    183183                        $key = md5(serialize($args['args']));
    184184                        $new_cron[$timestamp][$hook][$key] = $args;
    185185                }
  • feed.php

     
    398398        if ( !empty($post->post_password) && (!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
    399399                return;
    400400
    401         foreach (get_post_custom() as $key => $val) {
     401        foreach ( (array) get_post_custom() as $key => $val) {
    402402                if ($key == 'enclosure') {
    403                         foreach ((array)$val as $enc) {
     403                        foreach ( (array) $val as $enc ) {
    404404                                $enclosure = split("\n", $enc);
    405405                                echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
    406406                        }
     
    430430        if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
    431431                return;
    432432
    433         foreach (get_post_custom() as $key => $val) {
     433        foreach ( (array) get_post_custom() as $key => $val ) {
    434434                if ($key == 'enclosure') {
    435                         foreach ((array)$val as $enc) {
     435                        foreach ( (array) $val as $enc ) {
    436436                                $enclosure = split("\n", $enc);
    437437                                echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n");
    438438                        }
  • formatting.php

     
    708708
    709709function convert_smilies($text) {
    710710        global $wp_smiliessearch, $wp_smiliesreplace;
    711     $output = '';
     711        $output = '';
    712712        if ( get_option('use_smilies') && !empty($wp_smiliessearch) && !empty($wp_smiliesreplace) ) {
    713713                // HTML loop taken from texturize function, could possible be consolidated
    714714                $textarr = preg_split("/(<.*>)/U", $text, -1, PREG_SPLIT_DELIM_CAPTURE); // capture the tags as well as in between
  • functions.php

     
    421421                $options = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" );
    422422        $wpdb->show_errors($show);
    423423
    424         foreach ( $options as $option ) {
     424        foreach ( (array) $options as $option ) {
    425425                // "When trying to design a foolproof system,
    426426                //  never underestimate the ingenuity of the fools :)" -- Dougal
    427427                if ( in_array( $option->option_name, array( 'siteurl', 'home', 'category_base', 'tag_base' ) ) )
     
    777777        debug_fwrite( $log, 'Post contents:' );
    778778        debug_fwrite( $log, $content . "\n" );
    779779
    780         foreach ( $post_links_temp[0] as $link_test ) {
     780        foreach ( (array) $post_links_temp[0] as $link_test ) {
    781781                if ( !in_array( $link_test, $pung ) ) { // If we haven't pung it already
    782782                        $test = parse_url( $link_test );
    783783                        if ( isset( $test['query'] ) )
     
    787787                }
    788788        }
    789789
    790         foreach ( $post_links as $url ) {
     790        foreach ( (array) $post_links as $url ) {
    791791                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 . '%' ) ) ) {
    792792                        if ( $headers = wp_get_http_headers( $url) ) {
    793793                                $len = (int) $headers['content-length'];
     
    10071007                $qs[func_get_arg( 0 )] = func_get_arg( 1 );
    10081008        }
    10091009
    1010         foreach ( $qs as $k => $v ) {
     1010        foreach ( (array) $qs as $k => $v ) {
    10111011                if ( $v === false )
    10121012                        unset( $qs[$k] );
    10131013        }
     
    10311031 */
    10321032function remove_query_arg( $key, $query=false ) {
    10331033        if ( is_array( $key ) ) { // removing multiple keys
    1034                 foreach ( (array) $key as $k )
     1034                foreach ( $key as $k )
    10351035                        $query = add_query_arg( $k, false, $query );
    10361036                return $query;
    10371037        }
     
    10491049function add_magic_quotes( $array ) {
    10501050        global $wpdb;
    10511051
    1052         foreach ( $array as $k => $v ) {
     1052        foreach ( (array) $array as $k => $v ) {
    10531053                if ( is_array( $v ) ) {
    10541054                        $array[$k] = add_magic_quotes( $v );
    10551055                } else {
     
    23292329        return $url;
    23302330}
    23312331
    2332 ?>
    2333  No newline at end of file
     2332?>
  • general-template.php

     
    426426                }
    427427                if ( $arcresults ) {
    428428                        $afterafter = $after;
    429                         foreach ( $arcresults as $arcresult ) {
     429                        foreach ( (array) $arcresults as $arcresult ) {
    430430                                $url    = get_month_link($arcresult->year,      $arcresult->month);
    431431                                $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
    432432                                if ( $show_post_count )
     
    447447                }
    448448                if ($arcresults) {
    449449                        $afterafter = $after;
    450                         foreach ($arcresults as $arcresult) {
     450                        foreach ( (array) $arcresults as $arcresult) {
    451451                                $url = get_year_link($arcresult->year);
    452452                                $text = sprintf('%d', $arcresult->year);
    453453                                if ($show_post_count)
     
    468468                }
    469469                if ( $arcresults ) {
    470470                        $afterafter = $after;
    471                         foreach ( $arcresults as $arcresult ) {
     471                        foreach ( (array) $arcresults as $arcresult ) {
    472472                                $url    = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
    473473                                $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
    474474                                $text = mysql2date($archive_day_date_format, $date);
     
    492492                $arc_w_last = '';
    493493                $afterafter = $after;
    494494                if ( $arcresults ) {
    495                                 foreach ( $arcresults as $arcresult ) {
     495                                foreach ( (array) $arcresults as $arcresult ) {
    496496                                        if ( $arcresult->week != $arc_w_last ) {
    497497                                                $arc_year = $arcresult->yr;
    498498                                                $arc_w_last = $arcresult->week;
     
    520520                        $arcresults = $cache[ $key ];
    521521                }
    522522                if ( $arcresults ) {
    523                         foreach ( $arcresults as $arcresult ) {
     523                        foreach ( (array) $arcresults as $arcresult ) {
    524524                                if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
    525525                                        $url  = get_permalink($arcresult);
    526526                                        $arc_title = $arcresult->post_title;
     
    660660                AND post_type = 'post' AND post_status = 'publish'
    661661                AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
    662662        if ( $dayswithposts ) {
    663                 foreach ( $dayswithposts as $daywith ) {
     663                foreach ( (array) $dayswithposts as $daywith ) {
    664664                        $daywithpost[] = $daywith[0];
    665665                }
    666666        } else {
     
    681681                ."AND post_type = 'post' AND post_status = 'publish'"
    682682        );
    683683        if ( $ak_post_titles ) {
    684                 foreach ( $ak_post_titles as $ak_post_title ) {
     684                foreach ( (array) $ak_post_titles as $ak_post_title ) {
    685685
    686686                                $post_title = apply_filters( "the_title", $ak_post_title->post_title );
    687687                                $post_title = str_replace('"', '&quot;', wptexturize( $post_title ));
     
    748748function allowed_tags() {
    749749        global $allowedtags;
    750750        $allowed = '';
    751         foreach ( $allowedtags as $tag => $attributes ) {
     751        foreach ( (array) $allowedtags as $tag => $attributes ) {
    752752                $allowed .= '<'.$tag;
    753753                if ( 0 < count($attributes) ) {
    754754                        foreach ( $attributes as $attribute => $limits ) {
     
    10581058        extract($args, EXTR_SKIP);
    10591059
    10601060        // Who knows what else people pass in $args
    1061         $total    = (int) $total;
     1061        $total  = (int) $total;
    10621062        if ( $total < 2 )
    10631063                return;
    10641064        $current  = (int) $current;
  • kses.php

     
    793793function wp_kses_array_lc($inarray) {
    794794        $outarray = array ();
    795795
    796         foreach ($inarray as $inkey => $inval) {
     796        foreach ( (array) $inarray as $inkey => $inval) {
    797797                $outkey = strtolower($inkey);
    798798                $outarray[$outkey] = array ();
    799799
    800                 foreach ($inval as $inkey2 => $inval2) {
     800                foreach ( (array) $inval as $inkey2 => $inval2) {
    801801                        $outkey2 = strtolower($inkey2);
    802802                        $outarray[$outkey][$outkey2] = $inval2;
    803803                } # foreach $inval
  • locale.php

     
    190190                $this->number_format['thousands_sep'] = ('number_format_thousands_sep' == $trans) ? ',' : $trans;
    191191
    192192                // Import global locale vars set during inclusion of $locale.php.
    193                 foreach ( $this->locale_vars as $var ) {
     193                foreach ( (array) $this->locale_vars as $var ) {
    194194                        if ( isset($GLOBALS[$var]) )
    195195                                $this->$var = $GLOBALS[$var];
    196196                }
  • pluggable.php

     
    789789        $found = true;
    790790        while($found) {
    791791                $found = false;
    792                 foreach($strip as $val) {
     792                foreach( (array) $strip as $val) {
    793793                        while(strpos($location, $val) !== false) {
    794794                                $found = true;
    795795                                $location = str_replace($val, '', $location);
     
    15621562}
    15631563endif;
    15641564
    1565 ?>
    1566  No newline at end of file
     1565?>
  • plugin.php

     
    9090        if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) )
    9191                return false;
    9292
    93         foreach ( array_keys($wp_filter[$tag]) as $priority ) {
     93        foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) {
    9494                if ( isset($wp_filter[$tag][$priority][$idx]) )
    9595                        return $priority;
    9696        }
  • post-template.php

     
    252252function the_meta() {
    253253        if ( $keys = get_post_custom_keys() ) {
    254254                echo "<ul class='post-meta'>\n";
    255                 foreach ( $keys as $key ) {
     255                foreach ( (array) $keys as $key ) {
    256256                        $keyt = trim($key);
    257257                        if ( '_' == $keyt{0} )
    258258                                continue;
  • post.php

     
    143143        if ( $output == OBJECT ) {
    144144                return $kids;
    145145        } elseif ( $output == ARRAY_A ) {
    146                 foreach ( $kids as $kid )
     146                foreach ( (array) $kids as $kid )
    147147                        $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
    148148                return $weeuns;
    149149        } elseif ( $output == ARRAY_N ) {
    150                 foreach ( $kids as $kid )
     150                foreach ( (array) $kids as $kid )
    151151                        $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
    152152                return $babes;
    153153        } else {
     
    14971497        wp_transition_post_status('publish', $old_status, $post);
    14981498
    14991499        // Update counts for the post's terms.
    1500         foreach ( get_object_taxonomies('post') as $taxonomy ) {
     1500        foreach ( (array) get_object_taxonomies('post') as $taxonomy ) {
    15011501                $terms = wp_get_object_terms($post_id, $taxonomy, 'fields=tt_ids');
    15021502                wp_update_term_count($terms, $taxonomy);
    15031503        }
     
    17631763                }
    17641764
    17651765                $trackback_urls = explode(',', $tb_list);
    1766                 foreach($trackback_urls as $tb_url) {
     1766                foreach( (array) $trackback_urls as $tb_url) {
    17671767                                $tb_url = trim($tb_url);
    17681768                                trackback($tb_url, stripslashes($post_title), $excerpt, $post_id);
    17691769                }
     
    18441844        $page_paths = '/' . trim($page_path, '/');
    18451845        $leaf_path  = sanitize_title(basename($page_paths));
    18461846        $page_paths = explode('/', $page_paths);
    1847         foreach($page_paths as $pathdir)
     1847        foreach( (array) $page_paths as $pathdir)
    18481848                $full_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
    18491849
    18501850        $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 ));
     
    19051905 */
    19061906function &get_page_children($page_id, $pages) {
    19071907        $page_list = array();
    1908         foreach ( $pages as $page ) {
     1908        foreach ( (array) $pages as $page ) {
    19091909                if ( $page->post_parent == $page_id ) {
    19101910                        $page_list[] = $page;
    19111911                        if ( $children = get_page_children($page->ID, $pages) )
     
    19311931 */
    19321932function get_page_hierarchy($posts, $parent = 0) {
    19331933        $result = array ( );
    1934         if ($posts) { foreach ($posts as $post) {
     1934        if ($posts) { foreach ( (array) $posts as $post) {
    19351935                if ($post->post_parent == $parent) {
    19361936                        $result[$post->ID] = $post->post_name;
    19371937                        $children = get_page_hierarchy($posts, $post->ID);
     
    29462946                        $cache[$id] = array();
    29472947        }
    29482948
    2949         foreach ( array_keys($cache) as $post)
     2949        foreach ( (array) array_keys($cache) as $post)
    29502950                wp_cache_set($post, $cache[$post], 'post_meta');
    29512951
    29522952        return $cache;
  • query.php

     
    214214
    215215        $page = (array) $page;
    216216
    217     if ( in_array( $page_obj->ID, $page ) )
     217        if ( in_array( $page_obj->ID, $page ) )
    218218                return true;
    219219        elseif ( in_array( $page_obj->post_title, $page ) )
    220220                return true;
     
    987987                        }
    988988                        $n = ($q['exact']) ? '' : '%';
    989989                        $searchand = '';
    990                         foreach((array)$q['search_terms'] as $term) {
     990                        foreach( (array) $q['search_terms'] as $term) {
    991991                                $term = addslashes_gpc($term);
    992992                                $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
    993993                                $searchand = ' AND ';
     
    10121012                        $cat_array = preg_split('/[,\s]+/', $q['cat']);
    10131013                        $q['cat'] = '';
    10141014                        $req_cats = array();
    1015                         foreach ( $cat_array as $cat ) {
     1015                        foreach ( (array) $cat_array as $cat ) {
    10161016                                $cat = intval($cat);
    10171017                                $req_cats[] = $cat;
    10181018                                $in = ($cat > 0);
  • rewrite.php

     
    157157                        global $wp;
    158158                        parse_str($query, $query_vars);
    159159                        $query = array();
    160                         foreach ( $query_vars as $key => $value ) {
     160                        foreach ( (array) $query_vars as $key => $value ) {
    161161                                if ( in_array($key, $wp->public_query_vars) )
    162162                                        $query[$key] = $value;
    163163                        }
     
    390390                $front = $this->front;
    391391                preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
    392392                $tok_index = 1;
    393                 foreach ($tokens[0] as $token) {
     393                foreach ( (array) $tokens[0] as $token) {
    394394                        if ( ($token == '%post_id%') && ($tok_index <= 3) ) {
    395395                                $front = $front . 'date/';
    396396                                break;
     
    574574        function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
    575575                //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
    576576                $feedregex2 = '';
    577                 foreach ($this->feeds as $feed_name) {
     577                foreach ( (array) $this->feeds as $feed_name) {
    578578                        $feedregex2 .= $feed_name . '|';
    579579                }
    580580                $feedregex2 = '(' . trim($feedregex2, '|') .  ')/?$';
     
    589589                //build up an array of endpoint regexes to append => queries to append
    590590                if ($endpoints) {
    591591                        $ep_query_append = array ();
    592                         foreach ($this->endpoints as $endpoint) {
     592                        foreach ( (array) $this->endpoints as $endpoint) {
    593593                                //match everything after the endpoint name, but allow for nothing to appear there
    594594                                $epmatch = $endpoint[1] . '(/(.*))?/?$';
    595595                                //this will be appended on to the rest of the query for each dir
     
    688688
    689689                        //do endpoints
    690690                        if ($endpoints) {
    691                                 foreach ($ep_query_append as $regex => $ep) {
     691                                foreach ( (array) $ep_query_append as $regex => $ep) {
    692692                                        //add the endpoints on if the mask fits
    693693                                        if ($ep[0] & $ep_mask || $ep[0] & $ep_mask_specific) {
    694694                                                $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
     
    745745                                        $subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
    746746
    747747                                        //do endpoints for attachments
    748                                         if (! empty($endpoint) ) { foreach ($ep_query_append as $regex => $ep) {
     748                                        if ( !empty($endpoint) ) { foreach ( (array) $ep_query_append as $regex => $ep ) {
    749749                                                if ($ep[0] & EP_ATTACHMENT) {
    750750                                                        $rewrite[$sub1 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
    751751                                                        $rewrite[$sub2 . $regex] = $subquery . '?' . $ep[1] . $this->preg_index(2);
     
    893893                $rules .= "RewriteBase $home_root\n";
    894894
    895895                //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
    896                 foreach ($this->non_wp_rules as $match => $query) {
     896                foreach ( (array) $this->non_wp_rules as $match => $query) {
    897897                        // Apache 1.3 does not support the reluctant (non-greedy) modifier.
    898898                        $match = str_replace('.+?', '.+', $match);
    899899
     
    914914                                "RewriteCond %{REQUEST_FILENAME} -d\n" .
    915915                                "RewriteRule ^.*$ - [S=$num_rules]\n";
    916916
    917                         foreach ($rewrite as $match => $query) {
     917                        foreach ( (array) $rewrite as $match => $query) {
    918918                                // Apache 1.3 does not support the reluctant (non-greedy) modifier.
    919919                                $match = str_replace('.+?', '.+', $match);
    920920
  • rss.php

     
    534534        $rss = new MagpieRSS( $resp->results );
    535535
    536536        // if RSS parsed successfully
    537         if ( $rss and !$rss->ERROR) {
     537        if ( $rss && !$rss->ERROR) {
    538538
    539539                // find Etag, and Last-Modified
    540                 foreach($resp->headers as $h) {
     540                foreach( (array) $resp->headers as $h) {
    541541                        // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1"
    542542                        if (strpos($h, ": ")) {
    543543                                list($field, $val) = explode(": ", $h, 2);
     
    843843                        $rss->items = array_slice( $rss->items, 0, $num_items );
    844844                }
    845845
    846                 foreach ( $rss->items as $item ) {
     846                foreach ( (array) $rss->items as $item ) {
    847847                        printf(
    848848                                '<li><a href="%1$s" title="%2$s">%3$s</a></li>',
    849849                                clean_url( $item['link'] ),
     
    864864        $rss = fetch_rss($url);
    865865        if ( $rss ) {
    866866                $rss->items = array_slice($rss->items, 0, $num_items);
    867                 foreach ($rss->items as $item ) {
     867                foreach ( (array) $rss->items as $item ) {
    868868                        echo "<li>\n";
    869869                        echo "<a href='$item[link]' title='$item[description]'>";
    870870                        echo htmlentities($item['title']);
     
    877877}
    878878endif;
    879879
    880 ?>
    881  No newline at end of file
     880?>
  • taxonomy.php

     
    4949        $object = (array) $object;
    5050
    5151        $taxonomies = array();
    52         foreach ( $wp_taxonomies as $taxonomy ) {
     52        foreach ( (array) $wp_taxonomies as $taxonomy ) {
    5353                if ( array_intersect($object, (array) $taxonomy->object_type) )
    5454                        $taxonomies[] = $taxonomy->name;
    5555        }
     
    230230        if ( !is_array($taxonomies) )
    231231                $taxonomies = array($taxonomies);
    232232
    233         foreach ( $taxonomies as $taxonomy ) {
     233        foreach ( (array) $taxonomies as $taxonomy ) {
    234234                if ( ! is_taxonomy($taxonomy) )
    235235                        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    236236        }
     
    425425
    426426        $children = $terms[$term];
    427427
    428         foreach ( $terms[$term] as $child ) {
     428        foreach ( (array) $terms[$term] as $child ) {
    429429                if ( isset($terms[$child]) )
    430430                        $children = array_merge($children, get_term_children($child, $taxonomy));
    431431        }
     
    558558                $taxonomies = array($taxonomies);
    559559        }
    560560
    561         foreach ( $taxonomies as $taxonomy ) {
     561        foreach ( (array) $taxonomies as $taxonomy ) {
    562562                if ( ! is_taxonomy($taxonomy) )
    563563                        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    564564        }
     
    626626                $exclude = '';
    627627                $interms = preg_split('/[\s,]+/',$include);
    628628                if ( count($interms) ) {
    629                         foreach ( $interms as $interm ) {
     629                        foreach ( (array) $interms as $interm ) {
    630630                                if (empty($inclusions))
    631631                                        $inclusions = ' AND ( t.term_id = ' . intval($interm) . ' ';
    632632                                else
     
    643643        if ( !empty($exclude) ) {
    644644                $exterms = preg_split('/[\s,]+/',$exclude);
    645645                if ( count($exterms) ) {
    646                         foreach ( $exterms as $exterm ) {
     646                        foreach ( (array) $exterms as $exterm ) {
    647647                                if (empty($exclusions))
    648648                                        $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
    649649                                else
     
    721721                _pad_term_counts($terms, $taxonomies[0]);
    722722
    723723        // Make sure we show empty categories that have children.
    724         if ( $hierarchical && $hide_empty ) {
     724        if ( $hierarchical && $hide_empty && is_array($terms) ) {
    725725                foreach ( $terms as $k => $term ) {
    726726                        if ( ! $term->count ) {
    727727                                $children = _get_term_children($term->term_id, $terms, $taxonomies[0]);
    728                                 foreach ( $children as $child )
    729                                         if ( $child->count )
    730                                                 continue 2;
     728                                if( is_array($children) )
     729                                        foreach ( $children as $child )
     730                                                if ( $child->count )
     731                                                        continue 2;
    731732
    732733                                // It really is empty
    733734                                unset($terms[$k]);
     
    824825        if ( is_object($term) )
    825826                $do_object = true;
    826827
    827         foreach ( $fields as $field ) {
     828        foreach ( (array) $fields as $field ) {
    828829                if ( $do_object )
    829830                        $term->$field = sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context);
    830831                else
     
    955956        if ( !is_array($taxonomies) )
    956957                $taxonomies = array($taxonomies);
    957958
    958         foreach ( $taxonomies as $taxonomy ) {
     959        foreach ( (array) $taxonomies as $taxonomy ) {
    959960                $terms = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
    960961                $in_terms = "'" . implode("', '", $terms) . "'";
    961962                $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_terms)", $object_id) );
     
    10821083        if ( !is_array($taxonomies) )
    10831084                $taxonomies = array($taxonomies);
    10841085
    1085         foreach ( $taxonomies as $taxonomy ) {
     1086        foreach ( (array) $taxonomies as $taxonomy ) {
    10861087                if ( ! is_taxonomy($taxonomy) )
    10871088                        return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));
    10881089        }
     
    13231324        $tt_ids = array();
    13241325        $term_ids = array();
    13251326
    1326         foreach ($terms as $term) {
     1327        foreach ( (array) $terms as $term) {
    13271328                if ( !strlen(trim($term)) )
    13281329                        continue;
    13291330
     
    15871588        static $_deferred = array();
    15881589
    15891590        if ( $do_deferred ) {
    1590                 foreach ( array_keys($_deferred) as $tax ) {
     1591                foreach ( (array) array_keys($_deferred) as $tax ) {
    15911592                        wp_update_term_count_now( $_deferred[$tax], $tax );
    15921593                        unset( $_deferred[$tax] );
    15931594                }
     
    16281629                call_user_func($taxonomy->update_count_callback, $terms);
    16291630        } else {
    16301631                // Default count updater
    1631                 foreach ($terms as $term) {
     1632                foreach ( (array) $terms as $term) {
    16321633                        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
    16331634                        $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    16341635                }
     
    18211822 * @param string $taxonomy Optional. Update Term to this taxonomy in cache
    18221823 */
    18231824function update_term_cache($terms, $taxonomy = '') {
    1824         foreach ( $terms as $term ) {
     1825        foreach ( (array) $terms as $term ) {
    18251826                $term_taxonomy = $taxonomy;
    18261827                if ( empty($term_taxonomy) )
    18271828                        $term_taxonomy = $term->taxonomy;
     
    18961897        if  ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) )
    18971898                return $empty_array;
    18981899
    1899         foreach ( $terms as $term ) {
     1900        foreach ( (array) $terms as $term ) {
    19001901                $use_id = false;
    19011902                if ( !is_object($term) ) {
    19021903                        $term = get_term($term, $taxonomy);
     
    19561957
    19571958        $term_items = array();
    19581959
    1959         foreach ( $terms as $key => $term ) {
     1960        foreach ( (array) $terms as $key => $term ) {
    19601961                $terms_by_id[$term->term_id] = & $terms[$key];
    19611962                $term_ids[$term->term_taxonomy_id] = $term->term_id;
    19621963        }
     
    20062007function _update_post_term_count( $terms ) {
    20072008        global $wpdb;
    20082009
    2009         foreach ( $terms as $term ) {
     2010        foreach ( (array) $terms as $term ) {
    20102011                $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 ) );
    20112012                $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    20122013        }
     
    21542155        return get_object_taxonomies($post);
    21552156}
    21562157
    2157 ?>
    2158  No newline at end of file
     2158?>
  • user.php

     
    286286                if ( $show_option_none )
    287287                        $output .= "\t<option value='-1'>$show_option_none</option>\n";
    288288
    289                 foreach ( $users as $user ) {
     289                foreach ( (array) $users as $user ) {
    290290                        $user->ID = (int) $user->ID;
    291291                        $_selected = $user->ID == $selected ? " selected='selected'" : '';
    292292                        $output .= "\t<option value='$user->ID'$_selected>" . wp_specialchars($user->$show) . "</option>\n";
     
    311311        $wpdb->show_errors($show);
    312312
    313313        if ( $metavalues ) {
    314                 foreach ( $metavalues as $meta ) {
     314                foreach ( (array) $metavalues as $meta ) {
    315315                        $value = maybe_unserialize($meta->meta_value);
    316316                        $user->{$meta->meta_key} = $value;
    317317                }
  • widgets.php

     
    208208                $index = "sidebar-$index";
    209209        } else {
    210210                $index = sanitize_title($index);
    211                 foreach ( $wp_registered_sidebars as $key => $value ) {
     211                foreach ( (array) $wp_registered_sidebars as $key => $value ) {
    212212                        if ( sanitize_title($value['name']) == $index ) {
    213213                                $index = $key;
    214214                                break;
     
    224224        $sidebar = $wp_registered_sidebars[$index];
    225225
    226226        $did_one = false;
    227         foreach ( $sidebars_widgets[$index] as $id ) {
     227        foreach ( (array) $sidebars_widgets[$index] as $id ) {
    228228                $params = array_merge(
    229229                        array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
    230230                        (array) $wp_registered_widgets[$id]['params']
     
    274274function is_dynamic_sidebar() {
    275275        global $wp_registered_widgets, $wp_registered_sidebars;
    276276        $sidebars_widgets = get_option('sidebars_widgets');
    277         foreach ( $wp_registered_sidebars as $index => $sidebar ) {
     277        foreach ( (array) $wp_registered_sidebars as $index => $sidebar ) {
    278278                if ( count($sidebars_widgets[$index]) ) {
    279                         foreach ( $sidebars_widgets[$index] as $widget )
     279                        foreach ( (array) $sidebars_widgets[$index] as $widget )
    280280                                if ( array_key_exists($widget, $wp_registered_widgets) )
    281281                                        return true;
    282282                }
     
    297297
    298298        switch ( $sidebars_widgets['array_version'] ) {
    299299                case 1 :
    300                         foreach ( $sidebars_widgets as $index => $sidebar )
     300                        foreach ( (array) $sidebars_widgets as $index => $sidebar )
    301301                        if ( is_array($sidebar) )
    302                         foreach ( $sidebar as $i => $name ) {
     302                        foreach ( (array) $sidebar as $i => $name ) {
    303303                                $id = strtolower($name);
    304304                                if ( isset($wp_registered_widgets[$id]) ) {
    305305                                        $_sidebars_widgets[$index][$i] = $id;
     
    338338                        $sidebars = array_keys( $wp_registered_sidebars );
    339339                        if ( !empty( $sidebars ) ) {
    340340                                // Move the known-good ones first
    341                                 foreach ( $sidebars as $id ) {
     341                                foreach ( (array) $sidebars as $id ) {
    342342                                        if ( array_key_exists( $id, $sidebars_widgets ) ) {
    343343                                                $_sidebars_widgets[$id] = $sidebars_widgets[$id];
    344344                                                unset($sidebars_widgets[$id], $sidebars[$id]);
     
    373373
    374374        $defaults = array();
    375375
    376         foreach ( $wp_registered_sidebars as $index => $sidebar )
     376        foreach ( (array) $wp_registered_sidebars as $index => $sidebar )
    377377                $defaults[$index] = array();
    378378
    379379        return $defaults;
     
    635635                else
    636636                        $this_sidebar = array();
    637637
    638                 foreach ( $this_sidebar as $_widget_id ) {
     638                foreach ( (array) $this_sidebar as $_widget_id ) {
    639639                        if ( 'wp_widget_text' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    640640                                $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
    641641                                if ( !in_array( "text-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
     
    683683        $name = __('Text');
    684684
    685685        $id = false;
    686         foreach ( array_keys($options) as $o ) {
     686        foreach ( (array) array_keys($options) as $o ) {
    687687                // Old widgets can have null values for some reason
    688688                if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) )
    689689                        continue;
     
    729729
    730730<script type='text/javascript'>
    731731/* <![CDATA[ */
    732     var dropdown = document.getElementById("cat");
    733     function onCatChange() {
     732        var dropdown = document.getElementById("cat");
     733        function onCatChange() {
    734734                if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    735735                        location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
    736736                }
    737     }
    738     dropdown.onchange = onCatChange;
     737        }
     738        dropdown.onchange = onCatChange;
    739739/* ]]> */
    740740</script>
    741741
     
    777777                else
    778778                        $this_sidebar = array();
    779779
    780                 foreach ( $this_sidebar as $_widget_id ) {
     780                foreach ( (array) $this_sidebar as $_widget_id ) {
    781781                        if ( 'wp_widget_categories' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    782782                                $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
    783783                                if ( !in_array( "categories-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
     
    852852        $name = __( 'Categories' );
    853853
    854854        $id = false;
    855         foreach ( array_keys($options) as $o ) {
     855        foreach ( (array) array_keys($options) as $o ) {
    856856                // Old widgets can have null values for some reason
    857857                if ( !isset($options[$o]['title']) )
    858858                        continue;
     
    986986                <?php echo $before_widget; ?>
    987987                        <?php echo $before_title . $title . $after_title; ?>
    988988                        <ul id="recentcomments"><?php
    989                         if ( $comments ) : foreach ($comments as $comment) :
     989                        if ( $comments ) : foreach ( (array) $comments as $comment) :
    990990                        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>';
    991991                        endforeach; endif;?></ul>
    992992                <?php echo $after_widget; ?>
     
    11171117        if ( is_array( $rss->items ) && !empty( $rss->items ) ) {
    11181118                $rss->items = array_slice($rss->items, 0, $items);
    11191119                echo '<ul>';
    1120                 foreach ($rss->items as $item ) {
     1120                foreach ( (array) $rss->items as $item ) {
    11211121                        while ( strstr($item['link'], 'http') != $item['link'] )
    11221122                                $item['link'] = substr($item['link'], 1);
    11231123                        $link = clean_url(strip_tags($item['link']));
     
    11911191                $options = array();
    11921192
    11931193        $urls = array();
    1194         foreach ( $options as $option )
     1194        foreach ( (array) $options as $option )
    11951195                if ( isset($option['url']) )
    11961196                        $urls[$option['url']] = true;
    11971197
     
    12041204                else
    12051205                        $this_sidebar = array();
    12061206
    1207                 foreach ( $this_sidebar as $_widget_id ) {
     1207                foreach ( (array) $this_sidebar as $_widget_id ) {
    12081208                        if ( 'wp_widget_rss' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    12091209                                $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
    12101210                                if ( !in_array( "rss-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
     
    13491349        $name = __('RSS');
    13501350
    13511351        $id = false;
    1352         foreach ( array_keys($options) as $o ) {
     1352        foreach ( (array) array_keys($options) as $o ) {
    13531353                // Old widgets can have null values for some reason
    13541354                if ( !isset($options[$o]['url']) || !isset($options[$o]['title']) || !isset($options[$o]['items']) )
    13551355                        continue;
  • wp-db.php

     
    378378                $old_prefix = $this->prefix;
    379379                $this->prefix = $prefix;
    380380
    381                 foreach ( $this->tables as $table )
     381                foreach ( (array) $this->tables as $table )
    382382                        $this->$table = $this->prefix . $table;
    383383
    384384                if ( defined('CUSTOM_USER_TABLE') )
     
    677677        function update($table, $data, $where){
    678678                $data = add_magic_quotes($data);
    679679                $bits = $wheres = array();
    680                 foreach ( array_keys($data) as $k )
     680                foreach ( (array) array_keys($data) as $k )
    681681                        $bits[] = "`$k` = '$data[$k]'";
    682682
    683683                if ( is_array( $where ) )
     
    805805                        // Return an integer-keyed array of...
    806806                        if ( $this->last_result ) {
    807807                                $i = 0;
    808                                 foreach( $this->last_result as $row ) {
     808                                foreach( (array) $this->last_result as $row ) {
    809809                                        if ( $output == ARRAY_N ) {
    810810                                                // ...integer-keyed row arrays
    811811                                                $new_array[$i] = array_values( get_object_vars( $row ) );
     
    833833                if ( $this->col_info ) {
    834834                        if ( $col_offset == -1 ) {
    835835                                $i = 0;
    836                                 foreach($this->col_info as $col ) {
     836                                foreach( (array) $this->col_info as $col ) {
    837837                                        $new_array[$i] = $col->{$info_type};
    838838                                        $i++;
    839839                                }
     
    941941                $bt = debug_backtrace();
    942942                $caller = '';
    943943
    944                 foreach ( $bt as $trace ) {
     944                foreach ( (array) $bt as $trace ) {
    945945                        if ( @$trace['class'] == __CLASS__ )
    946946                                continue;
    947947                        elseif ( strtolower(@$trace['function']) == 'call_user_func_array' )