From fac9f5f9fb6c81be48060dedfca2abf7142cb3a0 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Thu, 21 Mar 2019 18:59:52 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@44965 git-svn-id: http://core.svn.wordpress.org/trunk@44796 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-terms-controller.php | 12 ++++++++---- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index ff399cc60e..527a8bc199 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -685,11 +685,15 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { } if ( isset( $request['parent'] ) && ! empty( $schema['properties']['parent'] ) ) { - $parent_term_id = 0; - $parent_term = get_term( (int) $request['parent'], $this->taxonomy ); + $parent_term_id = 0; + $requested_parent = (int) $request['parent']; - if ( $parent_term ) { - $parent_term_id = $parent_term->term_id; + if ( $requested_parent ) { + $parent_term = get_term( $requested_parent, $this->taxonomy ); + + if ( $parent_term instanceof WP_Term ) { + $parent_term_id = $parent_term->term_id; + } } $prepared_term->parent = $parent_term_id; diff --git a/wp-includes/version.php b/wp-includes/version.php index 40b1a3b030..9f6e12dcd6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-alpha-44964'; +$wp_version = '5.2-alpha-44965'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.