Messenger Customer Chat - Version 1.4

Version Description

  • Simplify installation flow
Download this release

Release Info

Developer Facebook
Plugin Icon 128x128 Messenger Customer Chat
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

Files changed (5) hide show
  1. facebook-messenger-customer-chat.php +18 -5
  2. options.php +11 -61
  3. readme.txt +11 -4
  4. script.js +0 -41
  5. uninstall.php +26 -0
facebook-messenger-customer-chat.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Messenger Customer Chat
4
  Description: Messenger Customer Chat is the official free Messenger customer chat plugin for WordPress by Facebook. This plugin allows you to interact with your customers using Messenger by integrating it on your WordPress website in three simple steps. To get started, go to your Wordpress Dashboard -> Customer Chat -> click on "Setup Customer Chat."
5
  Author: Facebook
6
  Author URI: https://developers.facebook.com
7
- Version: 1.3
8
 
9
  * Copyright (C) 2017-present, Facebook, Inc.
10
  *
@@ -19,16 +19,29 @@ Version: 1.3
19
  */
20
 
21
  class Facebook_Messenger_Customer_Chat {
22
- const URL_PREFIX = 'https://connect.facebook.net/';
23
- const URL_SUFFIX = '/sdk.js#xfbml=1&version=v2.12&autoLogAppEvents=1';
24
-
25
  function __construct() {
26
  include( plugin_dir_path( __FILE__ ) . 'options.php' );
27
  add_action( 'wp_footer', array( $this, 'fbmcc_inject_messenger' ) );
28
  }
29
 
30
  function fbmcc_inject_messenger() {
31
- if( get_option( 'fbmcc_enabled' ) == '1'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  && get_option( 'fbmcc_generatedCode' ) != ''
33
  ) {
34
  _e( stripslashes( get_option( 'fbmcc_generatedCode' ) ) );
4
  Description: Messenger Customer Chat is the official free Messenger customer chat plugin for WordPress by Facebook. This plugin allows you to interact with your customers using Messenger by integrating it on your WordPress website in three simple steps. To get started, go to your Wordpress Dashboard -> Customer Chat -> click on "Setup Customer Chat."
5
  Author: Facebook
6
  Author URI: https://developers.facebook.com
7
+ Version: 1.4
8
 
9
  * Copyright (C) 2017-present, Facebook, Inc.
10
  *
19
  */
20
 
21
  class Facebook_Messenger_Customer_Chat {
 
 
 
22
  function __construct() {
23
  include( plugin_dir_path( __FILE__ ) . 'options.php' );
24
  add_action( 'wp_footer', array( $this, 'fbmcc_inject_messenger' ) );
25
  }
26
 
27
  function fbmcc_inject_messenger() {
28
+ if( get_option( 'fbmcc_pageID' ) != '' ) {
29
+ $genCode .= "
30
+ <div id='fb-root'></div>
31
+ <script>(function(d, s, id) {
32
+ var js, fjs = d.getElementsByTagName(s)[0];
33
+ js = d.createElement(s); js.id = id;
34
+ js.src = 'https://connect.facebook.net/".get_option( 'fbmcc_locale' )."/sdk/xfbml.customerchat.js#xfbml=1&version=v6.0&autoLogAppEvents=1';
35
+ fjs.parentNode.insertBefore(js, fjs);
36
+ }(document, 'script', 'facebook-jssdk'));</script>
37
+ <div class='fb-customerchat'
38
+ attribution='wordpress'
39
+ page_id=".get_option( 'fbmcc_pageID' )."
40
+ >
41
+ </div>
42
+ ";
43
+ _e($genCode);
44
+ }else if( get_option( 'fbmcc_enabled' ) == '1'
45
  && get_option( 'fbmcc_generatedCode' ) != ''
46
  ) {
47
  _e( stripslashes( get_option( 'fbmcc_generatedCode' ) ) );
options.php CHANGED
@@ -48,17 +48,12 @@ add_action( 'admin_menu', function() {
48
  add_action( 'admin_enqueue_scripts', 'fbmcc_add_styles' );
49
  add_action( 'admin_enqueue_scripts', 'fmcc_localize_ajax' );
50
 
51
- add_action( 'admin_init', function() {
52
- register_setting( 'messenger-integration-plugin-settings', 'fbmcc_enabled' );
53
- register_setting( 'messenger-integration-plugin-settings', 'fbmcc_generatedCode' );
54
- });
55
-
56
  add_action( 'wp_ajax_update_options', 'fbmcc_update_options');
57
 
58
  function fbmcc_update_options() {
59
  check_ajax_referer( 'update_fmcc_code' );
60
- update_option( 'fbmcc_enabled', "1" );
61
- update_option( 'fbmcc_generatedCode', sanitize_textarea_field( $_POST['fbmcc_generatedCode'] ) );
62
  wp_die();
63
  }
64
 
@@ -85,19 +80,15 @@ function fmcc_localize_ajax() {
85
  function fbmcc_integration_settings() {
86
  ?>
87
  <div class="wrap">
88
- <form action="options.php" method="post">
89
  <h2>Messenger Customer Chat Settings</h2>
90
- <?php
91
- settings_fields( 'messenger-integration-plugin-settings' );
92
- do_settings_sections( 'messenger-integration-plugin-settings' );
93
- ?>
94
  <div class="fbmcc-card card">
95
  <div class="intro">
96
  <div>
97
  <h2>Getting Started?</h2>
98
  <p class="fbmcc-instructions">Let people start a conversation on your
99
  website and continue in Messenger. It's easy to set up. We'll
100
- give you the code to add to your website.</p>
 
101
  </div>
102
  <div class="fbmcc-buttonContainer">
103
  <button
@@ -106,7 +97,7 @@ function fbmcc_integration_settings() {
106
  onclick="fbmcc_setupCustomerChat()"
107
  >
108
  <?php
109
- if( get_option( 'fbmcc_generatedCode' ) == "" ) {
110
  _e( 'Setup Customer Chat' );
111
  } else {
112
  _e( 'Edit Customer Chat' );
@@ -119,61 +110,20 @@ function fbmcc_integration_settings() {
119
  <div
120
  id="fbmcc-page-params"
121
  class="fbmcc-card card"
122
- <?php if( get_option( 'fbmcc_generatedCode' ) == "" ) {
123
  _e( 'style="display:none;"' );
124
  } ?>>
125
  <div>
126
- <p class="fbmcc-instructions">The code has already been added into your
127
- website. You can always go back through the setup process or edit
128
- the code manually below.
129
  </p>
130
  </div>
131
- <table class="fbmcc-settings">
132
- <tr valign="top">
133
- <th scope="row">Enabled</th>
134
- <td class="fbmcc-table-container">
135
- <div>
136
- <label class="fbmcc-switch">
137
- <input
138
- id="fbmcc-enabled"
139
- value="1"
140
- name="fbmcc_enabled"
141
- type="checkbox"
142
- <?php checked( '1', get_option( 'fbmcc_enabled' ) ); ?>
143
- >
144
- <span class="fbmcc-slider round"></span>
145
- </label>
146
- </div>
147
- </td>
148
- </tr>
149
- <tr valign="top">
150
- <th scope="row">Code Snippet</th>
151
- </tr>
152
- </table>
153
- <div class="fbmcc-codeContainer">
154
- <button id="fbmcc-editButton"
155
- class="fbmcc-editButton"
156
- type="button"
157
- onclick="fbmcc_editCode()"
158
- >
159
- Edit Code
160
- </button>
161
- <textarea
162
- id="fbmcc-codeArea"
163
- name="fbmcc_generatedCode"
164
- class="fbmcc-code-area"
165
- rows="17"
166
- cols="70"
167
- readonly="true"
168
- ><?php esc_html_e( stripslashes( get_option( 'fbmcc_generatedCode' ) ) ); ?>
169
- </textarea>
170
- </div>
171
- <?php submit_button(); ?>
172
  </div>
173
- </form>
174
  <div class="fbmcc-card card">
175
  <div class="intro">
176
- <p class="fbmcc-instructions"> Having a problem with Messenger customer chat?
 
 
177
  Report the issue on the <a
178
  href='https://developers.facebook.com/support/bugs/'
179
  target='_blank'>
48
  add_action( 'admin_enqueue_scripts', 'fbmcc_add_styles' );
49
  add_action( 'admin_enqueue_scripts', 'fmcc_localize_ajax' );
50
 
 
 
 
 
 
51
  add_action( 'wp_ajax_update_options', 'fbmcc_update_options');
52
 
53
  function fbmcc_update_options() {
54
  check_ajax_referer( 'update_fmcc_code' );
55
+ update_option( 'fbmcc_pageID', sanitize_text_field($_POST['pageID']));
56
+ update_option( 'fbmcc_locale', sanitize_text_field($_POST['locale']));
57
  wp_die();
58
  }
59
 
80
  function fbmcc_integration_settings() {
81
  ?>
82
  <div class="wrap">
 
83
  <h2>Messenger Customer Chat Settings</h2>
 
 
 
 
84
  <div class="fbmcc-card card">
85
  <div class="intro">
86
  <div>
87
  <h2>Getting Started?</h2>
88
  <p class="fbmcc-instructions">Let people start a conversation on your
89
  website and continue in Messenger. It's easy to set up. We'll
90
+ give you the code to add to your website.
91
+ </p>
92
  </div>
93
  <div class="fbmcc-buttonContainer">
94
  <button
97
  onclick="fbmcc_setupCustomerChat()"
98
  >
99
  <?php
100
+ if( get_option( 'fbmcc_pageID' ) == "" ) {
101
  _e( 'Setup Customer Chat' );
102
  } else {
103
  _e( 'Edit Customer Chat' );
110
  <div
111
  id="fbmcc-page-params"
112
  class="fbmcc-card card"
113
+ <?php if( get_option( 'fbmcc_pageID' ) == "" ) {
114
  _e( 'style="display:none;"' );
115
  } ?>>
116
  <div>
117
+ <p class="fbmcc-instructions">The plugin code has already been added into your
118
+ website. You can always go back through the setup process to customize the plugin.
 
119
  </p>
120
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  </div>
 
122
  <div class="fbmcc-card card">
123
  <div class="intro">
124
+ <p class="fbmcc-instructions">
125
+ Use of this plugin is subject to <a href='https://developers.facebook.com/policy/'>Facebook's Platform Policies</a><br><br>
126
+ Having a problem with Messenger customer chat?
127
  Report the issue on the <a
128
  href='https://developers.facebook.com/support/bugs/'
129
  target='_blank'>
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: facebook
3
  Tags: Facebook, Messenger, Customer Care, Chat, Messaging
4
  Requires at least: 3.9
5
- Tested up to: 5.2.1
6
- Stable tag: 1.3
7
  Requires PHP: 5.2.4
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -38,8 +38,8 @@ Following the [Facebook platform and versioning](https://developers.facebook.com
38
  After navigating to the Messenger customer chat plugin settings page, click on 'Setup Customer Chat.' A new window will appear for setting up the plugin and you will be asked to select the Facebook Page you want to use. Next, you will go through the plugin setup with the following steps:
39
  1. You will be asked to select the language and you can customize the greeting message. The default greeting is "Hi! How can we help you?"
40
  2. The next screen allows you to select your response time and chat color. By setting the response time, you can set expectations with your customers on when they will receive a response
41
- 3. Next, click on 'Finish' to save these settings and click 'Done' to close this window. The Messenger customer chat plugin code should now be visible in your WordPress Dashboard
42
- 4. Finally, clicking 'Save Changes' will save the plugin onto your WordPress site. You can edit this code manually by clicking 'Edit Code' or rerun the setup by clicking 'Edit Customer Chat'
43
 
44
  <br />
45
  That's it! You're all set. Now all visitors to your WordPress website will see the Messenger customer chat plugin and can message you.
@@ -86,6 +86,10 @@ Of course! This plugin is open sourced on the Facebook Incubator GitHub. You can
86
 
87
  == Changelog ==
88
 
 
 
 
 
89
  = 1.3 - June 17, 2019 =
90
  * Tested up to WordPress 5.2.1
91
  * Fixed security issue
@@ -104,6 +108,9 @@ Of course! This plugin is open sourced on the Facebook Incubator GitHub. You can
104
 
105
  == Upgrade Notice ==
106
 
 
 
 
107
  = 1.3 =
108
  * Fix security issue
109
 
2
  Contributors: facebook
3
  Tags: Facebook, Messenger, Customer Care, Chat, Messaging
4
  Requires at least: 3.9
5
+ Tested up to: 5.3.2
6
+ Stable tag: 1.4
7
  Requires PHP: 5.2.4
8
  License: GPLv2
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
38
  After navigating to the Messenger customer chat plugin settings page, click on 'Setup Customer Chat.' A new window will appear for setting up the plugin and you will be asked to select the Facebook Page you want to use. Next, you will go through the plugin setup with the following steps:
39
  1. You will be asked to select the language and you can customize the greeting message. The default greeting is "Hi! How can we help you?"
40
  2. The next screen allows you to select your response time and chat color. By setting the response time, you can set expectations with your customers on when they will receive a response
41
+ 3. Next, click on 'Finish' to save these settings and click 'Done' to close this window. The Messenger customer chat plugin should now be installed.
42
+ 4. You can rerun the setup by clicking 'Edit Customer Chat'. To remove the plugin, you can diactivate the plugin/uninstall it.
43
 
44
  <br />
45
  That's it! You're all set. Now all visitors to your WordPress website will see the Messenger customer chat plugin and can message you.
86
 
87
  == Changelog ==
88
 
89
+ = 1.4 - April 13, 2020 =
90
+ * Tested up to WordPress 5.3.2
91
+ * Simplify installation flow
92
+
93
  = 1.3 - June 17, 2019 =
94
  * Tested up to WordPress 5.2.1
95
  * Fixed security issue
108
 
109
  == Upgrade Notice ==
110
 
111
+ = 1.4 =
112
+ * Simplify installation flow
113
+
114
  = 1.3 =
115
  * Fix security issue
116
 
script.js CHANGED
@@ -33,53 +33,20 @@ function fbmcc_setupCustomerChat() {
33
  'action' : 'update_options',
34
  'pageID' : fbmcc_sanitizeNumbersOnly($data_json["pageID"]),
35
  'locale' : fbmcc_sanitizeLocale($data_json["locale"]),
36
- 'themeColor' : fbmcc_sanitizeHexColor($data_json["themeColorCode"]),
37
- 'greetingText' : $data_json["greetingTextCode"],
38
  '_wpnonce' : ajax_object.nonce,
39
  };
40
- data.generatedCode = fbmcc_genScript(
41
- data.pageID,
42
- data.locale,
43
- data.themeColor,
44
- data.greetingText,
45
- ).replace(/^\s*\n/gm, "");
46
  jQuery.ajax({
47
  type: 'POST',
48
  url: ajaxurl,
49
  data: data,
50
  success: function(results) {
51
- jQuery('#fbmcc-codeArea').val(data.generatedCode);
52
  jQuery('#fbmcc-page-params').css('display', 'inline-block');
53
- jQuery('#fbmcc-enabled').prop('checked', true);
54
  }
55
  });
56
  }
57
  });
58
  }
59
 
60
- function fbmcc_genScript( pageID, locale, themeColor, greetingText ) {
61
- const hasNoGreeting = (greetingText === null || greetingText === undefined );
62
- return `<div id='fb-root'></div>
63
- <script>(function(d, s, id) {
64
- var js, fjs = d.getElementsByTagName(s)[0];
65
- js = d.createElement(s); js.id = id;
66
- js.src = 'https://connect.facebook.net/${locale}/sdk/xfbml.customerchat.js#xfbml=1&version=v2.12&autoLogAppEvents=1';
67
- fjs.parentNode.insertBefore(js, fjs);
68
- }(document, 'script', 'facebook-jssdk'));</script>
69
- <div class='fb-customerchat'
70
- attribution="wordpress"
71
- page_id='${pageID}'
72
- ${themeColor === null ? '' : `theme_color='${themeColor}'`}
73
- ${hasNoGreeting ? '' : `logged_in_greeting='${greetingText}'`}
74
- ${hasNoGreeting ? '' : `logged_out_greeting='${greetingText}'`}
75
- >
76
- </div>`;
77
- }
78
-
79
- function fbmcc_editCode() {
80
- jQuery('#fbmcc-codeArea').prop('readonly', function(i, v) { return !v; });
81
- }
82
-
83
  function fbmcc_sanitizeNumbersOnly( number ) {
84
  if( /^\d+$/.test(number) ) {
85
  return number;
@@ -95,11 +62,3 @@ function fbmcc_sanitizeLocale( locale ) {
95
  return '';
96
  }
97
  }
98
-
99
- function fbmcc_sanitizeHexColor( color ) {
100
- if( /^#([A-Fa-f0-9]{3}){1,2}$/.test(color) ) {
101
- return color;
102
- } else {
103
- return null;
104
- }
105
- }
33
  'action' : 'update_options',
34
  'pageID' : fbmcc_sanitizeNumbersOnly($data_json["pageID"]),
35
  'locale' : fbmcc_sanitizeLocale($data_json["locale"]),
 
 
36
  '_wpnonce' : ajax_object.nonce,
37
  };
 
 
 
 
 
 
38
  jQuery.ajax({
39
  type: 'POST',
40
  url: ajaxurl,
41
  data: data,
42
  success: function(results) {
 
43
  jQuery('#fbmcc-page-params').css('display', 'inline-block');
 
44
  }
45
  });
46
  }
47
  });
48
  }
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  function fbmcc_sanitizeNumbersOnly( number ) {
51
  if( /^\d+$/.test(number) ) {
52
  return number;
62
  return '';
63
  }
64
  }
 
 
 
 
 
 
 
 
uninstall.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*
4
+ * Copyright (C) 2017-present, Facebook, Inc.
5
+ *
6
+ * This program is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; version 2 of the License.
9
+
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ */
15
+
16
+
17
+ // if uninstall.php is not called by WordPress, die
18
+ if (!defined('WP_UNINSTALL_PLUGIN')) {
19
+ die;
20
+ }
21
+
22
+ delete_option('fbmcc_pageID');
23
+ delete_option('fbmcc_locale');
24
+ delete_option('fbmcc_generatedCode');
25
+ delete_option('fbmcc_enabled');
26
+ ?>