Merge pull request #1226 from woocommerce/PCP-1482-remove-shortcode

Remove shortcodes from description
This commit is contained in:
Emili Castells 2023-03-16 15:13:27 +01:00 committed by GitHub
commit 1b27a27313
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 17 deletions

View file

@ -58,7 +58,7 @@ class ItemFactory {
mb_substr( $product->get_name(), 0, 127 ),
new Money( $price, $this->currency ),
$quantity,
substr( wp_strip_all_tags( $product->get_description() ), 0, 127 ) ?: '',
$this->prepare_description( $product->get_description() ),
null,
$product->get_sku(),
( $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
@ -130,7 +130,7 @@ class ItemFactory {
mb_substr( $item->get_name(), 0, 127 ),
new Money( $price_without_tax_rounded, $currency ),
$quantity,
substr( wp_strip_all_tags( $product instanceof WC_Product ? $product->get_description() : '' ), 0, 127 ) ?: '',
$product instanceof WC_Product ? $this->prepare_description( $product->get_description() ) : '',
null,
$product instanceof WC_Product ? $product->get_sku() : '',
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS
@ -198,4 +198,15 @@ class ItemFactory {
$category
);
}
/**
* Cleanups the description and prepares it for sending to PayPal.
*
* @param string $description Item description.
* @return string
*/
protected function prepare_description( string $description ): string {
$description = strip_shortcodes( wp_strip_all_tags( $description ) );
return substr( $description, 0, 127 ) ?: '';
}
}

View file

@ -43,9 +43,8 @@ class ItemFactoryTest extends TestCase
->expects('get_cart_contents')
->andReturn($items);
expect('wp_strip_all_tags')
->with('description')
->andReturn('description');
expect('wp_strip_all_tags')->andReturnFirstArg();
expect('strip_shortcodes')->andReturnFirstArg();
$woocommerce = Mockery::mock(\WooCommerce::class);
$session = Mockery::mock(\WC_Session::class);
@ -99,9 +98,8 @@ class ItemFactoryTest extends TestCase
->expects('get_cart_contents')
->andReturn($items);
expect('wp_strip_all_tags')
->with('description')
->andReturn('description');
expect('wp_strip_all_tags')->andReturnFirstArg();
expect('strip_shortcodes')->andReturnFirstArg();
$woocommerce = Mockery::mock(\WooCommerce::class);
$session = Mockery::mock(\WC_Session::class);
@ -130,9 +128,9 @@ class ItemFactoryTest extends TestCase
$product
->expects('is_virtual')
->andReturn(false);
expect('wp_strip_all_tags')
->with('description')
->andReturn('description');
expect('wp_strip_all_tags')->andReturnFirstArg();
expect('strip_shortcodes')->andReturnFirstArg();
$item = Mockery::mock(\WC_Order_Item_Product::class);
$item
@ -190,9 +188,8 @@ class ItemFactoryTest extends TestCase
->expects('is_virtual')
->andReturn(true);
expect('wp_strip_all_tags')
->with('description')
->andReturn('description');
expect('wp_strip_all_tags')->andReturnFirstArg();
expect('strip_shortcodes')->andReturnFirstArg();
$item = Mockery::mock(\WC_Order_Item_Product::class);
$item
@ -245,9 +242,8 @@ class ItemFactoryTest extends TestCase
->expects('is_virtual')
->andReturn(true);
expect('wp_strip_all_tags')
->with($description)
->andReturn(mb_substr( $description, 0, 127 ));
expect('wp_strip_all_tags')->andReturnFirstArg();
expect('strip_shortcodes')->andReturnFirstArg();
$item = Mockery::mock(\WC_Order_Item_Product::class);
$item