From d6a87f2c16e2ab028fd593faac3585b687ddc389 Mon Sep 17 00:00:00 2001 From: Dima Date: Wed, 4 Jan 2023 15:49:03 +0200 Subject: [PATCH 1/3] Remove Facebook info banner. --- assets/css/facebook-infobanner.css | 56 ---- facebook-commerce.php | 20 -- includes/fbinfobanner.php | 241 ------------------ .../WCFacebookCommerceIntegrationTest.php | 48 ---- 4 files changed, 365 deletions(-) delete mode 100644 assets/css/facebook-infobanner.css delete mode 100644 includes/fbinfobanner.php diff --git a/assets/css/facebook-infobanner.css b/assets/css/facebook-infobanner.css deleted file mode 100644 index 5b34f3484..000000000 --- a/assets/css/facebook-infobanner.css +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved - * - * This source code is licensed under the license found in the - * LICENSE file in the root directory of this source tree. - * - * @package FacebookCommerce - */ -#fbinfobanner .btn { - /* container: */ - background-color: rgb(86,120,227); - border: 1px solid; - border-color: #435a8b #3c5488 #334c83; - border-radius: 2px; - padding: 5px 10px 5px 10px; - /* Get started: */ - font-family: helvetica, arial, sans-serif; - font-size: 12px; - font-weight: 600; - color: #FFFFFF; - text-align: center; - text-decoration: none; - display: inline-block; - margin: 5px 10px 1px 1px; -} - -#fbinfobanner .btn.dismiss { - margin: 5px 10px 5px 1px; -} - -#fbinfobanner .btn.grey{ - background: #f6f7f8; - border-color: #e0e1e2; - color: #4e5665; -} - -#fbinfobanner .iconDetails { - margin: 5px 10px 5px 3px; - float:left; - height:50px; - width:50px; -} - -#fbinfobanner .tipTitle { - padding: 1px 12px 1px 20px; - font-size: 14px; -} - -#fbinfobanner .tipContent { - padding: 1px 12px 1px 20px; - font-size: 14px; -} - -#fbinfobanner .tipButton { - margin-bottom: 0px; -} diff --git a/facebook-commerce.php b/facebook-commerce.php index 53511ac0c..530273091 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -235,25 +235,6 @@ public function __construct( WC_Facebookcommerce $facebook_for_woocommerce ) { include_once 'includes/fbutils.php'; } - // 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() ) { - $should_query_tip = - WC_Facebookcommerce_Utils::check_time_cap( - get_option( 'fb_info_banner_last_query_time', '' ), - self::FB_TIP_QUERY - ); - $last_tip_info = WC_Facebookcommerce_Utils::get_cached_best_tip(); - - if ( $should_query_tip || $last_tip_info ) { - if ( ! class_exists( 'WC_Facebookcommerce_Info_Banner' ) ) { - include_once 'includes/fbinfobanner.php'; - } - WC_Facebookcommerce_Info_Banner::get_instance( $this->get_external_merchant_settings_id(), $should_query_tip ); - } - } - if ( ! $this->get_pixel_install_time() && $this->get_facebook_pixel_id() ) { $this->update_pixel_install_time( time() ); } @@ -690,7 +671,6 @@ public function load_assets() { pixelId: 'get_facebook_pixel_id() ? esc_js( $this->get_facebook_pixel_id() ) : ''; ?>', advanced_matching_supported: true }, - diaSettingId: 'get_external_merchant_settings_id() ? esc_js( $this->get_external_merchant_settings_id() ) : ''; ?>', store: { baseUrl: window.location.protocol + '//' + window.location.host, baseCurrency:'', diff --git a/includes/fbinfobanner.php b/includes/fbinfobanner.php deleted file mode 100644 index 158d03b43..000000000 --- a/includes/fbinfobanner.php +++ /dev/null @@ -1,241 +0,0 @@ -should_query_tip = $should_query_tip; - $this->external_merchant_settings_id = $external_merchant_settings_id; - add_action( 'wp_ajax_ajax_woo_infobanner_post_click', array( $this, 'ajax_woo_infobanner_post_click' ) ); - add_action( 'wp_ajax_ajax_woo_infobanner_post_xout', array( $this, 'ajax_woo_infobanner_post_xout' ) ); - add_action( 'admin_notices', array( $this, 'banner' ) ); - add_action( 'admin_init', array( $this, 'dismiss_banner' ) ); - } - - /** - * Post click event when hit primary button. - */ - function ajax_woo_infobanner_post_click() { - WC_Facebookcommerce_Utils::check_woo_ajax_permissions( - 'post tip click event', - true - ); - check_ajax_referer( 'wc_facebook_infobanner_jsx' ); - $tip_info = WC_Facebookcommerce_Utils::get_cached_best_tip(); - $tip_id = isset( $tip_info->tip_id ) - ? $tip_info->tip_id - : null; - if ( $tip_id == null ) { - WC_Facebookcommerce_Utils::fblog( - 'Do not have tip id when click, sth went wrong', - array( 'tip_info' => $tip_info ), - true - ); - } else { - WC_Facebookcommerce_Utils::tip_events_log( - $tip_id, - self::CHANNEL_ID, - 'click' - ); - } - } - - /** - * Post xout event when hit dismiss button. - */ - function ajax_woo_infobanner_post_xout() { - WC_Facebookcommerce_Utils::check_woo_ajax_permissions( - 'post tip xout event', - true - ); - check_ajax_referer( 'wc_facebook_infobanner_jsx' ); - $tip_info = WC_Facebookcommerce_Utils::get_cached_best_tip(); - $tip_id = isset( $tip_info->tip_id ) - ? $tip_info->tip_id - : null; - // Delete cached tip if xout. - update_option( 'fb_info_banner_last_best_tip', '' ); - if ( $tip_id == null ) { - WC_Facebookcommerce_Utils::fblog( - 'Do not have tip id when xout, sth went wrong', - array( 'tip_info' => $tip_info ), - true - ); - } else { - WC_Facebookcommerce_Utils::tip_events_log( - $tip_id, - self::CHANNEL_ID, - 'xout' - ); - } - } - - /** - * Display a info banner on Woocommerce pages. - */ - public function banner() { - $screen = get_current_screen(); - if ( ! in_array( - $screen->base, - array( - 'woocommerce_page_wc-reports', - 'woocommerce_page_wc-settings', - 'woocommerce_page_wc-status', - ) - ) || - $screen->is_network || $screen->action ) { - return; - } - - $tip_info = null; - if ( ! $this->should_query_tip ) { - // If last query is less than 1 day, either has last best tip or default - // tip pass time cap. - $tip_info = WC_Facebookcommerce_Utils::get_cached_best_tip(); - } else { - - try { - $tip_info = facebook_for_woocommerce()->get_api()->get_tip_info( $this->external_merchant_settings_id ); - update_option( 'fb_info_banner_last_query_time', current_time( 'mysql' ) ); - } catch ( ApiException $exception ) { - // always log this error, regardless of debug setting - facebook_for_woocommerce()->log( 'Could not retrieve tip. ' . $exception->getMessage() ); - } - } - - // Not render if no cached best tip, or no best tip returned from FB. - if ( ! $tip_info || ( $tip_info === self::FB_NO_TIP_EXISTS ) ) { - // Delete cached tip if should query and get no tip. - delete_option( 'fb_info_banner_last_best_tip' ); - return; - } else { - // Get tip creatives via API - $tip_title = $tip_info->get_tip_title_html() ?? null; - $tip_body = $tip_info->get_tip_body_html() ?? null; - $tip_action_link = $tip_info->tip_action_link ?? null; - $tip_action = $tip_info->get_tip_action_html() ?? null; - $tip_img_url = isset( $tip_info->tip_img_url ) - ? self::DEFAULT_TIP_IMG_URL_PREFIX . $tip_info->tip_img_url - : null; - - if ( $tip_title == null || $tip_body == null || $tip_action_link == null || $tip_action == null || $tip_action == null ) { - WC_Facebookcommerce_Utils::fblog( - 'Unexpected response from FB for tip info.', - array( 'tip_info' => $tip_info ), - true - ); - return; - } - update_option( - 'fb_info_banner_last_best_tip', - is_object( $tip_info ) || is_array( $tip_info ) - ? json_encode( $tip_info ) : $tip_info - ); - } - - $dismiss_url = $this->dismiss_url(); - - echo '
'; - echo '
'; - echo '
'; - echo '

