wp_insert_term can return an error so handle appropriately in class-wc-product-attribute.php

Fixes #14429
This commit is contained in:
Mike Jolley 2017-04-17 12:05:36 +01:00
parent d11337706e
commit 4fcada6fe9
1 changed files with 2 additions and 2 deletions

View File

@ -77,7 +77,7 @@ class WC_Product_Attribute implements ArrayAccess {
if ( ! $term || is_wp_error( $term ) ) { if ( ! $term || is_wp_error( $term ) ) {
$new_term = wp_insert_term( $option, $this->get_name() ); $new_term = wp_insert_term( $option, $this->get_name() );
$term = get_term_by( 'id', $new_term['term_id'], $this->get_name() ); $term = is_wp_error( $new_term ) ? false : get_term_by( 'id', $new_term['term_id'], $this->get_name() );
} }
} }
if ( $term && ! is_wp_error( $term ) ) { if ( $term && ! is_wp_error( $term ) ) {
@ -105,7 +105,7 @@ class WC_Product_Attribute implements ArrayAccess {
if ( ! $term || is_wp_error( $term ) ) { if ( ! $term || is_wp_error( $term ) ) {
$new_term = wp_insert_term( $option, $this->get_name() ); $new_term = wp_insert_term( $option, $this->get_name() );
$term = get_term_by( 'id', $new_term['term_id'], $this->get_name() ); $term = is_wp_error( $new_term ) ? false : get_term_by( 'id', $new_term['term_id'], $this->get_name() );
} }
} }
if ( $term && ! is_wp_error( $term ) ) { if ( $term && ! is_wp_error( $term ) ) {