diff --git a/class-wc-facebookcommerce.php b/class-wc-facebookcommerce.php index 45198886b..9720d336c 100644 --- a/class-wc-facebookcommerce.php +++ b/class-wc-facebookcommerce.php @@ -1,5 +1,4 @@ heartbeat = new Heartbeat( WC()->queue() ); $this->heartbeat->init(); - $this->feed_manager = new WooCommerce\Facebook\Feed\FeedManager(); - $this->checkout = new WooCommerce\Facebook\Checkout(); - $this->product_feed = new WooCommerce\Facebook\Products\Feed(); - $this->products_stock_handler = new WooCommerce\Facebook\Products\Stock(); - $this->products_sync_handler = new WooCommerce\Facebook\Products\Sync(); - $this->sync_background_handler = new WooCommerce\Facebook\Products\Sync\Background(); - $this->configuration_detection = new WooCommerce\Facebook\Feed\FeedConfigurationDetection(); + $this->feed_manager = new WooCommerce\Facebook\Feed\FeedManager(); + $this->checkout = new WooCommerce\Facebook\Checkout(); + $this->product_feed = new WooCommerce\Facebook\Products\Feed(); + $this->products_stock_handler = new WooCommerce\Facebook\Products\Stock(); + $this->products_sync_handler = new WooCommerce\Facebook\Products\Sync(); + $this->sync_background_handler = new WooCommerce\Facebook\Products\Sync\Background(); + $this->configuration_detection = new WooCommerce\Facebook\Feed\FeedConfigurationDetection(); $this->legacy_product_sets_sync_handler = new WooCommerce\Facebook\ProductSets\Sync(); - $this->product_sets_sync_handler = new WooCommerce\Facebook\ProductSets\ProductSetSync(); - $this->commerce_handler = new WooCommerce\Facebook\Commerce(); - $this->fb_categories = new WooCommerce\Facebook\Products\FBCategories(); - $this->external_version_update = new WooCommerce\Facebook\ExternalVersionUpdate\Update(); + $this->product_sets_sync_handler = new WooCommerce\Facebook\ProductSets\ProductSetSync(); + $this->commerce_handler = new WooCommerce\Facebook\Commerce(); + $this->fb_categories = new WooCommerce\Facebook\Products\FBCategories(); + $this->external_version_update = new WooCommerce\Facebook\ExternalVersionUpdate\Update(); if ( wp_doing_ajax() ) { $this->ajax = new WooCommerce\Facebook\AJAX(); @@ -235,15 +239,13 @@ public function init() { $this->background_remove_duplicate_visibility_meta = new Background_Remove_Duplicate_Visibility_Meta(); } - new WooCommerce\Facebook\API\Plugin\InitializeRestAPI(); $this->connection_handler = new WooCommerce\Facebook\Handlers\Connection( $this ); new WooCommerce\Facebook\Handlers\MetaExtension(); - $this->webhook_handler = new WooCommerce\Facebook\Handlers\WebHook( $this ); + $this->webhook_handler = new WooCommerce\Facebook\Handlers\WebHook( $this ); $this->whatsapp_webhook_handler = new WooCommerce\Facebook\Handlers\Whatsapp_Webhook( $this ); - $this->tracker = new WooCommerce\Facebook\Utilities\Tracker(); - $this->rollout_switches = new WooCommerce\Facebook\RolloutSwitches( $this ); - + $this->tracker = new WooCommerce\Facebook\Utilities\Tracker(); + $this->rollout_switches = new WooCommerce\Facebook\RolloutSwitches( $this ); // Init jobs $this->job_manager = new WooCommerce\Facebook\Jobs\JobManager(); @@ -254,12 +256,12 @@ public function init() { // load admin handlers, before admin_init if ( is_admin() ) { - if ($this->use_enhanced_onboarding()) { + if ( $this->use_enhanced_onboarding() ) { $this->admin_enhanced_settings = new WooCommerce\Facebook\Admin\Enhanced_Settings( $this ); } else { $this->admin_settings = new WooCommerce\Facebook\Admin\Settings( $this ); } - $this->plugin_render_handler = new \WooCommerce\Facebook\Handlers\PluginRender($this); + $this->plugin_render_handler = new \WooCommerce\Facebook\Handlers\PluginRender( $this ); } } } @@ -387,7 +389,7 @@ public function log_api_request( $request, $response, $log_id = null ) { } // Maybe remove headers from the debug log. - if( ! $this->get_integration()->are_headers_requested_for_debug() ) { + if ( ! $this->get_integration()->are_headers_requested_for_debug() ) { unset( $request['headers'] ); unset( $response['headers'] ); } @@ -541,8 +543,8 @@ public function force_user_agent_in_latin( array $http_request_headers ) { if ( isset( $http_request_headers['user-agent'] ) ) { $http_request_headers['user-agent'] = sprintf( '%s/%s (WooCommerce/%s; WordPress/%s)', - WC_Facebookcommerce::PLUGIN_USER_AGENT_NAME, - WC_Facebookcommerce::PLUGIN_VERSION, + self::PLUGIN_USER_AGENT_NAME, + self::PLUGIN_VERSION, defined( 'WC_VERSION' ) ? WC_VERSION : WC_Facebook_Loader::MINIMUM_WC_VERSION, $GLOBALS['wp_version'] ); @@ -561,7 +563,7 @@ public function force_user_agent_in_latin( array $http_request_headers ) { * * @param string $access_token access token to use for this API request * @return WooCommerce\Facebook\API - * @throws ApiException + * @throws ApiException If the access token is missing. */ public function get_api( string $access_token = '' ): WooCommerce\Facebook\API { // if none provided, use the general access token @@ -913,25 +915,25 @@ protected function get_current_page_id() { } /** - * Add checkout fields to collect whatsapp consent if consent collection is enabled - * - * @since 2.3.0 - * - * @param array $fields - * - * @return array - */ - function add_whatsapp_consent_checkout_fields($fields) { - if (get_option('wc_facebook_whatsapp_consent_collection_setting_status', 'disabled') === 'enabled') { + * Add checkout fields to collect whatsapp consent if consent collection is enabled + * + * @since 2.3.0 + * + * @param array $fields + * + * @return array + */ + public function add_whatsapp_consent_checkout_fields( $fields ) { + if ( get_option( 'wc_facebook_whatsapp_consent_collection_setting_status', 'disabled' ) === 'enabled' ) { woocommerce_register_additional_checkout_field( - array( - 'id' => 'wc_facebook/whatsapp_consent_checkbox', // id = namespace/field_name - 'label' => esc_html('Get order updates on WhatsApp'), - 'location' => 'address', - 'type' => 'checkbox', - 'optionalLabel' => esc_html('Get order updates on WhatsApp') - ) - ); + array( + 'id' => 'wc_facebook/whatsapp_consent_checkbox', // id = namespace/field_name + 'label' => esc_html( 'Get order updates on WhatsApp' ), + 'location' => 'address', + 'type' => 'checkbox', + 'optionalLabel' => esc_html( 'Get order updates on WhatsApp' ), + ) + ); } return $fields; } @@ -940,7 +942,6 @@ function add_whatsapp_consent_checkout_fields($fields) { * Determines if the enhanced onboarding (iframe) should be used. * * @return bool - * */ public function use_enhanced_onboarding(): bool { $connection_handler = $this->get_connection_handler(); @@ -961,7 +962,9 @@ public function use_enhanced_onboarding(): bool { * @since 1.10.0 * * @return \WC_Facebookcommerce instance of the plugin + * + * phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed */ function facebook_for_woocommerce() { - return apply_filters('wc_facebook_instance', \WC_Facebookcommerce::instance()); + return apply_filters( 'wc_facebook_instance', \WC_Facebookcommerce::instance() ); }