Skip to content

Commit

Permalink
Updated to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pacotole committed Feb 20, 2018
1 parent 293d3e8 commit 3c34ae6
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 171 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Si dispones de Google Analytics se dispara un evento cuando el usuario lanza Wha

## Changelog

- **v 1.1.0** Added Custom CTA or hide on every post/page.
- **v 1.0.0** First version
59 changes: 37 additions & 22 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
=== WhatsApp Me ===
Contributors: creapuntome, pacotole
=== WhatsApp me ===
Contributors: creapuntome, pacotole, davidlillo
Tags: whatsapp, button, chat, support, contact
Requires at least: 3.0.1
Tested up to: 4.9.2
Requires PHP: 5.3
Stable tag: 1.0.0
Stable tag: 1.1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Add support to your visitors directly with WhatsApp.

== Description ==

## EN
Include a direct link to your WhatsApp profile on the web to support your users.
### The perfect plugin to engage and retain customers.

Options:
- **Phone number**
- **Only on mobile**, on the desktop you will open WhatsApp Web (if available).
- **Call to Action**, write a message to encourage users to contact you through WhatsApp
- **Delay**, you can define a timeout to show the call-to-action message
#### Communication with your customers can be very easy

If you have Google Analytics, an event is triggered when the user launches WhatsApp.
With **WhatsApp me** you will get the visitors of your website to contact you through WhatsApp with a single click.

## ES
Incluye en la web un enlace directo a tu perfil de WhastApp para dar soporte a tus usuarios.
#### Why WhatsApp?
WhatsApp is used in more than 100 countries and supports more than 50 languages. Recent surveys say that 96% of users prefer to use a *messaging app* before calling by phone. If none of this has convinced you, think one thing, your grandmother knows how to use WhatsApp. Do not lose more customers and sales. Try **WhatsApp me**.

Opciones:
Options:
1. Phone: Enter the phone number.
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).
3. Call to action: Write a message to encourage users to contact you through WhatsApp.
4. Delay: You can define a timeout to display the call-to-action message.
5. If you have Google Analytics, an event is triggered when the user launches WhatsApp.
6. Can override call to action or hide button on every post, page or custom post.

- **Teléfono**
- **Solo en móviles**, en el escritorio se abrirá WhastApp Web (si está disponible)
- **Llamada a la acción**, escribe un mensaje para animar a los usuarios a contactar a través de WhatsApp
- **Retardo**, puedes definir un tiempo de espera para mostrar el mensaje de llamada a la acción
== Installation ==

Si dispones de Google Analytics se dispara un evento cuando el usuario lanza WhatsApp.
1. Upload the entire `creame-whatsapp-me` folder to the `/wp-content/plugins/` directory.
1. Activate the plugin through the 'Plugins' menu in WordPress.

== Installation ==
== Screenshots ==

1. Upload the entire `whatsappme` folder to the `/wp-content/plugins/` directory.
2. Activate the plugin through the 'Plugins' menu in WordPress.
1. WhatsApp me settings.
2. Button on desktop.
3. Call to action on desktop.
4. Button and call to action on mobile.

== Changelog ==

= 1.1.0 =
* Added posts/pages option to override CTA or hide button
* Don't enqueue assets if not show button
* Added filters for developers

= 1.0.3 =
* Readme texts

= 1.0.2 =
* Fix plugin version

= 1.0.1 =
* Fix text domain

