PluginProbe ʕ •ᴥ•ʔ
Meta for WooCommerce / 3.3.0
Meta for WooCommerce v3.3.0
3.7.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.5.0 2.5.1 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.18 2.6.19 2.6.2 2.6.20 2.6.21 2.6.22 2.6.23 2.6.24 2.6.25 2.6.26 2.6.27 2.6.28 2.6.29 2.6.3 2.6.30 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.4.0 3.4.1 3.4.10 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.10 3.5.11 3.5.12 3.5.13 3.5.14 3.5.15 3.5.16 3.5.17 3.5.18 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0
facebook-for-woocommerce / class-wc-facebookcommerce.php
facebook-for-woocommerce Last commit date
assets 1 year ago data 2 years ago i18n 1 year ago includes 1 year ago vendor 1 year ago LICENSE 7 years ago changelog.txt 1 year ago class-wc-facebookcommerce.php 1 year ago facebook-commerce-events-tracker.php 1 year ago facebook-commerce-pixel-event.php 2 years ago facebook-commerce.php 1 year ago facebook-config-warmer.php 3 years ago facebook-for-woocommerce.php 1 year ago readme.txt 1 year ago
class-wc-facebookcommerce.php
859 lines
1 <?php
2 // phpcs:ignoreFile
3 /**
4 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
5 *
6 * This source code is licensed under the license found in the
7 * LICENSE file in the root directory of this source tree.
8 *
9 * @package FacebookCommerce
10 */
11
12 require_once __DIR__ . '/includes/fbutils.php';
13
14 use Automattic\WooCommerce\Admin\Features\Features as WooAdminFeatures;
15 use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
16 use WooCommerce\Facebook\Admin\Tasks\Setup;
17 use WooCommerce\Facebook\Admin\Notes\SettingsMoved;
18 use WooCommerce\Facebook\Framework\Api\Exception as ApiException;
19 use WooCommerce\Facebook\Framework\Helper;
20 use WooCommerce\Facebook\Framework\Plugin\Compatibility;
21 use WooCommerce\Facebook\Integrations\Bookings as BookingsIntegration;
22 use WooCommerce\Facebook\Lifecycle;
23 use WooCommerce\Facebook\ProductSync\ProductValidator as ProductSyncValidator;
24 use WooCommerce\Facebook\Utilities\Background_Handle_Virtual_Products_Variations;
25 use WooCommerce\Facebook\Utilities\Background_Remove_Duplicate_Visibility_Meta;
26 use WooCommerce\Facebook\Utilities\DebugTools;
27 use WooCommerce\Facebook\Utilities\Heartbeat;
28
29 class WC_Facebookcommerce extends WooCommerce\Facebook\Framework\Plugin {
30 /** @var string the plugin version */
31 const VERSION = WC_Facebook_Loader::PLUGIN_VERSION;
32
33 /** @var string for backwards compatibility TODO: remove this in v2.0.0 {CW 2020-02-06} */
34 const PLUGIN_VERSION = self::VERSION;
35
36 /** @var string the plugin ID */
37 const PLUGIN_ID = 'facebook_for_woocommerce';
38
39 /** @var string the integration ID */
40 const INTEGRATION_ID = 'facebookcommerce';
41
42 /** @var string the product set categories meta name */
43 const PRODUCT_SET_META = '_wc_facebook_product_cats';
44
45 /** @var string the plugin user agent name to use for HTTP calls within User-Agent header */
46 const PLUGIN_USER_AGENT_NAME = 'Facebook-for-WooCommerce';
47
48 /** @var WC_Facebookcommerce singleton instance */
49 protected static $instance;
50
51 /** @var WooCommerce\Facebook\API instance */
52 private $api;
53
54 /** @var \WC_Facebookcommerce_Integration instance */
55 private $integration;
56
57 /** @var WooCommerce\Facebook\Admin admin handler instance */
58 private $admin;
59
60 /** @var WooCommerce\Facebook\Admin\Settings */
61 private $admin_settings;
62
63 /** @var WooCommerce\Facebook\AJAX Ajax handler instance */
64 private $ajax;
65
66 /** @var WooCommerce\Facebook\Products\Feed product feed handler */
67 private $product_feed;
68
69 /** @var Background_Handle_Virtual_Products_Variations instance */
70 protected $background_handle_virtual_products_variations;
71
72 /** @var Background_Remove_Duplicate_Visibility_Meta job handler instance */
73 protected $background_remove_duplicate_visibility_meta;
74
75 /** @var WooCommerce\Facebook\Products\Stock products stock handler */
76 private $products_stock_handler;
77
78 /** @var WooCommerce\Facebook\Products\Sync products sync handler */
79 private $products_sync_handler;
80
81 /** @var WooCommerce\Facebook\Products\Sync\Background background sync handler */
82 private $sync_background_handler;
83
84 /** @var WooCommerce\Facebook\ProductSets\Sync product sets sync handler */
85 private $product_sets_sync_handler;
86
87 /** @var WooCommerce\Facebook\Handlers\Connection connection handler */
88 private $connection_handler;
89
90 /** @var WooCommerce\Facebook\Handlers\WebHook webhook handler */
91 private $webhook_handler;
92
93 /** @var WooCommerce\Facebook\Commerce commerce handler */
94 private $commerce_handler;
95
96 /** @var WooCommerce\Facebook\Utilities\Tracker */
97 private $tracker;
98
99 /** @var WooCommerce\Facebook\Jobs\JobManager */
100 public $job_manager;
101
102 /** @var WooCommerce\Facebook\Utilities\Heartbeat */
103 public $heartbeat;
104
105 /** @var WooCommerce\Facebook\ExternalVersionUpdate */
106 private $external_version_update;
107
108 /** @var WooCommerce\Facebook\Feed\FeedConfigurationDetection instance. */
109 private $configuration_detection;
110
111 /** @var WooCommerce\Facebook\Products\FBCategories instance. */
112 private $fb_categories;
113
114 /**
115 * The Debug tools instance.
116 *
117 * @var WooCommerce\Facebook\Utilities\DebugTools
118 */
119 private $debug_tools;
120
121 /**
122 * Constructs the plugin.
123 *
124 * @since 1.0.0
125 */
126 public function __construct() {
127 parent::__construct(
128 self::PLUGIN_ID,
129 self::VERSION,
130 [ 'text_domain' => 'facebook-for-woocommerce' ]
131 );
132 $this->init();
133 $this->init_admin();
134 }
135
136 /**
137 * __get method for backward compatibility.
138 *
139 * @param string $key property name
140 * @return mixed
141 * @since 3.0.32
142 */
143 public function __get( $key ) {
144 // Add warning for private properties.
145 if ( in_array( $key, array( 'configuration_detection', 'fb_categories' ), true ) ) {
146 /* translators: %s property name. */
147 _doing_it_wrong( __FUNCTION__, sprintf( esc_html__( 'The %s property is private and should not be accessed outside its class.', 'facebook-for-woocommerce' ), esc_html( $key ) ), '3.0.32' );
148 return $this->$key;
149 }
150
151 return null;
152 }
153
154 /**
155 * Initializes the plugin.
156 *
157 * @internal
158 */
159 public function init() {
160 add_action( 'init', array( $this, 'get_integration' ) );
161 add_action( 'init', array( $this, 'register_custom_taxonomy' ) );
162 add_action( 'add_meta_boxes_product', array( $this, 'remove_product_fb_product_set_metabox' ), 50 );
163 add_filter( 'fb_product_set_row_actions', array( $this, 'product_set_links' ) );
164 add_filter( 'manage_edit-fb_product_set_columns', array( $this, 'manage_fb_product_set_columns' ) );
165
166 // 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.
167 add_action( 'init', array( $this, 'add_setup_task' ), 20 );
168 add_action( 'admin_notices', array( $this, 'add_inbox_notes' ) );
169
170 // Product Set breadcrumb filters
171 add_filter( 'woocommerce_navigation_is_connected_page', array( $this, 'is_current_page_conected_filter' ), 99, 2 );
172 add_filter( 'woocommerce_navigation_get_breadcrumbs', array( $this, 'wc_page_breadcrumbs_filter' ), 99 );
173
174 add_filter(
175 'wc_' . WC_Facebookcommerce::PLUGIN_ID . '_http_request_args',
176 array( $this, 'force_user_agent_in_latin' )
177 );
178
179 if ( \WC_Facebookcommerce_Utils::isWoocommerceIntegration() ) {
180 include_once 'facebook-commerce.php';
181
182 require_once __DIR__ . '/includes/fbproductfeed.php';
183
184 $this->heartbeat = new Heartbeat( WC()->queue() );
185 $this->heartbeat->init();
186
187 $this->product_feed = new WooCommerce\Facebook\Products\Feed();
188 $this->products_stock_handler = new WooCommerce\Facebook\Products\Stock();
189 $this->products_sync_handler = new WooCommerce\Facebook\Products\Sync();
190 $this->sync_background_handler = new WooCommerce\Facebook\Products\Sync\Background();
191 $this->configuration_detection = new WooCommerce\Facebook\Feed\FeedConfigurationDetection();
192 $this->product_sets_sync_handler = new WooCommerce\Facebook\ProductSets\Sync();
193 $this->commerce_handler = new WooCommerce\Facebook\Commerce();
194 $this->fb_categories = new WooCommerce\Facebook\Products\FBCategories();
195 $this->external_version_update = new WooCommerce\Facebook\ExternalVersionUpdate\Update();
196
197 if ( wp_doing_ajax() ) {
198 $this->ajax = new WooCommerce\Facebook\AJAX();
199 }
200
201 // Load integrations.
202 require_once __DIR__ . '/includes/fbwpml.php';
203 new WC_Facebook_WPML_Injector();
204 new BookingsIntegration();
205
206 if ( 'yes' !== get_option( 'wc_facebook_background_handle_virtual_products_variations_complete', 'no' ) ) {
207 $this->background_handle_virtual_products_variations = new Background_Handle_Virtual_Products_Variations();
208 }
209
210 if ( 'yes' !== get_option( 'wc_facebook_background_remove_duplicate_visibility_meta_complete', 'no' ) ) {
211 $this->background_remove_duplicate_visibility_meta = new Background_Remove_Duplicate_Visibility_Meta();
212 }
213
214 $this->connection_handler = new WooCommerce\Facebook\Handlers\Connection( $this );
215 $this->webhook_handler = new WooCommerce\Facebook\Handlers\WebHook( $this );
216 $this->tracker = new WooCommerce\Facebook\Utilities\Tracker();
217
218 // Init jobs
219 $this->job_manager = new WooCommerce\Facebook\Jobs\JobManager();
220 add_action( 'init', [ $this->job_manager, 'init' ] );
221
222 // Instantiate the debug tools.
223 $this->debug_tools = new DebugTools();
224
225 // load admin handlers, before admin_init
226 if ( is_admin() ) {
227 $this->admin_settings = new WooCommerce\Facebook\Admin\Settings( $this->connection_handler->is_connected() );
228 }
229 }
230 }
231
232
233 /**
234 * Initializes the admin handling.
235 *
236 * @internal
237 *
238 * @since 1.10.0
239 */
240 public function init_admin() {
241 add_action(
242 'admin_init',
243 function () {
244 $this->admin = new WooCommerce\Facebook\Admin();
245 },
246 0
247 );
248 }
249
250 /**
251 * Add Inbox notes.
252 */
253 public function add_inbox_notes() {
254 if ( Compatibility::is_enhanced_admin_available() ) {
255 if ( class_exists( WooAdminFeatures::class ) ) {
256 $is_marketing_enabled = WooAdminFeatures::is_enabled( 'marketing' );
257 } else {
258 $is_marketing_enabled = is_callable( '\Automattic\WooCommerce\Admin\Loader::is_feature_enabled' )
259 && \Automattic\WooCommerce\Admin\Loader::is_feature_enabled( 'marketing' );
260 }
261
262 if ( $is_marketing_enabled && class_exists( '\Automattic\WooCommerce\Admin\Notes\Note' ) ) { // Checking for Note class is for backward compatibility.
263 SettingsMoved::possibly_add_or_delete_note();
264 }
265 }
266 }
267
268 /**
269 * Gets deprecated and removed hooks.
270 *
271 * @since 2.1.0
272 *
273 * @return array
274 */
275 protected function get_deprecated_hooks() {
276 return array(
277 'wc_facebook_page_access_token' => array(
278 'version' => '2.1.0',
279 'replacement' => false,
280 ),
281 );
282 }
283
284 /**
285 * Adds the setup task to the Tasklists.
286 *
287 * @since 2.6.29
288 */
289 public function add_setup_task() {
290 if ( class_exists( TaskLists::class ) ) { // This is added for backward compatibility.
291 TaskLists::add_task(
292 'extended',
293 new Setup(
294 TaskLists::get_list( 'extended' )
295 )
296 );
297 }
298 }
299
300 /**
301 * Get the last event from the plugin lifecycle.
302 *
303 * @since 2.6.29
304 * @return array
305 */
306 public function get_last_event_from_history() {
307 $last_event = array();
308 $history_events = $this->lifecycle_handler->get_event_history();
309
310 if ( isset( $history_events[0] ) ) {
311 $last_event = $history_events[0];
312 }
313 return $last_event;
314 }
315
316 public function add_wordpress_integration() {
317 new WP_Facebook_Integration();
318 }
319
320 /**
321 * Saves errors or messages to WooCommerce Log (woocommerce/logs/plugin-id-xxx.txt)
322 *
323 * @since 2.3.3
324 * @param string $message error or message to save to log
325 * @param string $log_id optional log id to segment the files by, defaults to plugin id
326 */
327 public function log( $message, $log_id = null ) {
328 // Bail if site is connected and user has disabled logging.
329 // If site is disconnected, force-enable logging so merchant can diagnose connection issues.
330 if ( ( ! $this->get_integration() || ! $this->get_integration()->is_debug_mode_enabled() ) && $this->get_connection_handler()->is_connected() ) {
331 return;
332 }
333
334 parent::log( $message, $log_id );
335 }
336
337 /**
338 * Logs an API request.
339 *
340 * @since 2.0.0
341 *
342 * @param array $request request data
343 * @param array $response response data
344 * @param null $log_id log ID
345 */
346 public function log_api_request( $request, $response, $log_id = null ) {
347 // bail if logging isn't enabled
348 if ( ! $this->get_integration() || ! $this->get_integration()->is_debug_mode_enabled() ) {
349 return;
350 }
351
352 // Maybe remove headers from the debug log.
353 if( ! $this->get_integration()->are_headers_requested_for_debug() ) {
354 unset( $request['headers'] );
355 unset( $response['headers'] );
356 }
357
358 $this->log( $this->get_api_log_message( $request ), $log_id );
359
360 if ( ! empty( $response ) ) {
361 $this->log( $this->get_api_log_message( $response ), $log_id );
362 }
363 }
364
365 /**
366 * Remove Product Set metabox from Product edit page
367 *
368 * @since 2.3.0
369 */
370 public function remove_product_fb_product_set_metabox() {
371 remove_meta_box( 'fb_product_setdiv', 'product', 'side' );
372 }
373
374 /**
375 * Register Facebook Product Set Taxonomy
376 *
377 * @since 2.3.0
378 */
379 public function register_custom_taxonomy() {
380 $plural = esc_html__( 'Facebook Product Sets', 'facebook-for-woocommerce' );
381 $singular = esc_html__( 'Facebook Product Set', 'facebook-for-woocommerce' );
382
383 $args = array(
384 'labels' => array(
385 'name' => $plural,
386 'singular_name' => $singular,
387 'menu_name' => $plural,
388 // translators: Edit item label
389 'edit_item' => sprintf( esc_html__( 'Edit %s', 'facebook-for-woocommerce' ), $singular ),
390 // translators: Add new label
391 'add_new_item' => sprintf( esc_html__( 'Add new %s', 'facebook-for-woocommerce' ), $singular ),
392 // translators: No items found text
393 'not_found' => sprintf( esc_html__( 'No %s found.', 'facebook-for-woocommerce' ), $plural ),
394 // translators: Search label
395 'search_items' => sprintf( esc_html__( 'Search %s', 'facebook-for-woocommerce' ), $plural ),
396 // translators: Text label
397 'separate_items_with_commas' => sprintf( esc_html__( 'Separate %s with commas', 'facebook-for-woocommerce' ), $plural ),
398 // translators: Text label
399 'choose_from_most_used' => sprintf( esc_html__( 'Choose from the most used %s', 'facebook-for-woocommerce' ), $plural ),
400 // translators: Backlink item label
401 'back_to_items' => sprintf( esc_html__( '&larr; Go to %s', 'facebook-for-woocommerce' ), $plural ),
402 ),
403 'hierarchical' => true,
404 'public' => true,
405 'show_in_nav_menus' => false,
406 'show_tagcloud' => false,
407 'show_in_menu' => false,
408 );
409
410 register_taxonomy( 'fb_product_set', array( 'product' ), $args );
411 }
412
413
414 /**
415 * Filter Facebook Product Set Taxonomy table links
416 *
417 * @since 2.3.0
418 *
419 * @param array $actions Item Actions.
420 *
421 * @return array
422 */
423 public function product_set_links( $actions ) {
424 unset( $actions['inline hide-if-no-js'] );
425 unset( $actions['view'] );
426 return $actions;
427 }
428
429
430 /**
431 * Remove posts count column from Facebook Product Set custom taxonomy
432 *
433 * @since 2.3.0
434 *
435 * @param array $columns Taxonomy columns.
436 *
437 * @return array
438 */
439 public function manage_fb_product_set_columns( $columns ) {
440 unset( $columns['posts'] );
441 return $columns;
442 }
443
444
445 /**
446 * Filter WC Breadcrumbs when the page is Facebook Product Sets
447 *
448 * @since 2.3.0
449 *
450 * @param array $breadcrumbs Page breadcrumbs.
451 *
452 * @return array
453 */
454 public function wc_page_breadcrumbs_filter( $breadcrumbs ) {
455
456 if ( 'edit-fb_product_set' !== $this->get_current_page_id() ) {
457 return $breadcrumbs;
458 }
459
460 $breadcrumbs = array(
461 array( 'admin.php?page=wc-admin', 'WooCommerce' ),
462 array( 'edit.php?post_type=product', 'Products' ),
463 );
464
465 $term_id = empty( $_GET['tag_ID'] ) ? '' : wc_clean( wp_unslash( $_GET['tag_ID'] ) ); //phpcs:ignore WordPress.Security
466 if ( ! empty( $term_id ) ) {
467 $breadcrumbs[] = array( 'edit-tags.php?taxonomy=fb_product_set&post_type=product', 'Products Sets' );
468 }
469
470 $breadcrumbs[] = ( empty( $term_id ) ? 'Product Sets' : 'Edit Product Set' );
471 return $breadcrumbs;
472 }
473
474
475 /**
476 * Return that Facebook Product Set page is a WC Conected Page
477 *
478 * @since 2.3.0
479 *
480 * @param boolean $is_conected If it's connected or not.
481 *
482 * @return boolean
483 */
484 public function is_current_page_conected_filter( $is_conected ) {
485 if ( 'edit-fb_product_set' === $this->get_current_page_id() ) {
486 return true;
487 }
488
489 return $is_conected;
490 }
491
492 /**
493 * Filter is responsible to always set latin user agent header value, because translated plugin names
494 * may contain characters which Facebook does not accept and return 400 response for requests with such
495 * header values.
496 * Applying either sanitize_title() nor remove_accents() on header value will not work for all the languages
497 * we support translations to e.g. Hebrew is going to convert into something %d7%90%d7%a8%d7%99%d7%92 which is
498 * not acceptable neither.
499 *
500 * @param array $http_request_headers - http request headers
501 * @return array
502 */
503 public function force_user_agent_in_latin( array $http_request_headers ) {
504 if ( isset( $http_request_headers['user-agent'] ) ) {
505 $http_request_headers['user-agent'] = sprintf(
506 '%s/%s (WooCommerce/%s; WordPress/%s)',
507 WC_Facebookcommerce::PLUGIN_USER_AGENT_NAME,
508 WC_Facebookcommerce::PLUGIN_VERSION,
509 defined( 'WC_VERSION' ) ? WC_VERSION : WC_Facebook_Loader::MINIMUM_WC_VERSION,
510 $GLOBALS['wp_version']
511 );
512 }
513 return $http_request_headers;
514 }
515
516
517 /** Getter methods ********************************************************************************************/
518
519
520 /**
521 * Gets the API instance.
522 *
523 * @since 2.0.0
524 *
525 * @param string $access_token access token to use for this API request
526 * @return WooCommerce\Facebook\API
527 * @throws ApiException
528 */
529 public function get_api( string $access_token = '' ): WooCommerce\Facebook\API {
530 // if none provided, use the general access token
531 if ( ! $access_token ) {
532 $access_token = $this->get_connection_handler()->get_access_token();
533 }
534 if ( ! is_object( $this->api ) ) {
535 if ( ! $access_token ) {
536 throw new ApiException( __( 'Cannot create the API instance because the access token is missing.', 'facebook-for-woocommerce' ) );
537 }
538 $this->api = new WooCommerce\Facebook\API( $access_token );
539 } else {
540 $this->api->set_access_token( $access_token );
541 }
542 return $this->api;
543 }
544
545 /**
546 * Gets the category handler.
547 *
548 * @since 1.11.0
549 *
550 * @return WooCommerce\Facebook\Products\FBCategories
551 */
552 public function get_facebook_category_handler() {
553 return $this->fb_categories;
554 }
555
556 /**
557 * Gets the background handle virtual products and variations handler instance.
558 *
559 * @since 2.0.0
560 *
561 * @return Background_Handle_Virtual_Products_Variations
562 */
563 public function get_background_handle_virtual_products_variations_instance() {
564 return $this->background_handle_virtual_products_variations;
565 }
566
567
568 /**
569 * Gets the background remove duplicate visibility meta data handler instance.
570 *
571 * @since 2.0.3
572 *
573 * @return Background_Remove_Duplicate_Visibility_Meta
574 */
575 public function get_background_remove_duplicate_visibility_meta_instance() {
576 return $this->background_remove_duplicate_visibility_meta;
577 }
578
579
580 /**
581 * Gets the products sync handler.
582 *
583 * @since 2.0.0
584 *
585 * @return WooCommerce\Facebook\Products\Sync
586 */
587 public function get_products_sync_handler() {
588 return $this->products_sync_handler;
589 }
590
591
592 /**
593 * Gets the products sync background handler.
594 *
595 * @since 2.0.0
596 *
597 * @return WooCommerce\Facebook\Products\Sync\Background
598 */
599 public function get_products_sync_background_handler() {
600 return $this->sync_background_handler;
601 }
602
603
604 /**
605 * Gets the connection handler.
606 *
607 * @since 2.0.0
608 *
609 * @return WooCommerce\Facebook\Handlers\Connection
610 */
611 public function get_connection_handler() {
612 return $this->connection_handler;
613 }
614
615
616 /**
617 * Gets the integration instance.
618 *
619 * @since 1.10.0
620 *
621 * @return WC_Facebookcommerce_Integration instance
622 */
623 public function get_integration() {
624 if ( null === $this->integration ) {
625 $this->integration = new WC_Facebookcommerce_Integration( $this );
626 }
627
628 return $this->integration;
629 }
630
631
632 /**
633 * Gets the commerce handler instance.
634 *
635 * @since 2.1.0
636 *
637 * @return WooCommerce\Facebook\Commerce commerce handler instance
638 */
639 public function get_commerce_handler() {
640 return $this->commerce_handler;
641 }
642
643 /**
644 * Gets tracker instance.
645 *
646 * @since 2.6.0
647 *
648 * @return WooCommerce\Facebook\Utilities\Tracker
649 */
650 public function get_tracker() {
651 return $this->tracker;
652 }
653
654 /**
655 * Gets the debug profiling logger instance.
656 *
657 * @return WooCommerce\Facebook\Debug\ProfilingLogger
658 */
659 public function get_profiling_logger() {
660 static $instance = null;
661 if ( null === $instance ) {
662 $is_enabled = defined( 'FACEBOOK_FOR_WOOCOMMERCE_PROFILING_LOG_ENABLED' ) && FACEBOOK_FOR_WOOCOMMERCE_PROFILING_LOG_ENABLED;
663 $instance = new WooCommerce\Facebook\Debug\ProfilingLogger( $is_enabled );
664 }
665
666 return $instance;
667 }
668
669 /**
670 * Get the product sync validator class.
671 *
672 * @param WC_Product $product A product object to be validated.
673 *
674 * @return ProductSyncValidator
675 */
676 public function get_product_sync_validator( WC_Product $product ) {
677 return new ProductSyncValidator( $this->get_integration(), $product );
678 }
679
680 /**
681 * Gets the advertise tab page URL.
682 *
683 * @since 2.6.29
684 *
685 * @return string
686 */
687 public function get_advertise_tab_url() {
688 return admin_url( 'admin.php?page=wc-facebook&tab=advertise' );
689 }
690
691 /**
692 * Gets the settings page URL.
693 *
694 * @since 1.10.0
695 *
696 * @param null $plugin_id unused
697 * @return string
698 */
699 public function get_settings_url( $plugin_id = null ) {
700 return admin_url( 'admin.php?page=wc-facebook' );
701 }
702
703 /**
704 * Gets the plugin's documentation URL.
705 *
706 * @since 1.10.0
707 *
708 * @return string
709 */
710 public function get_documentation_url() {
711 return 'https://woocommerce.com/document/facebook-for-woocommerce/';
712 }
713
714
715 /**
716 * Gets the plugin's support URL.
717 *
718 * @since 1.10.0
719 *
720 * @return string
721 */
722 public function get_support_url() {
723 return 'https://wordpress.org/support/plugin/facebook-for-woocommerce/';
724 }
725
726
727 /**
728 * Gets the plugin's sales page URL.
729 *
730 * @since 1.10.0
731 *
732 * @return string
733 */
734 public function get_sales_page_url() {
735 return 'https://woocommerce.com/products/facebook/';
736 }
737
738
739 /**
740 * Gets the plugin's reviews URL.
741 *
742 * @since 1.10.0
743 *
744 * @return string
745 */
746 public function get_reviews_url() {
747 return 'https://wordpress.org/support/plugin/facebook-for-woocommerce/reviews/';
748 }
749
750
751 /**
752 * Gets the plugin name.
753 *
754 * @since 1.10.0
755 *
756 * @return string
757 */
758 public function get_plugin_name() {
759 return __( 'Facebook for WooCommerce', 'facebook-for-woocommerce' );
760 }
761
762 /**
763 * Gets the url for the assets build directory.
764 *
765 * @since 2.3.4
766 *
767 * @return string
768 */
769 public function get_asset_build_dir_url() {
770 return $this->get_plugin_url() . '/assets/build';
771 }
772
773
774 /** Conditional methods ***************************************************************************************/
775
776
777 /**
778 * Determines if viewing the plugin settings in the admin.
779 *
780 * @since 1.10.0
781 *
782 * @return bool
783 */
784 public function is_plugin_settings() {
785 return is_admin() && WooCommerce\Facebook\Admin\Settings::PAGE_ID === Helper::get_requested_value( 'page' );
786 }
787
788
789 /** Utility methods *******************************************************************************************/
790
791
792 /**
793 * Initializes the lifecycle handler.
794 *
795 * @since 1.10.0
796 */
797 protected function init_lifecycle_handler() {
798 $this->lifecycle_handler = new Lifecycle( $this );
799 }
800
801
802 /**
803 * Gets the plugin singleton instance.
804 *
805 * @see \facebook_for_woocommerce()
806 *
807 * @since 1.10.0
808 *
809 * @return \WC_Facebookcommerce the plugin singleton instance
810 */
811 public static function instance() {
812 if ( null === self::$instance ) {
813 self::$instance = new self();
814 }
815 return self::$instance;
816 }
817
818
819 /**
820 * Gets the plugin file.
821 *
822 * @since 1.10.0
823 *
824 * @return string
825 */
826 protected function get_file() {
827 return __FILE__;
828 }
829
830
831 /**
832 * Return current page ID
833 *
834 * @since 2.3.0
835 *
836 * @return string
837 */
838 protected function get_current_page_id() {
839 $current_screen_id = '';
840 $current_screen = get_current_screen();
841 if ( ! empty( $current_screen ) ) {
842 $current_screen_id = $current_screen->id;
843 }
844 return $current_screen_id;
845 }
846 }
847
848
849 /**
850 * Gets the Facebook for WooCommerce plugin instance.
851 *
852 * @since 1.10.0
853 *
854 * @return \WC_Facebookcommerce instance of the plugin
855 */
856 function facebook_for_woocommerce() {
857 return \WC_Facebookcommerce::instance();
858 }
859