WhatsApp me - Version 2.0.0

Version Description

  • NEW: Advanced visibility settings to define where to show WhatsApp me button.
  • NEW: WooCommerce integration.
  • UPDATED International Telephone Input library to v.13.
  • Minor fixes on fields cleanup and other improvements.
Download this release

Release Info

Developer creapuntome
Plugin Icon 128x128 WhatsApp me
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.4.3 to 2.0.0

README.txt CHANGED
@@ -5,7 +5,7 @@ Tags: whatsapp, button, chat, support, contact
5
Requires at least: 3.0.1
6
Tested up to: 4.9.4
7
Requires PHP: 5.3
8
- Stable tag: 1.4.3
9
License: GPLv2 or later
10
License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
@@ -29,8 +29,9 @@ Options:
29
3. Call to action: Write a message to encourage users to contact you through WhatsApp.
30
4. Delay: You can define a timeout to display the call-to-action message.
31
5. Message: You can define the first message to send.
32
- 6. If you have Google Analytics, an event is triggered when the user launches WhatsApp.
33
- 7. Can override call to action and message or hide button on every post, page or custom post.
34
35
== Installation ==
36
@@ -51,13 +52,20 @@ WhatsApp me don't save any personal data and don't use cookies.
51
52
== Screenshots ==
53
54
- 1. WhatsApp me settings.
55
- 2. Button on desktop.
56
- 3. Call to action on desktop.
57
- 4. Button and call to action on mobile.
58
59
== Changelog ==
60
61
= 1.4.3 =
62
* NEW support for Google Analytics Global Site Tag (gtag.js).
63
* CHANGE events label now is the destination URL to match general behavior.
5
Requires at least: 3.0.1
6
Tested up to: 4.9.4
7
Requires PHP: 5.3
8
+ Stable tag: 2.0.0
9
License: GPLv2 or later
10
License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
29
3. Call to action: Write a message to encourage users to contact you through WhatsApp.
30
4. Delay: You can define a timeout to display the call-to-action message.
31
5. Message: You can define the first message to send.
32
+ 6. Advanced: configure on which pages you want to show or hide your WhatsApp button.
33
+ 7. If you have Google Analytics, an event is triggered when the user launches WhatsApp.
34
+ 8. Can override call to action, message or visibility on every post, page or custom post.
35
36
== Installation ==
37
52
53
== Screenshots ==
54
55
+ 1. WhatsApp me general settings.
56
+ 2. WhatsApp me advanced visibility settings.
57
+ 3. Button on desktop.
58
+ 4. Call to action on desktop.
59
+ 5. Button and call to action on mobile.
60
61
== Changelog ==
62
63
+ = 2.0.0 =
64
+ * **NEW: Advanced visibility settings to define where to show *WhatsApp me* button.**
65
+ * **NEW:** WooCommerce integration.
66
+ * UPDATED International Telephone Input library to v.13.
67
+ * Minor fixes on fields cleanup and other improvements.
68
+
69
= 1.4.3 =
70
* NEW support for Google Analytics Global Site Tag (gtag.js).
71
* CHANGE events label now is the destination URL to match general behavior.
admin/class-whatsappme-admin.php CHANGED
@@ -7,6 +7,7 @@
7
* enqueue the admin-specific stylesheet and JavaScript.
8
*
9
* @since 1.0.0
10
* @package WhatsAppMe
11
* @subpackage WhatsAppMe/admin
12
* @author Creame <hola@crea.me>
@@ -69,6 +70,7 @@ class WhatsAppMe_Admin {
69
* Get all settings or set defaults
70
*
71
* @since 1.0.0
72
*/
73
private function get_settings() {
74
@@ -79,6 +81,7 @@ class WhatsAppMe_Admin {
79
'message_delay' => 10000,
80
'message_send' => '',
81
'position' => 'right',
82
);
83
84
$saved_settings = get_option( 'whatsappme' );
@@ -96,11 +99,15 @@ class WhatsAppMe_Admin {
96
* Register the stylesheets for the admin area.
97
*
98
* @since 1.2.0
99
*/
100
public function enqueue_styles($hook) {
101
102
if ( 'settings_page_whatsappme' == $hook && $this->enhanced_phone ) {
103
- wp_enqueue_style( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/12.1.15/css/intlTelInput.css', array(), null, 'all' );
104
}
105
106
}
@@ -109,11 +116,13 @@ class WhatsAppMe_Admin {
109
* Register the JavaScript for the admin area.
110
*
111
* @since 1.2.0
112
*/
113
public function enqueue_scripts($hook) {
114
115
if ( 'settings_page_whatsappme' == $hook && $this->enhanced_phone ) {
116
- wp_enqueue_script( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/12.1.15/js/intlTelInput.min.js', array( 'jquery' ), null, true );
117
wp_enqueue_script( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'js/whatsappme.js', array( 'intl-tel-input' ), $this->version, true );
118
}
119
@@ -124,15 +133,21 @@ class WhatsAppMe_Admin {
124
* From v1.2.0 also set filter to disable enhanced phone input
125
*
126
* @since 1.0.0
127
* @access public
128
* @return void
129
*/
130
public function settings_init(){
131
132
register_setting( 'whatsappme', 'whatsappme', array( $this, 'settings_validate' ) );
133
- add_settings_section( 'whatsappme_section', null, array( $this, 'section_text' ), 'whatsappme' );
134
135
- $field_names = array(
136
'telephone' => __( 'Telephone', 'creame-whatsapp-me' ),
137
'mobile_only' => __( 'Mobile only', 'creame-whatsapp-me' ),
138
'message_text' => __( 'Call to action', 'creame-whatsapp-me' ),
@@ -141,10 +156,97 @@ class WhatsAppMe_Admin {
141
'position' => __( 'Position on screen', 'creame-whatsapp-me' ),
142
);
143
144
- foreach ( $this->settings as $key => $value ) {
145
- add_settings_field( 'whatsappme_' . $key, $field_names[ $key ], array( $this, 'field_' . $key ), 'whatsappme', 'whatsappme_section' );
146
}
147
148
$this->enhanced_phone = apply_filters( 'whatsappme_enhanced_phone', $this->enhanced_phone );
149
}
150
@@ -152,18 +254,20 @@ class WhatsAppMe_Admin {
152
* Validate settings, clean and set defaults before save
153
*
154
* @since 1.0.0
155
* @return array
156
*/
157
public function settings_validate($input) {
158
159
- if ( !array_key_exists( 'mobile_only', $input) ){
160
- $input['mobile_only'] = 'no';
161
- }
162
- $input['telephone'] = sanitize_text_field($input['telephone']);
163
- $input['message_text'] = trim($input['message_text']);
164
- $input['message_delay'] = intval($input['message_delay']);
165
- $input['message_send'] = trim($input['message_send']);
166
$input['position'] = $input['position'] != 'left' ? 'right' : 'left';
167
168
add_settings_error( 'whatsappme', 'settings_updated', __( 'Settings saved', 'creame-whatsapp-me' ), 'updated' );
169
@@ -171,13 +275,42 @@ class WhatsAppMe_Admin {
171
}
172
173
/**
174
- * Section 'whatsappme_section' output
175
*
176
* @since 1.0.0
177
* @return void
178
*/
179
- public function section_text() {
180
- echo '<p>' . __( 'From here you can configure the behavior of the WhatsApp button on your site.', 'creame-whatsapp-me' ) . '</p>';
181
}
182
183
/**
@@ -253,6 +386,44 @@ class WhatsAppMe_Admin {
253
__('Left', 'creame-whatsapp-me' ) . '</label></p></fieldset>';
254
}
255
256
/**
257
* Add menu to the options page in the wordpress admin
258
*
@@ -315,7 +486,7 @@ class WhatsAppMe_Admin {
315
// Default post types
316
$builtin_post_types = array( 'post', 'page' );
317
// Custom post types with public url
318
- $custom_post_types = array_keys( get_post_types( array( 'rewrite' => true ), 'names' ) );
319
320
// Add/remove posts types for "WhatsApp me" meta box
321
$post_types = apply_filters( 'whatsappme_post_types_meta_box', array_merge( $builtin_post_types, $custom_post_types ) );
@@ -324,7 +495,7 @@ class WhatsAppMe_Admin {
324
add_meta_box(
325
'whatsappme',
326
__( 'WhatsApp me', 'creame-whatsapp-me' ),
327
- array( $this, 'add_meta_box' ),
328
$post_type,
329
'side',
330
'default'
@@ -335,38 +506,56 @@ class WhatsAppMe_Admin {
335
/**
336
* Generate Meta Box html
337
*
338
- * @since 1.1.0
339
* @access public
340
* @return void
341
*/
342
- public function add_meta_box( $post ) {
343
344
$metadata = get_post_meta( $post->ID, '_whatsappme', true ) ?: array();
345
$metadata = array_merge( array(
346
'message_text' => '',
347
'message_send' => '',
348
- 'hide' => false
349
), $metadata );
350
351
- $post_type = get_post_type_object( get_post_type( $post->ID ) );
352
- $post_type_name = function_exists( 'mb_strtolower' ) ?
353
- mb_strtolower( $post_type->labels->singular_name ) :
354
- strtolower( $post_type->labels->singular_name );
355
356
wp_nonce_field( 'whatsappme_data', 'whatsappme_nonce' );
357
?>
358
- <p>
359
- <label for="whatsappme_message"><?php _e( 'Call to action', 'creame-whatsapp-me' ); ?></label><br>
360
- <textarea name="whatsappme_message" rows="2" class="large-text"><?php echo $metadata['message_text']; ?></textarea>
361
- </p>
362
- <p>
363
- <label for="whatsappme_message_send"><?php _e( 'Message', 'creame-whatsapp-me' ); ?></label><br>
364
- <textarea name="whatsappme_message_send" rows="2" class="large-text"><?php echo $metadata['message_send']; ?></textarea>
365
- </p>
366
- <p>
367
- <input type="checkbox" name="whatsappme_hide" id="whatsappme_hide" value="1" <?php echo $metadata['hide'] ? 'checked' : ''; ?>>
368
- <label for="whatsappme_hide"><?php printf( __( 'Hide on this %s', 'creame-whatsapp-me' ), $post_type_name ); ?></label>
369
- </p>
370
<?php
371
}
372
@@ -374,6 +563,7 @@ class WhatsAppMe_Admin {
374
* Save meta data from "WhatsApp me" Meta Box on post save
375
*
376
* @since 1.1.0
377
* @access public
378
* @return void
379
*/
@@ -384,12 +574,12 @@ class WhatsAppMe_Admin {
384
return;
385
}
386
387
- // Delete empty/false fields
388
- $metadata = array_filter( array(
389
- 'message_text' => trim( $_POST['whatsappme_message'] ),
390
- 'message_send' => trim( $_POST['whatsappme_message_send'] ),
391
- 'hide' => isset( $_POST['whatsappme_hide'] ) ? 1 : 0,
392
- ) );
393
394
if ( count( $metadata ) ) {
395
update_post_meta( $post_id, '_whatsappme', $metadata );
@@ -397,4 +587,22 @@ class WhatsAppMe_Admin {
397
delete_post_meta( $post_id, '_whatsappme' );
398
}
399
}
400
}
7
* enqueue the admin-specific stylesheet and JavaScript.
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>
70
* Get all settings or set defaults
71
*
72
* @since 1.0.0
73
+ * @since 2.0.0 Added visibility setting
74
*/
75
private function get_settings() {
76
81
'message_delay' => 10000,
82
'message_send' => '',
83
'position' => 'right',
84
+ 'visibility' => array( 'all' => 'yes' ),
85
);
86
87
$saved_settings = get_option( 'whatsappme' );
99
* Register the stylesheets for the admin area.
100
*
101
* @since 1.2.0
102
+ * @since 2.0.0 Added whatsappme-admin styles
103
+ * @param string $hook The name of the page.
104
+ * @return void
105
*/
106
public function enqueue_styles($hook) {
107
108
if ( 'settings_page_whatsappme' == $hook && $this->enhanced_phone ) {
109
+ wp_enqueue_style( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/13.0.3/css/intlTelInput.css', array(), null, 'all' );
110
+ wp_enqueue_style( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'css/whatsappme.css', array(), $this->version, 'all' );
111
}
112
113
}
116
* Register the JavaScript for the admin area.
117
*
118
* @since 1.2.0
119
+ * @param string $hook The id of the page.
120
+ * @return void
121
*/
122
public function enqueue_scripts($hook) {
123
124
if ( 'settings_page_whatsappme' == $hook && $this->enhanced_phone ) {
125
+ wp_enqueue_script( 'intl-tel-input', 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/13.0.3/js/intlTelInput.min.js', array( 'jquery' ), null, true );
126
wp_enqueue_script( 'whatsappme-admin', plugin_dir_url( __FILE__ ) . 'js/whatsappme.js', array( 'intl-tel-input' ), $this->version, true );
127
}
128
133
* From v1.2.0 also set filter to disable enhanced phone input
134
*
135
* @since 1.0.0
136
+ * @since 2.0.0 Added tabs for general and Advanced settings
137
* @access public
138
* @return void
139
*/
140
public function settings_init(){
141
142
register_setting( 'whatsappme', 'whatsappme', array( $this, 'settings_validate' ) );
143
144
+ /*
145
+ * General Settings
146
+ */
147
+
148
+ add_settings_section( 'whatsappme_section_general', null, array( $this, 'section_text' ), 'whatsappme' );
149
+
150
+ $general_fields = array(
151
'telephone' => __( 'Telephone', 'creame-whatsapp-me' ),
152
'mobile_only' => __( 'Mobile only', 'creame-whatsapp-me' ),
153
'message_text' => __( 'Call to action', 'creame-whatsapp-me' ),
156
'position' => __( 'Position on screen', 'creame-whatsapp-me' ),
157
);
158
159
+ foreach ( $general_fields as $key => $value ) {
160
+ add_settings_field( 'whatsappme_' . $key, $value, array( $this, 'field_' . $key ), 'whatsappme', 'whatsappme_section_general' );
161
+ }
162
+
163
+ /*
164
+ * Advanced Settings / All
165
+ */
166
+
167
+ add_settings_section( 'whatsappme_section_advanced_all', null, array( $this, 'section_text' ), 'whatsappme' );
168
+ add_settings_field( 'whatsappme_view_all', __( 'Global', 'creame-whatsapp-me' ), array( $this, 'field_view_all' ), 'whatsappme', 'whatsappme_section_advanced_all' );
169
+
170
+ /*
171
+ * Advanced Settings / WP
172
+ */
173
+
174
+ add_settings_section( 'whatsappme_section_advanced_wp', null, array( $this, 'section_text' ), 'whatsappme' );
175
+
176
+ $advanced_fields = array(
177
+ 'front_page' => __( 'Front Page', 'creame-whatsapp-me' ),
178
+ 'blog_page' => __( 'Blog Page', 'creame-whatsapp-me' ),
179
+ '404_page' => __( '404 Page', 'creame-whatsapp-me' ),
180
+ 'search' => __( 'Search Results', 'creame-whatsapp-me' ),
181
+ 'archive' => __( 'Archives', 'creame-whatsapp-me' ),
182
+ 'date' => '— ' . __( 'Date Archives', 'creame-whatsapp-me' ),
183
+ 'author' => '— ' . __( 'Author Archives', 'creame-whatsapp-me' ),
184
+ 'singular' => __( 'Singular', 'creame-whatsapp-me' ),
185
+ 'page' => '— ' . __( 'Page', 'creame-whatsapp-me' ),
186
+ 'post' => '— ' . __( 'Post', 'creame-whatsapp-me' ),
187
+ );
188
+
189
+ // If isn't set Blog Page or is the same than Front Page unset blog_page option
190
+ if ( get_option( 'show_on_front' ) == 'posts' || get_option( 'page_for_posts' ) == 0 ) {
191
+ unset( $advanced_fields['blog_page'] );
192
+ }
193
+
194
+ foreach ( $advanced_fields as $key => $value ) {
195
+ add_settings_field( 'whatsappme_view_' . $key, $value, array( $this, 'field_view' ), 'whatsappme', 'whatsappme_section_advanced_wp', array( 'field' => $key ) );
196
+ }
197
+
198
+ /*
199
+ * Advanced Settings / Woocommerce
200
+ */
201
+
202
+ if ( class_exists( 'WooCommerce' ) ) {
203
+
204
+ add_settings_section( 'whatsappme_section_advanced_woo', 'WooCommerce', array( $this, 'section_text' ), 'whatsappme' );
205
+
206
+ $woo_fields = array(
207
+ 'woocommerce' => __( 'Shop', 'creame-whatsapp-me' ),
208
+ // 'shop' => __( 'Shop', 'creame-whatsapp-me' ),
209
+ 'product' => '— ' . __( 'Product Page', 'creame-whatsapp-me' ),
210
+ 'cart' => '— ' . __( 'Cart', 'creame-whatsapp-me' ),
211
+ 'checkout' => '— ' . __( 'Checkout', 'creame-whatsapp-me' ),
212
+ 'account_page' => '— ' . __( 'My Account', 'creame-whatsapp-me' ),
213
+ );
214
+
215
+ foreach ( $woo_fields as $key => $value ) {
216
+ add_settings_field( 'whatsappme_view_' . $key, $value, array( $this, 'field_view' ), 'whatsappme', 'whatsappme_section_advanced_woo', array( 'field' => $key ) );
217
+ }
218
+ }
219
+
220
+ /*
221
+ * Advanced Settings / Custom Post Types
222
+ */
223
+
224
+ $custom_post_types = array_keys( get_post_types( array( 'has_archive' => true ), 'names' ) );
225
+ // Product CPT already defined in WooCommerce section
226
+ if ( class_exists( 'WooCommerce' ) ) {
227
+ $custom_post_types = array_diff( $custom_post_types, array( 'product' ) );
228
+ }
229
+
230
+ // Add/remove posts types on advanced settings
231
+ $custom_post_types = apply_filters( 'whatsappme_custom_post_types', $custom_post_types );
232
+
233
+ if ( count( $custom_post_types ) ) {
234
+
235
+ add_settings_section( 'whatsappme_section_advanced_cpt', __( 'Custom Post Types', 'creame-whatsapp-me' ), array( $this, 'section_text' ), 'whatsappme' );
236
+
237
+ foreach ( $custom_post_types as $custom_post_type ) {
238
+
239
+ $post_type = get_post_type_object( $custom_post_type );
240
+ $post_type_name = function_exists( 'mb_convert_case' ) ?
241
+ mb_convert_case( $post_type->labels->name, MB_CASE_TITLE ) :
242
+ strtolower( $post_type->labels->name );
243
+
244
+ 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 ) );
245
+ }
246
}
247
248
+ add_settings_section( 'whatsappme_section_end', null, array( $this, 'section_text' ), 'whatsappme' );
249
+
250
$this->enhanced_phone = apply_filters( 'whatsappme_enhanced_phone', $this->enhanced_phone );
251
}
252
254
* Validate settings, clean and set defaults before save
255
*
256
* @since 1.0.0
257
+ * @since 2.0.0 Added visibility setting
258
+ * @param array $input contain keys 'id', 'title' and 'callback'.
259
* @return array
260
*/
261
public function settings_validate($input) {
262
263
+ $input['mobile_only'] = isset( $input['mobile_only'] ) ? 'yes' : 'no';
264
+ $input['telephone'] = $this->clean_input( $input['telephone'] );
265
+ $input['message_text'] = $this->clean_input( $input['message_text'] );
266
+ $input['message_delay'] = intval( $input['message_delay'] );
267
+ $input['message_send'] = $this->clean_input( $input['message_send'] );
268
$input['position'] = $input['position'] != 'left' ? 'right' : 'left';
269
+ $input['visibility'] = array_filter( $input['view'], function($v) { return $v == 'yes' || $v == 'no'; } );
270
+ unset( $input['view'] );
271
272
add_settings_error( 'whatsappme', 'settings_updated', __( 'Settings saved', 'creame-whatsapp-me' ), 'updated' );
273
275
}
276
277
/**
278
+ * Section HTML output
279
*
280
* @since 1.0.0
281
+ * @since 2.0.0 Now accept $args and echo the appropriate section html
282
+ * @param array $args Section info.
283
* @return void
284
*/
285
+ public function section_text($args) {
286
+ switch ( $args['id'] ) {
287
+ case 'whatsappme_section_general':
288
+ echo '<h2 class="nav-tab-wrapper wp-clearfix">' .
289
+ '<a href="#tab-general" class="nav-tab nav-tab-active">' . __( 'General', 'creame-whatsapp-me' ) . '</a>' .
290
+ '<a href="#tab-advanced" class="nav-tab">' . __( 'Advanced', 'creame-whatsapp-me' ) . '</a>' .
291
+ '</h2>' .
292
+ '<div class="tabs">' .
293
+ '<div id="tab-general" class="tab tab-active">' .
294
+ '<p>' . __( 'From here you can configure the behavior of the WhatsApp button on your site.', 'creame-whatsapp-me' ) . '</p>';
295
+ break;
296
+
297
+ case 'whatsappme_section_advanced_all':
298
+ echo '</div><div id="tab-advanced" class="tab">' .
299
+ '<p>' . __( 'From here you can configure on which pages the WhatsApp button will be visible.', 'creame-whatsapp-me' ) .
300
+ ' <a href="#" class="whatsappme_view_reset">' . __( 'Restore default visibility', 'creame-whatsapp-me' ) . '</a></p>';
301
+ break;
302
+
303
+ case 'whatsappme_section_advanced_wp':
304
+ echo '<hr>';
305
+ break;
306
+
307
+ case 'whatsappme_section_end':
308
+ echo '</div></div><!-- end tabs -->';
309
+ break;
310
+
311
+ default:
312
+ break;
313
+ }
314
}
315
316
/**
386
__('Left', 'creame-whatsapp-me' ) . '</label></p></fieldset>';
387
}
388
389
+ /**
390
+ * Field 'field_view_all' output
391
+ *
392
+ * @since 2.0.0
393
+ * @return void
394
+ */
395
+ public function field_view_all() {
396
+ if ( isset( $this->settings['visibility']['all'] ) && $this->settings['visibility']['all'] == 'no' ) {
397
+ $value = 'no';
398
+ } else {
399
+ $value = 'yes';
400
+ }
401
+
402
+ echo '<label class="whatsappme_view_all"><input type="radio" name="whatsappme[view][all]" value="yes"' . checked( 'yes', $value, false ) . '> ' .
403
+ '<span class="dashicons dashicons-visibility" title="' . __( 'Show', 'creame-whatsapp-me' ) . '"></span></label>' .
404
+ '<label class="whatsappme_view_all"><input type="radio" name="whatsappme[view][all]" value="no"' . checked( 'no', $value, false ) . '> ' .
405
+ '<span class="dashicons dashicons-hidden" title="' . __( 'Hide', 'creame-whatsapp-me' ) . '"></span></label>';
406
+ }
407
+
408
+ /**
409
+ * Field 'field_view' output
410
+ *
411
+ * @since 2.0.0
412
+ * @param array $args array with key field.
413
+ * @return void
414
+ */
415
+ public function field_view($args) {
416
+ $field = $args['field'];
417
+ $value = isset( $this->settings['visibility'][ $field ] ) ? $this->settings['visibility'][ $field ] : '';
418
+
419
+ echo '<label><input type="radio" name="whatsappme[view][' . $field . ']" value="yes"' . checked( 'yes', $value, false ) . '> ' .
420
+ '<span class="dashicons dashicons-visibility" title="' . __( 'Show', 'creame-whatsapp-me' ) . '"></span></label>' .
421
+ '<label><input type="radio" name="whatsappme[view][' . $field . ']" value="no"' . checked( 'no', $value, false ) . '> ' .
422
+ '<span class="dashicons dashicons-hidden" title="' . __( 'Hide', 'creame-whatsapp-me' ) . '"></span></label>' .
423
+ '<label><input type="radio" name="whatsappme[view][' . $field . ']" value=""' . checked( '', $value, false ) . '> ' .
424
+ __( 'Inherit', 'creame-whatsapp-me' ) . ' <span class="dashicons dashicons-visibility view_inheritance_' . $field . '"></span></label>';
425
+ }
426
+
427
/**
428
* Add menu to the options page in the wordpress admin
429
*
486
// Default post types
487
$builtin_post_types = array( 'post', 'page' );
488
// Custom post types with public url
489
+ $custom_post_types = array_keys( get_post_types( array( 'has_archive' => true ), 'names' ) );
490
491
// Add/remove posts types for "WhatsApp me" meta box
492
$post_types = apply_filters( 'whatsappme_post_types_meta_box', array_merge( $builtin_post_types, $custom_post_types ) );
495
add_meta_box(
496
'whatsappme',
497
__( 'WhatsApp me', 'creame-whatsapp-me' ),
498
+ array( $this, 'meta_box' ),
499
$post_type,
500
'side',
501
'default'
506
/**
507
* Generate Meta Box html
508
*
509
+ * @since 1.1.0 (previously named "add_meta_box")
510
+ * @since 2.0.0 Now can set as [show, hide, default]
511
* @access public
512
* @return void
513
*/
514
+ public function meta_box( $post ) {
515
516
$metadata = get_post_meta( $post->ID, '_whatsappme', true ) ?: array();
517
$metadata = array_merge( array(
518
'message_text' => '',
519
'message_send' => '',
520
+ 'hide' => false,
521
+ 'view' => '',
522
), $metadata );
523
524
+ // Move old 'hide' to new 'view' field
525
+ if ( $metadata['hide'] ) {
526
+ $metadata['view'] = 'no';
527
+ }
528
+ unset( $metadata['hide'] );
529
530
wp_nonce_field( 'whatsappme_data', 'whatsappme_nonce' );
531
?>
532
+ <div class="whatsappme-metabox">
533
+ <p>
534
+ <label for="whatsappme_message"><?php _e( 'Call to action', 'creame-whatsapp-me' ); ?></label><br>
535
+ <textarea name="whatsappme_message" rows="2" class="large-text"><?php echo $metadata['message_text']; ?></textarea>
536
+ </p>
537
+ <p>
538
+ <label for="whatsappme_message_send"><?php _e( 'Message', 'creame-whatsapp-me' ); ?></label><br>
539
+ <textarea name="whatsappme_message_send" rows="2" class="large-text"><?php echo $metadata['message_send']; ?></textarea>
540
+ <small><?php _e( 'You can use vars <code>{SITE} {URL} {TITLE}</code>', 'creame-whatsapp-me' ); ?></small>
541
+ </p>
542
+ <p>
543
+ <label><input type="radio" name="whatsappme_view" value="yes" <?php checked( 'yes', $metadata['view'] ); ?>>
544
+ <span class="dashicons dashicons-visibility" title="<?php echo __( 'Show', 'creame-whatsapp-me' ); ?>"></span></label>
545
+ <label><input type="radio" name="whatsappme_view" value="no" <?php checked( 'no', $metadata['view'] ); ?>>
546
+ <span class="dashicons dashicons-hidden" title="<?php echo __( 'Hide', 'creame-whatsapp-me' ); ?>"></span></label>
547
+ <label><input type="radio" name="whatsappme_view" value="" <?php checked( '', $metadata['view'] ); ?>>
548
+ <?php echo __( 'Default visibility', 'creame-whatsapp-me' ); ?></label>
549
+ </p>
550
+ </div>
551
+ <style>
552
+ .whatsappme-metabox code { font-size:smaller; vertical-align:text-bottom; }
553
+ .whatsappme-metabox .dashicons { opacity:.5; }
554
+ .whatsappme-metabox input[type=radio] { margin-right:2px; }
555
+ .whatsappme-metabox input[type=radio]+span { margin-right:5px; transition:all 200ms; }
556
+ .whatsappme-metabox input[type=radio]:checked+span { color:#79ba49; opacity:1; }
557
+ .whatsappme-metabox input[type=radio]:checked+.dashicons-hidden { color:#ca4a1f; }
558
+ </style>
559
<?php
560
}
561
563
* Save meta data from "WhatsApp me" Meta Box on post save
564
*
565
* @since 1.1.0
566
+ * @since 2.0.0 Change 'hide' key to 'view' now values can be [yes, no]
567
* @access public
568
* @return void
569
*/
574
return;
575
}
576
577
+ // Clean and delete empty/false fields
578
+ $metadata = array_filter( $this->clean_input( array(
579
+ 'message_text' => $_POST['whatsappme_message'],
580
+ 'message_send' => $_POST['whatsappme_message_send'],
581
+ 'view' => $_POST['whatsappme_view'],
582
+ ) ) );
583
584
if ( count( $metadata ) ) {
585
update_post_meta( $post_id, '_whatsappme', $metadata );
587
delete_post_meta( $post_id, '_whatsappme' );
588
}
589
}
590
+
591
+ /**
592
+ * Clean user input fields
593
+ *
594
+ * @since 2.0.0
595
+ * @param mixed $value to clean
596
+ * @return mixed $value cleaned
597
+ */
598
+ public function clean_input($value) {
599
+ if ( is_array( $value ) ) {
600
+ return array_map( array( $this, 'clean_input' ), $value );
601
+ } else if ( is_string( $value ) ) {
602
+ // Split lines, clean and re-join lines
603
+ return implode( "\n", array_map( 'sanitize_text_field', explode( "\n", trim( $value ) ) ) );
604
+ } else {
605
+ return $value;
606
+ }
607
+ }
608
}
admin/css/whatsappme.css ADDED
@@ -0,0 +1,37 @@
1
+ .tab {
2
+ display: none;
3
+ }
4
+
5
+ .tab-active {
6
+ display: block;
7
+ }
8
+
9
+ #tab-advanced tr:hover {
10
+ background: rgba(0, 0, 0, .05);
11
+ }
12
+
13
+ #tab-advanced th,
14
+ #tab-advanced td {
15
+ padding: 7px 15px;
16
+ }
17
+
18
+ #tab-advanced label {
19
+ margin-right: 15px;
20
+ }
21
+
22
+ #tab-advanced .dashicons {
23
+ opacity: .5;
24
+ }
25
+
26
+ #tab-advanced input[type=radio]+span {
27
+ transition: all 200ms;
28
+ }
29
+
30
+ #tab-advanced input[type=radio]:checked+span {
31
+ color: #79ba49;
32
+ opacity: 1;
33
+ }
34
+
35
+ #tab-advanced input[type=radio]:checked+.dashicons-hidden {
36
+ color: #ca4a1f;
37
+ }
admin/js/whatsappme.js CHANGED
@@ -31,5 +31,55 @@
31
$phone.css('border-color', $.trim($phone.val()) && !$phone.intlTelInput("isValidNumber") ? '#ff0000' : '');
32
});
33
34
});
35
})(jQuery);
31
$phone.css('border-color', $.trim($phone.val()) && !$phone.intlTelInput("isValidNumber") ? '#ff0000' : '');
32
});
33
34
+ $('.nav-tab').click(function (e) {
35
+ var $tab = $(this);
36
+ e.preventDefault();
37
+
38
+ $('.nav-tab').removeClass('nav-tab-active');
39
+ $tab.addClass('nav-tab-active').blur();
40
+ $('.tab').removeClass('tab-active');
41
+ $($tab.attr('href')).addClass('tab-active');
42
+ });
43
+
44
+ var $tab_advanced = $('#tab-advanced');
45
+ var inheritance = {
46
+ 'all': ['front_page', 'blog_page', '404_page', 'search', 'archive', 'singular', 'woocommerce', 'cpts'],
47
+ 'archive': ['date', 'author'],
48
+ 'singular': ['page', 'post'],
49
+ 'woocommerce': ['product', 'cart', 'checkout', 'account_page']
50
+ };
51
+
52
+ $('input', $tab_advanced).change(function () {
53
+ propagate_inheritance();
54
+ });
55
+
56
+ function propagate_inheritance(field, show) {
57
+ field = field || 'all';
58
+ show = show || $('input[name="whatsappme[view][' + field + ']"]:checked').val();
59
+
60
+ $('.view_inheritance_' + field)
61
+ .toggleClass('dashicons-visibility', show == 'yes')
62
+ .toggleClass('dashicons-hidden', show == 'no');
63
+
64
+ if (field == 'cpts') {
65
+ $('[class*=view_inheritance_cpt_]')
66
+ .toggleClass('dashicons-visibility', show == 'yes')
67
+ .toggleClass('dashicons-hidden', show == 'no');
68
+ } else if (field in inheritance) {
69
+ var value = $('input[name="whatsappme[view][' + field + ']"]:checked').val();
70
+ value = value === '' ? show : value;
71
+
72
+ $.each(inheritance[field], function () { propagate_inheritance(this, value); });
73
+ }
74
+ }
75
+
76
+ $('.whatsappme_view_reset').click(function (e) {
77
+ e.preventDefault();
78
+ $('input[value=""]', $tab_advanced).prop('checked', true);
79
+ $('.whatsappme_view_all input', $tab_advanced).first().prop('checked', true);
80
+ propagate_inheritance();
81
+ });
82
+
83
+ propagate_inheritance();
84
});
85
})(jQuery);
languages/creame-whatsapp-me.pot CHANGED
@@ -2,7 +2,7 @@
2
msgid ""
3
msgstr ""
4
"Project-Id-Version: WhatsApp Me\n"
5
- "POT-Creation-Date: 2018-04-16 11:42+0000\n"
6
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
7
"Last-Translator: Your Name <you@example.com>\n"
8
"Language-Team: Creame <hola@crea.me>\n"
@@ -21,112 +21,215 @@ msgstr ""
21
"X-Generator: Loco https://localise.biz/\n"
22
"X-Poedit-SearchPath-0: ."
23
24
- #: admin/class-whatsappme-admin.php:136
25
msgid "Telephone"
26
msgstr ""
27
28
- #: admin/class-whatsappme-admin.php:137 admin/class-whatsappme-admin.php:237
29
msgid "Mobile only"
30
msgstr ""
31
32
- #: admin/class-whatsappme-admin.php:138 admin/class-whatsappme-admin.php:359
33
msgid "Call to action"
34
msgstr ""
35
36
- #: admin/class-whatsappme-admin.php:139
37
msgid "Delay"
38
msgstr ""
39
40
- #: admin/class-whatsappme-admin.php:140 admin/class-whatsappme-admin.php:363
41
msgid "Message"
42
msgstr ""
43
44
- #: admin/class-whatsappme-admin.php:141 admin/class-whatsappme-admin.php:249
45
msgid "Position on screen"
46
msgstr ""
47
48
#: admin/class-whatsappme-admin.php:168
49
- msgid "Settings saved"
50
msgstr ""
51
52
#: admin/class-whatsappme-admin.php:180
53
msgid ""
54
"From here you can configure the behavior of the WhatsApp button on your site."
55
msgstr ""
56
57
- #: admin/class-whatsappme-admin.php:192
58
msgid ""
59
"Contact phone number. <strong>The button will not be shown if it's empty."
60
"</strong>"
61
msgstr ""
62
63
- #: admin/class-whatsappme-admin.php:202
64
msgid ""
65
"Hello 👋\n"
66
"Can we help you?"
67
msgstr ""
68
69
- #: admin/class-whatsappme-admin.php:203
70
msgid ""
71
"<strong>Optional.</strong> Text to invite the user to use the contact via "
72
"WhatsApp."
73
msgstr ""
74
75
- #: admin/class-whatsappme-admin.php:204
76
msgid ""
77
"You can use formatting styles like in WhatsApp: _<em>italic</em>_ *<strong>"
78
"bold</strong>* ~<del>strikethrough</del>~"
79
msgstr ""
80
81
- #: admin/class-whatsappme-admin.php:214
82
msgid "milliseconds"
83
msgstr ""
84
85
- #: admin/class-whatsappme-admin.php:215
86
msgid ""
87
"The <strong>Call to action</strong> will only be displayed once when the "
88
"user exceeds the estimated delay on a page. It will also be displayed when "
89
"the user stops the cursor over the WhatsApp button."
90
msgstr ""
91
92
- #: admin/class-whatsappme-admin.php:225
93
msgid "Hi {SITE}! I need more info about {TITLE}"
94
msgstr ""
95
96
- #: admin/class-whatsappme-admin.php:226
97
msgid "<strong>Optional.</strong> Default message to start the conversation."
98
msgstr ""
99
100
- #: admin/class-whatsappme-admin.php:227
101
msgid ""
102
"You can use vars <code>{SITE} {URL} {TITLE}</code> that will be replaced "
103
"with the values of the current page."
104
msgstr ""
105
106
- #: admin/class-whatsappme-admin.php:239
107
msgid "Only display the button on mobile devices"
108
msgstr ""
109
110
- #: admin/class-whatsappme-admin.php:251
111
msgid "Right"
112
msgstr ""
113
114
- #: admin/class-whatsappme-admin.php:253
115
msgid "Left"
116
msgstr ""
117
118
- #: admin/class-whatsappme-admin.php:278
119
msgid "Settings"
120
msgstr ""
121
122
#. Name of the plugin
123
- #: admin/class-whatsappme-admin.php:326
124
msgid "WhatsApp me"
125
msgstr ""
126
127
- #: admin/class-whatsappme-admin.php:368
128
- #, php-format
129
- msgid "Hide on this %s"
130
msgstr ""
131
132
#. Description of the theme
@@ -134,7 +237,7 @@ msgid "Add support to your clients directly with WhatsApp."
134
msgstr ""
135
136
#. URI of the plugin
137
- msgid "https://crea.me/productos/whatsapp-me/"
138
msgstr ""
139
140
#. Author of the plugin
2
msgid ""
3
msgstr ""
4
"Project-Id-Version: WhatsApp Me\n"
5
+ "POT-Creation-Date: 2018-08-30 09:03+0000\n"
6
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
7
"Last-Translator: Your Name <you@example.com>\n"
8
"Language-Team: Creame <hola@crea.me>\n"
21
"X-Generator: Loco https://localise.biz/\n"
22
"X-Poedit-SearchPath-0: ."
23
24
+ #: admin/class-whatsappme-admin.php:151
25
msgid "Telephone"
26
msgstr ""
27
28
+ #: admin/class-whatsappme-admin.php:152 admin/class-whatsappme-admin.php:370
29
msgid "Mobile only"
30
msgstr ""
31
32
+ #: admin/class-whatsappme-admin.php:153 admin/class-whatsappme-admin.php:534
33
msgid "Call to action"
34
msgstr ""
35
36
+ #: admin/class-whatsappme-admin.php:154
37
msgid "Delay"
38
msgstr ""
39
40
+ #: admin/class-whatsappme-admin.php:155 admin/class-whatsappme-admin.php:538
41
msgid "Message"
42
msgstr ""
43
44
+ #: admin/class-whatsappme-admin.php:156 admin/class-whatsappme-admin.php:382
45
msgid "Position on screen"
46
msgstr ""
47
48
#: admin/class-whatsappme-admin.php:168
49
+ msgid "Global"
50
+ msgstr ""
51
+
52
+ #: admin/class-whatsappme-admin.php:177
53
+ msgid "Front Page"
54
+ msgstr ""
55
+
56
+ #: admin/class-whatsappme-admin.php:178
57
+ msgid "Blog Page"
58
+ msgstr ""
59
+
60
+ #: admin/class-whatsappme-admin.php:179
61
+ msgid "404 Page"
62
msgstr ""
63
64
#: admin/class-whatsappme-admin.php:180
65
+ msgid "Search Results"
66
+ msgstr ""
67
+
68
+ #: admin/class-whatsappme-admin.php:181
69
+ msgid "Archives"
70
+ msgstr ""
71
+
72
+ #: admin/class-whatsappme-admin.php:182
73
+ msgid "Date Archives"
74
+ msgstr ""
75
+
76
+ #: admin/class-whatsappme-admin.php:183
77
+ msgid "Author Archives"
78
+ msgstr ""
79
+
80
+ #: admin/class-whatsappme-admin.php:184
81
+ msgid "Singular"
82
+ msgstr ""
83
+
84
+ #: admin/class-whatsappme-admin.php:185
85
+ msgid "Page"
86
+ msgstr ""
87
+
88
+ #: admin/class-whatsappme-admin.php:186
89
+ msgid "Post"
90
+ msgstr ""
91
+
92
+ #: admin/class-whatsappme-admin.php:207
93
+ msgid "Shop"
94
+ msgstr ""
95
+
96
+ #: admin/class-whatsappme-admin.php:209
97
+ msgid "Product Page"
98
+ msgstr ""
99
+
100
+ #: admin/class-whatsappme-admin.php:210
101
+ msgid "Cart"
102
+ msgstr ""
103
+
104
+ #: admin/class-whatsappme-admin.php:211
105
+ msgid "Checkout"
106
+ msgstr ""
107
+
108
+ #: admin/class-whatsappme-admin.php:212
109
+ msgid "My Account"
110
+ msgstr ""
111
+
112
+ #: admin/class-whatsappme-admin.php:235
113
+ msgid "Custom Post Types"
114
+ msgstr ""
115
+
116
+ #: admin/class-whatsappme-admin.php:272
117
+ msgid "Settings saved"
118
+ msgstr ""
119
+
120
+ #: admin/class-whatsappme-admin.php:289
121
+ msgid "General"
122
+ msgstr ""
123
+
124
+ #: admin/class-whatsappme-admin.php:290
125
+ msgid "Advanced"
126
+ msgstr ""
127
+
128
+ #: admin/class-whatsappme-admin.php:294
129
msgid ""
130
"From here you can configure the behavior of the WhatsApp button on your site."
131
msgstr ""
132
133
+ #: admin/class-whatsappme-admin.php:299
134
+ msgid ""
135
+ "From here you can configure on which pages the WhatsApp button will be "
136
+ "visible."
137
+ msgstr ""
138
+
139
+ #: admin/class-whatsappme-admin.php:300
140
+ msgid "Restore default visibility"
141
+ msgstr ""
142
+
143
+ #: admin/class-whatsappme-admin.php:325
144
msgid ""
145
"Contact phone number. <strong>The button will not be shown if it's empty."
146
"</strong>"
147
msgstr ""
148
149
+ #: admin/class-whatsappme-admin.php:335
150
msgid ""
151
"Hello 👋\n"
152
"Can we help you?"
153
msgstr ""
154
155
+ #: admin/class-whatsappme-admin.php:336
156
msgid ""
157
"<strong>Optional.</strong> Text to invite the user to use the contact via "
158
"WhatsApp."
159
msgstr ""
160
161
+ #: admin/class-whatsappme-admin.php:337
162
msgid ""
163
"You can use formatting styles like in WhatsApp: _<em>italic</em>_ *<strong>"
164
"bold</strong>* ~<del>strikethrough</del>~"
165
msgstr ""
166
167
+ #: admin/class-whatsappme-admin.php:347
168
msgid "milliseconds"
169
msgstr ""
170
171
+ #: admin/class-whatsappme-admin.php:348
172
msgid ""
173
"The <strong>Call to action</strong> will only be displayed once when the "
174
"user exceeds the estimated delay on a page. It will also be displayed when "
175
"the user stops the cursor over the WhatsApp button."
176
msgstr ""
177
178
+ #: admin/class-whatsappme-admin.php:358
179
msgid "Hi {SITE}! I need more info about {TITLE}"
180
msgstr ""
181
182
+ #: admin/class-whatsappme-admin.php:359
183
msgid "<strong>Optional.</strong> Default message to start the conversation."
184
msgstr ""
185
186
+ #: admin/class-whatsappme-admin.php:360
187
msgid ""
188
"You can use vars <code>{SITE} {URL} {TITLE}</code> that will be replaced "
189
"with the values of the current page."
190
msgstr ""
191
192
+ #: admin/class-whatsappme-admin.php:372
193
msgid "Only display the button on mobile devices"
194
msgstr ""
195
196
+ #: admin/class-whatsappme-admin.php:384
197
msgid "Right"
198
msgstr ""
199
200
+ #: admin/class-whatsappme-admin.php:386
201
msgid "Left"
202
msgstr ""
203
204
+ #: admin/class-whatsappme-admin.php:403 admin/class-whatsappme-admin.php:420
205
+ #: admin/class-whatsappme-admin.php:544
206
+ msgid "Show"
207
+ msgstr ""
208
+
209
+ #: admin/class-whatsappme-admin.php:405 admin/class-whatsappme-admin.php:422
210
+ #: admin/class-whatsappme-admin.php:546
211
+ msgid "Hide"
212
+ msgstr ""
213
+
214
+ #: admin/class-whatsappme-admin.php:424
215
+ msgid "Inherit"
216
+ msgstr ""
217
+
218
+ #: admin/class-whatsappme-admin.php:449
219
msgid "Settings"
220
msgstr ""
221
222
#. Name of the plugin
223
+ #: admin/class-whatsappme-admin.php:497
224
msgid "WhatsApp me"
225
msgstr ""
226
227
+ #: admin/class-whatsappme-admin.php:540
228
+ msgid "You can use vars <code>{SITE} {URL} {TITLE}</code>"
229
+ msgstr ""
230
+
231
+ #: admin/class-whatsappme-admin.php:548
232
+ msgid "Default visibility"
233
msgstr ""
234
235
#. Description of the theme
237
msgstr ""
238
239
#. URI of the plugin
240
+ msgid "http://wame.chat"
241
msgstr ""
242
243
#. Author of the plugin
public/class-whatsappme-public.php CHANGED
@@ -43,8 +43,9 @@ class WhatsAppMe_Public {
43
* Initialize the class and set its properties.
44
*
45
* @since 1.0.0
46
- * @param string $plugin_name The name of the plugin.
47
- * @param string $version The version of this plugin.
48
*/
49
public function __construct( $plugin_name, $version ) {
50
@@ -58,6 +59,7 @@ class WhatsAppMe_Public {
58
'message_send' => '',
59
'mobile_only' => false,
60
'position' => 'right',
61
);
62
63
}
@@ -66,6 +68,8 @@ class WhatsAppMe_Public {
66
* Get global settings and current post settings and prepare
67
*
68
* @since 1.0.0
69
*/
70
public function get_settings() {
71
@@ -82,9 +86,14 @@ class WhatsAppMe_Public {
82
// Post custom settings
83
$post_settings = is_object( $post ) ? get_post_meta( $post->ID, '_whatsappme', true ) : '';
84
85
// Prepare settings
86
$settings['telephone'] = preg_replace( '/^0+|\D/', '', $settings['telephone'] );
87
- $settings['show'] = $settings['telephone'] != '' && ! isset( $post_settings['hide'] );
88
$settings['position'] = $settings['position'] != 'left' ? 'right' : 'left';
89
$settings['mobile_only'] = $settings['mobile_only'] == 'yes';
90
if ( isset( $post_settings['message_text'] ) ) {
@@ -95,6 +104,13 @@ class WhatsAppMe_Public {
95
}
96
$settings['message_send'] = $this->formated_message_send( $settings['message_send'] );
97
98
$this->settings = $settings;
99
}
100
@@ -140,9 +156,12 @@ class WhatsAppMe_Public {
140
*/
141
public function footer_html() {
142
143
if ( $this->settings['show'] ) {
144
?>
145
- <div class="whatsappme whatsappme--<?php echo $this->settings['position']; ?>" data-settings="<?php echo esc_attr(json_encode($this->settings)); ?>">
146
<div class="whatsappme__button">
147
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M.057 24l1.687-6.163c-1.041-1.804-1.588-3.849-1.587-5.946.003-6.556 5.338-11.891 11.893-11.891 3.181.001 6.167 1.24 8.413 3.488 2.245 2.248 3.481 5.236 3.48 8.414-.003 6.557-5.338 11.892-11.893 11.892-1.99-.001-3.951-.5-5.688-1.448l-6.305 1.654zm6.597-3.807c1.676.995 3.276 1.591 5.392 1.592 5.448 0 9.886-4.434 9.889-9.885.002-5.462-4.415-9.89-9.881-9.892-5.452 0-9.887 4.434-9.889 9.884-.001 2.225.651 3.891 1.746 5.634l-.999 3.648 3.742-.981zm11.387-5.464c-.074-.124-.272-.198-.57-.347-.297-.149-1.758-.868-2.031-.967-.272-.099-.47-.149-.669.149-.198.297-.768.967-.941 1.165-.173.198-.347.223-.644.074-.297-.149-1.255-.462-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.297-.347.446-.521.151-.172.2-.296.3-.495.099-.198.05-.372-.025-.521-.075-.148-.669-1.611-.916-2.206-.242-.579-.487-.501-.669-.51l-.57-.01c-.198 0-.52.074-.792.372s-1.04 1.016-1.04 2.479 1.065 2.876 1.213 3.074c.149.198 2.095 3.2 5.076 4.487.709.306 1.263.489 1.694.626.712.226 1.36.194 1.872.118.571-.085 1.758-.719 2.006-1.413.248-.695.248-1.29.173-1.414z" fill="currentColor"/></svg>
148
</div>
@@ -234,4 +253,109 @@ class WhatsAppMe_Public {
234
return apply_filters( 'whatsappme_get_title', $title );
235
236
}
237
}
43
* Initialize the class and set its properties.
44
*
45
* @since 1.0.0
46
+ * @since 2.0.0 Added visibility setting
47
+ * @param string $plugin_name The name of the plugin.
48
+ * @param string $version The version of this plugin.
49
*/
50
public function __construct( $plugin_name, $version ) {
51
59
'message_send' => '',
60
'mobile_only' => false,
61
'position' => 'right',
62
+ 'visibility' => array( 'all' => 'yes' ),
63
);
64
65
}
68
* Get global settings and current post settings and prepare
69
*
70
* @since 1.0.0
71
+ * @since 2.0.0 Check visibility
72
+ * @return void
73
*/
74
public function get_settings() {
75
86
// Post custom settings
87
$post_settings = is_object( $post ) ? get_post_meta( $post->ID, '_whatsappme', true ) : '';
88
89
+ // Move old 'hide' to new 'view' field
90
+ if ( isset( $post_settings['hide'] ) ) {
91
+ $post_settings['view'] = 'no';
92
+ unset( $post_settings['hide'] );
93
+ }
94
+
95
// Prepare settings
96
$settings['telephone'] = preg_replace( '/^0+|\D/', '', $settings['telephone'] );
97
$settings['position'] = $settings['position'] != 'left' ? 'right' : 'left';
98
$settings['mobile_only'] = $settings['mobile_only'] == 'yes';
99
if ( isset( $post_settings['message_text'] ) ) {
104
}
105
$settings['message_send'] = $this->formated_message_send( $settings['message_send'] );
106
107
+ $settings['show'] = $settings['telephone'] != '';
108
+ if ( $settings['show'] ) {
109
+ $settings['show'] = isset( $post_settings['view'] ) ?
110
+ $post_settings['view'] == 'yes' :
111
+ $this->check_visibility( $settings['visibility'] );
112
+ }
113
+
114
$this->settings = $settings;
115
}
116
156
*/
157
public function footer_html() {
158
159
+ // Clean unnecessary settings on front
160
+ $data = array_diff_key( $this->settings, array_flip( array( 'show', 'visibility', 'position' ) ) );
161
+
162
if ( $this->settings['show'] ) {
163
?>
164
+ <div class="whatsappme whatsappme--<?php echo $this->settings['position']; ?>" data-settings="<?php echo esc_attr( json_encode( $data ) ); ?>">
165
<div class="whatsappme__button">
166
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M.057 24l1.687-6.163c-1.041-1.804-1.588-3.849-1.587-5.946.003-6.556 5.338-11.891 11.893-11.891 3.181.001 6.167 1.24 8.413 3.488 2.245 2.248 3.481 5.236 3.48 8.414-.003 6.557-5.338 11.892-11.893 11.892-1.99-.001-3.951-.5-5.688-1.448l-6.305 1.654zm6.597-3.807c1.676.995 3.276 1.591 5.392 1.592 5.448 0 9.886-4.434 9.889-9.885.002-5.462-4.415-9.89-9.881-9.892-5.452 0-9.887 4.434-9.889 9.884-.001 2.225.651 3.891 1.746 5.634l-.999 3.648 3.742-.981zm11.387-5.464c-.074-.124-.272-.198-.57-.347-.297-.149-1.758-.868-2.031-.967-.272-.099-.47-.149-.669.149-.198.297-.768.967-.941 1.165-.173.198-.347.223-.644.074-.297-.149-1.255-.462-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.297-.347.446-.521.151-.172.2-.296.3-.495.099-.198.05-.372-.025-.521-.075-.148-.669-1.611-.916-2.206-.242-.579-.487-.501-.669-.51l-.57-.01c-.198 0-.52.074-.792.372s-1.04 1.016-1.04 2.479 1.065 2.876 1.213 3.074c.149.198 2.095 3.2 5.076 4.487.709.306 1.263.489 1.694.626.712.226 1.36.194 1.872.118.571-.085 1.758-.719 2.006-1.413.248-.695.248-1.29.173-1.414z" fill="currentColor"/></svg>
167
</div>
253
return apply_filters( 'whatsappme_get_title', $title );
254
255
}
256
+
257
+ /**
258
+ * Check visibility on current page
259
+ *
260
+ * @since 2.0.0
261
+ * @param array $options array of visibility settings
262
+ * @return boolean is visible or not on current page
263
+ */
264
+ public function check_visibility($options) {
265
+
266
+ $global = isset( $options['all'] ) ? $options['all'] == 'yes' : true;
267
+
268
+ // Check front page
269
+ if ( is_front_page() ) {
270
+ return isset( $options['front_page'] ) ? $options['front_page'] == 'yes' : $global;
271
+ }
272
+
273
+ // Check blog page
274
+ if ( is_home() ) {
275
+ return isset( $options['blog_page'] ) ? $options['blog_page'] == 'yes' : $global;
276
+ }
277
+
278
+ // Check 404 page
279
+ if ( is_404() ) {
280
+ return isset( $options['404_page'] ) ? $options['404_page'] == 'yes' : $global;
281
+ }
282
+
283
+ // Check WooCommerce
284
+ if ( class_exists( 'WooCommerce' ) ) {
285
+ $woo = isset( $options['woocommerce'] ) ? $options['woocommerce'] == 'yes' : $global;
286
+
287
+ // Product page
288
+ if ( is_product() ) {
289
+ return isset( $options['product'] ) ? $options['product'] == 'yes' : $woo;
290
+ }
291
+
292
+ // Cart page
293
+ if ( is_cart() ) {
294
+ return isset( $options['cart'] ) ? $options['cart'] == 'yes' : $woo;
295
+ }
296
+
297
+ // Checkout page
298
+ if ( is_checkout() ) {
299
+ return isset( $options['checkout'] ) ? $options['checkout'] == 'yes' : $woo;
300
+ }
301
+
302
+ // Customer account pages
303
+ if ( is_account_page() ) {
304
+ return isset( $options['account_page'] ) ? $options['account_page'] == 'yes': $woo;
305
+ }
306
+
307
+ if ( is_woocommerce() ) {
308
+ return $woo;
309
+ }
310
+ }
311
+
312
+ // Check Custom Post Types
313
+ $cpts = array_filter( $options, function($k){ return substr( $k, 0, 4 ) == 'cpt_'; }, ARRAY_FILTER_USE_KEY );
314
+
315
+ foreach ($cpts as $cpt => $view) {
316
+ $cpt = substr( $cpt, 4 );
317
+ if ( is_singular( $cpt ) || is_post_type_archive( $cpt) ) {
318
+ return $view == 'yes';
319
+ }
320
+ }
321
+
322
+ // Search results
323
+ if ( is_search() ) {
324
+ return isset( $options['search'] ) ? $options['search'] == 'yes' : $global;
325
+ }
326
+
327
+ // Check archives
328
+ if ( is_archive() ) {
329
+
330
+ // Date archive
331
+ if ( isset( $options['date'] ) && is_date() ) {
332
+ return $options['date'] == 'yes';
333
+ }
334
+
335
+ // Author archive
336
+ if ( isset( $options['author'] ) && is_author() ) {
337
+ return $options['author'] == 'yes';
338
+ }
339
+
340
+ return isset( $options['archive'] ) ? $options['archive'] == 'yes' : $global;
341
+ }
342
+
343
+ // Check singular
344
+ if ( is_singular() ) {
345
+
346
+ // Page
347
+ if ( isset( $options['page'] ) && is_page() ) {
348
+ return $options['page'] == 'yes';
349
+ }
350
+
351
+ // Post (or other custom posts)
352
+ if ( isset( $options['post'] ) && is_single() ) {
353
+ return $options['post'] == 'yes';
354
+ }
355
+
356
+ return isset( $options['singular'] ) ? $options['singular'] == 'yes' : $global;
357
+ }
358
+
359
+ return $global;
360
+ }
361
}
public/css/whatsappme.css CHANGED
@@ -69,8 +69,12 @@
69
}
70
71
.whatsappme__header {
72
height: 70px;
73
padding: 0 26px;
74
background-color: #2e8c7d;
75
color: rgba(255, 255, 255, .5);
76
}
69
}
70
71
.whatsappme__header {
72
+ display: block;
73
+ position: static;
74
+ width: 100%;
75
height: 70px;
76
padding: 0 26px;
77
+ margin: 0;
78
background-color: #2e8c7d;
79
color: rgba(255, 255, 255, .5);
80
}
whatsappme.php CHANGED
@@ -7,9 +7,9 @@
7
*
8
* @wordpress-plugin
9
* Plugin Name: WhatsApp me
10
- * Plugin URI: https://crea.me/productos/whatsapp-me/
11
* Description: Add support to your clients directly with WhatsApp.
12
- * Version: 1.4.3
13
* Author: Creame
14
* Author URI: https://crea.me
15
* License: GPL-2.0+
@@ -27,7 +27,7 @@ if ( ! defined( 'WPINC' ) ) {
27
* Currently plugin version.
28
* Start at version 1.0.0 and use SemVer - https://semver.org
29
*/
30
- define( 'WHATSAPPME_VERSION', '1.4.3' );
31
32
/**
33
* The core plugin class that is used to define internationalization,
7
*
8
* @wordpress-plugin
9
* Plugin Name: WhatsApp me
10
+ * Plugin URI: http://wame.chat
11
* Description: Add support to your clients directly with WhatsApp.
12
+ * Version: 2.0.0
13
* Author: Creame
14
* Author URI: https://crea.me
15
* License: GPL-2.0+
27
* Currently plugin version.
28
* Start at version 1.0.0 and use SemVer - https://semver.org
29
*/
30
+ define( 'WHATSAPPME_VERSION', '2.0.0' );
31
32
/**
33
* The core plugin class that is used to define internationalization,