= 1.0.0 =
* First version
119 changes: 102 additions & 17 deletions admin/class-whatsappme-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public function settings_init(){
add_settings_section( 'whatsappme_section', null, array( $this, 'section_text' ), 'whatsappme' );

$field_names = array(
'telephone' => __( 'Telephone', 'whatsappme' ),
'mobile_only' => __( 'Only mobile', 'whatsappme' ),
'message_text' => __( 'Call to action', 'whatsappme' ),
'message_delay' => __( 'Delay', 'whatsappme' ),
'telephone' => __( 'Telephone', 'creame-whatsapp-me' ),
'mobile_only' => __( 'Mobile only', 'creame-whatsapp-me' ),
'message_text' => __( 'Call to action', 'creame-whatsapp-me' ),
'message_delay' => __( 'Delay', 'creame-whatsapp-me' ),
);

foreach ( $this->settings as $key => $value ) {
Expand All @@ -106,7 +106,7 @@ public function settings_init(){
}

/**
* Validate settings, claen and set defaults before save
* Validate settings, clean and set defaults before save
*
* @since 1.0.0
* @return array
Expand All @@ -120,7 +120,7 @@ public function settings_validate($input) {
$input['message_text'] = trim($input['message_text']);
$input['message_delay'] = intval($input['message_delay']);

add_settings_error( 'whatsappme', 'settings_updated', __( 'Settings saved', 'whatsappme' ), 'updated' );
add_settings_error( 'whatsappme', 'settings_updated', __( 'Settings saved', 'creame-whatsapp-me' ), 'updated' );

return $input;
}
Expand All @@ -132,7 +132,7 @@ public function settings_validate($input) {
* @return void
*/
public function section_text() {
echo '<p>' . __( 'From here you can configure the behavior of the WhatsApp button on your site.', 'whatsappme' ) . '</p>';
echo '<p>' . __( 'From here you can configure the behavior of the WhatsApp button on your site.', 'creame-whatsapp-me' ) . '</p>';
}

/**
Expand All @@ -143,7 +143,7 @@ public function section_text() {
*/
public function field_telephone() {
echo '<input name="whatsappme[telephone]" value="' . $this->settings['telephone'] . '" class="regular-text" type="text">' .
'<p class="description">' . __( "Contact phone number. <strong>The button will not be shown if it's empty.</strong>", 'whatsappme' ) . '</p>';
'<p class="description">' . __( "Contact phone number. <strong>The button will not be shown if it's empty.</strong>", 'creame-whatsapp-me' ) . '</p>';
}

/**
Expand All @@ -154,7 +154,7 @@ public function field_telephone() {
*/
public function field_message_text() {
echo '<textarea name="whatsappme[message_text]" rows="3" class="regular-text">' . $this->settings['message_text'] . '</textarea>' .
'<p class="description">' . __( 'Optional text to invite the user to use the contact via WhatsApp. <strong>Leave empty to disable.</strong>', 'whatsappme' ) . '</p>';
'<p class="description">' . __( 'Optional text to invite the user to use the contact via WhatsApp. <strong>Leave empty to disable.</strong>', 'creame-whatsapp-me' ) . '</p>';
}

/**
Expand All @@ -164,9 +164,8 @@ public function field_message_text() {
* @return void
*/
public function field_message_delay() {
echo '<input name="whatsappme[message_delay]" value="' . $this->settings['message_delay'] . '" class="small-text" type="number" min="0"> ' . __( 'milliseconds', 'whatsappme' ) .
'<p class="description"> ' . __( 'The <strong>Call to action</strong> will only be displayed once when the user exceeds the estimated delay on a page. ' .
'It will also be displayed when the user stops the cursor over the WhatsApp button.', 'whatsappme' ) . '</p>';
echo '<input name="whatsappme[message_delay]" value="' . $this->settings['message_delay'] . '" class="small-text" type="number" min="0"> ' . __( 'milliseconds', 'creame-whatsapp-me' ) .
'<p class="description"> ' . __( 'The <strong>Call to action</strong> will only be displayed once when the user exceeds the estimated delay on a page. It will also be displayed when the user stops the cursor over the WhatsApp button.', 'creame-whatsapp-me' ) . '</p>';
}

/**
Expand All @@ -176,9 +175,9 @@ public function field_message_delay() {
* @return void
*/
public function field_mobile_only() {
echo '<fieldset><legend class="screen-reader-text"><span>Solo móvil</span></legend>' .
echo '<fieldset><legend class="screen-reader-text"><span>' . __( 'Mobile only', 'creame-whatsapp-me' ) . '</span></legend>' .
'<label><input name="whatsappme[mobile_only]" value="yes" type="checkbox"' . checked( 'yes', $this->settings['mobile_only'], false ) . '> ' .
__('Only display the button on mobile devices', 'whatsappme' ) . '</label></fieldset>';
__('Only display the button on mobile devices', 'creame-whatsapp-me' ) . '</label></fieldset>';
}

/**
Expand All @@ -190,7 +189,7 @@ public function field_mobile_only() {
*/
public function add_menu() {

add_options_page('WhatsApp Me', 'WhatsApp Me', 'manage_options', 'whatsappme', array( $this, 'options_page' ));
add_options_page('WhatsApp me', 'WhatsApp me', 'manage_options', 'whatsappme', array( $this, 'options_page' ));

}

Expand All @@ -203,7 +202,7 @@ public function add_menu() {
*/
public function settings_link( $links ) {

$settings_link = '<a href="options-general.php?page=' . $this->plugin_name . '">' . __( 'Settings', 'whatsappme' ) . '</a>';
$settings_link = '<a href="options-general.php?page=' . $this->plugin_name . '">' . __( 'Settings', 'creame-whatsapp-me' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;

Expand All @@ -219,7 +218,7 @@ public function settings_link( $links ) {
function options_page() {
?>
<div class="wrap">
<h1>WhatsApp Me</h1>
<h1>WhatsApp me</h1>

<form method="post" id="whatsappme_form" action="options.php">
<?php
Expand All @@ -231,4 +230,90 @@ function options_page() {
</div>
<?php
}

/**
* Add Meta Box for all the public post types
*
* @since 1.1.0
* @access public
* @return void
*/
public function add_meta_boxes() {
// Default post types
$builtin_post_types = array( 'post', 'page' );
// Custom post types with public url
$custom_post_types = array_keys( get_post_types( array( 'rewrite' => true ), 'names' ) );

// Add/remove posts types for "WhatsApp me" meta box
$post_types = apply_filters( 'whatsappme_post_types_meta_box', array_merge( $builtin_post_types, $custom_post_types ) );

foreach ( $post_types as $post_type ) {
add_meta_box(
'whatsappme',
__( 'WhatsApp me', 'creame-whatsapp-me' ),
array( $this, 'add_meta_box' ),
$post_type,
'side',
'default'
);
}
}

/**
* Generate Meta Box html
*
* @since 1.1.0
* @access public
* @return void
*/
public function add_meta_box( $post ) {

$metadata = get_post_meta( $post->ID, '_whatsappme', true ) ?: array();
$metadata = array_merge( array(
'message_text' => '',
'hide' => false
), $metadata );

$post_type = get_post_type_object( get_post_type( $post->ID ) );
$post_type_name = mb_strtolower( $post_type->labels->singular_name );

wp_nonce_field( 'whatsappme_data', 'whatsappme_nonce' );
?>
<p>
<label for="whatsappme_message"><?php _e( 'Call to action', 'creame-whatsapp-me' ); ?></label><br>
<textarea name="whatsappme_message" rows="3" class="large-text"><?php echo $metadata['message_text']; ?></textarea>
</p>
<p>
<input type="checkbox" name="whatsappme_hide" id="whatsappme_hide" value="1" <?php echo $metadata['hide'] ? 'checked' : ''; ?>>
<label for="whatsappme_hide"><?php printf( __( 'Hide on this %s', 'creame-whatsapp-me' ), $post_type_name ); ?></label>
</p>
<?php
}

/**
* Save meta data from "WhatsApp me" Meta Box on post save
*
* @since 1.1.0
* @access public
* @return void
*/
public function save_post( $post_id ) {
if ( wp_is_post_autosave( $post_id ) ||
! isset( $_POST['whatsappme_nonce'] ) ||
! wp_verify_nonce( $_POST['whatsappme_nonce'], 'whatsappme_data' ) ) {
return;
}

// Delete empty/false fields
$metadata = array_filter( array(
'message_text' => trim( $_POST['whatsappme_message'] ),
'hide' => isset( $_POST['whatsappme_hide'] ) ? 1 : 0,
) );

if ( count( $metadata ) ) {
update_post_meta( $post_id, '_whatsappme', $metadata );
} else {
delete_post_meta( $post_id, '_whatsappme' );
}
}
}
2 changes: 1 addition & 1 deletion includes/class-whatsappme-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class WhatsAppMe_i18n {
public function load_plugin_textdomain() {

load_plugin_textdomain(
'whatsappme',
'creame-whatsapp-me',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);
Expand Down
5 changes: 4 additions & 1 deletion includes/class-whatsappme.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ private function define_admin_hooks() {

$this->loader->add_action( 'admin_init', $plugin_admin, 'settings_init' );
$this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu' );
$this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'add_meta_boxes' );
$this->loader->add_action( 'save_post', $plugin_admin, 'save_post' );

$this->loader->add_filter( "plugin_action_links_{$this->plugin_name}/{$this->plugin_name}.php", $plugin_admin, 'settings_link' );
$this->loader->add_filter( "plugin_action_links_creame-whatsapp-me/{$this->plugin_name}.php", $plugin_admin, 'settings_link' );

}

Expand All @@ -141,6 +143,7 @@ private function define_public_hooks() {

$plugin_public = new WhatsAppMe_Public( $this->get_plugin_name(), $this->get_version() );

$this->loader->add_action( 'wp', $plugin_public, 'get_settings' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
$this->loader->add_action( 'wp_footer', $plugin_public, 'footer_html' );
Expand Down
Binary file added languages/creame-whatsapp-me-es_ES.mo
Binary file not shown.
Loading

0 comments on commit 3c34ae6

Please sign in to comment.