WhatsApp me - Version 1.1.0

Version Description

  • Added posts/pages option to override CTA or hide button
  • Don't enqueue assets if not show button
  • Added filters for developers
Download this release

Release Info

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

Code changes from version 1.0.3 to 1.1.0

README.txt CHANGED
@@ -4,7 +4,7 @@ Tags: whatsapp, button, chat, support, contact
4
Requires at least: 3.0.1
5
Tested up to: 4.9.2
6
Requires PHP: 5.3
7
- Stable tag: 1.0.3
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -23,10 +23,11 @@ WhatsApp is used in more than 100 countries and supports more than 50 languages.
23
24
Options:
25
1. Phone: Enter the phone number.
26
- 1. Mobile only: Select if you want the button to be visible only on mobile devices. WhatsApp Web/App will open on the desktop (if available).
27
- 1. Call to action: Write a message to encourage users to contact you through WhatsApp.
28
- 1. Delay: You can define a timeout to display the call-to-action message.
29
- 1. If you have Google Analytics, an event is triggered when the user launches WhatsApp.
30
31
== Installation ==
32
@@ -42,6 +43,11 @@ Options:
42
43
== Changelog ==
44
45
= 1.0.3 =
46
* Readme texts
47
4
Requires at least: 3.0.1
5
Tested up to: 4.9.2
6
Requires PHP: 5.3
7
+ Stable tag: 1.1.0
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
23
24
Options:
25
1. Phone: Enter the phone number.
26
+ 2. Mobile only: Select if you want the button to be visible only on mobile devices. WhatsApp Web/App will open on the desktop (if available).
27
+ 3. Call to action: Write a message to encourage users to contact you through WhatsApp.
28
+ 4. Delay: You can define a timeout to display the call-to-action message.
29
+ 5. If you have Google Analytics, an event is triggered when the user launches WhatsApp.
30
+ 6. Can override call to action or hide button on every post, page or custom post.
31
32
== Installation ==
33
43
44
== Changelog ==
45
46
+ = 1.1.0 =
47
+ * Added posts/pages option to override CTA or hide button
48
+ * Don't enqueue assets if not show button
49
+ * Added filters for developers
50
+
51
= 1.0.3 =
52
* Readme texts
53
admin/class-whatsappme-admin.php CHANGED
@@ -106,7 +106,7 @@ class WhatsAppMe_Admin {
106
}
107
108
/**
109
- * Validate settings, claen and set defaults before save
110
*
111
* @since 1.0.0
112
* @return array
@@ -230,4 +230,90 @@ class WhatsAppMe_Admin {
230
</div>
231
<?php
232
}
233
}
106
}
107
108
/**
109
+ * Validate settings, clean and set defaults before save
110
*
111
* @since 1.0.0
112
* @return array
230
</div>
231
<?php
232
}
233
+
234
+ /**
235
+ * Add Meta Box for all the public post types
236
+ *
237
+ * @since 1.1.0
238
+ * @access public
239
+ * @return void
240
+ */
241
+ public function add_meta_boxes() {
242
+ // Default post types
243
+ $builtin_post_types = array( 'post', 'page' );
244
+ // Custom post types with public url
245
+ $custom_post_types = array_keys( get_post_types( array( 'rewrite' => true ), 'names' ) );
246
+
247
+ // Add/remove posts types for "WhatsApp me" meta box
248
+ $post_types = apply_filters( 'whatsappme_post_types_meta_box', array_merge( $builtin_post_types, $custom_post_types ) );
249
+
250
+ foreach ( $post_types as $post_type ) {
251
+ add_meta_box(
252
+ 'whatsappme',
253
+ __( 'WhatsApp me', 'creame-whatsapp-me' ),
254
+ array( $this, 'add_meta_box' ),
255
+ $post_type,
256
+ 'side',
257
+ 'default'
258
+ );
259
+ }
260
+ }
261
+
262
+ /**
263
+ * Generate Meta Box html
264
+ *
265
+ * @since 1.1.0
266
+ * @access public
267
+ * @return void
268
+ */
269
+ public function add_meta_box( $post ) {
270
+
271
+ $metadata = get_post_meta( $post->ID, '_whatsappme', true ) ?: array();
272
+ $metadata = array_merge( array(
273
+ 'message_text' => '',
274
+ 'hide' => false
275
+ ), $metadata );
276
+
277
+ $post_type = get_post_type_object( get_post_type( $post->ID ) );
278
+ $post_type_name = mb_strtolower( $post_type->labels->singular_name );
279
+
280
+ wp_nonce_field( 'whatsappme_data', 'whatsappme_nonce' );
281
+ ?>
282
+ <p>
283
+ <label for="whatsappme_message"><?php _e( 'Call to action', 'creame-whatsapp-me' ); ?></label><br>
284
+ <textarea name="whatsappme_message" rows="3" class="large-text"><?php echo $metadata['message_text']; ?></textarea>
285
+ </p>
286
+ <p>
287
+ <input type="checkbox" name="whatsappme_hide" id="whatsappme_hide" value="1" <?php echo $metadata['hide'] ? 'checked' : ''; ?>>
288
+ <label for="whatsappme_hide"><?php printf( __( 'Hide on this %s', 'creame-whatsapp-me' ), $post_type_name ); ?></label>
289
+ </p>
290
+ <?php
291
+ }
292
+
293
+ /**
294
+ * Save meta data from "WhatsApp me" Meta Box on post save
295
+ *
296
+ * @since 1.1.0
297
+ * @access public
298
+ * @return void
299
+ */
300
+ public function save_post( $post_id ) {
301
+ if ( wp_is_post_autosave( $post_id ) ||
302
+ ! isset( $_POST['whatsappme_nonce'] ) ||
303
+ ! wp_verify_nonce( $_POST['whatsappme_nonce'], 'whatsappme_data' ) ) {
304
+ return;
305
+ }
306
+
307
+ // Delete empty/false fields
308
+ $metadata = array_filter( array(
309
+ 'message_text' => trim( $_POST['whatsappme_message'] ),
310
+ 'hide' => isset( $_POST['whatsappme_hide'] ) ? 1 : 0,
311
+ ) );
312
+
313
+ if ( count( $metadata ) ) {
314
+ update_post_meta( $post_id, '_whatsappme', $metadata );
315
+ } else {
316
+ delete_post_meta( $post_id, '_whatsappme' );
317
+ }
318
+ }
319
}
includes/class-whatsappme.php CHANGED
@@ -125,6 +125,8 @@ class WhatsAppMe {
125
126
$this->loader->add_action( 'admin_init', $plugin_admin, 'settings_init' );
127
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu' );
128
129
$this->loader->add_filter( "plugin_action_links_creame-whatsapp-me/{$this->plugin_name}.php", $plugin_admin, 'settings_link' );
130
@@ -141,6 +143,7 @@ class WhatsAppMe {
141
142
$plugin_public = new WhatsAppMe_Public( $this->get_plugin_name(), $this->get_version() );
143
144
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
145
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
146
$this->loader->add_action( 'wp_footer', $plugin_public, 'footer_html' );
125
126
$this->loader->add_action( 'admin_init', $plugin_admin, 'settings_init' );
127
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu' );
128
+ $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'add_meta_boxes' );
129
+ $this->loader->add_action( 'save_post', $plugin_admin, 'save_post' );
130
131
$this->loader->add_filter( "plugin_action_links_creame-whatsapp-me/{$this->plugin_name}.php", $plugin_admin, 'settings_link' );
132
143
144
$plugin_public = new WhatsAppMe_Public( $this->get_plugin_name(), $this->get_version() );
145
146
+ $this->loader->add_action( 'wp', $plugin_public, 'get_settings' );
147
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
148
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
149
$this->loader->add_action( 'wp_footer', $plugin_public, 'footer_html' );
languages/creame-whatsapp-me-es_ES.mo CHANGED
Binary file
languages/creame-whatsapp-me-es_ES.po CHANGED
@@ -5,7 +5,7 @@ msgid ""
5
msgstr ""
6
"Project-Id-Version: WhatsApp me\n"
7
"Report-Msgid-Bugs-To: Translator Name <translations@example.com>\n"
8
- "POT-Creation-Date: 2018-02-12 19:16+0100\n"
9
"PO-Revision-Date: \n"
10
"Last-Translator: Pacotole <pacotole@crea.me>\n"
11
"Language-Team: Creame <hola@crea.me>\n"
@@ -31,7 +31,7 @@ msgstr "Teléfono"
31
msgid "Mobile only"
32
msgstr "Solo Móvil"
33
34
- #: admin/class-whatsappme-admin.php:99
35
msgid "Call to action"
36
msgstr "Llamada a la acción"
37
@@ -89,9 +89,15 @@ msgid "Settings"
89
msgstr "Ajustes"
90
91
#. Name of the plugin
92
msgid "WhatsApp me"
93
msgstr "WhatsApp me"
94
95
#. Description of the theme
96
msgid "Add support to your clients directly with WhatsApp."
97
msgstr "Da soporte a tus clientes directamente con WhatsApp."
5
msgstr ""
6
"Project-Id-Version: WhatsApp me\n"
7
"Report-Msgid-Bugs-To: Translator Name <translations@example.com>\n"
8
+ "POT-Creation-Date: 2018-02-20 12:21+0100\n"
9
"PO-Revision-Date: \n"
10
"Last-Translator: Pacotole <pacotole@crea.me>\n"
11
"Language-Team: Creame <hola@crea.me>\n"
31
msgid "Mobile only"
32
msgstr "Solo Móvil"
33
34
+ #: admin/class-whatsappme-admin.php:99 admin/class-whatsappme-admin.php:280
35
msgid "Call to action"
36
msgstr "Llamada a la acción"
37
89
msgstr "Ajustes"
90
91
#. Name of the plugin
92
+ #: admin/class-whatsappme-admin.php:253
93
msgid "WhatsApp me"
94
msgstr "WhatsApp me"
95
96
+ #: admin/class-whatsappme-admin.php:285
97
+ #, php-format
98
+ msgid "Hide on this %s"
99
+ msgstr "Ocultar en este %s"
100
+
101
#. Description of the theme
102
msgid "Add support to your clients directly with WhatsApp."
103
msgstr "Da soporte a tus clientes directamente con WhatsApp."
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-02-12 18:14+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"
@@ -10,7 +10,7 @@ msgstr ""
10
"MIME-Version: 1.0\n"
11
"Content-Type: text/plain; charset=UTF-8\n"
12
"Content-Transfer-Encoding: 8bit\n"
13
- "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION\n"
14
"X-Textdomain-Support: yesX-Generator: Poedit 1.6.4\n"
15
"X-Poedit-SourceCharset: UTF-8\n"
16
"X-Poedit-KeywordsList: __;_e;esc_html_e;esc_html_x:1,2c;esc_html__;"
@@ -18,7 +18,7 @@ msgstr ""
18
"1,2c;_n:1,2;_n_noop:1,2;__ngettext:1,2;__ngettext_noop:1,2;_c,_nc:4c,1,2\n"
19
"X-Poedit-Basepath: ..\n"
20
"Language: \n"
21
- "X-Generator: Loco - https://localise.biz/\n"
22
"X-Poedit-SearchPath-0: ."
23
24
#: admin/class-whatsappme-admin.php:97
@@ -29,7 +29,7 @@ msgstr ""
29
msgid "Mobile only"
30
msgstr ""
31
32
- #: admin/class-whatsappme-admin.php:99
33
msgid "Call to action"
34
msgstr ""
35
@@ -78,9 +78,15 @@ msgid "Settings"
78
msgstr ""
79
80
#. Name of the plugin
81
msgid "WhatsApp me"
82
msgstr ""
83
84
#. Description of the theme
85
msgid "Add support to your clients directly with WhatsApp."
86
msgstr ""
2
msgid ""
3
msgstr ""
4
"Project-Id-Version: WhatsApp Me\n"
5
+ "POT-Creation-Date: 2018-02-20 11: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"
10
"MIME-Version: 1.0\n"
11
"Content-Type: text/plain; charset=UTF-8\n"
12
"Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
14
"X-Textdomain-Support: yesX-Generator: Poedit 1.6.4\n"
15
"X-Poedit-SourceCharset: UTF-8\n"
16
"X-Poedit-KeywordsList: __;_e;esc_html_e;esc_html_x:1,2c;esc_html__;"
18
"1,2c;_n:1,2;_n_noop:1,2;__ngettext:1,2;__ngettext_noop:1,2;_c,_nc:4c,1,2\n"
19
"X-Poedit-Basepath: ..\n"
20
"Language: \n"
21
+ "X-Generator: Loco https://localise.biz/\n"
22
"X-Poedit-SearchPath-0: ."
23
24
#: admin/class-whatsappme-admin.php:97
29
msgid "Mobile only"
30
msgstr ""
31
32
+ #: admin/class-whatsappme-admin.php:99 admin/class-whatsappme-admin.php:280
33
msgid "Call to action"
34
msgstr ""
35
78
msgstr ""
79
80
#. Name of the plugin
81
+ #: admin/class-whatsappme-admin.php:253
82
msgid "WhatsApp me"
83
msgstr ""
84
85
+ #: admin/class-whatsappme-admin.php:285
86
+ #, php-format
87
+ msgid "Hide on this %s"
88
+ msgstr ""
89
+
90
#. Description of the theme
91
msgid "Add support to your clients directly with WhatsApp."
92
msgstr ""
public/class-whatsappme-public.php CHANGED
@@ -50,33 +50,53 @@ class WhatsAppMe_Public {
50
51
$this->plugin_name = $plugin_name;
52
$this->version = $version;
53
- $this->get_settings();
54
55
}
56
57
/**
58
- * Get all settings or set defaults
59
*
60
* @since 1.0.0
61
*/
62
- private function get_settings() {
63
64
- $this->settings = array(
65
- 'telephone' => '',
66
- 'message_text' => '',
67
- 'message_delay' => 10000,
68
- 'mobile_only' => 'no',
69
- );
70
71
- $saved_settings = get_option( 'whatsappme' );
72
73
- if ( is_array( $saved_settings ) ) {
74
- // clean unused saved settings
75
- $saved_settings = array_intersect_key( $saved_settings, $this->settings );
76
- // merge defaults with saved settings
77
- $this->settings = array_merge( $this->settings, $saved_settings );
78
}
79
80
}
81
82
/**
@@ -86,7 +106,9 @@ class WhatsAppMe_Public {
86
*/
87
public function enqueue_styles() {
88
89
- wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/whatsappme.css', array(), $this->version, 'all' );
90
91
}
92
@@ -97,7 +119,9 @@ class WhatsAppMe_Public {
97
*/
98
public function enqueue_scripts() {
99
100
- wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/whatsappme.js', array( 'jquery' ), $this->version, false );
101
102
}
103
@@ -108,7 +132,7 @@ class WhatsAppMe_Public {
108
*/
109
public function footer_html() {
110
111
- if ( $this->settings['telephone']) {
112
?>
113
<div class="whatsappme" data-settings="<?php echo esc_attr(json_encode($this->settings)); ?>">
114
<div class="whatsappme__button">
@@ -128,4 +152,5 @@ class WhatsAppMe_Public {
128
}
129
130
}
131
}
50
51
$this->plugin_name = $plugin_name;
52
$this->version = $version;
53
+ $this->settings = array(
54
+ 'show' => false,
55
+ 'telephone' => '',
56
+ 'message_text' => '',
57
+ 'message_delay' => 10000,
58
+ 'mobile_only' => false,
59
+ );
60
61
}
62
63
/**
64
+ * Get global settings and current post settings and prepare
65
*
66
* @since 1.0.0
67
*/
68
+ public function get_settings() {
69
70
+ global $post;
71
+
72
+ $global_settings = get_option( 'whatsappme' );
73
+
74
+ if ( is_array( $global_settings ) ) {
75
+ // Clean unused saved settings
76
+ $settings = array_intersect_key( $global_settings, $this->settings );
77
+ // Merge defaults with saved settings
78
+ $settings = array_merge( $this->settings, $settings );
79
80
+ // Post custom settings
81
+ $post_settings = get_post_meta( $post->ID, '_whatsappme', true ) ?: array();
82
83
+ // Prepare settings
84
+ $settings['show'] = $settings['telephone'] != '' && ! isset( $post_settings['hide'] );
85
+ $settings['mobile_only'] = $settings['mobile_only'] == 'yes';
86
+ if ( isset( $post_settings['message_text'] ) ) {
87
+ $settings['message_text'] = $post_settings['message_text'];
88
+ }
89
+
90
+ $this->settings = $settings;
91
}
92
93
+ // Apply filter to settings
94
+ $this->settings = apply_filters( 'whatsappme_get_settings', $this->settings, $post );
95
+
96
+ // Ensure not show if not phone
97
+ if ( ! $this->settings['telephone'] ) {
98
+ $this->settings['show'] = false;
99
+ }
100
}
101
102
/**
106
*/
107
public function enqueue_styles() {
108
109
+ if ( $this->settings['show'] ) {
110
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/whatsappme.css', array(), $this->version, 'all' );
111
+ }
112
113
}
114
119
*/
120
public function enqueue_scripts() {
121
122
+ if ( $this->settings['show'] ) {
123
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/whatsappme.js', array( 'jquery' ), $this->version, false );
124
+ }
125
126
}
127
132
*/
133
public function footer_html() {
134
135
+ if ( $this->settings['show'] ) {
136
?>
137
<div class="whatsappme" data-settings="<?php echo esc_attr(json_encode($this->settings)); ?>">
138
<div class="whatsappme__button">
152
}
153
154
}
155
+
156
}
public/js/whatsappme.js CHANGED
@@ -21,7 +21,7 @@
21
localStorage.whatsappme_views = views;
22
23
// show button / dialog
24
- if (settings.mobile_only == 'no' || is_mobile) {
25
setTimeout(function () {
26
$whatsappme.addClass('whatsappme--show');
27
}, delay_on_start);
21
localStorage.whatsappme_views = views;
22
23
// show button / dialog
24
+ if (!settings.mobile_only || is_mobile) {
25
setTimeout(function () {
26
$whatsappme.addClass('whatsappme--show');
27
}, delay_on_start);
whatsappme.php CHANGED
@@ -9,7 +9,7 @@
9
* Plugin Name: WhatsApp me
10
* Plugin URI: https://github.com/creame/whatsappme
11
* Description: Add support to your clients directly with WhatsApp.
12
- * Version: 1.0.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.0.3' );
31
32
/**
33
* The core plugin class that is used to define internationalization,
9
* Plugin Name: WhatsApp me
10
* Plugin URI: https://github.com/creame/whatsappme
11
* Description: Add support to your clients directly with WhatsApp.
12
+ * Version: 1.1.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', '1.1.0' );
31
32
/**
33
* The core plugin class that is used to define internationalization,