From b6925d49efecc8662a8e45818473e2e99f21aafe Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 19 Jan 2015 10:52:44 -0200 Subject: [PATCH] [API] Fixed errors when the description and short_description is empty in products endpoint --- includes/api/class-wc-api-products.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/api/class-wc-api-products.php b/includes/api/class-wc-api-products.php index 3e044aa4481..dc14d916eb7 100644 --- a/includes/api/class-wc-api-products.php +++ b/includes/api/class-wc-api-products.php @@ -207,11 +207,17 @@ class WC_API_Products extends WC_API_Resource { throw new WC_API_Exception( 'woocommerce_api_invalid_product_type', sprintf( __( 'Invalid product type - the product type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_product_types() ) ) ), 400 ); } - // enable description html tags. - $post_content = ( isset( $data['enable_html_description'] ) && 'true' === $data['enable_html_description'] ) ? $data['description'] : wc_clean( $data['description'] ); + // Enable description html tags. + $post_content = isset( $data['description'] ) ? wc_clean( $data['description'] ) : ''; + if ( $post_content && isset( $data['enable_html_description'] ) && 'true' === $data['enable_html_description'] ) { + $post_content = $data['description']; + } - // enable short description html tags. - $post_excerpt = ( isset( $data['enable_html_short_description'] ) && 'true' === $data['enable_html_short_description'] ) ? $data['short_description'] : wc_clean( $data['short_description'] ); + // Enable short description html tags. + $post_excerpt = isset( $data['short_description'] ) ? wc_clean( $data['short_description'] ) : ''; + if ( $post_excerpt && isset( $data['enable_html_short_description'] ) && 'true' === $data['enable_html_short_description'] ) { + $post_excerpt = $data['short_description']; + } $new_product = array( 'post_title' => wc_clean( $data['title'] ),