From 4fcada6fe9883238b4f99a000271c85575c88e14 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 17 Apr 2017 12:05:36 +0100 Subject: [PATCH] wp_insert_term can return an error so handle appropriately in class-wc-product-attribute.php Fixes #14429 --- includes/class-wc-product-attribute.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-product-attribute.php b/includes/class-wc-product-attribute.php index 25a525b1964..ab730ad22a8 100644 --- a/includes/class-wc-product-attribute.php +++ b/includes/class-wc-product-attribute.php @@ -77,7 +77,7 @@ class WC_Product_Attribute implements ArrayAccess { if ( ! $term || is_wp_error( $term ) ) { $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 ) ) { @@ -105,7 +105,7 @@ class WC_Product_Attribute implements ArrayAccess { if ( ! $term || is_wp_error( $term ) ) { $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 ) ) {