' . esc_html( $tip_title ) . "

\n"; - echo '

' . esc_html( $tip_body ) . '

'; - echo '

'; - echo ' ' . esc_html( $tip_action ) . ''; - echo ' ' . esc_html__( 'Dismiss', 'facebook-for-woocommerce' ) . ''; - echo '

'; - } - - /** - * Returns the url that the user clicks to remove the info banner - * - * @return (string) - */ - private function dismiss_url() { - $url = admin_url( 'admin.php' ); - - $url = add_query_arg( - array( - 'page' => 'wc-settings', - 'tab' => 'integration', - 'wc-notice' => 'dismiss-fb-info-banner', - ), - $url - ); - - return wp_nonce_url( $url, 'woocommerce_info_banner_dismiss' ); - } - - - /** - * Handles the action that dismisses the info banner. - * - * The banner will remain dismissed for at least one day and until a new info tip can be retrieved. - * - * @see \WC_Facebookcommerce_Integration::FB_TIP_QUERY - */ - public function dismiss_banner() { - - if ( ! isset( $_GET['wc-notice'] ) ) { - return; - } - - if ( 'dismiss-fb-info-banner' !== $_GET['wc-notice'] ) { - return; - } - - if ( ! check_admin_referer( 'woocommerce_info_banner_dismiss' ) ) { - return; - } - - // Delete cached tip if xout. - delete_option( 'fb_info_banner_last_best_tip' ); - if ( wp_get_referer() ) { - wp_safe_redirect( wp_get_referer() ); - } else { - wp_safe_redirect( admin_url( 'admin.php?page=wc-settings&tab=integration' ) ); - } - } - - -} diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index a3fe6e41a..473aeb578 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -1929,54 +1929,6 @@ function ( $product_catalog_id ) { $this->assertEquals( '3213-2132-1321-3213-2132', $product_catalog_id ); } - /** - * Tests get_external_merchant_settings_id returns id from object properly with no filters on it. - * - * @return void - */ - public function test_get_external_merchant_settings_id_returns_settings_id_from_initialised_property_using_no_filter() { - $this->integration->external_merchant_settings_id = '123123123123123123'; - remove_all_filters( 'wc_facebook_external_merchant_settings_id' ); - - $external_merchant_settings_id = $this->integration->get_external_merchant_settings_id(); - - $this->assertEquals( '123123123123123123', $external_merchant_settings_id ); - } - - /** - * Tests get_external_merchant_settings_id returns id from options with no filters on it. - * - * @return void - */ - public function test_get_external_merchant_settings_id_returns_settings_id_from_options_using_no_filter() { - $this->integration->external_merchant_settings_id = null; - add_option( WC_Facebookcommerce_Integration::OPTION_EXTERNAL_MERCHANT_SETTINGS_ID, '321321321321321321' ); - remove_all_filters( 'wc_facebook_external_merchant_settings_id' ); - - $external_merchant_settings_id = $this->integration->get_external_merchant_settings_id(); - - $this->assertEquals( '321321321321321321', $external_merchant_settings_id ); - $this->assertEquals( '321321321321321321', $this->integration->external_merchant_settings_id ); - } - - /** - * Tests get_external_merchant_settings_id returns id with filters on it. - * - * @return void - */ - public function test_get_external_merchant_settings_id_returns_settings_id_with_filter() { - add_filter( - 'wc_facebook_external_merchant_settings_id', - function ( $external_merchant_settings_id ) { - return '3213-2132-1321-3213-2132'; - } - ); - - $external_merchant_settings_id = $this->integration->get_external_merchant_settings_id(); - - $this->assertEquals( '3213-2132-1321-3213-2132', $external_merchant_settings_id ); - } - /** * Tests get_feed_id returns id from object properly with no filters on it. * From bc2902a3c87aeed89f9fa239821cef49bbbc7685 Mon Sep 17 00:00:00 2001 From: Dima Date: Wed, 4 Jan 2023 15:51:00 +0200 Subject: [PATCH 2/3] Remove Facebook info banner. --- facebook-commerce.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index 530273091..b7b2f05d7 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -633,27 +633,6 @@ public function allow_full_batch_api_sync() { * Load DIA specific JS Data */ public function load_assets() { - $ajax_data = [ - 'nonce' => wp_create_nonce( 'wc_facebook_infobanner_jsx' ), - ]; - // load banner assets - wp_enqueue_script( - 'wc_facebook_infobanner_jsx', - $this->facebook_for_woocommerce->get_asset_build_dir_url() . '/admin/infobanner.js', - [], - \WC_Facebookcommerce::PLUGIN_VERSION - ); - wp_localize_script( 'wc_facebook_infobanner_jsx', 'wc_facebook_infobanner_jsx', $ajax_data ); - wp_enqueue_style( - 'wc_facebook_infobanner_css', - plugins_url( - '/assets/css/facebook-infobanner.css', - __FILE__ - ), - [], - \WC_Facebookcommerce::PLUGIN_VERSION - ); - if ( ! $this->facebook_for_woocommerce->is_plugin_settings() ) { return; } From 0735ffc65b7e13f006970ddce2a7467f0c2daf4e Mon Sep 17 00:00:00 2001 From: Dima Date: Wed, 4 Jan 2023 16:43:13 +0200 Subject: [PATCH 3/3] Adjust tests to exclude Facebook Info banner checks. --- tests/Unit/WCFacebookCommerceIntegrationTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index 473aeb578..1a1625904 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -449,8 +449,6 @@ public function test_load_assets_loads_only_info_banner_assets_for_not_admin_or_ do_action( 'wp_enqueue_scripts' ); do_action( 'wp_enqueue_styles' ); - $this->assertTrue( wp_script_is( 'wc_facebook_infobanner_jsx' ) ); - $this->assertTrue( wp_style_is( 'wc_facebook_infobanner_css' ) ); $this->assertFalse( wp_style_is( 'wc_facebook_css' ) ); } @@ -471,8 +469,6 @@ public function test_load_assets_loads_only_info_banner_assets_for_admin_at_plug do_action( 'wp_enqueue_scripts' ); do_action( 'wp_enqueue_styles' ); - $this->assertTrue( wp_script_is( 'wc_facebook_infobanner_jsx' ) ); - $this->assertTrue( wp_style_is( 'wc_facebook_infobanner_css' ) ); $this->assertTrue( wp_style_is( 'wc_facebook_css' ) ); $this->assertRegExp( '/window.facebookAdsToolboxConfig = {/', $output ); }