WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/21/2019 06:58:50 PM (2 years ago)
Author:
kadamwhite
Message:

REST API: Avoid undefined-property notice when setting parent term to 0.

Only try to access term_id once $parent_term is known to be a WP_Term.

Props dlh, earnjam.
Fixes #44983.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r43987 r44965  
    686686
    687687        if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) {
    688             $parent_term_id = 0;
    689             $parent_term    = get_term( (int) $request['parent'], $this->taxonomy );
    690 
    691             if ( $parent_term ) {
    692                 $parent_term_id = $parent_term->term_id;
     688            $parent_term_id   = 0;
     689            $requested_parent = (int) $request['parent'];
     690
     691            if ( $requested_parent ) {
     692                $parent_term = get_term( $requested_parent, $this->taxonomy );
     693
     694                if ( $parent_term instanceof WP_Term ) {
     695                    $parent_term_id = $parent_term->term_id;
     696                }
    693697            }
    694698
Note: See TracChangeset for help on using the changeset viewer.