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-commerce-messenger-chat.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-commerce-messenger-chat.php
115 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 use WooCommerce\Facebook\Locale;
13
14 if ( ! class_exists( 'WC_Facebookcommerce_MessengerChat' ) ) :
15
16 if ( ! class_exists( 'WC_Facebookcommerce_Utils' ) ) {
17 include_once 'includes/fbutils.php';
18 }
19
20 /**
21 * Messenger chat handler class.
22 */
23 class WC_Facebookcommerce_MessengerChat {
24
25 /** @var string Facebook Page ID. */
26 private $page_id;
27
28 /** @var string|null JS SDK Version. */
29 private $jssdk_version;
30
31 /**
32 * Class constructor.
33 *
34 * @param array $settings FB page settings array.
35 */
36 public function __construct( $settings ) {
37
38 $this->page_id = isset( $settings['fb_page_id'] )
39 ? $settings['fb_page_id']
40 : '';
41
42 $this->jssdk_version = isset( $settings['facebook_jssdk_version'] )
43 ? $settings['facebook_jssdk_version']
44 : '';
45
46 add_action( 'wp_footer', array( $this, 'inject_messenger_chat_plugin' ) );
47 }
48
49 /**
50 * __get method for backward compatibility.
51 *
52 * @param string $key property name
53 * @return mixed
54 * @since 3.0.32
55 */
56 public function __get( $key ) {
57 // Add warning for private properties.
58 if ( in_array( $key, array( 'page_id', 'jssdk_version' ), true ) ) {
59 /* translators: %s property name. */
60 _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' );
61 return $this->$key;
62 }
63
64 return null;
65 }
66
67 /**
68 * Outputs the Facebook Messenger chat script.
69 *
70 * @internal
71 */
72 public function inject_messenger_chat_plugin() {
73
74 if ( facebook_for_woocommerce()->get_integration()->is_messenger_enabled() ) :
75
76 printf(
77 "
78 <div
79 attribution=\"fbe_woocommerce\"
80 class=\"fb-customerchat\"
81 page_id=\"%s\"
82 ></div>
83 <!-- Facebook JSSDK -->
84 <script>
85 window.fbAsyncInit = function() {
86 FB.init({
87 appId : '',
88 autoLogAppEvents : true,
89 xfbml : true,
90 version : '%s'
91 });
92 };
93
94 (function(d, s, id){
95 var js, fjs = d.getElementsByTagName(s)[0];
96 if (d.getElementById(id)) {return;}
97 js = d.createElement(s); js.id = id;
98 js.src = 'https://connect.facebook.net/%s/sdk/xfbml.customerchat.js';
99 fjs.parentNode.insertBefore(js, fjs);
100 }(document, 'script', 'facebook-jssdk'));
101 </script>
102 <div></div>
103 ",
104 esc_attr( $this->page_id ),
105 esc_js( $this->jssdk_version ?: 'v5.0' ),
106 esc_js( facebook_for_woocommerce()->get_integration()->get_messenger_locale() ?: 'en_US' )
107 );
108
109 endif;
110 }
111
112 }
113
114 endif;
115