From e1e90f05e528e7144e63abfd54e3483bb3119f16 Mon Sep 17 00:00:00 2001 From: Angelo Ou Date: Tue, 27 May 2025 16:19:33 -0400 Subject: [PATCH 1/2] Fix linter errors for ./facebook-commerce.php --- facebook-commerce.php | 185 +++++++++------------- includes/ExternalVersionUpdate/Update.php | 4 +- 2 files changed, 73 insertions(+), 116 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index 7e55f64e0..e10869b6f 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -1,6 +1,4 @@ Facebook for WooCommerce
'; public const FB_SYNC_IN_PROGRESS = 'fb_sync_in_progress'; - public const FB_SYNC_REMAINING = 'fb_sync_remaining'; - public const FB_SYNC_TIMEOUT = 30; - public const FB_PRIORITY_MID = 9; + public const FB_SYNC_REMAINING = 'fb_sync_remaining'; + public const FB_SYNC_TIMEOUT = 30; + public const FB_PRIORITY_MID = 9; /** * Facebook exception test mode switch. @@ -256,8 +258,8 @@ public function __construct( WC_Facebookcommerce $facebook_for_woocommerce ) { WC_Facebookcommerce_Utils::$ems = $this->get_external_merchant_settings_id(); // Set meta diagnosis to yes by default - if(!get_option( self::SETTING_ENABLE_META_DIAGNOSIS )) { - update_option(self::SETTING_ENABLE_META_DIAGNOSIS, 'yes'); + if ( ! get_option( self::SETTING_ENABLE_META_DIAGNOSIS ) ) { + update_option( self::SETTING_ENABLE_META_DIAGNOSIS, 'yes' ); } if ( is_admin() ) { @@ -270,8 +272,8 @@ public function __construct( WC_Facebookcommerce $facebook_for_woocommerce ) { // Display an info banner for eligible pixel and user. if ( $this->get_external_merchant_settings_id() - && $this->get_facebook_pixel_id() - && $this->get_pixel_install_time() ) { + && $this->get_facebook_pixel_id() + && $this->get_pixel_install_time() ) { $should_query_tip = WC_Facebookcommerce_Utils::check_time_cap( get_option( 'fb_info_banner_last_query_time', '' ), @@ -446,7 +448,7 @@ public function init_pixel() { if ( WC_Facebookcommerce_Utils::is_valid_id( $settings_pixel_id ) && ( ! WC_Facebookcommerce_Utils::is_valid_id( $pixel_id ) || - $pixel_id != $settings_pixel_id + $pixel_id !== $settings_pixel_id ) ) { WC_Facebookcommerce_Pixel::set_pixel_id( $settings_pixel_id ); @@ -475,7 +477,6 @@ public function init_pixel() { * * @return AAMSettings * @since 2.0.3 - * */ private function load_aam_settings_of_pixel() { $installed_pixel = $this->get_facebook_pixel_id(); @@ -488,7 +489,7 @@ private function load_aam_settings_of_pixel() { $refresh_interval = 20 * MINUTE_IN_SECONDS; $aam_settings = null; // If wc_facebook_aam_settings is present in the DB it is converted into an AAMSettings object. - if ( $saved_value !== false ) { + if ( false !== $saved_value ) { $cached_aam_settings = new AAMSettings( json_decode( $saved_value, true ) ); // This condition is added because // it is possible that the AAMSettings saved do not belong to the current @@ -575,11 +576,10 @@ public function ajax_fb_background_check_queue() { * Gets a list of Product Item IDs indexed by the ID of the variation. * * @param WC_Facebook_Product|WC_Product $product product - * @param string $product_group_id product group ID + * @param string $product_group_id product group ID * * @return array * @since 2.0.0 - * */ public function get_variation_product_item_ids( $product, $product_group_id ) { $product_item_ids_by_variation_id = []; @@ -587,8 +587,10 @@ public function get_variation_product_item_ids( $product, $product_group_id ) { // get the product item IDs from meta data and build a list of variations that don't have a product item ID stored foreach ( $product->get_children() as $variation_id ) { - if ( $variation = wc_get_product( $variation_id ) ) { - if ( $product_item_id = $variation->get_meta( self::FB_PRODUCT_ITEM_ID ) ) { + $variation = wc_get_product( $variation_id ); + if ( $variation ) { + $product_item_id = $variation->get_meta( self::FB_PRODUCT_ITEM_ID ); + if ( $product_item_id ) { $product_item_ids_by_variation_id[ $variation_id ] = $product_item_id; } else { $retailer_id = WC_Facebookcommerce_Utils::get_fb_retailer_id( $variation ); @@ -800,7 +802,6 @@ public function load_assets() { * @since 2.3.0 * * @internal - * */ private function get_removed_from_sync_products_to_delete() { $posted_products = Helper::get_posted_value( WC_Facebook_Product::FB_REMOVE_FROM_SYNC ); @@ -819,7 +820,6 @@ private function get_removed_from_sync_products_to_delete() { * @since 1.10.0 * * @internal - * */ public function on_product_save( int $wp_id ) { $product = wc_get_product( $wp_id ); @@ -855,7 +855,7 @@ public function on_product_save( int $wp_id ) { } } - if( $sync_enabled ) { + if ( $sync_enabled ) { Products::enable_sync_for_products( [ $product ] ); Products::set_product_visibility( $product, Admin::SYNC_MODE_SYNC_AND_HIDE !== $sync_mode ); $this->save_product_settings( $product ); @@ -948,7 +948,6 @@ private function save_variable_product_settings( $product ) { * @param \WC_Product $product the product object * * @since 1.10.0 - * */ private function save_product_settings( WC_Product $product ) { $woo_product = new WC_Facebook_Product( $product->get_id() ); @@ -956,7 +955,7 @@ private function save_product_settings( WC_Product $product ) { // phpcs:disable WordPress.Security.NonceVerification.Missing if ( isset( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ) ) { $woo_product->set_description( sanitize_text_field( wp_unslash( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ) ) ); - $woo_product->set_rich_text_description( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ); + $woo_product->set_rich_text_description( sanitize_text_field( wp_unslash( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ) ) ); } if ( isset( $_POST[ WC_Facebook_Product::FB_PRODUCT_PRICE ] ) ) { @@ -1017,7 +1016,6 @@ public function on_product_delete( int $product_id ) { * @since 2.3.0 * * @internal - * */ public function delete_fb_product( $product ) { @@ -1051,12 +1049,11 @@ public function delete_fb_product( $product ) { /** * Updates Facebook Visibility upon trashing and restore. * - * @param string $new_status - * @param string $old_status + * @param string $new_status + * @param string $old_status * @param \WP_post $post * * @internal - * */ public function fb_change_product_published_status( $new_status, $old_status, $post ) { if ( ! $post ) { @@ -1087,7 +1084,7 @@ public function fb_change_product_published_status( $new_status, $old_status, $p $visibility = $product->is_visible() ? self::FB_SHOP_PRODUCT_VISIBLE : self::FB_SHOP_PRODUCT_HIDDEN; - if ( $visibility === self::FB_SHOP_PRODUCT_VISIBLE ) { + if ( self::FB_SHOP_PRODUCT_VISIBLE === $visibility ) { // - new status is 'publish' regardless of old status, sync to Facebook $this->on_product_publish( $product->get_id() ); } else { @@ -1101,7 +1098,6 @@ public function fb_change_product_published_status( $new_status, $old_status, $p * @param int $post_id * * @internal - * */ public function fb_restore_untrashed_variable_product( $post_id ) { $product = wc_get_product( $post_id ); @@ -1116,7 +1112,7 @@ public function fb_restore_untrashed_variable_product( $post_id ) { $visibility = $product->is_visible() ? self::FB_SHOP_PRODUCT_VISIBLE : self::FB_SHOP_PRODUCT_HIDDEN; - if ( $visibility === self::FB_SHOP_PRODUCT_VISIBLE ) { + if ( self::FB_SHOP_PRODUCT_VISIBLE === $visibility ) { // - new status is 'publish' regardless of old status, sync to Facebook $this->on_product_publish( $product->get_id() ); } @@ -1135,10 +1131,9 @@ public function fb_restore_untrashed_variable_product( $post_id ) { * * @return bool * @since 2.0.2 - * */ private function should_update_visibility_for_product_status_change( $new_status, $old_status ) { - return ( $old_status === 'publish' && $new_status !== 'publish' ) || ( $old_status === 'trash' && $new_status === 'publish' ) || ( $old_status === 'future' && $new_status === 'publish' ); + return ( 'publish' === $old_status && 'publish' !== $new_status ) || ( 'trash' === $old_status && 'publish' === $new_status ) || ( 'future' === $old_status && 'publish' === $new_status ); } /** @@ -1185,7 +1180,7 @@ public function on_product_publish( $product_id ) { * If the user has opt-in to remove products that are out of stock, * this function will delete the product from FB Page as well. * - * @param int $wp_id + * @param int $wp_id * @param WC_Product $woo_product * * @return bool @@ -1204,7 +1199,7 @@ public function delete_on_out_of_stock( int $wp_id, WC_Product $woo_product ): b /** * Syncs product to Facebook when saving a variable product. * - * @param int $wp_id product post ID + * @param int $wp_id product post ID * @param WC_Facebook_Product|null $woo_product product object */ public function on_variable_product_publish( $wp_id, $woo_product = null ) { @@ -1247,7 +1242,7 @@ public function on_variable_product_publish( $wp_id, $woo_product = null ) { /** * Syncs product to Facebook when saving a simple product. * - * @param int $wp_id product post ID + * @param int $wp_id product post ID * @param WC_Facebook_Product|null $woo_product product object * @param WC_Facebook_Product|null $parent_product parent object * @@ -1285,7 +1280,6 @@ public function on_simple_product_publish( $wp_id, $woo_product = null, &$parent * @param WC_Product $product product object * * @since 2.0.0 - * */ public function product_should_be_synced( WC_Product $product ): bool { try { @@ -1301,24 +1295,22 @@ public function product_should_be_synced( WC_Product $product ): bool { * Create product group and product, store fb-specific info. * * @param WC_Facebook_Product $woo_product - * @param string|null $fb_product_group_id * * @return string */ - public function create_product_simple( WC_Facebook_Product $woo_product): string { + public function create_product_simple( WC_Facebook_Product $woo_product ): string { $retailer_id = WC_Facebookcommerce_Utils::get_fb_retailer_id( $woo_product ); return $this->create_product_item_batch_api( $woo_product, $retailer_id ); } /** * @param WC_Facebook_Product $woo_product - * @param string $retailer_id - * @param bool $variants + * @param string $retailer_id * * @return ?string */ public function create_product_group( WC_Facebook_Product $woo_product, string $retailer_id ): ?string { - $product_group_data = [ + $product_group_data = [ 'retailer_id' => $retailer_id, ]; $product_group_data['variants'] = $woo_product->prepare_variants_for_group(); @@ -1418,8 +1410,8 @@ public function update_product_group( WC_Facebook_Product $woo_product ) { * which is currently using facebook Product Item API implemented by `WC_Facebookcommerce_Integration::create_product_item` * * @param WC_Facebook_Product $woo_product - * @param string $retailer_id - **@since 3.1.7 + * @param string $retailer_id + * *@since 3.1.7 */ public function create_product_item_batch_api( $woo_product, $retailer_id ): string { try { @@ -1478,14 +1470,13 @@ public function create_product_item( $woo_product, $retailer_id, $product_group_ * Select closest matching if best can't be found. * * @param WC_Facebook_Product $woo_product - * @param string $fb_product_group_id + * @param string $fb_product_group_id * * @return integer|null Facebook Catalog variation id. * @since 2.1.2 * * @since 2.6.6 * The algorithm only considers the variations that already have been synchronized to the catalog successfully. - * */ private function get_product_group_default_variation( WC_Facebook_Product $woo_product, string $fb_product_group_id ) { $default_attributes = $woo_product->woo_product->get_default_attributes( 'edit' ); @@ -1560,7 +1551,6 @@ private function get_product_group_default_variation( WC_Facebook_Product $woo_p * * @return array * @since 2.1.2 - * */ private function get_product_variation_attributes( array $variation ): array { $final_attributes = []; @@ -1577,7 +1567,7 @@ private function get_product_variation_attributes( array $variation ): array { * Update existing product using batch API. * * @param WC_Facebook_Product $woo_product - * @param string $fb_product_item_id + * @param string $fb_product_item_id * * @return void */ @@ -1609,7 +1599,7 @@ public function update_product_item_batch_api( WC_Facebook_Product $woo_product, * Update existing product. * * @param WC_Facebook_Product $woo_product - * @param string $fb_product_item_id + * @param string $fb_product_item_id * * @return void */ @@ -1644,9 +1634,8 @@ public function update_product_item( WC_Facebook_Product $woo_product, string $f * Create or update product set * * @param array $product_set_data Product Set data. - * @param int $product_set_id Product Set Term Id. - **@since 2.3.0 - * + * @param int $product_set_id Product Set Term Id. + * *@since 2.3.0 */ public function create_or_update_product_set_item( $product_set_data, $product_set_id ) { // check if exists in FB @@ -1679,8 +1668,8 @@ public function create_or_update_product_set_item( $product_set_data, $product_s * @param string $fb_product_set_id Facebook Product Set ID. * * @return void - * @throws ApiException - * @throws \WooCommerce\Facebook\API\Exceptions\Request_Limit_Reached + * @throws ApiException If the request fails. + * @throws \WooCommerce\Facebook\API\Exceptions\Request_Limit_Reached If the request limit is reached. */ public function delete_product_set_item( string $fb_product_set_id ) { $allow_live_deletion = apply_filters( 'wc_facebook_commerce_allow_live_product_set_deletion', true, $fb_product_set_id ); @@ -1731,9 +1720,8 @@ public function display_batch_api_completed( $post ) { if ( $fb_product_item_id ) { $this->display_success_message( '' . - 'View product on Meta catalog' + $this->get_product_catalog_id() . + '/products/" target="_blank">View product on Meta catalog' ); } } @@ -1811,7 +1799,6 @@ public function ajax_check_feed_upload_status_v2() { * * @return void * @deprecated 2.1.0 - * */ public function display_success_message( string $msg ): void { $msg = self::FB_ADMIN_MESSAGE_PREPEND . $msg; @@ -1918,10 +1905,14 @@ public function ajax_woo_adv_bulk_edit_compat( string $import_id ): void { public function wp_all_import_compat( string $import_id ): void { $import = new PMXI_Import_Record(); $import->getById( $import_id ); - if ( ! $import->isEmpty() && in_array( $import->options['custom_type'], [ + if ( ! $import->isEmpty() && in_array( + $import->options['custom_type'], + [ 'product', - 'product_variation' - ], true ) ) { + 'product_variation', + ], + true + ) ) { $this->display_out_of_sync_message( 'import' ); } } @@ -1948,7 +1939,7 @@ public function display_out_of_sync_message( string $action_name ): void { * id error, update existing ID. * * @param stdClass $error_data - * @param int $wpid + * @param int $wpid * * @return null **/ @@ -2204,10 +2195,10 @@ private function sync_facebook_products() { /** * Syncs Facebook products using the background processor. * - * @return bool - * @throws ApiException Some comment. - * @throws PluginException If product sync disabled. * @since 1.10.2 + * + * @return bool + * @throws PluginException If the plugin is not configured or the Catalog ID is missing. */ private function sync_facebook_products_using_background_processor() { if ( ! $this->is_product_sync_enabled() ) { @@ -2345,7 +2336,6 @@ public function ajax_fb_toggle_visibility() { * * @return string * @since 1.10.0 - * */ public function get_product_catalog_id() { if ( ! is_string( $this->product_catalog_id ) ) { @@ -2360,7 +2350,6 @@ public function get_product_catalog_id() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return apply_filters( 'wc_facebook_product_catalog_id', $this->product_catalog_id, $this ); } @@ -2370,7 +2359,6 @@ public function get_product_catalog_id() { * * @return string * @since 1.10.0 - * */ public function get_external_merchant_settings_id() { if ( ! is_string( $this->external_merchant_settings_id ) ) { @@ -2385,7 +2373,6 @@ public function get_external_merchant_settings_id() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (string) apply_filters( 'wc_facebook_external_merchant_settings_id', $this->external_merchant_settings_id, $this ); } @@ -2395,7 +2382,6 @@ public function get_external_merchant_settings_id() { * * @return string * @since 1.10.0 - * */ public function get_feed_id() { if ( ! is_string( $this->feed_id ) ) { @@ -2410,7 +2396,6 @@ public function get_feed_id() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (string) apply_filters( 'wc_facebook_feed_id', $this->feed_id, $this ); } @@ -2420,7 +2405,6 @@ public function get_feed_id() { * * @return string * @since 1.11.0 - * */ public function get_upload_id() { if ( ! is_string( $this->upload_id ) ) { @@ -2435,7 +2419,6 @@ public function get_upload_id() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.11.0 - * */ return (string) apply_filters( 'wc_facebook_upload_id', $this->upload_id, $this ); } @@ -2445,11 +2428,11 @@ public function get_upload_id() { * * @return int * @since 1.10.0 - * */ public function get_pixel_install_time() { if ( ! (int) $this->pixel_install_time ) { - $value = (int) get_option( self::OPTION_PIXEL_INSTALL_TIME, 0 ); + $value = (int) get_option( self::OPTION_PIXEL_INSTALL_TIME, 0 ); + // phpcs:ignore Universal.Operators.DisallowShortTernary.Found $this->pixel_install_time = $value ?: null; } @@ -2460,7 +2443,6 @@ public function get_pixel_install_time() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (int) apply_filters( 'wc_facebook_pixel_install_time', $this->pixel_install_time, $this ); } @@ -2470,7 +2452,6 @@ public function get_pixel_install_time() { * * @return string * @since 1.10.0 - * */ public function get_js_sdk_version() { if ( ! is_string( $this->js_sdk_version ) ) { @@ -2485,7 +2466,6 @@ public function get_js_sdk_version() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (string) apply_filters( 'wc_facebook_js_sdk_version', $this->js_sdk_version, $this ); } @@ -2495,7 +2475,6 @@ public function get_js_sdk_version() { * * @return string * @since 1.10.0 - * */ public function get_facebook_page_id() { /** @@ -2505,7 +2484,6 @@ public function get_facebook_page_id() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (string) apply_filters( 'wc_facebook_page_id', get_option( self::SETTING_FACEBOOK_PAGE_ID, '' ), $this ); } @@ -2515,7 +2493,6 @@ public function get_facebook_page_id() { * * @return string * @since 1.10.0 - * */ public function get_facebook_pixel_id() { /** @@ -2525,7 +2502,6 @@ public function get_facebook_pixel_id() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (string) apply_filters( 'wc_facebook_pixel_id', get_option( self::SETTING_FACEBOOK_PIXEL_ID, '' ), $this ); } @@ -2535,7 +2511,6 @@ public function get_facebook_pixel_id() { * * @return int[] * @since 1.10.0 - * */ public function get_excluded_product_category_ids() { /** @@ -2545,7 +2520,6 @@ public function get_excluded_product_category_ids() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (array) apply_filters( 'wc_facebook_excluded_product_category_ids', get_option( self::SETTING_EXCLUDED_PRODUCT_CATEGORY_IDS, [] ), $this ); } @@ -2555,7 +2529,6 @@ public function get_excluded_product_category_ids() { * * @return int[] * @since 1.10.0 - * */ public function get_excluded_product_tag_ids() { /** @@ -2565,7 +2538,6 @@ public function get_excluded_product_tag_ids() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (array) apply_filters( 'wc_facebook_excluded_product_tag_ids', get_option( self::SETTING_EXCLUDED_PRODUCT_TAG_IDS, [] ), $this ); } @@ -2579,7 +2551,6 @@ public function get_excluded_product_tag_ids() { * @param string $value product catalog ID value * * @since 1.10.0 - * */ public function update_product_catalog_id( $value ) { $this->product_catalog_id = $this->sanitize_facebook_credential( $value ); @@ -2593,7 +2564,6 @@ public function update_product_catalog_id( $value ) { * @param string $value external merchant settings ID value * * @since 1.10.0 - * */ public function update_external_merchant_settings_id( $value ) { $this->external_merchant_settings_id = $this->sanitize_facebook_credential( $value ); @@ -2607,7 +2577,6 @@ public function update_external_merchant_settings_id( $value ) { * @param string $value feed ID value * * @since 1.10.0 - * */ public function update_feed_id( $value ) { $this->feed_id = $this->sanitize_facebook_credential( $value ); @@ -2621,7 +2590,6 @@ public function update_feed_id( $value ) { * @param string $value upload ID value * * @since 1.11.0 - * */ public function update_upload_id( $value ) { $this->upload_id = $this->sanitize_facebook_credential( $value ); @@ -2635,13 +2603,13 @@ public function update_upload_id( $value ) { * @param int $value pixel install time, in UTC seconds * * @since 1.10.0 - * */ public function update_pixel_install_time( $value ) { $value = (int) $value; - + // phpcs:ignore Universal.Operators.DisallowShortTernary.Found $this->pixel_install_time = $value ?: null; + // phpcs:ignore Universal.Operators.DisallowShortTernary.Found update_option( self::OPTION_PIXEL_INSTALL_TIME, $value ?: '' ); } @@ -2651,7 +2619,6 @@ public function update_pixel_install_time( $value ) { * @param string $value JS SDK version * * @since 1.10.0 - * */ public function update_js_sdk_version( $value ) { $this->js_sdk_version = $this->sanitize_facebook_credential( $value ); @@ -2666,7 +2633,6 @@ public function update_js_sdk_version( $value ) { * * @return string * @since 1.10.0 - * */ private function sanitize_facebook_credential( $value ) { return wc_clean( is_string( $value ) ? $value : '' ); @@ -2677,7 +2643,6 @@ private function sanitize_facebook_credential( $value ) { * * @return bool * @since 1.10.0 - * */ public function is_configured() { return $this->get_facebook_page_id() && $this->facebook_for_woocommerce->get_connection_handler()->is_connected(); @@ -2688,7 +2653,6 @@ public function is_configured() { * * @return bool * @since 1.10.0 - * */ public function is_advanced_matching_enabled() { /** @@ -2698,7 +2662,6 @@ public function is_advanced_matching_enabled() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (bool) apply_filters( 'wc_facebook_is_advanced_matching_enabled', true, $this ); } @@ -2708,7 +2671,6 @@ public function is_advanced_matching_enabled() { * * @return bool * @since 1.10.0 - * */ public function is_product_sync_enabled() { /** @@ -2718,7 +2680,6 @@ public function is_product_sync_enabled() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.0 - * */ return (bool) apply_filters( 'wc_facebook_is_product_sync_enabled', 'yes' === get_option( self::SETTING_ENABLE_PRODUCT_SYNC, 'yes' ), $this ); } @@ -2748,7 +2709,6 @@ public function is_legacy_feed_file_generation_enabled() { * * @return bool * @since 3.4.4 - * */ public function is_meta_diagnosis_enabled() { return (bool) ( 'yes' === get_option( self::SETTING_ENABLE_META_DIAGNOSIS ) ); @@ -2759,7 +2719,6 @@ public function is_meta_diagnosis_enabled() { * * @return bool * @since 1.10.2 - * */ public function is_debug_mode_enabled() { /** @@ -2769,7 +2728,6 @@ public function is_debug_mode_enabled() { * @param \WC_Facebookcommerce_Integration $integration the integration instance * * @since 1.10.2 - * */ return (bool) apply_filters( 'wc_facebook_is_debug_mode_enabled', 'yes' === get_option( self::SETTING_ENABLE_DEBUG_MODE ), $this ); } @@ -2779,7 +2737,6 @@ public function is_debug_mode_enabled() { * * @return bool * @since 2.6.6 - * */ public function is_new_style_feed_generation_enabled() { return (bool) ( 'yes' === get_option( self::SETTING_ENABLE_NEW_STYLE_FEED_GENERATOR ) ); @@ -2801,7 +2758,6 @@ public function are_headers_requested_for_debug() { * * @return bool * @since 1.11.0 - * */ public function is_feed_migrated() { if ( ! is_bool( $this->feed_migrated ) ) { @@ -2819,10 +2775,12 @@ public function is_feed_migrated() { * @param string $type * * @return string + * + * phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped */ private function get_message_html( string $message, string $type = 'error' ): string { ob_start(); - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + printf( '

%s

', esc_attr( $type ), @@ -2876,11 +2834,12 @@ public function maybe_display_facebook_api_messages() { /** * Admin Panel Options + * + * phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped */ public function admin_options() { $this->facebook_for_woocommerce->get_message_handler()->show_messages(); - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( '
%s
', ! $this->is_configured() ? 'style="display: none"' : '', @@ -2932,7 +2891,7 @@ public function fb_duplicate_product_reset_meta( array $to_delete ): array { * Helper function to update FB visibility. * * @param int|WC_Product $product_id product ID or product object - * @param string $visibility visibility + * @param string $visibility visibility */ public function update_fb_visibility( $product_id, $visibility ) { // bail if the plugin is not configured properly @@ -2947,7 +2906,7 @@ public function update_fb_visibility( $product_id, $visibility ) { return; } - $should_set_visible = $visibility === self::FB_SHOP_PRODUCT_VISIBLE; + $should_set_visible = self::FB_SHOP_PRODUCT_VISIBLE === $visibility; if ( $product->is_type( 'variation' ) ) { Products::set_product_visibility( $product, $should_set_visible ); $this->facebook_for_woocommerce->get_products_sync_handler()->create_or_update_products( [ $product->get_id() ] ); @@ -2993,7 +2952,6 @@ public function update_fb_visibility( $product_id, $visibility ) { * @param \WC_Product $product product object * * @internal - * */ public function on_quick_and_bulk_edit_save( $product ) { // bail if not a product or product is not enabled for sync @@ -3004,7 +2962,7 @@ public function on_quick_and_bulk_edit_save( $product ) { $wp_id = $product->get_id(); $visibility = get_post_status( $wp_id ) === 'publish' ? self::FB_SHOP_PRODUCT_VISIBLE : self::FB_SHOP_PRODUCT_HIDDEN; - if ( $visibility === self::FB_SHOP_PRODUCT_VISIBLE ) { + if ( self::FB_SHOP_PRODUCT_VISIBLE === $visibility ) { // - new status is 'publish' regardless of old status, sync to Facebook $this->on_product_publish( $wp_id ); } else { @@ -3017,8 +2975,8 @@ public function on_quick_and_bulk_edit_save( $product ) { /** * Gets Facebook product ID from meta or from Facebook API. * - * @param string $fbid_type ID type (group or item) - * @param int $wp_id post ID + * @param string $fbid_type ID type (group or item) + * @param int $wp_id post ID * @param WC_Facebook_Product|null $woo_product product * * @return string facebook product id or an empty string @@ -3044,13 +3002,13 @@ public function get_product_fbid( string $fbid_type, int $wp_id, $woo_product = ); if ( $response->data && $response->data[0] && $response->data[0]['id'] ) { - $fb_id = $fbid_type == self::FB_PRODUCT_GROUP_ID + $fb_id = self::FB_PRODUCT_GROUP_ID === $fbid_type ? $response->data[0]['product_group']['id'] : $response->data[0]['id']; update_post_meta( $wp_id, $fbid_type, $fb_id ); return $fb_id; } elseif ( $response->id ) { - $fb_id = $fbid_type == self::FB_PRODUCT_GROUP_ID + $fb_id = self::FB_PRODUCT_GROUP_ID === $fbid_type ? $response->get_facebook_product_group_id() : $response->id; update_post_meta( $wp_id, $fbid_type, $fb_id ); @@ -3083,7 +3041,7 @@ public function ajax_display_test_result() { $test_pass = get_option( 'fb_test_pass', null ); if ( ! isset( $test_pass ) ) { $response['pass'] = 'in progress'; - } elseif ( $test_pass === 0 ) { + } elseif ( 0 === $test_pass ) { $response['pass'] = 'false'; $response['debug_info'] = get_transient( 'facebook_plugin_test_fail' ); $response['stack_trace'] = @@ -3112,5 +3070,4 @@ public function load_whatsapp_utility_event_processor() { } } } - } diff --git a/includes/ExternalVersionUpdate/Update.php b/includes/ExternalVersionUpdate/Update.php index f78c0e493..0f08e34b7 100644 --- a/includes/ExternalVersionUpdate/Update.php +++ b/includes/ExternalVersionUpdate/Update.php @@ -81,9 +81,9 @@ public function send_new_version_to_facebook_server() { // Send the request to the Meta server with the latest plugin version. try { - $external_business_id = $plugin->get_connection_handler()->get_external_business_id(); + $external_business_id = $plugin->get_connection_handler()->get_external_business_id(); $is_woo_all_product_opted_out = $plugin->get_plugin_render_handler()->is_master_sync_on() === false; - $response = $plugin->get_api()->update_plugin_version_configuration( $external_business_id, $is_woo_all_product_opted_out, WC_Facebookcommerce_Utils::PLUGIN_VERSION ); + $response = $plugin->get_api()->update_plugin_version_configuration( $external_business_id, $is_woo_all_product_opted_out, WC_Facebookcommerce_Utils::PLUGIN_VERSION ); if ( $response->has_api_error() ) { // If the request fails, we should retry it in the next heartbeat. return false; From 988ecdcc8526bd2d3743992d0da84344d654396c Mon Sep 17 00:00:00 2001 From: Angelo Ou Date: Wed, 28 May 2025 19:30:16 -0400 Subject: [PATCH 2/2] Fix rich text --- facebook-commerce.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index e10869b6f..d5e15ea03 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -955,7 +955,9 @@ private function save_product_settings( WC_Product $product ) { // phpcs:disable WordPress.Security.NonceVerification.Missing if ( isset( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ) ) { $woo_product->set_description( sanitize_text_field( wp_unslash( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ) ) ); - $woo_product->set_rich_text_description( sanitize_text_field( wp_unslash( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ) ) ); + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash + $woo_product->set_rich_text_description( $_POST[ self::FB_PRODUCT_DESCRIPTION ] ); } if ( isset( $_POST[ WC_Facebook_Product::FB_PRODUCT_PRICE ] ) ) {