PluginProbe ʕ •ᴥ•ʔ
Meta for WooCommerce / 3.1.2
Meta for WooCommerce v3.1.2
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 / facebook-for-woocommerce.php
facebook-for-woocommerce Last commit date
assets 2 years ago data 3 years ago i18n 2 years ago includes 2 years ago vendor 2 years ago LICENSE 7 years ago changelog.txt 2 years ago class-wc-facebookcommerce.php 2 years ago facebook-commerce-events-tracker.php 2 years ago facebook-commerce-messenger-chat.php 2 years ago facebook-commerce-pixel-event.php 2 years ago facebook-commerce.php 2 years ago facebook-config-warmer.php 3 years ago facebook-for-woocommerce.php 2 years ago readme.txt 2 years ago
facebook-for-woocommerce.php
484 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 * Plugin Name: Facebook for WooCommerce
10 * Plugin URI: https://github.com/woocommerce/facebook-for-woocommerce/
11 * 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.
12 * Author: Facebook
13 * Author URI: https://www.facebook.com/
14 * Version: 3.1.2
15 * Requires at least: 5.6
16 * Text Domain: facebook-for-woocommerce
17 * Tested up to: 6.3
18 * WC requires at least: 5.4
19 * WC tested up to: 8.2
20 *
21 * @package FacebookCommerce
22 */
23
24 use Automattic\WooCommerce\Utilities\FeaturesUtil;
25
26 defined( 'ABSPATH' ) || exit;
27
28 // HPOS compatibility declaration.
29 add_action(
30 'before_woocommerce_init',
31 function() {
32 if ( class_exists( FeaturesUtil::class ) ) {
33 FeaturesUtil::declare_compatibility( 'custom_order_tables', plugin_basename( __FILE__ ), true );
34 }
35 }
36 );
37 /**
38 * The plugin loader class.
39 *
40 * @since 1.10.0
41 */
42 class WC_Facebook_Loader {
43
44 /**
45 * @var string the plugin version. This must be in the main plugin file to be automatically bumped by Woorelease.
46 */
47 const PLUGIN_VERSION = '3.1.2'; // WRCS: DEFINED_VERSION.
48
49 // Minimum PHP version required by this plugin.
50 const MINIMUM_PHP_VERSION = '7.4.0';
51
52 // Minimum WordPress version required by this plugin.
53 const MINIMUM_WP_VERSION = '4.4';
54
55 // Minimum WooCommerce version required by this plugin.
56 const MINIMUM_WC_VERSION = '5.3';
57
58 // SkyVerge plugin framework version used by this plugin.
59 const FRAMEWORK_VERSION = '5.10.0';
60
61 // The plugin name, for displaying notices.
62 const PLUGIN_NAME = 'Facebook for WooCommerce';
63
64
65 /**
66 * This class instance.
67 *
68 * @var \WC_Facebook_Loader single instance of this class.
69 */
70 private static $instance;
71
72 /**
73 * Admin notices to add.
74 *
75 * @var array Array of admin notices.
76 */
77 private $notices = array();
78
79
80 /**
81 * Constructs the class.
82 *
83 * @since 1.10.0
84 */
85 protected function __construct() {
86
87 register_activation_hook( __FILE__, array( $this, 'activation_check' ) );
88
89 add_action( 'admin_init', array( $this, 'check_environment' ) );
90
91 add_action( 'admin_notices', array( $this, 'add_plugin_notices' ) ); // admin_init is too early for the get_current_screen() function.
92 add_action( 'admin_notices', array( $this, 'admin_notices' ), 15 );
93
94 // If the environment check fails, initialize the plugin.
95 if ( $this->is_environment_compatible() ) {
96 add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
97 }
98 }
99
100
101 /**
102 * Cloning instances is forbidden due to singleton pattern.
103 *
104 * @since 1.10.0
105 */
106 public function __clone() {
107
108 wc_doing_it_wrong( __FUNCTION__, sprintf( 'You cannot clone instances of %s.', get_class( $this ) ), '1.10.0' );
109 }
110
111
112 /**
113 * Unserializing instances is forbidden due to singleton pattern.
114 *
115 * @since 1.10.0
116 */
117 public function __wakeup() {
118
119 wc_doing_it_wrong( __FUNCTION__, sprintf( 'You cannot unserialize instances of %s.', get_class( $this ) ), '1.10.0' );
120 }
121
122
123 /**
124 * Initializes the plugin.
125 *
126 * @since 1.10.0
127 */
128 public function init_plugin() {
129
130 if ( ! $this->plugins_compatible() ) {
131 return;
132 }
133
134 require_once plugin_dir_path( __FILE__ ) . 'class-wc-facebookcommerce.php';
135
136 // fire it up!
137 if ( function_exists( 'facebook_for_woocommerce' ) ) {
138 facebook_for_woocommerce();
139 }
140 }
141
142
143 /**
144 * Gets the framework version in namespace form.
145 *
146 * @since 1.10.0
147 *
148 * @return string
149 */
150 public function get_framework_version_namespace() {
151 return 'v' . str_replace( '.', '_', $this->get_framework_version() );
152 }
153
154
155 /**
156 * Gets the framework version used by this plugin.
157 *
158 * @since 1.10.0
159 *
160 * @return string
161 */
162 public function get_framework_version() {
163
164 return self::FRAMEWORK_VERSION;
165 }
166
167
168 /**
169 * Checks the server environment and other factors and deactivates plugins as necessary.
170 *
171 * Based on http://wptavern.com/how-to-prevent-wordpress-plugins-from-activating-on-sites-with-incompatible-hosting-environments
172 *
173 * @internal
174 *
175 * @since 1.10.0
176 */
177 public function activation_check() {
178
179 if ( ! $this->is_environment_compatible() ) {
180
181 $this->deactivate_plugin();
182
183 wp_die( esc_html( self::PLUGIN_NAME . ' could not be activated. ' . $this->get_environment_message() ) );
184 }
185 }
186
187
188 /**
189 * Checks the environment on loading WordPress, just in case the environment changes after activation.
190 *
191 * @internal
192 *
193 * @since 1.10.0
194 */
195 public function check_environment() {
196
197 if ( ! $this->is_environment_compatible() && is_plugin_active( plugin_basename( __FILE__ ) ) ) {
198
199 $this->deactivate_plugin();
200
201 $this->add_admin_notice( 'bad_environment', 'error', self::PLUGIN_NAME . ' has been deactivated. ' . $this->get_environment_message() );
202 }
203 }
204
205
206 /**
207 * Adds notices for out-of-date WordPress and/or WooCommerce versions.
208 *
209 * @internal
210 *
211 * @since 1.10.0
212 */
213 public function add_plugin_notices() {
214
215 if ( ! $this->is_wp_compatible() ) {
216 if ( current_user_can( 'update_core' ) ) {
217 $this->add_admin_notice(
218 'update_wordpress',
219 'error',
220 sprintf(
221 /* translators: %1$s - plugin name, %2$s - minimum WordPress version required, %3$s - update WordPress link open, %4$s - update WordPress link close */
222 esc_html__( '%1$s requires WordPress version %2$s or higher. Please %3$supdate WordPress &raquo;%4$s', 'facebook-for-woocommerce' ),
223 '<strong>' . self::PLUGIN_NAME . '</strong>',
224 self::MINIMUM_WP_VERSION,
225 '<a href="' . esc_url( admin_url( 'update-core.php' ) ) . '">',
226 '</a>'
227 )
228 );
229 }
230 }
231
232 // Notices to install and activate or update WooCommerce.
233 $screen = get_current_screen();
234 if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
235 return; // Do not display the install/update/activate notice in the update plugin screen.
236 }
237
238 $plugin = 'woocommerce/woocommerce.php';
239 // Check if WooCommerce is activated.
240 if ( ! $this->is_wc_activated() ) {
241
242 if ( $this->is_wc_installed() ) {
243 // WooCommerce is installed but not activated. Ask the user to activate WooCommerce.
244 if ( current_user_can( 'activate_plugins' ) ) {
245 $activation_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin );
246 $message = sprintf(
247 /* translators: %1$s - Plugin Name, %2$s - activate WooCommerce link open, %3$s - activate WooCommerce link close. */
248 esc_html__( '%1$s requires WooCommerce to be activated. Please %2$sactivate WooCommerce%3$s.', 'facebook-for-woocommerce' ),
249 '<strong>' . self::PLUGIN_NAME . '</strong>',
250 '<a href="' . esc_url( $activation_url ) . '">',
251 '</a>'
252 );
253 $this->add_admin_notice(
254 'activate_woocommerce',
255 'error',
256 $message
257 );
258 }
259 } else {
260 // WooCommerce is not installed. Ask the user to install WooCommerce.
261 if ( current_user_can( 'install_plugins' ) ) {
262 $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=woocommerce' ), 'install-plugin_woocommerce' );
263 $message = sprintf(
264 /* translators: %1$s - Plugin Name, %2$s - install WooCommerce link open, %3$s - install WooCommerce link close. */
265 esc_html__( '%1$s requires WooCommerce to be installed and activated. Please %2$sinstall WooCommerce%3$s.', 'facebook-for-woocommerce' ),
266 '<strong>' . self::PLUGIN_NAME . '</strong>',
267 '<a href="' . esc_url( $install_url ) . '">',
268 '</a>'
269 );
270 $this->add_admin_notice(
271 'install_woocommerce',
272 'error',
273 $message
274 );
275 }
276 }
277 } elseif ( ! $this->is_wc_compatible() ) { // If WooCommerce is activated, check for the version.
278 if ( current_user_can( 'update_plugins' ) ) {
279 $update_url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $plugin, 'upgrade-plugin_' . $plugin );
280 $this->add_admin_notice(
281 'update_woocommerce',
282 'error',
283 sprintf(
284 /* translators: %1$s - Plugin Name, %2$s - minimum WooCommerce version, %3$s - update WooCommerce link open, %4$s - update WooCommerce link close, %5$s - download minimum WooCommerce link open, %6$s - download minimum WooCommerce link close. */
285 esc_html__( '%1$s requires WooCommerce version %2$s or higher. Please %3$supdate WooCommerce%4$s to the latest version, or %5$sdownload the minimum required version &raquo;%6$s', 'facebook-for-woocommerce' ),
286 '<strong>' . self::PLUGIN_NAME . '</strong>',
287 self::MINIMUM_WC_VERSION,
288 '<a href="' . esc_url( $update_url ) . '">',
289 '</a>',
290 '<a href="' . esc_url( 'https://downloads.wordpress.org/plugin/woocommerce.' . self::MINIMUM_WC_VERSION . '.zip' ) . '">',
291 '</a>'
292 )
293 );
294 }
295 }
296 }
297
298
299 /**
300 * Determines if the required plugins are compatible.
301 *
302 * @since 1.10.0
303 *
304 * @return bool
305 */
306 private function plugins_compatible() {
307 return $this->is_wp_compatible() && $this->is_wc_compatible();
308 }
309
310
311 /**
312 * Determines if the WordPress compatible.
313 *
314 * @since 1.10.0
315 *
316 * @return bool
317 */
318 private function is_wp_compatible() {
319
320 if ( ! self::MINIMUM_WP_VERSION ) {
321 return true;
322 }
323
324 return version_compare( get_bloginfo( 'version' ), self::MINIMUM_WP_VERSION, '>=' );
325 }
326
327 /**
328 * Query WooCommerce activation.
329 *
330 * @since 2.6.24
331 * @return bool
332 */
333 private function is_wc_activated() {
334 return class_exists( 'WooCommerce' ) ? true : false;
335 }
336
337 /**
338 * Determins if WooCommerce is installed.
339 *
340 * @since 2.6.24
341 * @return bool
342 */
343 private function is_wc_installed() {
344 $plugin = 'woocommerce/woocommerce.php';
345 $installed_plugins = get_plugins();
346
347 return isset( $installed_plugins[ $plugin ] );
348 }
349
350 /**
351 * Determines if the WooCommerce compatible.
352 *
353 * @since 1.10.0
354 *
355 * @return bool
356 */
357 private function is_wc_compatible() {
358
359 if ( ! self::MINIMUM_WC_VERSION ) {
360 return true;
361 }
362
363 return defined( 'WC_VERSION' ) && version_compare( WC_VERSION, self::MINIMUM_WC_VERSION, '>=' );
364 }
365
366
367 /**
368 * Deactivates the plugin.
369 *
370 * @internal
371 *
372 * @since 1.10.0
373 */
374 protected function deactivate_plugin() {
375
376 deactivate_plugins( plugin_basename( __FILE__ ) );
377
378 if ( isset( $_GET['activate'] ) ) {
379 unset( $_GET['activate'] );
380 }
381 }
382
383
384 /**
385 * Adds an admin notice to be displayed.
386 *
387 * @since 1.10.0
388 *
389 * @param string $slug The slug for the notice.
390 * @param string $class The css class for the notice.
391 * @param string $message The notice message.
392 */
393 private function add_admin_notice( $slug, $class, $message ) {
394
395 $this->notices[ $slug ] = array(
396 'class' => $class,
397 'message' => $message,
398 );
399 }
400
401
402 /**
403 * Displays any admin notices added with \WC_Facebook_Loader::add_admin_notice()
404 *
405 * @internal
406 *
407 * @since 1.10.0
408 */
409 public function admin_notices() {
410
411 foreach ( (array) $this->notices as $notice_key => $notice ) {
412
413 ?>
414 <div class="<?php echo esc_attr( $notice['class'] ); ?>">
415 <p>
416 <?php
417 echo wp_kses(
418 $notice['message'],
419 array(
420 'a' => array(
421 'href' => array(),
422 ),
423 'strong' => array(),
424 )
425 );
426 ?>
427 </p>
428 </div>
429 <?php
430 }
431 }
432
433
434 /**
435 * Determines if the server environment is compatible with this plugin.
436 *
437 * Override this method to add checks for more than just the PHP version.
438 *
439 * @since 1.10.0
440 *
441 * @return bool
442 */
443 private function is_environment_compatible() {
444 return version_compare( PHP_VERSION, self::MINIMUM_PHP_VERSION, '>=' );
445 }
446
447
448 /**
449 * Gets the message for display when the environment is incompatible with this plugin.
450 *
451 * @since 1.10.0
452 *
453 * @return string
454 */
455 private function get_environment_message() {
456
457 return sprintf( 'The minimum PHP version required for this plugin is %1$s. You are running %2$s.', self::MINIMUM_PHP_VERSION, PHP_VERSION );
458 }
459
460
461 /**
462 * Gets the main \WC_Facebook_Loader instance.
463 *
464 * Ensures only one instance can be loaded.
465 *
466 * @since 1.10.0
467 *
468 * @return \WC_Facebook_Loader
469 */
470 public static function instance() {
471
472 if ( null === self::$instance ) {
473 self::$instance = new self();
474 }
475
476 return self::$instance;
477 }
478
479
480 }
481
482 // fire it up!
483 WC_Facebook_Loader::instance();
484