forked from vahidkay-meta/facebook-for-woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
facebook-commerce-messenger-chat.php
executable file
·108 lines (87 loc) · 2.58 KB
/
facebook-commerce-messenger-chat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
// phpcs:ignoreFile
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
* @package FacebookCommerce
*/
use SkyVerge\WooCommerce\Facebook\Locale;
if ( ! class_exists( 'WC_Facebookcommerce_MessengerChat' ) ) :
if ( ! class_exists( 'WC_Facebookcommerce_Utils' ) ) {
include_once 'includes/fbutils.php';
}
/**
* Messenger chat handler class.
*/
class WC_Facebookcommerce_MessengerChat {
/**
* Class constructor.
*
* @param array $settings FB page settings array.
*/
public function __construct( $settings ) {
$this->page_id = isset( $settings['fb_page_id'] )
? $settings['fb_page_id']
: '';
$this->jssdk_version = isset( $settings['facebook_jssdk_version'] )
? $settings['facebook_jssdk_version']
: '';
add_action( 'wp_footer', array( $this, 'inject_messenger_chat_plugin' ) );
}
/**
* Outputs the Facebook Messenger chat script.
*
* @internal
*/
public function inject_messenger_chat_plugin() {
if ( facebook_for_woocommerce()->get_integration()->is_messenger_enabled() ) :
printf(
"
<div
attribution=\"fbe_woocommerce\"
class=\"fb-customerchat\"
page_id=\"%s\"
></div>
<!-- Facebook JSSDK -->
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '',
autoLogAppEvents : true,
xfbml : true,
version : '%s'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/%s/sdk/xfbml.customerchat.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div></div>
",
esc_attr( $this->page_id ),
esc_js( $this->jssdk_version ?: 'v5.0' ),
esc_js( facebook_for_woocommerce()->get_integration()->get_messenger_locale() ?: 'en_US' )
);
endif;
}
/**
* Gets the locales supported by Facebook Messenger.
*
* @since 1.10.0
* @deprecated since 2.2.0
*
* @return array associative array of locale codes and names
*/
public static function get_supported_locales() {
wc_deprecated_function( __METHOD__, '2.2.0', '\\SkyVerge\\WooCommerce\\Facebook\\Locales::get_supported_locales_list()' );
return Locale::get_supported_locales();
}
}
endif;