diff --git a/.gitignore b/.gitignore index 7d1531631..0ed2159dc 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,8 @@ codeception.yml # local dev configurations .wp-env.json -php.ini \ No newline at end of file +php.ini +wp-config.php + +# IDE files +.vscode/* \ No newline at end of file diff --git a/changelog.txt b/changelog.txt index b079e8658..474b68c7d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,24 @@ *** Facebook for WooCommerce Changelog *** += 2.6.30 - 2022-11-09 = +* Fix - Add backward compatibility for WC 6.1, 6.2, and 6.3 versions. +* Fix - Sync product set when the term name changes. + += 2.6.29 - 2022-11-08 = +* Add - Facebook Product Set under the Marketing menu. +* Add - HPOS Compatibility. +* Add - Inbox note about Facebook menu moved under the Marketing menu. +* Add - Set up Facebook task to the WooCommerce admin tasks. +* Dev - Replaced methods from classes in the `Internal` namespace. +* Fix - Ensure the enhanced product enhance catalog attributes value is unslashed before saving in the post_meta table. +* Fix - Hosted Woo Updates. +* Fix - Release/2.6.28. +* Fix - duplicate InitiateCheckout when using checkout block. +* Tweak - WC 7.1 compatibility. +* Tweak - WP 6.1 compatibility. +* Update - FB Product Set name changed to Facebook Product Set. +* Update - On successful FBE install users will be redirected to Advertise tab of the plugin. + = 2.6.28 - 2022-10-25 = * Fix - Ensure bundles are not treated as virtual products on product_sync. * Fix - Ensure google-product-category-fields-loads.js loads only on the product category screens. diff --git a/class-wc-facebookcommerce.php b/class-wc-facebookcommerce.php index 05801bb7a..9226f9ad2 100644 --- a/class-wc-facebookcommerce.php +++ b/class-wc-facebookcommerce.php @@ -18,6 +18,10 @@ use SkyVerge\WooCommerce\Facebook\ProductSync\ProductValidator as ProductSyncValidator; use SkyVerge\WooCommerce\Facebook\Utilities\Heartbeat; use Automattic\WooCommerce\Admin\Features\Features as WooAdminFeatures; +use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists; +use Automattic\WooCommerce\Admin\Notes\Note; +use SkyVerge\WooCommerce\Facebook\Admin\Tasks\Setup; +use SkyVerge\WooCommerce\Facebook\Admin\Notes\SettingsMoved; if ( ! class_exists( 'WC_Facebookcommerce' ) ) : @@ -133,6 +137,9 @@ public function init() { add_filter( 'fb_product_set_row_actions', array( $this, 'product_set_links' ) ); add_filter( 'manage_edit-fb_product_set_columns', array( $this, 'manage_fb_product_set_columns' ) ); + // Hook the setup task. The hook admin_init is not triggered when the WC fetches the tasks using the endpoint: wp-json/wc-admin/onboarding/tasks and hence hooking into init. + add_action( 'init', array( $this, 'add_setup_task' ), 20 ); + // Product Set breadcrumb filters add_filter( 'woocommerce_navigation_is_connected_page', array( $this, 'is_current_page_conected_filter' ), 99, 2 ); add_filter( 'woocommerce_navigation_get_breadcrumbs', array( $this, 'wc_page_breadcrumbs_filter' ), 99 ); @@ -250,6 +257,21 @@ protected function get_deprecated_hooks() { ); } + /** + * Adds the setup task to the Tasklists. + * + * @since 2.6.29 + */ + public function add_setup_task() { + if ( class_exists( TaskLists::class ) ) { // This is added for backward compatibility. + TaskLists::add_task( + 'extended', + new Setup( + TaskLists::get_list( 'extended' ) + ) + ); + } + } /** * Adds the plugin admin notices. @@ -303,30 +325,6 @@ public function add_admin_notices() { ) ); } - - // otherwise, a general getting started message - } elseif ( ! $this->is_plugin_settings() ) { - - $message = sprintf( - /* translators: Placeholders %1$s - opening strong HTML tag, %2$s - closing strong HTML tag, %3$s - opening link HTML tag, %4$s - closing link HTML tag */ - esc_html__( - '%1$sFacebook for WooCommerce is almost ready.%2$s To complete your configuration, %3$scomplete the setup steps%4$s.', - 'facebook-for-woocommerce' - ), - '', - '', - '', - '' - ); - - $this->get_admin_notice_handler()->add_admin_notice( - $message, - self::PLUGIN_ID . '_get_started', - array( - 'dismissible' => true, - 'notice_class' => 'notice-info', - ) - ); } // notices for those connected to FBE 2 @@ -389,26 +387,27 @@ public function add_admin_notices() { && \Automattic\WooCommerce\Admin\Loader::is_feature_enabled( 'marketing' ); } - if ( $is_marketing_enabled ) { - - $this->get_admin_notice_handler()->add_admin_notice( - sprintf( - /* translators: Placeholders: %1$s - opening HTML link tag, %2$s - closing HTML link tag */ - esc_html__( 'Heads up! The Facebook menu is now located under the %1$sMarketing%2$s menu.', 'facebook-for-woocommerce' ), - '', - '' - ), - 'settings_moved_to_marketing', - array( - 'dismissible' => true, - 'always_show_on_settings' => false, - 'notice_class' => 'notice-info', - ) - ); + if ( $is_marketing_enabled && class_exists( Note::class ) ) { // Checking for Note class is for backward compatibility. + SettingsMoved::possibly_add_or_delete_note(); } } } + /** + * Get the last event from the plugin lifecycle. + * + * @since 2.6.29 + * @return array + */ + public function get_last_event_from_history() { + $last_event = array(); + $history_events = $this->lifecycle_handler->get_event_history(); + + if ( isset( $history_events[0] ) ) { + $last_event = $history_events[0]; + } + return $last_event; + } public function add_wordpress_integration() { new WP_Facebook_Integration(); @@ -470,14 +469,14 @@ public function remove_product_fb_product_set_metabox() { } /** - * Register FB Product Set Taxonomy + * Register Facebook Product Set Taxonomy * * @since 2.3.0 */ public function register_custom_taxonomy() { - $plural = esc_html__( 'FB Product Sets', 'facebook-for-woocommerce' ); - $singular = esc_html__( 'FB Product Set', 'facebook-for-woocommerce' ); + $plural = esc_html__( 'Facebook Product Sets', 'facebook-for-woocommerce' ); + $singular = esc_html__( 'Facebook Product Set', 'facebook-for-woocommerce' ); $args = array( 'labels' => array( @@ -502,6 +501,7 @@ public function register_custom_taxonomy() { 'public' => true, 'show_in_nav_menus' => false, 'show_tagcloud' => false, + 'show_in_menu' => false, ); register_taxonomy( 'fb_product_set', array( 'product' ), $args ); @@ -509,7 +509,7 @@ public function register_custom_taxonomy() { /** - * Filter FB Product Set Taxonomy table links + * Filter Facebook Product Set Taxonomy table links * * @since 2.3.0 * @@ -525,7 +525,7 @@ public function product_set_links( $actions ) { /** - * Remove posts count column from FB Product Set custom taxonomy + * Remove posts count column from Facebook Product Set custom taxonomy * * @since 2.3.0 * @@ -540,7 +540,7 @@ public function manage_fb_product_set_columns( $columns ) { /** - * Filter WC Breadcrumbs when the page is FB Product Sets + * Filter WC Breadcrumbs when the page is Facebook Product Sets * * @since 2.3.0 * @@ -572,7 +572,7 @@ public function wc_page_breadcrumbs_filter( $breadcrumbs ) { /** - * Return that FB Product Set page is a WC Conected Page + * Return that Facebook Product Set page is a WC Conected Page * * @since 2.3.0 * @@ -1016,6 +1016,19 @@ public function get_settings_url( $plugin_id = null ) { return admin_url( 'admin.php?page=wc-facebook' ); } + + /** + * Gets the advertise tab page URL. + * + * @since 2.6.29 + * + * @return string + */ + public function get_advertise_tab_url() { + + return admin_url( 'admin.php?page=wc-facebook&tab=advertise' ); + } + /** diff --git a/facebook-commerce-events-tracker.php b/facebook-commerce-events-tracker.php index 6773c1507..bb252eb0a 100644 --- a/facebook-commerce-events-tracker.php +++ b/facebook-commerce-events-tracker.php @@ -850,7 +850,7 @@ public function inject_add_to_cart_redirect_event() { */ public function inject_initiate_checkout_event() { - if ( ! $this->is_pixel_enabled() || $this->pixel->is_last_event( 'InitiateCheckout' ) ) { + if ( ! $this->is_pixel_enabled() || WC()->cart->get_cart_contents_count() === 0 || $this->pixel->is_last_event( 'InitiateCheckout' ) ) { return; } diff --git a/facebook-commerce.php b/facebook-commerce.php index fb2c573dd..b2f158b02 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -113,7 +113,7 @@ class WC_Facebookcommerce_Integration extends WC_Integration { /** @var string the short product description mode name */ const PRODUCT_DESCRIPTION_MODE_SHORT = 'short'; - /** @var string custom taxonomy FB product set ID */ + /** @var string custom taxonomy Facebook Product Set ID */ const FB_PRODUCT_SET_ID = 'fb_product_set_id'; /** @var string|null the configured product catalog ID */ @@ -1667,7 +1667,7 @@ public function create_or_update_product_set_item( $product_set_data, $product_s ) ); - // update product set to set FB Product Set ID + // update product set to set Facebook Product Set ID if ( $result && empty( $fb_product_set_id ) ) { // decode and get ID from result body diff --git a/facebook-for-woocommerce.php b/facebook-for-woocommerce.php index 95ef78b69..a77a648e0 100644 --- a/facebook-for-woocommerce.php +++ b/facebook-for-woocommerce.php @@ -11,18 +11,29 @@ * 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: 2.6.28 + * Version: 2.6.30 * Text Domain: facebook-for-woocommerce - * Tested up to: 6.0 - * WC requires at least: 3.5.0 - * WC tested up to: 7.0 + * Tested up to: 6.1 + * WC requires at least: 5.3 + * WC tested up to: 7.1 * Requires PHP: 7.0 * * @package FacebookCommerce */ +use Automattic\WooCommerce\Utilities\FeaturesUtil; + defined( 'ABSPATH' ) || exit; +// HPOS compatibility declaration. +add_action( + 'before_woocommerce_init', + function() { + if ( class_exists( FeaturesUtil::class ) ) { + FeaturesUtil::declare_compatibility( 'custom_order_tables', plugin_basename( __FILE__ ), true ); + } + } +); /** * The plugin loader class. * @@ -33,7 +44,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 = '2.6.28'; // WRCS: DEFINED_VERSION. + const PLUGIN_VERSION = '2.6.30'; // WRCS: DEFINED_VERSION. // Minimum PHP version required by this plugin. const MINIMUM_PHP_VERSION = '7.0.0'; @@ -42,7 +53,7 @@ class WC_Facebook_Loader { const MINIMUM_WP_VERSION = '4.4'; // Minimum WooCommerce version required by this plugin. - const MINIMUM_WC_VERSION = '3.5.0'; + const MINIMUM_WC_VERSION = '5.3'; // SkyVerge plugin framework version used by this plugin. const FRAMEWORK_VERSION = '5.10.0'; diff --git a/includes/Admin.php b/includes/Admin.php index a9d40e503..7eec0ff38 100644 --- a/includes/Admin.php +++ b/includes/Admin.php @@ -12,6 +12,7 @@ namespace SkyVerge\WooCommerce\Facebook; use SkyVerge\WooCommerce\PluginFramework\v5_10_0\SV_WC_Helper; +use Automattic\WooCommerce\Utilities\OrderUtil; defined( 'ABSPATH' ) or exit; @@ -46,13 +47,15 @@ class Admin { */ public function __construct() { + $order_screen_id = class_exists( OrderUtil::class ) ? OrderUtil::get_order_admin_screen() : 'shop_order'; + $this->screen_ids = [ 'product', 'edit-product', 'woocommerce_page_wc-facebook', 'marketing_page_wc-facebook', 'edit-product_cat', - 'shop_order', + $order_screen_id, ]; // enqueue admin scripts @@ -205,7 +208,7 @@ public function enqueue_scripts() { array( 'excluded_category_ids' => facebook_for_woocommerce()->get_integration()->get_excluded_product_category_ids(), - 'excluded_category_warning_message' => __( 'You have selected one or more categories currently excluded from the Facebook sync. Products belonging to the excluded categories will not be added to your FB product set.', 'facebook-for-woocommerce' ), + 'excluded_category_warning_message' => __( 'You have selected one or more categories currently excluded from the Facebook sync. Products belonging to the excluded categories will not be added to your Facebook Product Set.', 'facebook-for-woocommerce' ), ) ); } diff --git a/includes/Admin/Notes/SettingsMoved.php b/includes/Admin/Notes/SettingsMoved.php new file mode 100644 index 000000000..85319e4a4 --- /dev/null +++ b/includes/Admin/Notes/SettingsMoved.php @@ -0,0 +1,88 @@ +get_last_event_from_history(); + + if ( isset( $last_event['name'] ) && 'upgrade' === $last_event['name'] ) { + $last_version = $last_event['data']['from_version']; + if ( version_compare( $last_version, '2.2.0', '<' ) ) { + $should_display = true; + } + } + + return $should_display; + } + + /** + * Add or delete note depending on the conditions to display the note. + * + * @throws NotesUnavailableException Throws exception when notes are unavailable. + */ + public static function possibly_add_or_delete_note() { + // Verify the conditions to display the note. + if ( self::should_display() ) { + self::possibly_add_note(); + } elseif ( self::note_exists() ) { + self::possibly_delete_note(); + } + } + + /** + * Get the note. + * + * @return Note + */ + public static function get_note() { + + $settings_url = facebook_for_woocommerce()->get_settings_url(); + $content = esc_html__( 'Sync your products and reach customers across Facebook, Instagram, Messenger and WhatsApp through your Facebook plugin, which can be found at Marketing > Facebook.', 'facebook-for-woocommerce' ); + + $note = new Note(); + $note->set_title( esc_html__( 'Facebook is now found under Marketing', 'facebook-for-woocommerce' ) ); + $note->set_content( $content ); + $note->set_content_data( (object) array() ); + $note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); + $note->set_name( self::NOTE_NAME ); + $note->set_source( 'facebook-for-woocommerce' ); + $note->add_action( 'settings', esc_html__( 'Go to Facebook', 'facebook-for-woocommerce' ), $settings_url ); + return $note; + } +} diff --git a/includes/Admin/Product_Sets.php b/includes/Admin/Product_Sets.php index 00381443b..3b277af64 100644 --- a/includes/Admin/Product_Sets.php +++ b/includes/Admin/Product_Sets.php @@ -75,7 +75,7 @@ public function __construct() { /** - * Add field to FB Product Set new term + * Add field to Facebook Product Set new term * * @since 2.3.0 */ @@ -90,7 +90,7 @@ public function category_field_on_new() { /** - * Add field to FB Product Set new term + * Add field to Facebook Product Set new term * * @since 2.3.0 * @@ -179,7 +179,7 @@ class="select2 wc-facebook product_cats"