Make WordPress Core


Ignore:
Timestamp:
08/06/2008 08:31:54 PM (18 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/taxonomy.php

    r8433 r8572  
    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;
    … …  
    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'));
    … …  
    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));
    … …  
    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'));
    … …  
    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) . ' ';
    … …  
    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) . ' ';
    … …  
    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
    … …  
    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);
    … …  
    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) . "'";
    … …  
    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'));
    … …  
    13241325        $term_ids = array();
    13251326
    1326         foreach ($terms as $term) {
     1327        foreach ( (array) $terms as $term) {
    13271328                if ( !strlen(trim($term)) )
    13281329                        continue;
    … …  
    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] );
    … …  
    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 ) );
    … …  
    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) )
    … …  
    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) ) {
    … …  
    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;
    … …  
    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 ) );
Note: See TracChangeset for help on using the changeset viewer.