WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/06/2008 08:31:54 PM (13 years ago)
Author:
markjaquith
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/widgets.php

    r8567 r8572  
    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;
     
    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']) ) ),
     
    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;
     
    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]) ) {
     
    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];
     
    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
     
    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'];
     
    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']) )
     
    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>
     
    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'];
     
    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']) )
     
    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>
     
    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);
     
    11851185
    11861186    $urls = array();
    1187     foreach ( $options as $option )
     1187    foreach ( (array) $options as $option )
    11881188        if ( isset($option['url']) )
    11891189            $urls[$option['url']] = true;
     
    11981198            $this_sidebar = array();
    11991199
    1200         foreach ( $this_sidebar as $_widget_id ) {
     1200        foreach ( (array) $this_sidebar as $_widget_id ) {
    12011201            if ( 'wp_widget_rss' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
    12021202                $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
     
    13431343
    13441344    $id = false;
    1345     foreach ( array_keys($options) as $o ) {
     1345    foreach ( (array) array_keys($options) as $o ) {
    13461346        // Old widgets can have null values for some reason
    13471347        if ( !isset($options[$o]['url']) || !isset($options[$o]['title']) || !isset($options[$o]['items']) )
Note: See TracChangeset for help on using the changeset viewer.