Make WordPress Core


Ignore:
Timestamp:
10/19/2015 03:11:30 AM (9 years ago)
Author:
boonebgorges
Message:

Don't store data as a property on WP_Term objects.

wp_ajax_add_term() fetches a term using get_term(), and passes the term to
WP_Ajax_Response, which expects each of the term's properties to be scalar.
Having $data as a stdClass (meant to mimic WP_User::data, populated by
a get_row() database query) violated this expectation, causing fatal string
conversion errors. As a workaround, $term->data is converted so that it is
no longer an actual property of the term object, but is assembled only when
requested in the magic __get() method.

Fixes #34348.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term.php

    r35032 r35269  
    9797
    9898    /**
    99      * Info about the term, as stored in the database.
    100      *
    101      * @since 4.4.0
    102      * @access protected
    103      * @var array
    104      */
    105     protected $data = array();
    106 
    107     /**
    10899     * Stores the term object's sanitization level.
    109100     *
     
    167158            $this->$key = $value;
    168159        }
    169 
    170         $this->data = sanitize_term( $term, $this->taxonomy, $this->filter );
    171160    }
    172161
     
    206195        switch ( $key ) {
    207196            case 'data' :
    208                 return sanitize_term( $this->{$key}, $this->data->taxonomy, 'raw' );
     197                $data = new stdClass();
     198                $columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' );
     199                foreach ( $columns as $column ) {
     200                    $data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null;
     201                }
     202
     203                return sanitize_term( $data, $data->taxonomy, 'raw' );
    209204                break;
    210205        }
Note: See TracChangeset for help on using the changeset viewer.