Messenger Customer Chat - Version 1.0

Version Description

  • September 24, 2018 =
  • Plugin released for all users

=

Download this release

Release Info

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

Version 1.0

Files changed (6) hide show
  1. LICENSE.txt +304 -0
  2. facebook-messenger-customer-chat.php +40 -0
  3. options.php +179 -0
  4. readme.txt +88 -0
  5. script.js +110 -0
  6. settings.css +132 -0
LICENSE.txt ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
facebook-messenger-customer-chat.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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.0
8
+
9
+ * Copyright (C) 2017-present, Facebook, Inc.
10
+ *
11
+ * This program is free software; you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation; version 2 of the License.
14
+
15
+ * This program is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ * GNU General Public License for more details.
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' ) ) );
35
+ }
36
+ }
37
+ }
38
+
39
+ new Facebook_Messenger_Customer_Chat();
40
+ ?>
options.php ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Copyright (C) 2017-present, Facebook, Inc.
4
+ *
5
+ * This program is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; version 2 of the License.
8
+
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ */
14
+
15
+ // Settings page
16
+ add_action( 'admin_menu', function() {
17
+ wp_register_script(
18
+ 'launch_script',
19
+ plugins_url( '/script.js?2', __FILE__ ),
20
+ array( 'jquery' )
21
+ );
22
+ wp_enqueue_script( 'launch_script' );
23
+
24
+ add_menu_page(
25
+ 'Plugin settings',
26
+ 'Customer Chat',
27
+ 'manage_options',
28
+ 'messenger-customer-chat-plugin',
29
+ 'fbmcc_integration_settings',
30
+ 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgi'
31
+ . 'Pz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRw'
32
+ . 'Oi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVy'
33
+ . 'c2lvbj0iMS4xIiBpZD0iTWVzc2VuZ2VyX01hcmsiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9y'
34
+ . 'Zy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsi'
35
+ . 'IHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMTAwMHB4IiBoZWlnaHQ9IjEwMDBweCIgdmlld0Jv'
36
+ . 'eD0iMCAwIDEwMDAgMTAwMCIgZW5hYmxlLWJhY2tncm91bmQ9Im5ldyAwIDAgMTAwMCAxMDAw'
37
+ . 'IiB4bWw6c3BhY2U9InByZXNlcnZlIj48cGF0aCBpZD0iQnViYmxlX1NoYXBlIiBmaWxsPSIj'
38
+ . 'MjMxRjIwIiBkPSJNNDk5LjUsMTAzLjUwM2MtMjE3LjA0OSwwLTM5My4wMDIsMTY0LjUzMy0z'
39
+ . 'OTMuMDAyLDM2Ny40OTZjMCwxMTUuNDYsNTYuOTQ1LDIxOC40ODIsMTQ2LjAwMiwyODUuODU0'
40
+ . 'Vjg5Ny41bDEzNC4xMTgtNzQuMzk0YzM1Ljc1NCwxMC4wMDksNzMuNjQ2LDE1LjM4OSwxMTIu'
41
+ . 'ODgyLDE1LjM4OWMyMTcuMDQ5LDAsMzkzLjAwMi0xNjQuNTM0LDM5My4wMDItMzY3LjQ5N1M3'
42
+ . 'MTYuNTQ5LDEwMy41MDMsNDk5LjUsMTAzLjUwM3ogTTU0MC44OTEsNTk2LjMwOEw0MzkuMjQ3'
43
+ . 'LDQ5MC43MTRMMjQzLjUsNTk4Ljk2N2wyMTQuNjA5LTIyNy43NDFMNTU5Ljc1NCw0NzYuODJM'
44
+ . 'NzU1LjUsMzY4LjU2N0w1NDAuODkxLDU5Ni4zMDh6Ii8+PC9zdmc+'
45
+ );
46
+ });
47
+
48
+ add_action( 'admin_enqueue_scripts', 'fbmcc_add_styles' );
49
+
50
+ add_action( 'admin_init', function() {
51
+ register_setting( 'messenger-integration-plugin-settings', 'fbmcc_enabled' );
52
+ register_setting( 'messenger-integration-plugin-settings', 'fbmcc_generatedCode' );
53
+ });
54
+
55
+ add_action( 'wp_ajax_update_options', 'fbmcc_update_options');
56
+
57
+ function fbmcc_update_options() {
58
+ update_option( 'fbmcc_enabled', "1" );
59
+ update_option( 'fbmcc_generatedCode', sanitize_textarea_field( $_POST['fbmcc_generatedCode'] ) );
60
+ wp_die();
61
+ }
62
+
63
+ function fbmcc_add_styles() {
64
+ wp_enqueue_style(
65
+ 'admin-styles',
66
+ plugins_url( '/settings.css', __FILE__ ),
67
+ false,
68
+ '1.0',
69
+ 'all'
70
+ );
71
+ }
72
+
73
+ function fbmcc_integration_settings() {
74
+ ?>
75
+ <div class="wrap">
76
+ <form action="options.php" method="post">
77
+ <h2>Messenger Customer Chat Settings</h2>
78
+ <?php
79
+ settings_fields( 'messenger-integration-plugin-settings' );
80
+ do_settings_sections( 'messenger-integration-plugin-settings' );
81
+ ?>
82
+ <div class="fbmcc-card card">
83
+ <div class="intro">
84
+ <div>
85
+ <h2>Getting Started?</h2>
86
+ <p class="fbmcc-instructions">Let people start a conversation on your
87
+ website and continue in Messenger. It's easy to set up. We'll
88
+ give you the code to add to your website.</p>
89
+ </div>
90
+ <div class="fbmcc-buttonContainer">
91
+ <button
92
+ class="fbmcc-setupButton"
93
+ type="button"
94
+ onclick="fbmcc_setupCustomerChat()"
95
+ >
96
+ <?php
97
+ if( get_option( 'fbmcc_generatedCode' ) == "" ) {
98
+ _e( 'Setup Customer Chat' );
99
+ } else {
100
+ _e( 'Edit Customer Chat' );
101
+ }
102
+ ?>
103
+ </button>
104
+ </div>
105
+ </div>
106
+ </div>
107
+ <div
108
+ id="fbmcc-page-params"
109
+ class="fbmcc-card card"
110
+ <?php if( get_option( 'fbmcc_generatedCode' ) == "" ) {
111
+ _e( 'style="display:none;"' );
112
+ } ?>>
113
+ <div>
114
+ <p class="fbmcc-instructions">The code has already been added into your
115
+ website. You can always go back through the setup process or edit
116
+ the code manually below.
117
+ </p>
118
+ </div>
119
+ <table class="fbmcc-settings">
120
+ <tr valign="top">
121
+ <th scope="row">Enabled</th>
122
+ <td class="fbmcc-table-container">
123
+ <div>
124
+ <label class="fbmcc-switch">
125
+ <input
126
+ id="fbmcc-enabled"
127
+ value="1"
128
+ name="fbmcc_enabled"
129
+ type="checkbox"
130
+ <?php checked( '1', get_option( 'fbmcc_enabled' ) ); ?>
131
+ >
132
+ <span class="fbmcc-slider round"></span>
133
+ </label>
134
+ </div>
135
+ </td>
136
+ </tr>
137
+ <tr valign="top">
138
+ <th scope="row">Code Snippet</th>
139
+ </tr>
140
+ </table>
141
+ <div class="fbmcc-codeContainer">
142
+ <button id="fbmcc-editButton"
143
+ class="fbmcc-editButton"
144
+ type="button"
145
+ onclick="fbmcc_editCode()"
146
+ >
147
+ Edit Code
148
+ </button>
149
+ <textarea
150
+ id="fbmcc-codeArea"
151
+ name="fbmcc_generatedCode"
152
+ class="fbmcc-code-area"
153
+ rows="17"
154
+ cols="70"
155
+ readonly="true"
156
+ ><?php esc_html_e( stripslashes( get_option( 'fbmcc_generatedCode' ) ) ); ?>
157
+ </textarea>
158
+ </div>
159
+ <?php submit_button(); ?>
160
+ </div>
161
+ </form>
162
+ <div class="fbmcc-card card">
163
+ <div class="intro">
164
+ <p class="fbmcc-instructions"> Having a problem with Messenger customer chat?
165
+ Report the issue on the <a
166
+ href='https://developers.facebook.com/support/bugs/'
167
+ target='_blank'>
168
+ Facebook Platform Bug Reports</a> page. If you get stuck or have questions,
169
+ you can ask for help in the
170
+ <a
171
+ href='https://wordpress.org/support/plugin/facebook-messenger-customer-chat'
172
+ target='_blank'>
173
+ Messenger Customer Chat plugin forum</a>.
174
+ </p>
175
+ </div>
176
+ </div>
177
+ </div>
178
+ <?php }
179
+ ?>
readme.txt ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Messenger Customer Chat ===
2
+ Contributors: facebook
3
+ Tags: Facebook, Messenger, Customer Care, Chat, Messaging
4
+ Requires at least: 3.9
5
+ Tested up to: 4.9.8
6
+ Stable tag: 1.0
7
+ Requires PHP: 5.2.4
8
+ License: GPLv2
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ The official Messenger customer chat plugin from Facebook.
12
+
13
+ == Description ==
14
+ 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. You can learn more about Messenger customer chat by clicking [here](https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin).
15
+
16
+ == Installation ==
17
+
18
+ = Pre-requisites =
19
+ __Requires WordPress Version:__ 3.9 or higher
20
+ <br />
21
+
22
+ __Requires PHP Version:__ 5.2.4 or higher
23
+ <br />
24
+
25
+ __Facebook Presence__ <br />
26
+ In order to use the Messenger customer chat plugin, you will need to have a published Facebook Page. You can find a list of your Facebook Pages by following this [link](https://www.facebook.com/bookmarks/pages). If you do not have a Facebook Page, you can create one for free [here](https://www.facebook.com/pages/creation/?ref_type=pages_you_admin).
27
+ Once you have your Facebook Page ready, you will be asked to login to Facebook on the computer or device you are using to install the plugin. You can then follow the directions below.
28
+
29
+ = Installing =
30
+ To install the Messenger customer chat plugin: <br />
31
+ 1. Log in to your WordPress dashboard, navigate to the Plugins menu and click Add New. <br />
32
+ 2. In the search field, type 'Messenger customer chat' and click 'Search Plugins'. Select the plugin authored by 'Facebook'. You can install it by simply clicking 'Install Now'.
33
+
34
+ = Updating =
35
+ Following the [Facebook platform and versioning](https://developers.facebook.com/docs/apps/versions), all versions will be supported for 2 years from launch. Updating should be safe and easy.
36
+
37
+ = Configure plugin for first use =
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.
46
+
47
+ = Support =
48
+ If you get stuck, or have any questions, you can ask for help in the [Messenger Customer Chat plugin forum](https://wordpress.org/support/plugin/facebook-messenger-customer-chat).
49
+
50
+ == Screenshots ==
51
+ 1. Messenger customer chat on your website
52
+ 2. Messenger customer chat settings page on first installation
53
+ 3. Select Facebook Page in setup
54
+ 4. Set your desired language and customize the greeting text
55
+ 5. Set your response time and customize your chat color
56
+ 6. Messenger customer chat settings page after successful setup
57
+
58
+ == Frequently Asked Questions ==
59
+
60
+ = Where can I find more information on Messenger customer chat? =
61
+ You can find more information on the [Messenger customer chat page](https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin).
62
+
63
+ = What do I need before setting up Messenger customer chat on my website? =
64
+ You will need to have a published Facebook Page and be logged into Facebook on your computer or device.
65
+
66
+ = How does the plugin work? =
67
+ The plugin is a snippet of JavaScript code that runs on your WordPress website. There will be a small Messenger chat bubble that loads with your website in the lower right corner. Your customers can click on it at anytime and message you. It works on both mobile and desktop. You can find more information in our Developer Docs on the [Messenger customer chat page](https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin).
68
+
69
+ = Where can I see all my messages? =
70
+ You can see all messages and responses to your Facebook Page in your Page Inbox. Navigate to your Facebook Page on Facebook and click on 'Inbox' at the top.
71
+
72
+ = Can I see messaging analytics for my Facebook page? =
73
+ You can see all messages and responses to your Facebook Page in your Page Inbox. Additionally, you can view analytics for your Facebook Page in Page Analytics or via Facebook Analytics. You can learn more about Page Analytics [here](https://developers.facebook.com/docs/analytics/getting-started/pages). If you want more insights on your Facebook Page, visit Page Insights [here](https://www.facebook.com/business/a/page/page-insights).
74
+
75
+ = Where can I find support? =
76
+ If you get stuck, or have any questions, you can ask for help in the [Messenger Customer Chat plugin forum](https://wordpress.org/support/plugin/facebook-messenger-customer-chat). If you would like to file a bug, please use the Facebook Bug tool found [here](https://developers.facebook.com/support/bugs/).
77
+
78
+ = I am a developer. Can I help improve the plugin? =
79
+ Of course! This plugin is open sourced on the Facebook Incubator GitHub. You can find the code and contribution instructions in the [WordPress Messenger customer chat plugin repository](https://github.com/facebookincubator/wordpress-messenger-customer-chat-plugin).
80
+
81
+ == Changelog ==
82
+
83
+ = 1.0 - September 24, 2018 =
84
+ * Plugin released for all users
85
+
86
+ == Upgrade Notice ==
87
+
88
+ No upgrades at this time.
script.js ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright (C) 2017-present, Facebook, Inc.
3
+ *
4
+ * This program is free software; you can redistribute it and/or modify
5
+ * it under the terms of the GNU General Public License as published by
6
+ * the Free Software Foundation; version 2 of the License.
7
+
8
+ * This program is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ * GNU General Public License for more details.
12
+ */
13
+
14
+ function fbmcc_setupCustomerChat() {
15
+ const WRONG_ORIGIN_ERROR_MSG =
16
+ "ERROR:\n"
17
+ + "Message origin is not from https://www.facebook.com.\n"
18
+ + "Code gen aborted.";
19
+ const FACEBOOK_URL = "https://www.facebook.com";
20
+ var baseURL = "https://www.facebook.com/customer_chat/dialog/?domain=";
21
+ var urlParam = encodeURI(
22
+ window.location.protocol
23
+ + '//'
24
+ + window.location.hostname
25
+ + (window.location.port ? ':' + window.location.port : '')
26
+ );
27
+ var customerWindow = window.open(
28
+ baseURL + urlParam,
29
+ "_blank",
30
+ "width=1200,height=800"
31
+ );
32
+
33
+ jQuery(window).on("message", function(e) {
34
+ if (e.originalEvent.origin === FACEBOOK_URL) {
35
+ $data_json = JSON.parse(e.originalEvent.data);
36
+ var data = {
37
+ 'action' : 'update_options',
38
+ 'pageID' : fbmcc_sanitizeNumbersOnly($data_json["pageID"]),
39
+ 'locale' : fbmcc_sanitizeLocale($data_json["locale"]),
40
+ 'themeColor' : fbmcc_sanitizeHexColor($data_json["themeColorCode"]),
41
+ 'greetingText' : $data_json["greetingTextCode"],
42
+ };
43
+ data.generatedCode = fbmcc_genScript(
44
+ data.pageID,
45
+ data.locale,
46
+ data.themeColor,
47
+ data.greetingText,
48
+ ).replace(/^\s*\n/gm, "");
49
+ jQuery.ajax({
50
+ type: 'POST',
51
+ url: ajaxurl,
52
+ data: data,
53
+ success: function(results) {
54
+ jQuery('#fbmcc-codeArea').val(data.generatedCode);
55
+ jQuery('#fbmcc-page-params').css('display', 'inline-block');
56
+ jQuery('#fbmcc-enabled').prop('checked', true);
57
+ }
58
+ });
59
+ } else {
60
+ jQuery('#fbmcc-codeArea').val(WRONG_ORIGIN_ERROR_MSG);
61
+ };
62
+ });
63
+ }
64
+
65
+ function fbmcc_genScript( pageID, locale, themeColor, greetingText ) {
66
+ return `<div id='fb-root'></div>
67
+ <script>(function(d, s, id) {
68
+ var js, fjs = d.getElementsByTagName(s)[0];
69
+ if (d.getElementById(id)) return;
70
+ js = d.createElement(s); js.id = id;
71
+ js.src = 'https://connect.facebook.net/${locale}/sdk.js#xfbml=1&version=v2.12&autoLogAppEvents=1';
72
+ fjs.parentNode.insertBefore(js, fjs);
73
+ }(document, 'script', 'facebook-jssdk'));</script>
74
+ <div class='fb-customerchat'
75
+ attribution="wordpress"
76
+ page_id='${pageID}'
77
+ ${themeColor === null ? '' : `theme_color='${themeColor}'`}
78
+ ${greetingText === null ? '' : `logged_in_greeting='${greetingText}'`}
79
+ ${greetingText === null ? '' : `logged_out_greeting='${greetingText}'`}
80
+ >
81
+ </div>`;
82
+ }
83
+
84
+ function fbmcc_editCode() {
85
+ jQuery('#fbmcc-codeArea').prop('readonly', function(i, v) { return !v; });
86
+ }
87
+
88
+ function fbmcc_sanitizeNumbersOnly( number ) {
89
+ if( /^\d+$/.test(number) ) {
90
+ return number;
91
+ } else {
92
+ return '';
93
+ }
94
+ }
95
+
96
+ function fbmcc_sanitizeLocale( locale ) {
97
+ if( /^[A-Za-z_]{4,5}$/.test(locale) ) {
98
+ return locale;
99
+ } else {
100
+ return '';
101
+ }
102
+ }
103
+
104
+ function fbmcc_sanitizeHexColor( color ) {
105
+ if( /^#([A-Fa-f0-9]{3}){1,2}$/.test(color) ) {
106
+ return color;
107
+ } else {
108
+ return null;
109
+ }
110
+ }
settings.css ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright 2017-present, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ .fbmcc-card {
10
+ background-color: #fff;
11
+ width: 600px;
12
+ }
13
+
14
+ .fbmcc-settings {
15
+ text-align: left;
16
+ }
17
+
18
+ .fbmcc-instructions,
19
+ .fbmcc-buttonContainer {
20
+ color: #444444;
21
+ margin-bottom: 10px;
22
+ }
23
+
24
+ .fbmcc-code-area {
25
+ margin-top: 10px;
26
+ width: 100%;
27
+ }
28
+
29
+ .fbmcc-setupButton,
30
+ .fbmcc-editButton {
31
+ background-color: #f7f7f7;
32
+ border-radius: 4px;
33
+ box-shadow: 0 1px 0 #aaa;
34
+ color: #555555;
35
+ }
36
+
37
+ .fbmcc-codeTitle{
38
+ float: left;
39
+ }
40
+
41
+ .fbmcc-setupButton {
42
+ height: 28px;
43
+ width: 148px;
44
+ }
45
+
46
+ .fbmcc-editButton {
47
+ float: right;
48
+ height: 28px;
49
+ position: absolute;
50
+ right: 5px;
51
+ top: 15px;
52
+ width: 88px;
53
+ }
54
+
55
+ .fbmcc-codeContainer {
56
+ position: relative;
57
+ }
58
+
59
+ .fbmcc-setupButton:hover {
60
+ background-color: #fbfbfb;
61
+ cursor:pointer;
62
+ }
63
+
64
+ .fbmcc-setupButton:active {
65
+ background-color: #eeeeee;
66
+ transform: translateY(1px);
67
+ }
68
+
69
+ td {
70
+ padding: 0 20px 0 20px;
71
+ }
72
+
73
+ table
74
+ {
75
+ border-collapse:separate;
76
+ border-spacing:0 10px;
77
+ }
78
+
79
+ .fbmcc-switch {
80
+ position: relative;
81
+ display: inline-block;
82
+ width: 30px;
83
+ height: 17px;
84
+ }
85
+
86
+ .fbmcc-switch input {display:none;}
87
+
88
+ .fbmcc-slider {
89
+ position: absolute;
90
+ cursor: pointer;
91
+ top: 0;
92
+ left: 0;
93
+ right: 0;
94
+ bottom: 0;
95
+ background-color: #ccc;
96
+ -webkit-transition: .4s;
97
+ transition: .4s;
98
+ }
99
+
100
+ .fbmcc-slider:before {
101
+ position: absolute;
102
+ content: "";
103
+ height: 13px;
104
+ width: 13px;
105
+ left: 2px;
106
+ bottom: 2px;
107
+ background-color: white;
108
+ -webkit-transition: .4s;
109
+ transition: .4s;
110
+ }
111
+
112
+ input:checked + .fbmcc-slider {
113
+ background-color: #2196F3;
114
+ }
115
+
116
+ input:focus + .fbmcc-slider {
117
+ box-shadow: 0 0 1px #2196F3;
118
+ }
119
+
120
+ input:checked + .fbmcc-slider:before {
121
+ -webkit-transform: translateX(13px);
122
+ -ms-transform: translateX(13px);
123
+ transform: translateX(13px);
124
+ }
125
+
126
+ .fbmcc-slider.round {
127
+ border-radius: 17px;
128
+ }
129
+
130
+ .fbmcc-slider.round:before {
131
+ border-radius: 50%;
132
+ }