-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cf7120a
Showing
14 changed files
with
464 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?php | ||
|
||
// If this file is called directly, abort. | ||
if ( ! defined( 'WPINC' ) ) { | ||
die; | ||
} | ||
|
||
class Open_Whatsapp_Chat_Settings { | ||
/** | ||
* Holds the values to be used in the fields callbacks | ||
*/ | ||
private $options; | ||
|
||
/** | ||
* Start up | ||
*/ | ||
public function __construct() { | ||
add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); | ||
add_action( 'admin_init', array( $this, 'page_init' ) ); | ||
} | ||
|
||
/** | ||
* Add options page | ||
*/ | ||
public function add_plugin_page() { | ||
// This page will be under "Settings" | ||
add_options_page( | ||
__( 'Settings Admin', 'open-whatsapp-chat' ), | ||
'Open WhatsApp Chat', | ||
'manage_options', | ||
'open-whatsapp-chat', | ||
array( $this, 'create_admin_page' ) | ||
); | ||
} | ||
|
||
/** | ||
* Options page callback | ||
*/ | ||
public function create_admin_page() { | ||
// Set class property | ||
$this->options = get_option( 'owc_option' ); | ||
?> | ||
<div class="wrap owc-settings-wrap"> | ||
<h1><?php _e( 'Open WhatsApp Chat Plugin Settings', 'open-whatsapp-chat' ); ?></h1> | ||
<form method="post" action="options.php"> | ||
<?php | ||
// This prints out all hidden setting fields | ||
settings_fields( 'owc_option_group' ); | ||
do_settings_sections( 'open-whatsapp-chat' ); | ||
echo '<div class="owc-line">'; | ||
$text_button = __( 'Save Settings', 'open-whatsapp-chat' ); | ||
submit_button( $text_button ); | ||
echo '</div>'; | ||
?> | ||
</form> | ||
</div> | ||
<?php | ||
} | ||
|
||
/** | ||
* Register and add settings | ||
*/ | ||
public function page_init() { | ||
register_setting( | ||
'owc_option_group', // Option group | ||
'owc_option', // Option name | ||
array( $this, 'sanitize' ) // Sanitize | ||
); | ||
|
||
add_settings_section( | ||
'setting_section_id', // ID | ||
'', // Title | ||
'', // Callback | ||
'open-whatsapp-chat' // Page | ||
); | ||
|
||
add_settings_field( | ||
'owc_number', // ID | ||
__( 'WhatsApp Number', 'open-whatsapp-chat' ), // Title | ||
array( $this, 'owc_number_callback' ), // Callback | ||
'open-whatsapp-chat', // Page | ||
'setting_section_id' // Section | ||
); | ||
|
||
add_settings_field( | ||
'owc_button', // ID | ||
__( 'WhatsApp Button Text', 'open-whatsapp-chat' ), // Title | ||
array( $this, 'owc_button_callback' ), // Callback | ||
'open-whatsapp-chat', // Page | ||
'setting_section_id' // Section | ||
); | ||
|
||
add_settings_field( | ||
'owc_message', // ID | ||
__( 'WhatsApp Message', 'open-whatsapp-chat' ), // Title | ||
array( $this, 'owc_message_callback' ), // Callback | ||
'open-whatsapp-chat', // Page | ||
'setting_section_id' // Section | ||
); | ||
} | ||
|
||
/** | ||
* Sanitize each setting field as needed | ||
* | ||
* @param array $input contains all settings fields as array keys | ||
*/ | ||
public function sanitize( $input ) { | ||
|
||
$new_input = array(); | ||
|
||
if ( isset( $input['owc_number'] ) ) | ||
$new_input['owc_number'] = absint( $input['owc_number'] ); | ||
|
||
if ( isset( $input['owc_button'] ) ) | ||
$new_input['owc_button'] = sanitize_text_field( $input['owc_button'] ); | ||
|
||
if ( isset( $input['owc_message'] ) ) | ||
$new_input['owc_message'] = sanitize_text_field( $input['owc_message'] ); | ||
|
||
return $new_input; | ||
|
||
} | ||
|
||
/** | ||
* Get the settings option array and print one of its values | ||
*/ | ||
public function owc_number_callback() { | ||
printf( | ||
'<input type="text" id="owc_number" name="owc_option[owc_number]" value="%s" /><span class="owc-desc">' . __( 'Only numbers, example 5511988887777', 'open-whatsapp-chat' ) . '</span>', | ||
isset( $this->options['owc_number'] ) ? esc_attr( $this->options['owc_number'] ) : '' | ||
); | ||
} | ||
|
||
/** | ||
* Get the settings option array and print one of its values | ||
* @version 0.0.1 | ||
* @since 25/02/2019 | ||
*/ | ||
public function owc_button_callback() { | ||
printf( | ||
'<input type="text" id="owc_button" name="owc_option[owc_button]" value="%s" /><span class="owc-desc">' . __( 'Empty for use only the WhatsApp logo.', 'open-whatsapp-chat' ) . '</span>', | ||
isset( $this->options['owc_button'] ) ? esc_attr( $this->options['owc_button'] ) : '' | ||
); | ||
} | ||
|
||
/** | ||
* Get the settings option array and print one of its values | ||
*/ | ||
public function owc_message_callback() { | ||
printf( | ||
'<textarea id="owc_message" name="owc_option[owc_message]">%s</textarea>', | ||
isset( $this->options['owc_message'] ) ? esc_attr( $this->options['owc_message'] ) : '' | ||
); | ||
} | ||
} | ||
|
||
if ( is_admin() ) | ||
$owc_settings_page = new Open_Whatsapp_Chat_Settings(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php // Silence is golden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.owc-settings-wrap input[type="text"], | ||
.owc-settings-wrap textarea { | ||
display: block; | ||
padding: 10px; | ||
width: 100%; | ||
} | ||
.owc-desc { | ||
display: block; | ||
font-style: italic; | ||
margin: 4px 0 0 2px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
.owc-button { | ||
background: url( '../images/icon-whatsapp-3d.png' ) center center no-repeat #00A700; | ||
background-size: auto 100%; | ||
bottom: 30px; | ||
border-radius: 200px 200px 200px 200px; | ||
-moz-border-radius: 200px 200px 200px 200px; | ||
-webkit-border-radius: 200px 200px 200px 200px; | ||
height: 60px; | ||
right: 30px; | ||
position: fixed; | ||
transition: all .2s ease-in-out; | ||
-moz-transition: all .2s ease-in-out; | ||
-webkit-transition: all .2s ease-in-out; | ||
text-indent: -999px; | ||
width: 60px; | ||
z-index: 999; | ||
-webkit-box-shadow: -3px 3px 8px 0px rgba(110,110,110,0.5); | ||
-moz-box-shadow: -3px 3px 8px 0px rgba(110,110,110,0.5); | ||
box-shadow: -3px 3px 8px 0px rgba(110,110,110,0.5); | ||
} | ||
@media ( min-width: 767px ) { | ||
.owc-button.owc-text { | ||
background-position: left; | ||
text-indent: 0; | ||
width: auto; | ||
} | ||
.owc-button.owc-text span { | ||
color: #fff; | ||
display: block; | ||
margin: 19px 15px 0 55px; | ||
} | ||
} | ||
.owc-button:hover { | ||
bottom: 40px; | ||
text-decoration: none; | ||
} |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
/** | ||
* Open_Whatsapp_Chat | ||
* | ||
* @package Open_Whatsapp_Chat/Classes | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
|
||
// If this file is called directly, abort. | ||
if ( ! defined( 'WPINC' ) ) { | ||
die; | ||
} | ||
|
||
class Open_Whatsapp_Chat { | ||
|
||
/** | ||
* Setup the plugin | ||
*/ | ||
public function __construct() { | ||
|
||
if ( is_admin() ) { | ||
self::owc_admin_includes(); | ||
add_action( 'admin_head', array( $this, 'owc_admin_css' ), 50 ); | ||
} | ||
|
||
add_action( 'wp_enqueue_scripts', array( $this, 'owc_css' ), 50 ); | ||
add_action( 'wp_footer', array( $this, 'owc_print_button' ), 50 ); | ||
|
||
} | ||
|
||
/** | ||
* Admin includes. | ||
*/ | ||
private static function owc_admin_includes() { | ||
include_once dirname( OWC_FILE ) . '/admin/class-open-whatsapp-chat-settings.php'; | ||
} | ||
|
||
/** | ||
* Enqueue the CSS. | ||
* | ||
* @return void | ||
*/ | ||
public function owc_css() { | ||
wp_enqueue_style( 'owc-css', plugins_url( '/assets/css/style.css', OWC_FILE ) ); | ||
} | ||
|
||
/** | ||
* Enqueue the Admin CSS. | ||
* | ||
* @return void | ||
*/ | ||
public function owc_admin_css() { | ||
wp_enqueue_style( 'owc-admin-css', plugins_url( '/assets/css/style-admin.css', OWC_FILE ) ); | ||
} | ||
|
||
/** | ||
* | ||
* Verifica qual o navegador está sendo usado. | ||
* Passe como parâmetro o nome do navegador que deseja testar | ||
* por exemplo "Firefox". | ||
* | ||
* @author Everaldo Matias <http://everaldomatias.github.io> | ||
* @version 0.0.1 | ||
* @since 15/11/2018 | ||
* @return Booleano | ||
* | ||
*/ | ||
public function owc_what_browser( $browser ) { | ||
if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) { | ||
$agent = $_SERVER['HTTP_USER_AGENT']; | ||
} | ||
|
||
if ( strlen( strstr( $agent, $browser ) ) > 0 ) { | ||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Print button on front end. | ||
* | ||
* @return void | ||
*/ | ||
public function owc_print_button() { | ||
|
||
$owc_option = get_option( 'owc_option' ); | ||
if ( $owc_option['owc_number'] && $owc_option['owc_message'] ) { | ||
|
||
if ( $this->owc_what_browser( 'Firefox' ) ) { | ||
$link = 'https://web.whatsapp.com/send?phone=' ; | ||
} else { | ||
$link = 'https://wa.me/' ; | ||
} | ||
|
||
$message = urlencode( $owc_option['owc_message'] ); | ||
$message = str_replace( '+', '%20', $message ); | ||
|
||
if ( ! empty( $owc_option['owc_button'] ) ) { | ||
|
||
echo '<a target="_blank" href="' . esc_url( $link ) . esc_html( $owc_option['owc_number'] ) . '?text=' . $message . '" class="owc-button owc-text" title="' . __( 'Open the WhatsApp Chat', 'open-whatsapp-chat' ) . '">'; | ||
echo '<span>' . esc_html( $owc_option['owc_button'] ) . '</span>'; | ||
echo '</a>'; | ||
|
||
} else { | ||
|
||
echo '<a target="_blank" href="' . esc_url( $link ) . esc_html( $owc_option['owc_number'] ) . '?text=' . $message . '" class="owc-button" title="' . __( 'Open the WhatsApp Chat', 'open-whatsapp-chat' ) . '">'; | ||
echo '</a>'; | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
new Open_Whatsapp_Chat(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php // Silence is golden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php // Silence is gold ande code is poetry |
Oops, something went wrong.