Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/3.2.6 #2769

Merged
merged 14 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** Facebook for WooCommerce Changelog ***

= 3.2.6 - 2024-07-23 =
* Add - Filter facebook_for_woocommerce_fb_product_description.
* Fix - Remove deprecated FILTER_SANITIZE_STRING usage.
* Tweak - Align PHP require version to composer.json.

= 3.2.5 - 2024-07-10 =
* Tweak - WC 9.1 compatibility.
* Tweak - WP 6.6 compatibility.
Expand Down
5 changes: 3 additions & 2 deletions facebook-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
* Description: Grow your business on Facebook! Use this official plugin to help sell more of your products using Facebook. After completing the setup, you'll be ready to create ads that promote your products and you can also create a shop section on your Page where customers can browse your products on Facebook.
* Author: Facebook
* Author URI: https://www.facebook.com/
* Version: 3.2.5
* Version: 3.2.6
* Requires at least: 5.6
* Requires PHP: 7.4
* Text Domain: facebook-for-woocommerce
* Requires Plugins: woocommerce
* Tested up to: 6.6
Expand Down Expand Up @@ -48,7 +49,7 @@ class WC_Facebook_Loader {
/**
* @var string the plugin version. This must be in the main plugin file to be automatically bumped by Woorelease.
*/
const PLUGIN_VERSION = '3.2.5'; // WRCS: DEFINED_VERSION.
const PLUGIN_VERSION = '3.2.6'; // WRCS: DEFINED_VERSION.

// Minimum PHP version required by this plugin.
const MINIMUM_PHP_VERSION = '7.4.0';
Expand Down
8 changes: 4 additions & 4 deletions includes/Framework/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public static function str_truncate( $string, $length, $omission = '...' ) {
* @return string
*/
public static function str_to_ascii( $string ) {
// strip ASCII chars 32 and under
$string = filter_var( $string, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW );
// strip ASCII chars 127 and higher
return filter_var( $string, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH );
// Strip ASCII chars 32 and under
$string = preg_replace( '/[\x00-\x1F]/', '', $string );
// Strip ASCII chars 127 and higher
return preg_replace( '/[\x7F-\xFF]/', '', $string );
}


Expand Down
78 changes: 41 additions & 37 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,56 +391,60 @@ public function set_use_parent_image( $setting ) {
}

public function get_fb_description() {
$description = '';

if ( $this->fb_description ) {
return $this->fb_description;
$description = $this->fb_description;
}

$description = get_post_meta(
$this->id,
self::FB_PRODUCT_DESCRIPTION,
true
);

if ( $description ) {
return $description;
if ( empty( $description ) ) {
// Try to get description from post meta
$description = get_post_meta(
$this->id,
self::FB_PRODUCT_DESCRIPTION,
true
);
}

if ( WC_Facebookcommerce_Utils::is_variation_type( $this->woo_product->get_type() ) ) {

// Check if the product type is a variation and no description is found yet
if ( empty( $description ) && WC_Facebookcommerce_Utils::is_variation_type( $this->woo_product->get_type() ) ) {
$description = WC_Facebookcommerce_Utils::clean_string( $this->woo_product->get_description() );

if ( $description ) {
return $description;
}
if ( $this->main_description ) {
return $this->main_description;
// Fallback to main description
if ( empty( $description ) && $this->main_description ) {
$description = $this->main_description;
}
}

$post = $this->get_post_data();
// If no description is found from meta or variation, get from post
if ( empty( $description ) ) {
$post = $this->get_post_data();
$post_content = WC_Facebookcommerce_Utils::clean_string( $post->post_content );
$post_excerpt = WC_Facebookcommerce_Utils::clean_string( $post->post_excerpt );
$post_title = WC_Facebookcommerce_Utils::clean_string( $post->post_title );

$post_content = WC_Facebookcommerce_Utils::clean_string(
$post->post_content
);
$post_excerpt = WC_Facebookcommerce_Utils::clean_string(
$post->post_excerpt
);
$post_title = WC_Facebookcommerce_Utils::clean_string(
$post->post_title
);
// Prioritize content, then excerpt, then title
if ( ! empty( $post_content ) ) {
$description = $post_content;
}

// Sanitize description
if ( $post_content ) {
$description = $post_content;
}
if ( $this->sync_short_description || ( $description == '' && $post_excerpt ) ) {
$description = $post_excerpt;
}
if ( $description == '' ) {
$description = $post_title;
}
if ( $this->sync_short_description || ( empty( $description ) && ! empty( $post_excerpt ) ) ) {
$description = $post_excerpt;
}

return $description;
if ( empty( $description ) ) {
$description = $post_title;
}
}
/**
* Filters the FB product description.
*
* @since 3.2.6
*
* @param string $description Facebook product description.
* @param int $id WooCommerce Product ID.
*/
return apply_filters( 'facebook_for_woocommerce_fb_product_description', $description, $this->id );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facebook-for-woocommerce",
"version": "3.2.5",
"version": "3.2.6",
"author": "Facebook",
"homepage": "https://woocommerce.com/products/facebook/",
"license": "GPL-2.0",
Expand Down
15 changes: 10 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
=== Facebook for WooCommerce ===
Contributors: facebook, automattic, woothemes
Tags: facebook, woocommerce, marketing, product catalog feed, pixel
Requires at least: 4.4
Tested up to: 6.6
Stable tag: 3.2.5
Requires PHP: 5.6 or greater
Requires at least: 5.6
Tested up to: 6.6
Stable tag: 3.2.6
Requires PHP: 7.4
MySQL: 5.6 or greater
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -40,7 +40,12 @@ When opening a bug on GitHub, please give us as many details as possible.

== Changelog ==

= 3.2.5 - 2024-07-10 =
= 3.2.6 - 2024-07-23 =
* Add - Filter facebook_for_woocommerce_fb_product_description.
* Fix - Remove deprecated FILTER_SANITIZE_STRING usage.
* Tweak - Align PHP require version to composer.json.

= 3.2.5 - 2024-07-10 =
* Tweak - WC 9.1 compatibility.
* Tweak - WP 6.6 compatibility.

Expand Down
106 changes: 106 additions & 0 deletions tests/Unit/fbproductTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
declare(strict_types=1);


class fbproductTest extends WP_UnitTestCase {
private $parent_fb_product;

/**
* Test it gets description from post meta.
* @return void
*/
public function test_get_fb_description_from_post_meta() {
$product = WC_Helper_Product::create_simple_product();

$facebook_product = new \WC_Facebook_Product( $product );
$facebook_product->set_description( 'fb description' );
$description = $facebook_product->get_fb_description();

$this->assertEquals( $description, 'fb description');
}

/**
* Test it gets description from parent product if it is a variation.
* @return void
*/
public function test_get_fb_description_variable_product() {
$variable_product = WC_Helper_Product::create_variation_product();
$variable_product->set_description('parent description');
$variable_product->save();

$parent_fb_product = new \WC_Facebook_Product($variable_product);
$variation = wc_get_product($variable_product->get_children()[0]);

$facebook_product = new \WC_Facebook_Product( $variation, $parent_fb_product );
$description = $facebook_product->get_fb_description();
$this->assertEquals( $description, 'parent description' );

$variation->set_description( 'variation description' );
$variation->save();

$description = $facebook_product->get_fb_description();
$this->assertEquals( $description, 'variation description' );
}

/**
* Tests that if no description is found from meta or variation, it gets description from post
*
* @return void
*/
public function test_get_fb_description_from_post_content() {
$product = WC_Helper_Product::create_simple_product();

// Gets description from title
$facebook_product = new \WC_Facebook_Product( $product );
$description = $facebook_product->get_fb_description();

$this->assertEquals( $description, get_post( $product->get_id() )->post_title );

// Gets description from excerpt (product short description)
$product->set_short_description( 'short description' );
$product->save();

$description = $facebook_product->get_fb_description();
$this->assertEquals( $description, get_post( $product->get_id() )->post_excerpt );

// Gets description from content (product description)
$product->set_description( 'product description' );
$product->save();

$description = $facebook_product->get_fb_description();
$this->assertEquals( $description, get_post( $product->get_id() )->post_content );

// Gets description from excerpt ignoring content when short mode is set
add_option(
WC_Facebookcommerce_Integration::SETTING_PRODUCT_DESCRIPTION_MODE,
WC_Facebookcommerce_Integration::PRODUCT_DESCRIPTION_MODE_SHORT
);

$facebook_product = new \WC_Facebook_Product( $product );
$description = $facebook_product->get_fb_description();
$this->assertEquals( $description, get_post( $product->get_id() )->post_excerpt );
}

/**
* Test it filters description.
* @return void
*/
public function test_filter_fb_description() {
$product = WC_Helper_Product::create_simple_product();
$facebook_product = new \WC_Facebook_Product( $product );
$facebook_product->set_description( 'fb description' );

add_filter( 'facebook_for_woocommerce_fb_product_description', function( $description ) {
return 'filtered description';
});

$description = $facebook_product->get_fb_description();
$this->assertEquals( $description, 'filtered description' );

remove_all_filters( 'facebook_for_woocommerce_fb_product_description' );

$description = $facebook_product->get_fb_description();
$this->assertEquals( $description, 'fb description' );

}
}
Loading