Version Description
- NEW: Better Integration with WooCommerce: CTA and Custom Message for product pages and new dynamic variables {SKU}, {PRICE} {PRODUCT}.
- NEW: Admin help tab with styles and dynamic varibles info.
- NEW: For developers: a lot of new hooks to change or extend WAme functions.
- NEW: Custom javascript document event 'whatsappme:open' that allow trigger other actions and/or change the link url.
- CHANGED Rebrand "WhatsApp me" to "WAme chat".
- CHANGED Code linted following WordPress standar.
- FIX when post visibility was set as "hidden", it used default global visibility.
- FIX javascript error when "ga" global object is defined but isn't Google Analytics.
- FIX rtl styles for chat.
Download this release
Release Info
Developer | creapuntome |
Plugin | ![]() |
Version | 3.0.0 |
Comparing to | |
See all releases |
Code changes from version 2.3.3 to 3.0.0
- README.txt +27 -15
- admin/class-whatsappme-admin.php +412 -314
- admin/class-whatsappme-wooadmin.php +247 -0
- admin/css/whatsappme.css +52 -8
- admin/css/whatsappme.min.css +1 -1
- admin/index.php +1 -1
- admin/js/whatsappme.js +31 -11
- admin/js/whatsappme.min.js +1 -1
- includes/class-whatsappme-integrations.php +42 -0
- includes/class-whatsappme-loader.php +75 -17
- includes/class-whatsappme.php +41 -16
- includes/index.php +1 -1
- index.php +1 -1
- languages/creame-whatsapp-me.pot +208 -107
- public/class-whatsappme-public.php +126 -109
- public/class-whatsappme-woopublic.php +158 -0
- public/css/whatsappme.css +11 -0
- public/css/whatsappme.min.css +1 -1
- public/index.php +1 -1
- public/js/whatsappme.js +15 -5
- public/js/whatsappme.min.js +1 -1
- whatsappme.php +9 -7
README.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
===
|
2 |
Contributors: creapuntome, pacotole, davidlillo, monillo
|
3 |
Donate link: https://www.paypal.me/creapuntome/
|
4 |
Tags: whatsapp business, whatsapp, click to chat, button, whatsapp support chat, support, contact, directly message whatsapp, floating whatsapp, whatsapp chat
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 5.2
|
7 |
Requires PHP: 5.3
|
8 |
-
Stable tag:
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -13,10 +13,14 @@ Connect a WordPress chat with WhatsApp. The best solution for marketing and supp
|
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
-
[wame.chat](https://wame.chat) | [
|
17 |
|
18 |
### Connect a WordPress chat with WhatsApp. The best solution for marketing and support. Stop losing customers and increase your sales.
|
19 |
|
|
|
|
|
|
|
|
|
20 |
### ⌁ What you can do with WAme ✅
|
21 |
|
22 |
#### 🛎 Insert a WhatsApp button on your website.
|
@@ -71,7 +75,7 @@ Having many options is not an advantage, the configuration of WAme is so easy th
|
|
71 |
|
72 |
= Open WhatsApp Web on desktop =
|
73 |
|
74 |
-
By default,
|
75 |
|
76 |
If you prefer always open WhatsApp Web on desktop you can add this code in your functions.php:
|
77 |
|
@@ -89,11 +93,11 @@ Greater values of z-index are left over, the default value is 400.
|
|
89 |
|
90 |
= What about GDPR? =
|
91 |
|
92 |
-
|
93 |
|
94 |
= Google Analytics integration =
|
95 |
|
96 |
-
|
97 |
|
98 |
If Global Site Tag (gtag.js) detected:
|
99 |
|
@@ -105,21 +109,29 @@ If Universal Analtics (analytics.js) detected:
|
|
105 |
|
106 |
= Google Tag Manager integration =
|
107 |
|
108 |
-
|
109 |
|
110 |
`dataLayer.push({ 'event': 'WhatsAppMe', 'eventAction': 'click', 'eventLabel': out_url });`
|
111 |
|
112 |
== Screenshots ==
|
113 |
|
114 |
-
1.
|
115 |
-
2.
|
116 |
-
3.
|
117 |
-
4. Button on desktop.
|
118 |
-
5. Call to action on desktop.
|
119 |
-
6. Button and call to action on mobile.
|
120 |
|
121 |
== Changelog ==
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
= 2.3.3 =
|
124 |
* FIX javascript error when "ga" global object is defined but isn't Google Analytics.
|
125 |
|
@@ -172,7 +184,7 @@ WhatsApp me send an event (if GTM detected) when user click to launch WhatsApp:
|
|
172 |
* FIX removed array_filter function that requires PHP 5.6 min version.
|
173 |
|
174 |
= 2.0.0 =
|
175 |
-
* **NEW: Advanced visibility settings to define where to show
|
176 |
* **NEW:** WooCommerce integration.
|
177 |
* UPDATED International Telephone Input library to v.13.
|
178 |
* Minor fixes on fields cleanup and other improvements.
|
@@ -186,7 +198,7 @@ WhatsApp me send an event (if GTM detected) when user click to launch WhatsApp:
|
|
186 |
* FIX JavaScript error introduced on v1.4.1.
|
187 |
|
188 |
= 1.4.1 =
|
189 |
-
* Fix JS frontend sometimes can't load
|
190 |
* Fix better Google Analytics event tracking when leave page.
|
191 |
|
192 |
= 1.4.0 =
|
1 |
+
=== WAme chat ===
|
2 |
Contributors: creapuntome, pacotole, davidlillo, monillo
|
3 |
Donate link: https://www.paypal.me/creapuntome/
|
4 |
Tags: whatsapp business, whatsapp, click to chat, button, whatsapp support chat, support, contact, directly message whatsapp, floating whatsapp, whatsapp chat
|
5 |
Requires at least: 3.0.1
|
6 |
Tested up to: 5.2
|
7 |
Requires PHP: 5.3
|
8 |
+
Stable tag: 3.0.0
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
13 |
|
14 |
== Description ==
|
15 |
|
16 |
+
[wame.chat](https://wame.chat) | [Add-Ons](https://wame.chat/addons/) | [Plugin support](https://wordpress.org/support/plugin/creame-whatsapp-me/)
|
17 |
|
18 |
### Connect a WordPress chat with WhatsApp. The best solution for marketing and support. Stop losing customers and increase your sales.
|
19 |
|
20 |
+
### New in WAme 3.0 📍
|
21 |
+
|
22 |
+
🛒 **Better Integration with WooCommerce**. Define CTAs and Custom Messages for product pages, you can use dynamic variables such as {SKU}, {PRICE} or {PRODUCT}.
|
23 |
+
|
24 |
### ⌁ What you can do with WAme ✅
|
25 |
|
26 |
#### 🛎 Insert a WhatsApp button on your website.
|
75 |
|
76 |
= Open WhatsApp Web on desktop =
|
77 |
|
78 |
+
By default, WAme always opens api.whatsapp.com and try to launch the native application or if it doesn't exist redirects to WhatsApp Web. Depending on the browser and the operating system, sometimes it doesn't work.
|
79 |
|
80 |
If you prefer always open WhatsApp Web on desktop you can add this code in your functions.php:
|
81 |
|
93 |
|
94 |
= What about GDPR? =
|
95 |
|
96 |
+
WAme don't save any personal data and don't use cookies.
|
97 |
|
98 |
= Google Analytics integration =
|
99 |
|
100 |
+
WAme send an event when user click to launch WhatsApp.
|
101 |
|
102 |
If Global Site Tag (gtag.js) detected:
|
103 |
|
109 |
|
110 |
= Google Tag Manager integration =
|
111 |
|
112 |
+
WAme send an event (if GTM detected) when user click to launch WhatsApp:
|
113 |
|
114 |
`dataLayer.push({ 'event': 'WhatsAppMe', 'eventAction': 'click', 'eventLabel': out_url });`
|
115 |
|
116 |
== Screenshots ==
|
117 |
|
118 |
+
1. WAme general settings.
|
119 |
+
2. WAme advanced visibility settings.
|
120 |
+
3. WAme on post/page edition.
|
|
|
|
|
|
|
121 |
|
122 |
== Changelog ==
|
123 |
|
124 |
+
= 3.0.0 =
|
125 |
+
* **NEW:** Better Integration with WooCommerce: CTA and Custom Message for product pages and new dynamic variables {SKU}, {PRICE} {PRODUCT}.
|
126 |
+
* **NEW:** Admin help tab with styles and dynamic varibles info.
|
127 |
+
* **NEW:** For developers: a lot of new hooks to change or extend WAme functions.
|
128 |
+
* **NEW:** Custom javascript document event 'whatsappme:open' that allow trigger other actions and/or change the link url.
|
129 |
+
* CHANGED Rebrand "WhatsApp me" to "WAme chat".
|
130 |
+
* CHANGED Code linted following WordPress standar.
|
131 |
+
* FIX when post visibility was set as "hidden", it used default global visibility.
|
132 |
+
* FIX javascript error when "ga" global object is defined but isn't Google Analytics.
|
133 |
+
* FIX rtl styles for chat.
|
134 |
+
|
135 |
= 2.3.3 =
|
136 |
* FIX javascript error when "ga" global object is defined but isn't Google Analytics.
|
137 |
|
184 |
* FIX removed array_filter function that requires PHP 5.6 min version.
|
185 |
|
186 |
= 2.0.0 =
|
187 |
+
* **NEW: Advanced visibility settings to define where to show WAme button.**
|
188 |
* **NEW:** WooCommerce integration.
|
189 |
* UPDATED International Telephone Input library to v.13.
|
190 |
* Minor fixes on fields cleanup and other improvements.
|
198 |
* FIX JavaScript error introduced on v1.4.1.
|
199 |
|
200 |
= 1.4.1 =
|
201 |
+
* Fix JS frontend sometimes can't load WAme settings.
|
202 |
* Fix better Google Analytics event tracking when leave page.
|
203 |
|
204 |
= 1.4.0 =
|
admin/class-whatsappme-admin.php
CHANGED
@@ -8,6 +8,7 @@
|
|
8 |
*
|
9 |
* @since 1.0.0
|
10 |
* @since 2.0.0 Added advanced visibility settings
|
|
|
11 |
* @package WhatsAppMe
|
12 |
* @subpackage WhatsAppMe/admin
|
13 |
* @author Creame <hola@crea.me>
|
@@ -50,19 +51,32 @@ class WhatsAppMe_Admin {
|
|
50 |
*/
|
51 |
private $enhanced_phone;
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
/**
|
54 |
* Initialize the class and set its properties.
|
55 |
*
|
56 |
* @since 1.0.0
|
57 |
-
* @
|
58 |
-
* @param string
|
|
|
59 |
*/
|
60 |
public function __construct( $plugin_name, $version ) {
|
61 |
|
62 |
-
$this->plugin_name
|
63 |
-
$this->version
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
66 |
|
67 |
}
|
68 |
|
@@ -73,33 +87,51 @@ class WhatsAppMe_Admin {
|
|
73 |
* @since 2.0.0 Added visibility setting
|
74 |
* @since 2.1.0 Added message_badge
|
75 |
* @since 2.3.0 Added button_delay and whatsapp_web settings, message_delay in seconds
|
|
|
76 |
*/
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
'
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
);
|
91 |
|
92 |
$saved_settings = get_option( 'whatsappme' );
|
93 |
|
94 |
if ( is_array( $saved_settings ) ) {
|
95 |
// clean unused saved settings
|
96 |
-
$saved_settings = array_intersect_key( $saved_settings, $
|
97 |
// merge defaults with saved settings
|
98 |
-
$this->settings = array_merge( $
|
99 |
// miliseconds (<v2.3) to seconds
|
100 |
if ( $this->settings['message_delay'] > 120 ) {
|
101 |
$this->settings['message_delay'] = round( $this->settings['message_delay'] / 1000 );
|
102 |
}
|
|
|
|
|
103 |
}
|
104 |
|
105 |
}
|
@@ -107,20 +139,17 @@ class WhatsAppMe_Admin {
|
|
107 |
/**
|
108 |
* Register the stylesheets for the admin area.
|
109 |
*
|
110 |
-
* @since
|
111 |
-
* @
|
112 |
-
* @since 2.2.0 Only register (not enqueue)
|
113 |
-
* @since 2.2.2 minified
|
114 |
-
* @param string $hook The name of the page.
|
115 |
* @return void
|
116 |
*/
|
117 |
-
public function
|
118 |
|
119 |
$styles = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'whatsappme.css' : 'whatsappme.min.css';
|
120 |
wp_register_style( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'css/' . $styles, array(), $this->version, 'all' );
|
121 |
|
122 |
if ( $this->enhanced_phone ) {
|
123 |
-
wp_register_style( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/
|
124 |
}
|
125 |
|
126 |
}
|
@@ -128,19 +157,18 @@ class WhatsAppMe_Admin {
|
|
128 |
/**
|
129 |
* Register the JavaScript for the admin area.
|
130 |
*
|
131 |
-
* @since
|
132 |
-
* @
|
133 |
-
* @since 2.2.2 minified
|
134 |
-
* @param string $hook The id of the page.
|
135 |
* @return void
|
136 |
*/
|
137 |
-
public function
|
138 |
|
139 |
$script = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'whatsappme.js' : 'whatsappme.min.js';
|
140 |
|
141 |
if ( $this->enhanced_phone ) {
|
142 |
-
wp_register_script( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/
|
143 |
wp_register_script( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'js/' . $script, array( 'jquery', 'intl-tel-input' ), $this->version, true );
|
|
|
144 |
} else {
|
145 |
wp_register_script( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'js/' . $script, array( 'jquery' ), $this->version, true );
|
146 |
}
|
@@ -148,140 +176,132 @@ class WhatsAppMe_Admin {
|
|
148 |
}
|
149 |
|
150 |
/**
|
151 |
-
* Initialize the settings for
|
152 |
* From v1.2.0 also set filter to disable enhanced phone input
|
153 |
*
|
154 |
* @since 1.0.0
|
155 |
* @since 2.0.0 Added tabs for general and Advanced settings
|
156 |
* @since 2.3.0 Split general settings in Button and Window Chat
|
|
|
157 |
* @access public
|
158 |
* @return void
|
159 |
*/
|
160 |
-
public function settings_init(){
|
161 |
|
|
|
162 |
register_setting( 'whatsappme', 'whatsappme', array( $this, 'settings_validate' ) );
|
163 |
|
164 |
-
|
165 |
-
* General Settings
|
166 |
-
*/
|
167 |
|
168 |
-
|
169 |
|
170 |
-
|
171 |
-
'telephone' => '<label for="whatsappme_phone">' . __( 'Telephone', 'creame-whatsapp-me' ) . '</label>',
|
172 |
-
'mobile_only' => __( 'Mobile Only', 'creame-whatsapp-me' ),
|
173 |
-
'position' => __( 'Position On Screen', 'creame-whatsapp-me' ),
|
174 |
-
'button_delay' => '<label for="whatsappme_button_delay">' . __( 'Button Delay', 'creame-whatsapp-me' ) . '</label>',
|
175 |
-
'whatsapp_web' => __( 'WhatsApp Web', 'creame-whatsapp-me' ),
|
176 |
-
);
|
177 |
|
178 |
-
|
|
|
179 |
|
180 |
-
|
181 |
-
add_settings_field( 'whatsappme_' . $key, $value, array( $this, 'field_' . $key ), 'whatsappme', 'whatsappme_section_general_btn' );
|
182 |
-
}
|
183 |
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
190 |
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
add_settings_field( 'whatsappme_' . $key, $value, array( $this, 'field_' . $key ), 'whatsappme', 'whatsappme_section_general_cta' );
|
195 |
-
}
|
196 |
-
|
197 |
-
/*
|
198 |
-
* Advanced Settings / All
|
199 |
-
*/
|
200 |
-
|
201 |
-
add_settings_section( 'whatsappme_section_advanced_all', null, array( $this, 'section_text' ), 'whatsappme' );
|
202 |
-
add_settings_field( 'whatsappme_view_all', __( 'Global', 'creame-whatsapp-me' ), array( $this, 'field_view_all' ), 'whatsappme', 'whatsappme_section_advanced_all' );
|
203 |
-
|
204 |
-
/*
|
205 |
-
* Advanced Settings / WP
|
206 |
-
*/
|
207 |
-
|
208 |
-
add_settings_section( 'whatsappme_section_advanced_wp', null, array( $this, 'section_text' ), 'whatsappme' );
|
209 |
-
|
210 |
-
$advanced_fields = array(
|
211 |
-
'front_page' => __( 'Front Page', 'creame-whatsapp-me' ),
|
212 |
-
'blog_page' => __( 'Blog Page', 'creame-whatsapp-me' ),
|
213 |
-
'404_page' => __( '404 Page', 'creame-whatsapp-me' ),
|
214 |
-
'search' => __( 'Search Results', 'creame-whatsapp-me' ),
|
215 |
-
'archive' => __( 'Archives', 'creame-whatsapp-me' ),
|
216 |
-
'date' => '— ' . __( 'Date Archives', 'creame-whatsapp-me' ),
|
217 |
-
'author' => '— ' . __( 'Author Archives', 'creame-whatsapp-me' ),
|
218 |
-
'singular' => __( 'Singular', 'creame-whatsapp-me' ),
|
219 |
-
'page' => '— ' . __( 'Page', 'creame-whatsapp-me' ),
|
220 |
-
'post' => '— ' . __( 'Post', 'creame-whatsapp-me' ),
|
221 |
-
);
|
222 |
-
|
223 |
-
// If isn't set Blog Page or is the same than Front Page unset blog_page option
|
224 |
-
if ( get_option( 'show_on_front' ) == 'posts' || get_option( 'page_for_posts' ) == 0 ) {
|
225 |
-
unset( $advanced_fields['blog_page'] );
|
226 |
-
}
|
227 |
|
228 |
-
|
229 |
-
add_settings_field( 'whatsappme_view_' . $key, $value, array( $this, 'field_view' ), 'whatsappme', 'whatsappme_section_advanced_wp', array( 'field' => $key ) );
|
230 |
}
|
231 |
|
232 |
-
|
233 |
-
* Advanced Settings / Woocommerce
|
234 |
-
*/
|
235 |
-
|
236 |
-
if ( class_exists( 'WooCommerce' ) ) {
|
237 |
|
238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
'
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
);
|
248 |
|
249 |
-
|
250 |
-
|
|
|
251 |
}
|
252 |
-
}
|
253 |
-
|
254 |
-
/*
|
255 |
-
* Advanced Settings / Custom Post Types
|
256 |
-
*/
|
257 |
-
|
258 |
-
$custom_post_types = array_keys( get_post_types( array( 'has_archive' => true ), 'names' ) );
|
259 |
-
// Product CPT already defined in WooCommerce section
|
260 |
-
if ( class_exists( 'WooCommerce' ) ) {
|
261 |
-
$custom_post_types = array_diff( $custom_post_types, array( 'product' ) );
|
262 |
-
}
|
263 |
|
264 |
-
|
265 |
-
|
|
|
|
|
|
|
266 |
|
267 |
-
|
|
|
268 |
|
269 |
-
|
|
|
|
|
|
|
|
|
270 |
|
271 |
-
|
|
|
|
|
|
|
272 |
|
273 |
-
|
274 |
-
$post_type_name = function_exists( 'mb_convert_case' ) ?
|
275 |
-
mb_convert_case( $post_type->labels->name, MB_CASE_TITLE ) :
|
276 |
-
strtolower( $post_type->labels->name );
|
277 |
|
278 |
-
add_settings_field( 'whatsappme_view_cpt_' . $custom_post_type, $post_type_name, array( $this, 'field_view' ), 'whatsappme', 'whatsappme_section_advanced_cpt', array( 'field' => 'cpt_' . $custom_post_type ) );
|
279 |
-
}
|
280 |
}
|
281 |
|
282 |
-
|
|
|
283 |
|
284 |
-
$this->enhanced_phone = apply_filters( 'whatsappme_enhanced_phone', $this->enhanced_phone );
|
285 |
}
|
286 |
|
287 |
/**
|
@@ -291,25 +311,33 @@ class WhatsAppMe_Admin {
|
|
291 |
* @since 2.0.0 Added visibility setting
|
292 |
* @since 2.1.0 Added message_badge
|
293 |
* @since 2.3.0 Added button_delay and whatsapp_web settings, WPML integration
|
294 |
-
* @
|
|
|
295 |
* @return array
|
296 |
*/
|
297 |
-
public function settings_validate($input) {
|
298 |
|
299 |
-
$input['telephone'] =
|
300 |
$input['mobile_only'] = isset( $input['mobile_only'] ) ? 'yes' : 'no';
|
301 |
$input['button_delay'] = intval( $input['button_delay'] );
|
302 |
$input['whatsapp_web'] = isset( $input['whatsapp_web'] ) ? 'yes' : 'no';
|
303 |
-
$input['message_text'] =
|
304 |
$input['message_delay'] = intval( $input['message_delay'] );
|
305 |
$input['message_badge'] = isset( $input['message_badge'] ) ? 'yes' : 'no';
|
306 |
-
$input['message_send'] =
|
307 |
$input['position'] = $input['position'] != 'left' ? 'right' : 'left';
|
308 |
if ( isset( $input['view'] ) ) {
|
309 |
-
$input['visibility']
|
|
|
|
|
|
|
|
|
310 |
unset( $input['view'] );
|
311 |
}
|
312 |
|
|
|
|
|
|
|
313 |
/**
|
314 |
* Register WPML/Polylang strings for translation
|
315 |
* https://wpml.org/wpml-hook/wpml_register_single_string/
|
@@ -320,218 +348,271 @@ class WhatsAppMe_Admin {
|
|
320 |
do_action( 'wpml_register_single_string', 'WhatsApp me', 'Call To Action', $input['message_text'] );
|
321 |
do_action( 'wpml_register_single_string', 'WhatsApp me', 'Message', $input['message_send'] );
|
322 |
|
|
|
|
|
|
|
323 |
add_settings_error( 'whatsappme', 'settings_updated', __( 'Settings saved', 'creame-whatsapp-me' ), 'updated' );
|
324 |
|
325 |
return $input;
|
326 |
}
|
327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
/**
|
329 |
* Section HTML output
|
330 |
*
|
331 |
-
* @since
|
332 |
-
* @
|
333 |
-
* @param array $args Section info.
|
334 |
* @return void
|
335 |
*/
|
336 |
-
public function
|
337 |
-
|
338 |
-
case 'whatsappme_section_general':
|
339 |
-
echo '<h2 class="nav-tab-wrapper wp-clearfix">' .
|
340 |
-
'<a href="#tab-general" class="nav-tab nav-tab-active">' . __( 'General', 'creame-whatsapp-me' ) . '</a>' .
|
341 |
-
'<a href="#tab-advanced" class="nav-tab">' . __( 'Advanced', 'creame-whatsapp-me' ) . '</a>' .
|
342 |
-
'</h2>' .
|
343 |
-
'<div class="tabs">' .
|
344 |
-
'<div id="tab-general" class="tab tab-active">';
|
345 |
-
break;
|
346 |
|
347 |
-
|
348 |
-
|
|
|
349 |
'<p>' . __( 'Set the contact number and where you want the WhatsApp button to be displayed.', 'creame-whatsapp-me' ) . '</p>';
|
350 |
break;
|
351 |
|
352 |
-
case '
|
353 |
-
|
354 |
'<p>' .
|
355 |
__( 'Set the behavior of the chat window.', 'creame-whatsapp-me' ) . ' ' .
|
356 |
-
__(
|
357 |
-
|
358 |
'</p>';
|
359 |
break;
|
360 |
|
361 |
-
case '
|
362 |
-
|
363 |
-
'<h2 class="title">' . __( 'Advanced Visibility Settings', 'creame-whatsapp-me' ) . '</h2>' .
|
364 |
'<p>' . __( 'From here you can configure on which pages the WhatsApp button will be visible.', 'creame-whatsapp-me' ) .
|
365 |
' <a href="#" class="whatsappme_view_reset">' . __( 'Restore default visibility', 'creame-whatsapp-me' ) . '</a></p>';
|
366 |
break;
|
367 |
|
368 |
-
case '
|
369 |
-
|
370 |
break;
|
371 |
|
372 |
-
case '
|
373 |
-
|
374 |
break;
|
375 |
|
376 |
default:
|
|
|
377 |
break;
|
378 |
}
|
379 |
-
}
|
380 |
|
381 |
-
|
382 |
-
|
383 |
-
*
|
384 |
-
* @since 1.0.0
|
385 |
-
* @return void
|
386 |
-
*/
|
387 |
-
public function field_telephone() {
|
388 |
-
echo '<input id="whatsappme_phone" ' . ( $this->enhanced_phone ? 'data-' : '') . 'name="whatsappme[telephone]" value="' . $this->settings['telephone'] . '" type="text" style="width:15em">' .
|
389 |
-
'<p class="description">' . __( "Contact phone number <strong>(the button will not be shown if it's empty)</strong>", 'creame-whatsapp-me' ) . '</p>';
|
390 |
}
|
391 |
|
392 |
/**
|
393 |
-
* Field
|
394 |
*
|
395 |
-
* @since
|
396 |
* @return void
|
397 |
*/
|
398 |
-
public function
|
399 |
-
echo '<textarea id="whatsappme_message_text" name="whatsappme[message_text]" rows="4" class="regular-text" placeholder="' . esc_attr__( "Hello 👋\nCan we help you?", 'creame-whatsapp-me' ) . '">' . $this->settings['message_text'] . '</textarea>' .
|
400 |
-
'<p class="description">' . __( 'Define a text to encourage users to contact by WhatsApp <strong>(optional)</strong>', 'creame-whatsapp-me' ) . '</p>';
|
401 |
-
}
|
402 |
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
* @since 1.0.0
|
407 |
-
* @return void
|
408 |
-
*/
|
409 |
-
public function field_message_delay() {
|
410 |
-
echo '<input id="whatsappme_message_delay" name="whatsappme[message_delay]" value="' . $this->settings['message_delay'] . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds', 'creame-whatsapp-me' ) .
|
411 |
-
'<p class="description">' . __( 'Time since the WhatsApp button is displayed until the Chat Window opens', 'creame-whatsapp-me' ) . '</p>';
|
412 |
-
}
|
413 |
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
public function field_message_badge() {
|
421 |
-
echo '<fieldset><legend class="screen-reader-text"><span>' . __( 'Hide Chat', 'creame-whatsapp-me' ) . '</span></legend>' .
|
422 |
-
'<label><input name="whatsappme[message_badge]" value="yes" type="checkbox"' . checked( 'yes', $this->settings['message_badge'], false ) . '> ' .
|
423 |
-
__('Display a notification balloon instead of opening the Chat Window for a "less intrusive" mode', 'creame-whatsapp-me' ) . '</label></fieldset>';
|
424 |
-
}
|
425 |
|
426 |
-
|
427 |
-
* Field 'message_send' output
|
428 |
-
*
|
429 |
-
* @since 1.4.0
|
430 |
-
* @return void
|
431 |
-
*/
|
432 |
-
public function field_message_send() {
|
433 |
-
echo '<textarea id="whatsappme_message_send" name="whatsappme[message_send]" rows="3" class="regular-text" placeholder="' . esc_attr__( "Hi *{SITE}*! I need more info about {TITLE}", 'creame-whatsapp-me' ) . '">' . $this->settings['message_send'] . '</textarea>' .
|
434 |
-
'<p class="description">' . __( 'Predefined text with which user can start the conversation <strong>(optional)</strong>', 'creame-whatsapp-me' ) . '</p>';
|
435 |
-
}
|
436 |
-
|
437 |
-
/**
|
438 |
-
* Field 'mobile_only' output
|
439 |
-
*
|
440 |
-
* @since 1.0.0
|
441 |
-
* @return void
|
442 |
-
*/
|
443 |
-
public function field_mobile_only() {
|
444 |
-
echo '<fieldset><legend class="screen-reader-text"><span>' . __( 'Mobile Only', 'creame-whatsapp-me' ) . '</span></legend>' .
|
445 |
-
'<label><input id="whatsappme_mobile_only" name="whatsappme[mobile_only]" value="yes" type="checkbox"' . checked( 'yes', $this->settings['mobile_only'], false ) . '> ' .
|
446 |
-
__('Only display the button on mobile devices', 'creame-whatsapp-me' ) . '</label></fieldset>';
|
447 |
-
}
|
448 |
-
|
449 |
-
/**
|
450 |
-
* Field 'button_delay' output
|
451 |
-
*
|
452 |
-
* @since 2.3.0
|
453 |
-
* @return void
|
454 |
-
*/
|
455 |
-
public function field_button_delay() {
|
456 |
-
echo '<input id="whatsappme_button_delay" name="whatsappme[button_delay]" value="' . $this->settings['button_delay'] . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds', 'creame-whatsapp-me' ) .
|
457 |
-
'<p class="description">' . __( 'Time since the page is opened until the WhatsApp button is displayed', 'creame-whatsapp-me' ) . '</p>';
|
458 |
-
}
|
459 |
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
473 |
|
474 |
-
|
475 |
-
|
476 |
-
*
|
477 |
-
* @since 2.3.0
|
478 |
-
* @return void
|
479 |
-
*/
|
480 |
-
public function field_whatsapp_web() {
|
481 |
-
echo '<fieldset><legend class="screen-reader-text"><span>' . __( 'WhatsApp Web', 'creame-whatsapp-me' ) . '</span></legend>' .
|
482 |
-
'<label><input id="whatsappme_whatsapp_web" name="whatsappme[whatsapp_web]" value="yes" type="checkbox"' . checked( 'yes', $this->settings['whatsapp_web'], false ) . '> ' .
|
483 |
-
__('Open <em>WhatsApp Web</em> directly on desktop', 'creame-whatsapp-me' ) . '</label></fieldset>';
|
484 |
}
|
485 |
|
486 |
/**
|
487 |
* Field 'field_view_all' output
|
488 |
*
|
489 |
* @since 2.0.0
|
|
|
490 |
* @return void
|
491 |
*/
|
492 |
public function field_view_all() {
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
|
|
|
|
|
|
|
|
|
|
498 |
|
499 |
-
echo '<
|
|
|
500 |
'<span class="dashicons dashicons-visibility" title="' . __( 'Show', 'creame-whatsapp-me' ) . '"></span></label>' .
|
501 |
-
'<label
|
502 |
-
'<span class="dashicons dashicons-hidden" title="' . __( 'Hide', 'creame-whatsapp-me' ) . '"></span></label>';
|
503 |
}
|
504 |
|
505 |
/**
|
506 |
-
*
|
507 |
*
|
508 |
-
* @since
|
509 |
-
* @
|
510 |
* @return void
|
511 |
*/
|
512 |
-
public function
|
513 |
-
|
514 |
-
|
515 |
|
516 |
-
echo '<label><input type="radio" name="whatsappme[view][' . $field . ']" value="yes"' . checked( 'yes', $value, false ) . '> ' .
|
517 |
-
'<span class="dashicons dashicons-visibility" title="' . __( 'Show', 'creame-whatsapp-me' ) . '"></span></label>' .
|
518 |
-
'<label><input type="radio" name="whatsappme[view][' . $field . ']" value="no"' . checked( 'no', $value, false ) . '> ' .
|
519 |
-
'<span class="dashicons dashicons-hidden" title="' . __( 'Hide', 'creame-whatsapp-me' ) . '"></span></label>' .
|
520 |
-
'<label><input type="radio" name="whatsappme[view][' . $field . ']" value=""' . checked( '', $value, false ) . '> ' .
|
521 |
-
__( 'Inherit', 'creame-whatsapp-me' ) . ' <span class="dashicons dashicons-visibility view_inheritance_' . $field . '"></span></label>';
|
522 |
}
|
523 |
|
524 |
/**
|
525 |
-
* Add
|
526 |
*
|
527 |
-
* @since
|
528 |
* @access public
|
529 |
* @return void
|
530 |
*/
|
531 |
-
|
532 |
-
|
533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
534 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
535 |
}
|
536 |
|
537 |
/**
|
@@ -550,7 +631,7 @@ class WhatsAppMe_Admin {
|
|
550 |
}
|
551 |
|
552 |
/**
|
553 |
-
* Generate the options page in the
|
554 |
*
|
555 |
* @since 1.0.0
|
556 |
* @since 2.2.0 Enqueue scripts/styles
|
@@ -566,16 +647,22 @@ class WhatsAppMe_Admin {
|
|
566 |
if ( $this->enhanced_phone ) {
|
567 |
wp_enqueue_style( 'intl-tel-input' );
|
568 |
}
|
|
|
569 |
?>
|
570 |
<div class="wrap">
|
571 |
-
<h1>
|
572 |
|
573 |
<form method="post" id="whatsappme_form" action="options.php">
|
574 |
-
<?php
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
|
|
|
|
|
|
|
|
|
|
579 |
</form>
|
580 |
</div>
|
581 |
<?php
|
@@ -594,13 +681,13 @@ class WhatsAppMe_Admin {
|
|
594 |
// Custom post types with public url
|
595 |
$custom_post_types = array_keys( get_post_types( array( 'has_archive' => true ), 'names' ) );
|
596 |
|
597 |
-
// Add/remove posts types for "
|
598 |
$post_types = apply_filters( 'whatsappme_post_types_meta_box', array_merge( $builtin_post_types, $custom_post_types ) );
|
599 |
|
600 |
foreach ( $post_types as $post_type ) {
|
601 |
add_meta_box(
|
602 |
'whatsappme',
|
603 |
-
__( '
|
604 |
array( $this, 'meta_box' ),
|
605 |
$post_type,
|
606 |
'side',
|
@@ -619,7 +706,7 @@ class WhatsAppMe_Admin {
|
|
619 |
* @return void
|
620 |
*/
|
621 |
public function meta_box( $post ) {
|
622 |
-
|
623 |
// Enqueue assets
|
624 |
wp_enqueue_script( 'whatsappme-admin' );
|
625 |
|
@@ -628,13 +715,15 @@ class WhatsAppMe_Admin {
|
|
628 |
}
|
629 |
|
630 |
$metadata = get_post_meta( $post->ID, '_whatsappme', true ) ?: array();
|
631 |
-
$metadata = array_merge(
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
|
|
|
|
638 |
|
639 |
// Move old 'hide' to new 'view' field
|
640 |
if ( $metadata['hide'] ) {
|
@@ -642,6 +731,8 @@ class WhatsAppMe_Admin {
|
|
642 |
}
|
643 |
unset( $metadata['hide'] );
|
644 |
|
|
|
|
|
645 |
wp_nonce_field( 'whatsappme_data', 'whatsappme_nonce' );
|
646 |
?>
|
647 |
<div class="whatsappme-metabox">
|
@@ -656,7 +747,9 @@ class WhatsAppMe_Admin {
|
|
656 |
<p>
|
657 |
<label for="whatsappme_message_send"><?php _e( 'Message', 'creame-whatsapp-me' ); ?></label><br>
|
658 |
<textarea name="whatsappme_message_send" rows="2" class="large-text"><?php echo $metadata['message_send']; ?></textarea>
|
659 |
-
|
|
|
|
|
660 |
</p>
|
661 |
<p>
|
662 |
<label><input type="radio" name="whatsappme_view" value="yes" <?php checked( 'yes', $metadata['view'] ); ?>>
|
@@ -668,7 +761,7 @@ class WhatsAppMe_Admin {
|
|
668 |
</p>
|
669 |
</div>
|
670 |
<style>
|
671 |
-
.whatsappme-metabox code { font-size:smaller; vertical-align:text-bottom; }
|
672 |
.whatsappme-metabox .dashicons { opacity:.5; }
|
673 |
.whatsappme-metabox input::placeholder { color:#dedfe0; }
|
674 |
.whatsappme-metabox input::-ms-input-placeholder { color:#dedfe0; }
|
@@ -681,7 +774,7 @@ class WhatsAppMe_Admin {
|
|
681 |
}
|
682 |
|
683 |
/**
|
684 |
-
* Save meta data from "
|
685 |
*
|
686 |
* @since 1.1.0
|
687 |
* @since 2.0.0 Change 'hide' key to 'view' now values can be [yes, no]
|
@@ -697,12 +790,16 @@ class WhatsAppMe_Admin {
|
|
697 |
}
|
698 |
|
699 |
// Clean and delete empty/false fields
|
700 |
-
$metadata = array_filter(
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
|
|
|
|
|
|
|
|
706 |
|
707 |
if ( count( $metadata ) ) {
|
708 |
update_post_meta( $post_id, '_whatsappme', $metadata );
|
@@ -715,13 +812,14 @@ class WhatsAppMe_Admin {
|
|
715 |
* Clean user input fields
|
716 |
*
|
717 |
* @since 2.0.0
|
718 |
-
* @
|
|
|
719 |
* @return mixed $value cleaned
|
720 |
*/
|
721 |
-
public function clean_input($value) {
|
722 |
if ( is_array( $value ) ) {
|
723 |
-
return array_map(
|
724 |
-
}
|
725 |
// Split lines, clean and re-join lines
|
726 |
return implode( "\n", array_map( 'sanitize_text_field', explode( "\n", trim( $value ) ) ) );
|
727 |
} else {
|
8 |
*
|
9 |
* @since 1.0.0
|
10 |
* @since 2.0.0 Added advanced visibility settings
|
11 |
+
* @since 3.0.0 More extendable admin via hooks
|
12 |
* @package WhatsAppMe
|
13 |
* @subpackage WhatsAppMe/admin
|
14 |
* @author Creame <hola@crea.me>
|
51 |
*/
|
52 |
private $enhanced_phone;
|
53 |
|
54 |
+
/**
|
55 |
+
* Admin page tabs
|
56 |
+
*
|
57 |
+
* @since 3.0.0
|
58 |
+
* @access private
|
59 |
+
* @var array $tabs Admin page tabs.
|
60 |
+
*/
|
61 |
+
private $tabs;
|
62 |
+
|
63 |
/**
|
64 |
* Initialize the class and set its properties.
|
65 |
*
|
66 |
* @since 1.0.0
|
67 |
+
* @since 3.0.0 Added $tabs initilization and removed get_settings()
|
68 |
+
* @param string $plugin_name The name of this plugin.
|
69 |
+
* @param string $version The version of this plugin.
|
70 |
*/
|
71 |
public function __construct( $plugin_name, $version ) {
|
72 |
|
73 |
+
$this->plugin_name = $plugin_name;
|
74 |
+
$this->version = $version;
|
75 |
+
|
76 |
+
// Updated in get_settings() at 'admin_init' hook
|
77 |
+
$this->enhanced_phone = '16.0.3'; // intl-tel-input version
|
78 |
+
$this->tabs = array();
|
79 |
+
$this->settings = array();
|
80 |
|
81 |
}
|
82 |
|
87 |
* @since 2.0.0 Added visibility setting
|
88 |
* @since 2.1.0 Added message_badge
|
89 |
* @since 2.3.0 Added button_delay and whatsapp_web settings, message_delay in seconds
|
90 |
+
* @since 3.0.0 Is public and added plugin enhanced_phone and tabs
|
91 |
*/
|
92 |
+
public function get_settings() {
|
93 |
+
|
94 |
+
// Use International Telephone Input library version or false to disable
|
95 |
+
$this->enhanced_phone = apply_filters( 'whatsappme_enhanced_phone', $this->enhanced_phone );
|
96 |
+
|
97 |
+
// Admin tabs
|
98 |
+
$this->tabs = apply_filters(
|
99 |
+
'whatsappme_admin_tabs', array(
|
100 |
+
'general' => __( 'General', 'creame-whatsapp-me' ),
|
101 |
+
'advanced' => __( 'Advanced', 'creame-whatsapp-me' ),
|
102 |
+
)
|
103 |
+
);
|
104 |
+
|
105 |
+
// Default settings
|
106 |
+
$default_settings = array_merge(
|
107 |
+
array(
|
108 |
+
'telephone' => '',
|
109 |
+
'mobile_only' => 'no',
|
110 |
+
'button_delay' => 3,
|
111 |
+
'whatsapp_web' => 'no',
|
112 |
+
'message_text' => '',
|
113 |
+
'message_delay' => 10,
|
114 |
+
'message_badge' => 'no',
|
115 |
+
'message_send' => '',
|
116 |
+
'position' => 'right',
|
117 |
+
'visibility' => array( 'all' => 'yes' ),
|
118 |
+
),
|
119 |
+
apply_filters( 'whatsappme_extra_settings', array() )
|
120 |
);
|
121 |
|
122 |
$saved_settings = get_option( 'whatsappme' );
|
123 |
|
124 |
if ( is_array( $saved_settings ) ) {
|
125 |
// clean unused saved settings
|
126 |
+
$saved_settings = array_intersect_key( $saved_settings, $default_settings );
|
127 |
// merge defaults with saved settings
|
128 |
+
$this->settings = array_merge( $default_settings, $saved_settings );
|
129 |
// miliseconds (<v2.3) to seconds
|
130 |
if ( $this->settings['message_delay'] > 120 ) {
|
131 |
$this->settings['message_delay'] = round( $this->settings['message_delay'] / 1000 );
|
132 |
}
|
133 |
+
} else {
|
134 |
+
$this->settings = $default_settings;
|
135 |
}
|
136 |
|
137 |
}
|
139 |
/**
|
140 |
* Register the stylesheets for the admin area.
|
141 |
*
|
142 |
+
* @since 3.0.0
|
143 |
+
* @param string $hook The id of the page.
|
|
|
|
|
|
|
144 |
* @return void
|
145 |
*/
|
146 |
+
public function register_styles( $hook ) {
|
147 |
|
148 |
$styles = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'whatsappme.css' : 'whatsappme.min.css';
|
149 |
wp_register_style( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'css/' . $styles, array(), $this->version, 'all' );
|
150 |
|
151 |
if ( $this->enhanced_phone ) {
|
152 |
+
wp_register_style( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/' . $this->enhanced_phone . '/css/intlTelInput.css', array(), null, 'all' );
|
153 |
}
|
154 |
|
155 |
}
|
157 |
/**
|
158 |
* Register the JavaScript for the admin area.
|
159 |
*
|
160 |
+
* @since 3.0.0
|
161 |
+
* @param string $hook The id of the page.
|
|
|
|
|
162 |
* @return void
|
163 |
*/
|
164 |
+
public function register_scripts( $hook ) {
|
165 |
|
166 |
$script = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'whatsappme.js' : 'whatsappme.min.js';
|
167 |
|
168 |
if ( $this->enhanced_phone ) {
|
169 |
+
wp_register_script( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/' . $this->enhanced_phone . '/js/intlTelInput.min.js', array(), null, true );
|
170 |
wp_register_script( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'js/' . $script, array( 'jquery', 'intl-tel-input' ), $this->version, true );
|
171 |
+
wp_localize_script( 'intl-tel-input', 'intl_tel_input_version', $this->enhanced_phone );
|
172 |
} else {
|
173 |
wp_register_script( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'js/' . $script, array( 'jquery' ), $this->version, true );
|
174 |
}
|
176 |
}
|
177 |
|
178 |
/**
|
179 |
+
* Initialize the settings for WordPress admin
|
180 |
* From v1.2.0 also set filter to disable enhanced phone input
|
181 |
*
|
182 |
* @since 1.0.0
|
183 |
* @since 2.0.0 Added tabs for general and Advanced settings
|
184 |
* @since 2.3.0 Split general settings in Button and Window Chat
|
185 |
+
* @since 3.0.0 Admin organized by tabs and sections
|
186 |
* @access public
|
187 |
* @return void
|
188 |
*/
|
189 |
+
public function settings_init() {
|
190 |
|
191 |
+
// Register WordPress 'whatsappme' settings
|
192 |
register_setting( 'whatsappme', 'whatsappme', array( $this, 'settings_validate' ) );
|
193 |
|
194 |
+
foreach ( $this->tabs as $tab => $tab_name ) {
|
|
|
|
|
195 |
|
196 |
+
add_settings_section( "whatsappme_tab_{$tab}_open", null, array( $this, 'settings_tab_open' ), 'whatsappme' );
|
197 |
|
198 |
+
$sections = $this->get_tab_sections( $tab );
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
+
foreach ( $sections as $section => $fields ) {
|
201 |
+
$section_id = "whatsappme_tab_{$tab}__{$section}";
|
202 |
|
203 |
+
add_settings_section( $section_id, null, array( $this, 'section_output' ), 'whatsappme' );
|
|
|
|
|
204 |
|
205 |
+
foreach ( $fields as $field => $field_args ) {
|
206 |
+
if ( is_array( $field_args ) ) {
|
207 |
+
$field_name = $field_args['label'];
|
208 |
+
$field_callback = $field_args['callback'];
|
209 |
+
} else {
|
210 |
+
$field_name = $field_args;
|
211 |
+
$field_callback = array( $this, 'field_output' );
|
212 |
+
}
|
213 |
|
214 |
+
add_settings_field( "whatsappme_$field", $field_name, $field_callback, 'whatsappme', $section_id, $field );
|
215 |
+
}
|
216 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
+
add_settings_section( "whatsappme_tab_{$tab}_close", null, array( $this, 'settings_tab_close' ), 'whatsappme' );
|
|
|
219 |
}
|
220 |
|
221 |
+
}
|
|
|
|
|
|
|
|
|
222 |
|
223 |
+
/**
|
224 |
+
* Return an array of sections and fields for the admin tab
|
225 |
+
*
|
226 |
+
* @since 3.0.0
|
227 |
+
* @param string $tab The id of the admin tab.
|
228 |
+
* @return array
|
229 |
+
*/
|
230 |
+
private function get_tab_sections( $tab ) {
|
231 |
+
|
232 |
+
if ( 'general' == $tab ) {
|
233 |
+
|
234 |
+
$sections = array(
|
235 |
+
'button' => array(
|
236 |
+
'telephone' => '<label for="whatsappme_phone">' . __( 'Telephone', 'creame-whatsapp-me' ) . '</label>',
|
237 |
+
'mobile_only' => __( 'Mobile Only', 'creame-whatsapp-me' ),
|
238 |
+
'position' => __( 'Position On Screen', 'creame-whatsapp-me' ),
|
239 |
+
'button_delay' => '<label for="whatsappme_button_delay">' . __( 'Button Delay', 'creame-whatsapp-me' ) . '</label>',
|
240 |
+
'whatsapp_web' => __( 'WhatsApp Web', 'creame-whatsapp-me' ),
|
241 |
+
),
|
242 |
+
'chat' => array(
|
243 |
+
'message_text' => '<label for="whatsappme_message_text">' . __( 'Call To Action', 'creame-whatsapp-me' ) . '</label>',
|
244 |
+
'message_send' => '<label for="whatsappme_message_send">' . __( 'Message', 'creame-whatsapp-me' ) . '</label>',
|
245 |
+
'message_delay' => '<label for="whatsappme_message_delay">' . __( 'Chat Delay', 'creame-whatsapp-me' ) . '</label>',
|
246 |
+
'message_badge' => __( 'Hide Chat', 'creame-whatsapp-me' ),
|
247 |
+
),
|
248 |
+
);
|
249 |
|
250 |
+
} elseif ( 'advanced' == $tab ) {
|
251 |
+
|
252 |
+
$sections = array(
|
253 |
+
'global' => array(
|
254 |
+
'view__all' => array(
|
255 |
+
'label' => __( 'Global', 'creame-whatsapp-me' ),
|
256 |
+
'callback' => array( $this, 'field_view_all' ),
|
257 |
+
),
|
258 |
+
),
|
259 |
+
'wp' => array(
|
260 |
+
'view__front_page' => __( 'Front Page', 'creame-whatsapp-me' ),
|
261 |
+
'view__blog_page' => __( 'Blog Page', 'creame-whatsapp-me' ),
|
262 |
+
'view__404_page' => __( '404 Page', 'creame-whatsapp-me' ),
|
263 |
+
'view__search' => __( 'Search Results', 'creame-whatsapp-me' ),
|
264 |
+
'view__archive' => __( 'Archives', 'creame-whatsapp-me' ),
|
265 |
+
'view__date' => '— ' . __( 'Date Archives', 'creame-whatsapp-me' ),
|
266 |
+
'view__author' => '— ' . __( 'Author Archives', 'creame-whatsapp-me' ),
|
267 |
+
'view__singular' => __( 'Singular', 'creame-whatsapp-me' ),
|
268 |
+
'view__page' => '— ' . __( 'Page', 'creame-whatsapp-me' ),
|
269 |
+
'view__post' => '— ' . __( 'Post', 'creame-whatsapp-me' ),
|
270 |
+
),
|
271 |
);
|
272 |
|
273 |
+
// If isn't set Blog Page or is the same than Front Page unset blog_page option
|
274 |
+
if ( get_option( 'show_on_front' ) == 'posts' || get_option( 'page_for_posts' ) == 0 ) {
|
275 |
+
unset( $sections['wp']['view__blog_page'] );
|
276 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
|
278 |
+
// Custom Post Types
|
279 |
+
$custom_post_types = apply_filters(
|
280 |
+
'whatsappme_custom_post_types',
|
281 |
+
array_keys( get_post_types( array( 'has_archive' => true ), 'names' ) )
|
282 |
+
);
|
283 |
|
284 |
+
if ( count( $custom_post_types ) ) {
|
285 |
+
$sections['cpt'] = array();
|
286 |
|
287 |
+
foreach ( $custom_post_types as $custom_post_type ) {
|
288 |
+
$post_type = get_post_type_object( $custom_post_type );
|
289 |
+
$post_type_name = function_exists( 'mb_convert_case' ) ?
|
290 |
+
mb_convert_case( $post_type->labels->name, MB_CASE_TITLE ) :
|
291 |
+
strtolower( $post_type->labels->name );
|
292 |
|
293 |
+
$sections['cpt'][ "view__cpt_$custom_post_type" ] = $post_type_name;
|
294 |
+
}
|
295 |
+
}
|
296 |
+
} else {
|
297 |
|
298 |
+
$sections = array();
|
|
|
|
|
|
|
299 |
|
|
|
|
|
300 |
}
|
301 |
|
302 |
+
// Filter tab sections to add, remove or edit sections or fields
|
303 |
+
return apply_filters( "whatsappme_tab_{$tab}_sections", $sections );
|
304 |
|
|
|
305 |
}
|
306 |
|
307 |
/**
|
311 |
* @since 2.0.0 Added visibility setting
|
312 |
* @since 2.1.0 Added message_badge
|
313 |
* @since 2.3.0 Added button_delay and whatsapp_web settings, WPML integration
|
314 |
+
* @since 3.0.0 Added filter for extra settings and action for extra tasks
|
315 |
+
* @param array $input contain keys 'id', 'title' and 'callback'.
|
316 |
* @return array
|
317 |
*/
|
318 |
+
public function settings_validate( $input ) {
|
319 |
|
320 |
+
$input['telephone'] = self::clean_input( $input['telephone'] );
|
321 |
$input['mobile_only'] = isset( $input['mobile_only'] ) ? 'yes' : 'no';
|
322 |
$input['button_delay'] = intval( $input['button_delay'] );
|
323 |
$input['whatsapp_web'] = isset( $input['whatsapp_web'] ) ? 'yes' : 'no';
|
324 |
+
$input['message_text'] = self::clean_input( $input['message_text'] );
|
325 |
$input['message_delay'] = intval( $input['message_delay'] );
|
326 |
$input['message_badge'] = isset( $input['message_badge'] ) ? 'yes' : 'no';
|
327 |
+
$input['message_send'] = self::clean_input( $input['message_send'] );
|
328 |
$input['position'] = $input['position'] != 'left' ? 'right' : 'left';
|
329 |
if ( isset( $input['view'] ) ) {
|
330 |
+
$input['visibility'] = array_filter(
|
331 |
+
$input['view'], function( $v ) {
|
332 |
+
return 'yes' == $v || 'no' == $v;
|
333 |
+
}
|
334 |
+
);
|
335 |
unset( $input['view'] );
|
336 |
}
|
337 |
|
338 |
+
// Filter for other validations or extra settings
|
339 |
+
$input = apply_filters( 'whatsappme_settings_validate', $input );
|
340 |
+
|
341 |
/**
|
342 |
* Register WPML/Polylang strings for translation
|
343 |
* https://wpml.org/wpml-hook/wpml_register_single_string/
|
348 |
do_action( 'wpml_register_single_string', 'WhatsApp me', 'Call To Action', $input['message_text'] );
|
349 |
do_action( 'wpml_register_single_string', 'WhatsApp me', 'Message', $input['message_send'] );
|
350 |
|
351 |
+
// Action to register more WPML strings or other tasks
|
352 |
+
do_action( 'whatsappme_settings_validate', $input );
|
353 |
+
|
354 |
add_settings_error( 'whatsappme', 'settings_updated', __( 'Settings saved', 'creame-whatsapp-me' ), 'updated' );
|
355 |
|
356 |
return $input;
|
357 |
}
|
358 |
|
359 |
+
/**
|
360 |
+
* Tab open HTML output
|
361 |
+
*
|
362 |
+
* @since 3.0.0
|
363 |
+
* @param array $args Section info.
|
364 |
+
* @return void
|
365 |
+
*/
|
366 |
+
public function settings_tab_open( $args ) {
|
367 |
+
|
368 |
+
$tab_id = str_replace( '_open', '', $args['id'] );
|
369 |
+
|
370 |
+
echo '<div id="' . $tab_id . '" class="tab' . ( 'whatsappme_tab_general' == $tab_id ? ' tab-active' : '' ) . '">';
|
371 |
+
|
372 |
+
}
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Tab close HTML output
|
376 |
+
*
|
377 |
+
* @since 3.0.0
|
378 |
+
* @param array $args Section info.
|
379 |
+
* @return void
|
380 |
+
*/
|
381 |
+
public function settings_tab_close( $args ) {
|
382 |
+
|
383 |
+
echo '</div>';
|
384 |
+
|
385 |
+
}
|
386 |
+
|
387 |
/**
|
388 |
* Section HTML output
|
389 |
*
|
390 |
+
* @since 3.0.0
|
391 |
+
* @param array $args Section info.
|
|
|
392 |
* @return void
|
393 |
*/
|
394 |
+
public function section_output( $args ) {
|
395 |
+
$section_id = $args['id'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
|
397 |
+
switch ( $section_id ) {
|
398 |
+
case 'whatsappme_tab_general__button':
|
399 |
+
$output = '<h2 class="title">' . __( 'Button', 'creame-whatsapp-me' ) . '</h2>' .
|
400 |
'<p>' . __( 'Set the contact number and where you want the WhatsApp button to be displayed.', 'creame-whatsapp-me' ) . '</p>';
|
401 |
break;
|
402 |
|
403 |
+
case 'whatsappme_tab_general__chat':
|
404 |
+
$output = '<h2 class="title">' . __( 'Chat Window', 'creame-whatsapp-me' ) . '</h2>' .
|
405 |
'<p>' .
|
406 |
__( 'Set the behavior of the chat window.', 'creame-whatsapp-me' ) . ' ' .
|
407 |
+
' <em>' . __( 'You can use styles and dynamic variables', 'creame-whatsapp-me' ) . '</em> ' .
|
408 |
+
'<a class="whatsappme-show-help" href="#" title="' . __( 'Show Help', 'creame-whatsapp-me' ) . '">?</a>' .
|
409 |
'</p>';
|
410 |
break;
|
411 |
|
412 |
+
case 'whatsappme_tab_advanced__global':
|
413 |
+
$output = '<h2 class="title">' . __( 'Advanced Visibility Settings', 'creame-whatsapp-me' ) . '</h2>' .
|
|
|
414 |
'<p>' . __( 'From here you can configure on which pages the WhatsApp button will be visible.', 'creame-whatsapp-me' ) .
|
415 |
' <a href="#" class="whatsappme_view_reset">' . __( 'Restore default visibility', 'creame-whatsapp-me' ) . '</a></p>';
|
416 |
break;
|
417 |
|
418 |
+
case 'whatsappme_tab_advanced__wp':
|
419 |
+
$output = '<hr>';
|
420 |
break;
|
421 |
|
422 |
+
case 'whatsappme_tab_advanced__cpt':
|
423 |
+
$output = '<h2 class="title">' . __( 'Custom Post Types', 'creame-whatsapp-me' ) . '</h2>';
|
424 |
break;
|
425 |
|
426 |
default:
|
427 |
+
$output = '';
|
428 |
break;
|
429 |
}
|
|
|
430 |
|
431 |
+
// Filter section opening ouput
|
432 |
+
echo apply_filters( 'whatsappme_section_output', $output, $section_id );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
}
|
434 |
|
435 |
/**
|
436 |
+
* Field HTML output
|
437 |
*
|
438 |
+
* @since 3.0.0
|
439 |
* @return void
|
440 |
*/
|
441 |
+
public function field_output( $field_id ) {
|
|
|
|
|
|
|
442 |
|
443 |
+
if ( strpos( $field_id, 'view__' ) === 0 ) {
|
444 |
+
$field = substr( $field_id, 6 );
|
445 |
+
$value = isset( $this->settings['visibility'][ $field ] ) ? $this->settings['visibility'][ $field ] : '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
|
447 |
+
$output = '<label><input type="radio" name="whatsappme[view][' . $field . ']" value="yes"' . checked( 'yes', $value, false ) . '> ' .
|
448 |
+
'<span class="dashicons dashicons-visibility" title="' . __( 'Show', 'creame-whatsapp-me' ) . '"></span></label>' .
|
449 |
+
'<label><input type="radio" name="whatsappme[view][' . $field . ']" value="no"' . checked( 'no', $value, false ) . '> ' .
|
450 |
+
'<span class="dashicons dashicons-hidden" title="' . __( 'Hide', 'creame-whatsapp-me' ) . '"></span></label>' .
|
451 |
+
'<label><input type="radio" name="whatsappme[view][' . $field . ']" value=""' . checked( '', $value, false ) . '> ' .
|
452 |
+
__( 'Inherit', 'creame-whatsapp-me' ) . ' <span class="dashicons dashicons-visibility view_inheritance_' . $field . '"></span></label>';
|
|
|
|
|
|
|
|
|
|
|
453 |
|
454 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
455 |
|
456 |
+
$value = isset( $this->settings[ $field_id ] ) ? $this->settings[ $field_id ] : '';
|
457 |
+
|
458 |
+
switch ( $field_id ) {
|
459 |
+
case 'telephone':
|
460 |
+
$output = '<input id="whatsappme_phone" ' . ( $this->enhanced_phone ? 'data-' : '' ) . 'name="whatsappme[telephone]" value="' . $value . '" type="text" style="width:15em">' .
|
461 |
+
'<p class="description">' . __( "Contact phone number <strong>(the button will not be shown if it's empty)</strong>", 'creame-whatsapp-me' ) . '</p>' .
|
462 |
+
'<p class="whatsappme-addon">' . sprintf(
|
463 |
+
__( 'Add unlimited numbers with %s', 'creame-whatsapp-me' ),
|
464 |
+
'<a href="https://wame.chat/en/addons/random-phone-addon/" target="_blank">\'WAme Random Phone\'</a>'
|
465 |
+
) . '</p>';
|
466 |
+
break;
|
467 |
+
|
468 |
+
case 'mobile_only':
|
469 |
+
$output = '<fieldset><legend class="screen-reader-text"><span>' . __( 'Mobile Only', 'creame-whatsapp-me' ) . '</span></legend>' .
|
470 |
+
'<label><input id="whatsappme_mobile_only" name="whatsappme[mobile_only]" value="yes" type="checkbox"' . checked( 'yes', $value, false ) . '> ' .
|
471 |
+
__( 'Only display the button on mobile devices', 'creame-whatsapp-me' ) . '</label></fieldset>';
|
472 |
+
break;
|
473 |
+
|
474 |
+
case 'position':
|
475 |
+
$output = '<fieldset><legend class="screen-reader-text"><span>' . __( 'Position On Screen', 'creame-whatsapp-me' ) . '</span></legend>' .
|
476 |
+
'<label><input name="whatsappme[position]" value="left" type="radio"' . checked( 'left', $value, false ) . '> ' .
|
477 |
+
__( 'Left', 'creame-whatsapp-me' ) . '</label><br>' .
|
478 |
+
'<label><input name="whatsappme[position]" value="right" type="radio"' . checked( 'right', $value, false ) . '> ' .
|
479 |
+
__( 'Right', 'creame-whatsapp-me' ) . '</label></fieldset>';
|
480 |
+
break;
|
481 |
+
|
482 |
+
case 'button_delay':
|
483 |
+
$output = '<input id="whatsappme_button_delay" name="whatsappme[button_delay]" value="' . $value . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds', 'creame-whatsapp-me' ) .
|
484 |
+
'<p class="description">' . __( 'Time since the page is opened until the WhatsApp button is displayed', 'creame-whatsapp-me' ) . '</p>';
|
485 |
+
break;
|
486 |
+
|
487 |
+
case 'whatsapp_web':
|
488 |
+
$output = '<fieldset><legend class="screen-reader-text"><span>' . __( 'WhatsApp Web', 'creame-whatsapp-me' ) . '</span></legend>' .
|
489 |
+
'<label><input id="whatsappme_whatsapp_web" name="whatsappme[whatsapp_web]" value="yes" type="checkbox"' . checked( 'yes', $value, false ) . '> ' .
|
490 |
+
__( 'Open <em>WhatsApp Web</em> directly on desktop', 'creame-whatsapp-me' ) . '</label></fieldset>';
|
491 |
+
break;
|
492 |
+
|
493 |
+
case 'message_text':
|
494 |
+
$output = '<textarea id="whatsappme_message_text" name="whatsappme[message_text]" rows="4" class="regular-text" placeholder="' . esc_attr__( "Hello 👋\nCan we help you?", 'creame-whatsapp-me' ) . '">' . $value . '</textarea>' .
|
495 |
+
'<p class="description">' . __( 'Define a text to encourage users to contact by WhatsApp <strong>(optional)</strong>', 'creame-whatsapp-me' ) . '</p>';
|
496 |
+
break;
|
497 |
+
|
498 |
+
case 'message_send':
|
499 |
+
$output = '<textarea id="whatsappme_message_send" name="whatsappme[message_send]" rows="3" class="regular-text" placeholder="' . esc_attr__( 'Hi *{SITE}*! I need more info about {TITLE}', 'creame-whatsapp-me' ) . '">' . $value . '</textarea>' .
|
500 |
+
'<p class="description">' . __( 'Predefined text with which user can start the conversation <strong>(optional)</strong>', 'creame-whatsapp-me' ) . '</p>';
|
501 |
+
break;
|
502 |
+
|
503 |
+
case 'message_delay':
|
504 |
+
$output = '<input id="whatsappme_message_delay" name="whatsappme[message_delay]" value="' . $value . '" type="number" min="0" max="120" style="width:5em"> ' . __( 'seconds', 'creame-whatsapp-me' ) .
|
505 |
+
'<p class="description">' . __( 'Time since the WhatsApp button is displayed until the Chat Window opens', 'creame-whatsapp-me' ) . '</p>';
|
506 |
+
break;
|
507 |
+
|
508 |
+
case 'message_badge':
|
509 |
+
$output = '<fieldset><legend class="screen-reader-text"><span>' . __( 'Hide Chat', 'creame-whatsapp-me' ) . '</span></legend>' .
|
510 |
+
'<label><input name="whatsappme[message_badge]" value="yes" type="checkbox"' . checked( 'yes', $value, false ) . '> ' .
|
511 |
+
__( 'Display a notification balloon instead of opening the Chat Window for a "less intrusive" mode', 'creame-whatsapp-me' ) . '</label></fieldset>';
|
512 |
+
break;
|
513 |
+
|
514 |
+
default:
|
515 |
+
$output = '';
|
516 |
+
break;
|
517 |
+
}
|
518 |
+
}
|
519 |
|
520 |
+
// Filter field ouput
|
521 |
+
echo apply_filters( 'whatsappme_field_output', $output, $field_id, $this->settings );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
}
|
523 |
|
524 |
/**
|
525 |
* Field 'field_view_all' output
|
526 |
*
|
527 |
* @since 2.0.0
|
528 |
+
* @since 3.0.0 Added $inheritance data
|
529 |
* @return void
|
530 |
*/
|
531 |
public function field_view_all() {
|
532 |
+
$value = ( isset( $this->settings['visibility']['all'] ) && 'no' == $this->settings['visibility']['all'] ) ? 'no' : 'yes';
|
533 |
+
|
534 |
+
$inheritance = apply_filters(
|
535 |
+
'whatsappme_advanced_inheritance', array(
|
536 |
+
'all' => array( 'front_page', 'blog_page', '404_page', 'search', 'archive', 'singular', 'cpts' ),
|
537 |
+
'archive' => array( 'date', 'author' ),
|
538 |
+
'singular' => array( 'page', 'post' ),
|
539 |
+
// 'woocommerce': ['product', 'cart', 'checkout', 'account_page']
|
540 |
+
)
|
541 |
+
);
|
542 |
|
543 |
+
echo '<div class="whatsappme_view_all" data-inheritance="' . esc_attr( json_encode( $inheritance ) ) . '">' .
|
544 |
+
'<label><input type="radio" name="whatsappme[view][all]" value="yes"' . checked( 'yes', $value, false ) . '> ' .
|
545 |
'<span class="dashicons dashicons-visibility" title="' . __( 'Show', 'creame-whatsapp-me' ) . '"></span></label>' .
|
546 |
+
'<label><input type="radio" name="whatsappme[view][all]" value="no"' . checked( 'no', $value, false ) . '> ' .
|
547 |
+
'<span class="dashicons dashicons-hidden" title="' . __( 'Hide', 'creame-whatsapp-me' ) . '"></span></label></div>';
|
548 |
}
|
549 |
|
550 |
/**
|
551 |
+
* Add menu to the options page in the WordPress admin
|
552 |
*
|
553 |
+
* @since 1.0.0
|
554 |
+
* @access public
|
555 |
* @return void
|
556 |
*/
|
557 |
+
public function add_menu() {
|
558 |
+
|
559 |
+
add_options_page( 'WAme chat', 'WAme chat', 'manage_options', 'whatsappme', array( $this, 'options_page' ) );
|
560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
561 |
}
|
562 |
|
563 |
/**
|
564 |
+
* Add a help tab to the options page in the WordPress admin
|
565 |
*
|
566 |
+
* @since 3.0.0
|
567 |
* @access public
|
568 |
* @return void
|
569 |
*/
|
570 |
+
function help_tab() {
|
571 |
+
$screen = get_current_screen();
|
572 |
+
|
573 |
+
$screen->add_help_tab(
|
574 |
+
array(
|
575 |
+
'id' => 'styles-and-vars',
|
576 |
+
'title' => __( 'Styles and Variables', 'creame-whatsapp-me' ),
|
577 |
+
'content' => apply_filters(
|
578 |
+
'whatsappme_styles_and_vars_help',
|
579 |
+
'<p>' . __( 'You can use formatting styles like in WhatsApp: _<em>italic</em>_ *<strong>bold</strong>* ~<del>strikethrough</del>~.', 'creame-whatsapp-me' ) . '</p>' .
|
580 |
+
'<p>' . __( 'You can use dynamic variables that will be replaced by the values of the page the user visits:', 'creame-whatsapp-me' ) .
|
581 |
+
'<p>' .
|
582 |
+
'<span><code>{SITE}</code> ➜ ' . get_bloginfo( 'name', 'display' ) . '</span>, ' .
|
583 |
+
'<span><code>{URL}</code> ➜ ' . home_url( 'example' ) . '</span>, ' .
|
584 |
+
'<span><code>{TITLE}</code> ➜ ' . __( 'Page Title', 'creame-whatsapp-me' ) . '</span>' .
|
585 |
+
'</p>'
|
586 |
+
),
|
587 |
+
)
|
588 |
+
);
|
589 |
|
590 |
+
$screen->add_help_tab(
|
591 |
+
array(
|
592 |
+
'id' => 'support',
|
593 |
+
'title' => __( 'Support and Help', 'creame-whatsapp-me' ),
|
594 |
+
'content' =>
|
595 |
+
'<p>' . sprintf(
|
596 |
+
__( 'If you need help, please check the <a href="%s" rel="external" target="_blank">plugin support forum</a>.', 'creame-whatsapp-me' ),
|
597 |
+
esc_url( 'https://wordpress.org/support/plugin/creame-whatsapp-me/' )
|
598 |
+
) . '</p>' .
|
599 |
+
'<p>' . __( 'If you like WAme 😍', 'creame-whatsapp-me' ) . '</p>' .
|
600 |
+
'<ul>' .
|
601 |
+
'<li>' . sprintf(
|
602 |
+
__( 'Subscribe to our newsletter and our blog at %s.', 'creame-whatsapp-me' ),
|
603 |
+
'<a href="https://wame.chat/blog/" rel="external" target="_blank">wame.chat</a>'
|
604 |
+
) . '</li>' .
|
605 |
+
'<li>' . sprintf(
|
606 |
+
__( 'Learn from our tutorials on %s.', 'creame-whatsapp-me' ),
|
607 |
+
'<a href="https://www.youtube.com/channel/UCqHiSNPBaQ918fpVnCU1wog/" rel="external" target="_blank">Youtube</a>'
|
608 |
+
) . '</li>' .
|
609 |
+
'<li>' . sprintf(
|
610 |
+
__( 'Or rate us on %s.', 'creame-whatsapp-me' ),
|
611 |
+
'<a href="https://wordpress.org/support/plugin/creame-whatsapp-me/reviews/#new-post" rel="external" target="_blank">WordPress.org</a>'
|
612 |
+
) . '</li>' .
|
613 |
+
'</ul>',
|
614 |
+
)
|
615 |
+
);
|
616 |
}
|
617 |
|
618 |
/**
|
631 |
}
|
632 |
|
633 |
/**
|
634 |
+
* Generate the options page in the WordPress admin
|
635 |
*
|
636 |
* @since 1.0.0
|
637 |
* @since 2.2.0 Enqueue scripts/styles
|
647 |
if ( $this->enhanced_phone ) {
|
648 |
wp_enqueue_style( 'intl-tel-input' );
|
649 |
}
|
650 |
+
|
651 |
?>
|
652 |
<div class="wrap">
|
653 |
+
<h1>WAme chat</h1>
|
654 |
|
655 |
<form method="post" id="whatsappme_form" action="options.php">
|
656 |
+
<?php settings_fields( 'whatsappme' ); ?>
|
657 |
+
<h2 class="nav-tab-wrapper wp-clearfix">
|
658 |
+
<?php foreach ( $this->tabs as $tab => $name ) : ?>
|
659 |
+
<a href="#whatsappme_tab_<?php echo $tab; ?>" class="nav-tab <?php echo 'general' == $tab ? 'nav-tab-active' : ''; ?>"><?php echo $name; ?></a>
|
660 |
+
<?php endforeach; ?>
|
661 |
+
</h2>
|
662 |
+
<div class="tabs">
|
663 |
+
<?php do_settings_sections( 'whatsappme' ); ?>
|
664 |
+
</div><!-- end tabs -->
|
665 |
+
<?php submit_button(); ?>
|
666 |
</form>
|
667 |
</div>
|
668 |
<?php
|
681 |
// Custom post types with public url
|
682 |
$custom_post_types = array_keys( get_post_types( array( 'has_archive' => true ), 'names' ) );
|
683 |
|
684 |
+
// Add/remove posts types for "WAme chat" meta box
|
685 |
$post_types = apply_filters( 'whatsappme_post_types_meta_box', array_merge( $builtin_post_types, $custom_post_types ) );
|
686 |
|
687 |
foreach ( $post_types as $post_type ) {
|
688 |
add_meta_box(
|
689 |
'whatsappme',
|
690 |
+
__( 'WAme chat', 'creame-whatsapp-me' ),
|
691 |
array( $this, 'meta_box' ),
|
692 |
$post_type,
|
693 |
'side',
|
706 |
* @return void
|
707 |
*/
|
708 |
public function meta_box( $post ) {
|
709 |
+
// TODO: add hooks for more extendable metabox
|
710 |
// Enqueue assets
|
711 |
wp_enqueue_script( 'whatsappme-admin' );
|
712 |
|
715 |
}
|
716 |
|
717 |
$metadata = get_post_meta( $post->ID, '_whatsappme', true ) ?: array();
|
718 |
+
$metadata = array_merge(
|
719 |
+
array(
|
720 |
+
'telephone' => '',
|
721 |
+
'message_text' => '',
|
722 |
+
'message_send' => '',
|
723 |
+
'hide' => false,
|
724 |
+
'view' => '',
|
725 |
+
), $metadata
|
726 |
+
);
|
727 |
|
728 |
// Move old 'hide' to new 'view' field
|
729 |
if ( $metadata['hide'] ) {
|
731 |
}
|
732 |
unset( $metadata['hide'] );
|
733 |
|
734 |
+
$metabox_vars = apply_filters( 'whatsappme_metabox_vars', array( 'SITE', 'URL', 'TITLE' ) );
|
735 |
+
|
736 |
wp_nonce_field( 'whatsappme_data', 'whatsappme_nonce' );
|
737 |
?>
|
738 |
<div class="whatsappme-metabox">
|
747 |
<p>
|
748 |
<label for="whatsappme_message_send"><?php _e( 'Message', 'creame-whatsapp-me' ); ?></label><br>
|
749 |
<textarea name="whatsappme_message_send" rows="2" class="large-text"><?php echo $metadata['message_send']; ?></textarea>
|
750 |
+
<?php if ( count( $metabox_vars ) ) : ?>
|
751 |
+
<small><?php _e( 'You can use vars:', 'creame-whatsapp-me' ); ?> <code>{<?php echo join( '}</code> <code>{', $metabox_vars ); ?>}</code></small>
|
752 |
+
<?php endif; ?>
|
753 |
</p>
|
754 |
<p>
|
755 |
<label><input type="radio" name="whatsappme_view" value="yes" <?php checked( 'yes', $metadata['view'] ); ?>>
|
761 |
</p>
|
762 |
</div>
|
763 |
<style>
|
764 |
+
.whatsappme-metabox code { -webkit-user-select:all; -moz-user-select:all; -ms-user-select:all; user-select:all; padding:2px 1px; font-size:smaller; vertical-align:text-bottom; }
|
765 |
.whatsappme-metabox .dashicons { opacity:.5; }
|
766 |
.whatsappme-metabox input::placeholder { color:#dedfe0; }
|
767 |
.whatsappme-metabox input::-ms-input-placeholder { color:#dedfe0; }
|
774 |
}
|
775 |
|
776 |
/**
|
777 |
+
* Save meta data from "WAme chat" Meta Box on post save
|
778 |
*
|
779 |
* @since 1.1.0
|
780 |
* @since 2.0.0 Change 'hide' key to 'view' now values can be [yes, no]
|
790 |
}
|
791 |
|
792 |
// Clean and delete empty/false fields
|
793 |
+
$metadata = array_filter(
|
794 |
+
self::clean_input(
|
795 |
+
array(
|
796 |
+
'telephone' => $_POST['whatsappme_telephone'],
|
797 |
+
'message_text' => $_POST['whatsappme_message'],
|
798 |
+
'message_send' => $_POST['whatsappme_message_send'],
|
799 |
+
'view' => $_POST['whatsappme_view'],
|
800 |
+
)
|
801 |
+
)
|
802 |
+
);
|
803 |
|
804 |
if ( count( $metadata ) ) {
|
805 |
update_post_meta( $post_id, '_whatsappme', $metadata );
|
812 |
* Clean user input fields
|
813 |
*
|
814 |
* @since 2.0.0
|
815 |
+
* @access public
|
816 |
+
* @param mixed $value to clean
|
817 |
* @return mixed $value cleaned
|
818 |
*/
|
819 |
+
public static function clean_input( $value ) {
|
820 |
if ( is_array( $value ) ) {
|
821 |
+
return array_map( 'self::clean_input', $value );
|
822 |
+
} elseif ( is_string( $value ) ) {
|
823 |
// Split lines, clean and re-join lines
|
824 |
return implode( "\n", array_map( 'sanitize_text_field', explode( "\n", trim( $value ) ) ) );
|
825 |
} else {
|
admin/class-whatsappme-wooadmin.php
ADDED
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The admin-specific functionality of the WooCommerce integration.
|
5 |
+
*
|
6 |
+
* @since 3.0.0
|
7 |
+
* @package WhatsAppMe
|
8 |
+
* @subpackage WhatsAppMe/admin
|
9 |
+
* @author Creame <hola@crea.me>
|
10 |
+
*/
|
11 |
+
class WhatsAppMe_WooAdmin {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Initialize all hooks
|
15 |
+
*
|
16 |
+
* @since 3.0.0
|
17 |
+
* @param array $whatsappme WhatsAppMe object.
|
18 |
+
* @return void
|
19 |
+
*/
|
20 |
+
public function init( $whatsappme ) {
|
21 |
+
|
22 |
+
$loader = $whatsappme->get_loader();
|
23 |
+
|
24 |
+
$loader->add_filter( 'whatsappme_extra_settings', $this, 'extra_settings' );
|
25 |
+
$loader->add_filter( 'whatsappme_settings_validate', $this, 'settings_validate' );
|
26 |
+
$loader->add_filter( 'whatsappme_admin_tabs', $this, 'admin_tab' );
|
27 |
+
$loader->add_filter( 'whatsappme_custom_post_types', $this, 'custom_post_types' );
|
28 |
+
$loader->add_filter( 'whatsappme_tab_advanced_sections', $this, 'advanced_tab_section' );
|
29 |
+
$loader->add_filter( 'whatsappme_tab_woocommerce_sections', $this, 'woo_tab_sections' );
|
30 |
+
$loader->add_filter( 'whatsappme_section_output', $this, 'section_ouput', 10, 2 );
|
31 |
+
$loader->add_filter( 'whatsappme_field_output', $this, 'field_ouput', 10, 3 );
|
32 |
+
$loader->add_filter( 'whatsappme_advanced_inheritance', $this, 'advanced_inheritance' );
|
33 |
+
$loader->add_filter( 'whatsappme_styles_and_vars_help', $this, 'help_vars' );
|
34 |
+
$loader->add_filter( 'whatsappme_metabox_vars', $this, 'metabox_vars' );
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Add WooCommerce extra settings defaults
|
39 |
+
*
|
40 |
+
* @since 3.0.0
|
41 |
+
* @param array $settings current settings.
|
42 |
+
* @return array
|
43 |
+
*/
|
44 |
+
public function extra_settings( $settings ) {
|
45 |
+
|
46 |
+
$woo_settings = array(
|
47 |
+
'message_text_product' => '',
|
48 |
+
'message_send_product' => '',
|
49 |
+
);
|
50 |
+
|
51 |
+
return array_merge( $settings, $woo_settings );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* WooCommerce settings validation
|
56 |
+
*
|
57 |
+
* @since 3.0.0
|
58 |
+
* @param array $input form input.
|
59 |
+
* @return array
|
60 |
+
*/
|
61 |
+
public function settings_validate( $input ) {
|
62 |
+
|
63 |
+
$input['message_text_product'] = WhatsAppMe_Admin::clean_input( $input['message_text_product'] );
|
64 |
+
$input['message_send_product'] = WhatsAppMe_Admin::clean_input( $input['message_send_product'] );
|
65 |
+
|
66 |
+
return $input;
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Add WooCommerce admin tab
|
72 |
+
*
|
73 |
+
* @since 3.0.0
|
74 |
+
* @param array $tabs current admin tabs.
|
75 |
+
* @return array
|
76 |
+
*/
|
77 |
+
public function admin_tab( $tabs ) {
|
78 |
+
|
79 |
+
$tabs['woocommerce'] = 'WooCommerce';
|
80 |
+
|
81 |
+
return $tabs;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Remove WooCommerce product custom post type
|
86 |
+
*
|
87 |
+
* @since 3.0.0
|
88 |
+
* @param array $custom_post_types current tab sections and fields.
|
89 |
+
* @return array
|
90 |
+
*/
|
91 |
+
public function custom_post_types( $custom_post_types ) {
|
92 |
+
|
93 |
+
$custom_post_types = array_diff( $custom_post_types, array( 'product' ) );
|
94 |
+
|
95 |
+
return $custom_post_types;
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Woocommerce sections and fields for 'whatsappme_tab_advanced'
|
100 |
+
*
|
101 |
+
* @since 3.0.0
|
102 |
+
* @param array $sections current tab sections and fields.
|
103 |
+
* @return array
|
104 |
+
*/
|
105 |
+
public function advanced_tab_section( $sections ) {
|
106 |
+
|
107 |
+
$sections['woo'] = array(
|
108 |
+
'view__woocommerce' => __( 'Shop', 'creame-whatsapp-me' ),
|
109 |
+
'view__product' => '— ' . __( 'Product Page', 'creame-whatsapp-me' ),
|
110 |
+
'view__cart' => '— ' . __( 'Cart', 'creame-whatsapp-me' ),
|
111 |
+
'view__checkout' => '— ' . __( 'Checkout', 'creame-whatsapp-me' ),
|
112 |
+
'view__account_page' => '— ' . __( 'My Account', 'creame-whatsapp-me' ),
|
113 |
+
);
|
114 |
+
|
115 |
+
return $sections;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Woocommerce sections and fields for 'whatsappme_tab_woocommerce'
|
120 |
+
*
|
121 |
+
* @since 3.0.0
|
122 |
+
* @param array $sections current tab sections and fields.
|
123 |
+
* @return array
|
124 |
+
*/
|
125 |
+
public function woo_tab_sections( $sections ) {
|
126 |
+
|
127 |
+
$sections['chat'] = array(
|
128 |
+
'message_text_product' => '<label for="whatsappme_message_text_product">' . __( 'Call To Action', 'creame-whatsapp-me' ) . '</label>',
|
129 |
+
'message_send_product' => '<label for="whatsappme_message_send_product">' . __( 'Message', 'creame-whatsapp-me' ) . '</label>',
|
130 |
+
);
|
131 |
+
|
132 |
+
return $sections;
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Woocommerce sections HTML output
|
137 |
+
*
|
138 |
+
* @since 3.0.0
|
139 |
+
* @param string $output current section output.
|
140 |
+
* @param string $section_id current section id.
|
141 |
+
* @return string
|
142 |
+
*/
|
143 |
+
public function section_ouput( $output, $section_id ) {
|
144 |
+
|
145 |
+
if ( 'whatsappme_tab_advanced__woo' == $section_id ) {
|
146 |
+
|
147 |
+
$output = '<h2 class="title">' . __( 'WooCommerce', 'creame-whatsapp-me' ) . '</h2>';
|
148 |
+
|
149 |
+
} elseif ( 'whatsappme_tab_woocommerce__chat' == $section_id ) {
|
150 |
+
|
151 |
+
$output = '<h2 class="title">' . __( 'Product Chat Window', 'creame-whatsapp-me' ) . '</h2>' .
|
152 |
+
'<p>' .
|
153 |
+
__( 'You can define other different texts for the Chat Window on the product pages.', 'creame-whatsapp-me' ) .
|
154 |
+
' <em>' . __( 'You can use styles and dynamic variables', 'creame-whatsapp-me' ) . '</em> ' .
|
155 |
+
'<a class="whatsappme-show-help" href="#" title="' . __( 'Show Help', 'creame-whatsapp-me' ) . '">?</a>' .
|
156 |
+
'</p>';
|
157 |
+
|
158 |
+
}
|
159 |
+
|
160 |
+
return $output;
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Woocommerce fields HTML output
|
165 |
+
*
|
166 |
+
* @since 3.0.0
|
167 |
+
* @param string $output current field output.
|
168 |
+
* @param string $field_id current field id.
|
169 |
+
* @param array $settings current whatsappme settings.
|
170 |
+
* @return string
|
171 |
+
*/
|
172 |
+
public function field_ouput( $output, $field_id, $settings ) {
|
173 |
+
|
174 |
+
$value = isset( $settings[ $field_id ] ) ? $settings[ $field_id ] : '';
|
175 |
+
|
176 |
+
switch ( $field_id ) {
|
177 |
+
case 'message_text_product':
|
178 |
+
$output = '<textarea id="whatsappme_message_text_product" name="whatsappme[message_text_product]" rows="4" class="regular-text" ' .
|
179 |
+
'placeholder="' . esc_attr__( "This *{PRODUCT}* can be yours for only *{PRICE}*!\nIf you have any questions, ask us.", 'creame-whatsapp-me' ) . '">' .
|
180 |
+
$value . '</textarea>' .
|
181 |
+
'<p class="description">' . __( 'Define a text to encourage clients to contact by WhatsApp <strong>(optional)</strong>', 'creame-whatsapp-me' ) . '</p>';
|
182 |
+
break;
|
183 |
+
|
184 |
+
case 'message_send_product':
|
185 |
+
$output = '<textarea id="whatsappme_message_send_product" name="whatsappme[message_send_product]" rows="3" class="regular-text" ' .
|
186 |
+
'placeholder="' . esc_attr__( "*Hi {SITE}!*\nI have a question about *{PRODUCT} ({SKU})*", 'creame-whatsapp-me' ) . '">' . $value . '</textarea>' .
|
187 |
+
'<p class="description">' . __( 'Predefined text with which client can start the conversation <strong>(optional)</strong>', 'creame-whatsapp-me' ) . '</p>';
|
188 |
+
break;
|
189 |
+
}
|
190 |
+
|
191 |
+
return $output;
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Modify $inheritance array to properly inherit
|
196 |
+
* WooCommerce fields on advanced visibily admin tab.
|
197 |
+
*
|
198 |
+
* @since 3.0.0
|
199 |
+
* @param array $inheritance current section output.
|
200 |
+
* @return array
|
201 |
+
*/
|
202 |
+
public function advanced_inheritance( $inheritance ) {
|
203 |
+
|
204 |
+
// 'woocommerce' inherit from 'all' (Global)
|
205 |
+
$inheritance['all'][] = 'woocommerce';
|
206 |
+
// WooCommerce pages inherit from 'woocommerce'
|
207 |
+
$inheritance['woocommerce'] = array( 'product', 'cart', 'checkout', 'account_page' );
|
208 |
+
|
209 |
+
return $inheritance;
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Add WooCommerce variables info for help tab.
|
214 |
+
*
|
215 |
+
* @since 3.0.0
|
216 |
+
* @param string $text current help tab content.
|
217 |
+
* @return string
|
218 |
+
*/
|
219 |
+
public function help_vars( $text ) {
|
220 |
+
|
221 |
+
return $text .
|
222 |
+
'<p> ' . __( '<strong>WooCommerce</strong>, in product pages you can also use:', 'creame-whatsapp-me' ) . '</p>' .
|
223 |
+
'<p>' .
|
224 |
+
'<span><code>{PRODUCT}</code> ➜ ' . __( 'Product Name', 'creame-whatsapp-me' ) . '</span>, ' .
|
225 |
+
'<span><code>{PRICE}</code> ➜ ' . strip_tags( wc_price( 9.95 ) ) . '</span>, ' .
|
226 |
+
'<span><code>{SKU}</code> ➜ ABC98798</span>' .
|
227 |
+
'</p>';
|
228 |
+
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Add Product metabox variables info.
|
233 |
+
*
|
234 |
+
* @since 3.0.0
|
235 |
+
* @param array $vars current default vars.
|
236 |
+
* @return array
|
237 |
+
*/
|
238 |
+
public function metabox_vars( $vars ) {
|
239 |
+
global $post;
|
240 |
+
|
241 |
+
if ( 'product' == $post->post_type ) {
|
242 |
+
$vars = array_merge( $vars, array( 'PRODUCT', 'PRICE', 'SKU' ) );
|
243 |
+
}
|
244 |
+
|
245 |
+
return $vars;
|
246 |
+
}
|
247 |
+
}
|
admin/css/whatsappme.css
CHANGED
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
.tab {
|
2 |
display: none;
|
3 |
}
|
@@ -6,32 +11,71 @@
|
|
6 |
display: block;
|
7 |
}
|
8 |
|
9 |
-
#
|
10 |
background: rgba(0, 0, 0, .05);
|
11 |
}
|
12 |
|
13 |
-
#
|
14 |
-
#
|
15 |
padding: 7px 15px;
|
16 |
}
|
17 |
|
18 |
-
#
|
19 |
margin-right: 15px;
|
20 |
}
|
21 |
|
22 |
-
#
|
23 |
opacity: .5;
|
24 |
}
|
25 |
|
26 |
-
#
|
27 |
transition: all 200ms;
|
28 |
}
|
29 |
|
30 |
-
#
|
31 |
color: #79ba49;
|
32 |
opacity: 1;
|
33 |
}
|
34 |
|
35 |
-
#
|
36 |
color: #ca4a1f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
}
|
1 |
+
.js #whatsappme_form textarea {
|
2 |
+
overflow: hidden;
|
3 |
+
min-height: 100px;
|
4 |
+
}
|
5 |
+
|
6 |
.tab {
|
7 |
display: none;
|
8 |
}
|
11 |
display: block;
|
12 |
}
|
13 |
|
14 |
+
#whatsappme_tab_advanced tr:hover {
|
15 |
background: rgba(0, 0, 0, .05);
|
16 |
}
|
17 |
|
18 |
+
#whatsappme_tab_advanced th,
|
19 |
+
#whatsappme_tab_advanced td {
|
20 |
padding: 7px 15px;
|
21 |
}
|
22 |
|
23 |
+
#whatsappme_tab_advanced label {
|
24 |
margin-right: 15px;
|
25 |
}
|
26 |
|
27 |
+
#whatsappme_tab_advanced .dashicons {
|
28 |
opacity: .5;
|
29 |
}
|
30 |
|
31 |
+
#whatsappme_tab_advanced input[type=radio]+span {
|
32 |
transition: all 200ms;
|
33 |
}
|
34 |
|
35 |
+
#whatsappme_tab_advanced input[type=radio]:checked+span {
|
36 |
color: #79ba49;
|
37 |
opacity: 1;
|
38 |
}
|
39 |
|
40 |
+
#whatsappme_tab_advanced input[type=radio]:checked+.dashicons-hidden {
|
41 |
color: #ca4a1f;
|
42 |
+
}
|
43 |
+
|
44 |
+
.whatsappme-show-help {
|
45 |
+
display: inline-block;
|
46 |
+
width: 1.1em;
|
47 |
+
height: 1.1em;
|
48 |
+
line-height: 1.1em;
|
49 |
+
border-radius: 50%;
|
50 |
+
background: #999;
|
51 |
+
color: #fff;
|
52 |
+
font-weight: bold;
|
53 |
+
text-decoration: none;
|
54 |
+
text-align: center;
|
55 |
+
}
|
56 |
+
|
57 |
+
.whatsappme-show-help:hover,
|
58 |
+
.whatsappme-show-help:active,
|
59 |
+
.whatsappme-show-help:focus {
|
60 |
+
background: #444;
|
61 |
+
color: #fff;
|
62 |
+
}
|
63 |
+
|
64 |
+
#tab-panel-styles-and-vars span {
|
65 |
+
white-space: nowrap;
|
66 |
+
}
|
67 |
+
|
68 |
+
#tab-panel-styles-and-vars code {
|
69 |
+
-webkit-user-select: all;
|
70 |
+
-moz-user-select: all;
|
71 |
+
-ms-user-select: all;
|
72 |
+
user-select: all;
|
73 |
+
}
|
74 |
+
|
75 |
+
.form-table td p.whatsappme-addon {
|
76 |
+
font-size: 13px;
|
77 |
+
}
|
78 |
+
|
79 |
+
.iti--allow-dropdown input {
|
80 |
+
padding-left: 52px !important;
|
81 |
}
|
admin/css/whatsappme.min.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.tab{display:none}.tab-active{display:block}#
|
1 |
+
.js #whatsappme_form textarea{overflow:hidden;min-height:100px}.tab{display:none}.tab-active{display:block}#whatsappme_tab_advanced tr:hover{background:rgba(0,0,0,.05)}#whatsappme_tab_advanced td,#whatsappme_tab_advanced th{padding:7px 15px}#whatsappme_tab_advanced label{margin-right:15px}#whatsappme_tab_advanced .dashicons{opacity:.5}#whatsappme_tab_advanced input[type=radio]+span{transition:all .2s}#whatsappme_tab_advanced input[type=radio]:checked+span{color:#79ba49;opacity:1}#whatsappme_tab_advanced input[type=radio]:checked+.dashicons-hidden{color:#ca4a1f}.whatsappme-show-help{display:inline-block;width:1.1em;height:1.1em;line-height:1.1em;border-radius:50%;background:#999;color:#fff;font-weight:700;text-decoration:none;text-align:center}.whatsappme-show-help:active,.whatsappme-show-help:focus,.whatsappme-show-help:hover{background:#444;color:#fff}#tab-panel-styles-and-vars span{white-space:nowrap}#tab-panel-styles-and-vars code{-webkit-user-select:all;-moz-user-select:all;-ms-user-select:all;user-select:all}.form-table td p.whatsappme-addon{font-size:13px}.iti--allow-dropdown input{padding-left:52px!important}
|
admin/index.php
CHANGED
@@ -1 +1 @@
|
|
1 |
-
<?php // Silence is golden
|
1 |
+
<?php // Silence is golden
|
admin/js/whatsappme.js
CHANGED
@@ -5,31 +5,31 @@
|
|
5 |
if (typeof (intlTelInput) === 'function') {
|
6 |
var country_request = JSON.parse(localStorage.whatsappme_country_code || '{}');
|
7 |
var country_code = (country_request.code && country_request.date == new Date().toDateString()) ? country_request.code : false;
|
8 |
-
var $phone = $(
|
9 |
var iti = intlTelInput($phone.get(0), {
|
10 |
-
hiddenInput: $phone.data(
|
11 |
-
initialCountry:
|
12 |
preferredCountries: [country_code || ''],
|
13 |
geoIpLookup: function (callback) {
|
14 |
if (country_code) {
|
15 |
callback(country_code);
|
16 |
} else {
|
17 |
$.getJSON('https://ipinfo.io').always(function (resp) {
|
18 |
-
var countryCode = (resp && resp.country) ? resp.country :
|
19 |
localStorage.whatsappme_country_code = JSON.stringify({ code: countryCode, date: new Date().toDateString() });
|
20 |
callback(countryCode);
|
21 |
});
|
22 |
}
|
23 |
},
|
24 |
-
utilsScript:
|
25 |
});
|
26 |
|
27 |
-
$phone.on(
|
28 |
$phone.css('border-color', '');
|
29 |
// Ensures number it's updated on AJAX save (Gutemberg)
|
30 |
iti.hiddenInput.value = iti.getNumber();
|
31 |
});
|
32 |
-
$phone.on(
|
33 |
$phone.css('border-color', $phone.val().trim() && !iti.isValidNumber() ? '#ff0000' : '');
|
34 |
});
|
35 |
}
|
@@ -54,7 +54,12 @@
|
|
54 |
}
|
55 |
}
|
56 |
|
|
|
|
|
|
|
|
|
57 |
if ($('#whatsappme_form').length === 1) {
|
|
|
58 |
$('.nav-tab').click(function (e) {
|
59 |
var $tab = $(this);
|
60 |
e.preventDefault();
|
@@ -65,16 +70,31 @@
|
|
65 |
$($tab.attr('href')).addClass('tab-active');
|
66 |
});
|
67 |
|
|
|
68 |
$('#whatsappme_mobile_only').change(function () {
|
69 |
$('#whatsappme_whatsapp_web').closest('tr').toggleClass('hide-if-js', this.checked);
|
70 |
}).change();
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
'archive': ['date', 'author'],
|
76 |
'singular': ['page', 'post'],
|
77 |
-
'woocommerce': ['product', 'cart', 'checkout', 'account_page']
|
78 |
};
|
79 |
|
80 |
$('input', $tab_advanced).change(function () {
|
5 |
if (typeof (intlTelInput) === 'function') {
|
6 |
var country_request = JSON.parse(localStorage.whatsappme_country_code || '{}');
|
7 |
var country_code = (country_request.code && country_request.date == new Date().toDateString()) ? country_request.code : false;
|
8 |
+
var $phone = $('#whatsappme_phone');
|
9 |
var iti = intlTelInput($phone.get(0), {
|
10 |
+
hiddenInput: $phone.data('name') || 'whatsappme[telephone]',
|
11 |
+
initialCountry: 'auto',
|
12 |
preferredCountries: [country_code || ''],
|
13 |
geoIpLookup: function (callback) {
|
14 |
if (country_code) {
|
15 |
callback(country_code);
|
16 |
} else {
|
17 |
$.getJSON('https://ipinfo.io').always(function (resp) {
|
18 |
+
var countryCode = (resp && resp.country) ? resp.country : '';
|
19 |
localStorage.whatsappme_country_code = JSON.stringify({ code: countryCode, date: new Date().toDateString() });
|
20 |
callback(countryCode);
|
21 |
});
|
22 |
}
|
23 |
},
|
24 |
+
utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/' + intl_tel_input_version + '/js/utils.js'
|
25 |
});
|
26 |
|
27 |
+
$phone.on('keyup change', function () {
|
28 |
$phone.css('border-color', '');
|
29 |
// Ensures number it's updated on AJAX save (Gutemberg)
|
30 |
iti.hiddenInput.value = iti.getNumber();
|
31 |
});
|
32 |
+
$phone.on('blur', function () {
|
33 |
$phone.css('border-color', $phone.val().trim() && !iti.isValidNumber() ? '#ff0000' : '');
|
34 |
});
|
35 |
}
|
54 |
}
|
55 |
}
|
56 |
|
57 |
+
function textarea_autoheight() {
|
58 |
+
$(this).height(0).height(this.scrollHeight);
|
59 |
+
}
|
60 |
+
|
61 |
if ($('#whatsappme_form').length === 1) {
|
62 |
+
// Tabs
|
63 |
$('.nav-tab').click(function (e) {
|
64 |
var $tab = $(this);
|
65 |
e.preventDefault();
|
70 |
$($tab.attr('href')).addClass('tab-active');
|
71 |
});
|
72 |
|
73 |
+
// Toggle WhatsApp web option
|
74 |
$('#whatsappme_mobile_only').change(function () {
|
75 |
$('#whatsappme_whatsapp_web').closest('tr').toggleClass('hide-if-js', this.checked);
|
76 |
}).change();
|
77 |
|
78 |
+
// Show help
|
79 |
+
$('.whatsappme-show-help').click(function (e) {
|
80 |
+
e.preventDefault();
|
81 |
+
if ($('#contextual-help-wrap').is(':visible')) {
|
82 |
+
$("html, body").animate({ scrollTop: 0 });
|
83 |
+
} else {
|
84 |
+
$('#contextual-help-link').click();
|
85 |
+
}
|
86 |
+
$('#tab-link-styles-and-vars a').click();
|
87 |
+
});
|
88 |
+
|
89 |
+
// Texarea auto height
|
90 |
+
$('textarea', '#whatsappme_form').on('input', textarea_autoheight).each(textarea_autoheight);
|
91 |
+
|
92 |
+
// Advanced view inheritance
|
93 |
+
var $tab_advanced = $('#whatsappme_tab_advanced');
|
94 |
+
var inheritance = $('.whatsappme_view_all').data('inheritance') || {
|
95 |
+
'all': ['front_page', 'blog_page', '404_page', 'search', 'archive', 'singular', 'cpts'],
|
96 |
'archive': ['date', 'author'],
|
97 |
'singular': ['page', 'post'],
|
|
|
98 |
};
|
99 |
|
100 |
$('input', $tab_advanced).change(function () {
|
admin/js/whatsappme.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
!function(e){"use strict";e(function(){if("function"==typeof intlTelInput){var t=JSON.parse(localStorage.whatsappme_country_code||"{}"),a=!(!t.code||t.date!=(new Date).toDateString())&&t.code,
|
1 |
+
!function(e){"use strict";e(function(){if("function"==typeof intlTelInput){var t=JSON.parse(localStorage.whatsappme_country_code||"{}"),a=!(!t.code||t.date!=(new Date).toDateString())&&t.code,i=e("#whatsappme_phone"),n=intlTelInput(i.get(0),{hiddenInput:i.data("name")||"whatsappme[telephone]",initialCountry:"auto",preferredCountries:[a||""],geoIpLookup:function(t){a?t(a):e.getJSON("https://ipinfo.io").always(function(e){var a=e&&e.country?e.country:"";localStorage.whatsappme_country_code=JSON.stringify({code:a,date:(new Date).toDateString()}),t(a)})},utilsScript:"https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/"+intl_tel_input_version+"/js/utils.js"});i.on("keyup change",function(){i.css("border-color",""),n.hiddenInput.value=n.getNumber()}),i.on("blur",function(){i.css("border-color",i.val().trim()&&!n.isValidNumber()?"#ff0000":"")})}function s(t,a){if(t=t||"all",a=a||e('input[name="whatsappme[view]['+t+']"]:checked').val(),e(".view_inheritance_"+t).toggleClass("dashicons-visibility","yes"==a).toggleClass("dashicons-hidden","no"==a),"cpts"==t)e("[class*=view_inheritance_cpt_]").toggleClass("dashicons-visibility","yes"==a).toggleClass("dashicons-hidden","no"==a);else if(t in o){var i=e('input[name="whatsappme[view]['+t+']"]:checked').val();i=""===i?a:i,e.each(o[t],function(){s(this,i)})}}function c(){e(this).height(0).height(this.scrollHeight)}if(1===e("#whatsappme_form").length){e(".nav-tab").click(function(t){var a=e(this);t.preventDefault(),e(".nav-tab").removeClass("nav-tab-active"),a.addClass("nav-tab-active").blur(),e(".tab").removeClass("tab-active"),e(a.attr("href")).addClass("tab-active")}),e("#whatsappme_mobile_only").change(function(){e("#whatsappme_whatsapp_web").closest("tr").toggleClass("hide-if-js",this.checked)}).change(),e(".whatsappme-show-help").click(function(t){t.preventDefault(),e("#contextual-help-wrap").is(":visible")?e("html, body").animate({scrollTop:0}):e("#contextual-help-link").click(),e("#tab-link-styles-and-vars a").click()}),e("textarea","#whatsappme_form").on("input",c).each(c);var l=e("#whatsappme_tab_advanced"),o=e(".whatsappme_view_all").data("inheritance")||{all:["front_page","blog_page","404_page","search","archive","singular","cpts"],archive:["date","author"],singular:["page","post"]};e("input",l).change(function(){s()}),e(".whatsappme_view_reset").click(function(t){t.preventDefault(),e('input[value=""]',l).prop("checked",!0),e(".whatsappme_view_all input",l).first().prop("checked",!0),s()}),s()}})}(jQuery);
|
includes/class-whatsappme-integrations.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Define the third party plugins integration functionality.
|
5 |
+
*
|
6 |
+
* @since 3.0.0
|
7 |
+
* @package WhatsAppMe
|
8 |
+
* @subpackage WhatsAppMe/includes
|
9 |
+
* @author Creame <hola@crea.me>
|
10 |
+
*/
|