| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: Bazz CallBack Widget |
| 4 |
Plugin URI: http://viktor-web.ru |
| 5 |
Description: This plugin makes a simple widget for callback on your website. |
| 6 |
Author: Viktor Ievlev |
| 7 |
Version: 1.0 |
| 8 |
Author URI: http://viktor-web.ru |
| 9 |
*/ |
| 10 |
/* |
| 11 |
Copyright 2016 Viktor Ievlev (email: bazz@bk.ru) |
| 12 |
|
| 13 |
This program is free software; you can redistribute it and/or modify |
| 14 |
it under the terms of the GNU General Public License as published by |
| 15 |
the Free Software Foundation; either version 2 of the License, or |
| 16 |
(at your option) any later version. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with this program; if not, write to the Free Software |
| 25 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 |
*/ |
| 27 |
//activation hook |
| 28 |
register_activation_hook( __FILE__, 'bazz_install'); |
| 29 |
function bazz_install() { |
| 30 |
$bazz_options_arr = array( |
| 31 |
'email' => 'example@mail.com', |
| 32 |
'time' => '40', |
| 33 |
'button_text' => 'ПОЗВО-НИТЬ', |
| 34 |
'send_text' => 'Жду звонка!', |
| 35 |
'day_text' => 'Нагрузка крайне высокая, мы перезвоним Вам в ближайшее время. Спасибо!', |
| 36 |
'night_text' => 'Мы перезвоним Вам завтра. Спасибо!' |
| 37 |
); |
| 38 |
update_option('bazz_options', $bazz_options_arr); |
| 39 |
} |
| 40 |
//deactivation hook |
| 41 |
register_deactivation_hook( __FILE__, 'bazz_deactivate'); |
| 42 |
function bazz_deactivate() { |
| 43 |
|
| 44 |
} |
| 45 |
//styles and scripts |
| 46 |
add_action('init', 'bazz_widget_styles'); |
| 47 |
function bazz_widget_styles() { |
| 48 |
if(!is_admin()) { |
| 49 |
wp_enqueue_style('bazz_widget_style', plugins_url('css/bazz-widget.css', __FILE__)); |
| 50 |
} else { |
| 51 |
wp_enqueue_style('bazz_widget_style', plugins_url('css/bazz-widget-admin.css', __FILE__)); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
add_action('wp_enqueue_scripts', 'bazz_widget_scripts'); |
| 56 |
function bazz_widget_scripts() { |
| 57 |
wp_enqueue_script('jquery'); |
| 58 |
wp_enqueue_script('bazz_maskedinput', plugins_url('js/jquery.maskedinput.min.js', __FILE__), 'jquery'); |
| 59 |
wp_enqueue_script('bazz_draggable', plugins_url('js/jquery.draggable.min.js', __FILE__), 'jquery'); |
| 60 |
wp_enqueue_script('bazz_widget_script', plugins_url('js/bazz-widget.js', __FILE__)); |
| 61 |
} |
| 62 |
|
| 63 |
add_action('wp_enqueue_scripts', 'myajax_data', 99); |
| 64 |
function myajax_data(){ |
| 65 |
wp_localize_script('bazz_widget_script', 'myajax', |
| 66 |
array( |
| 67 |
'url' => admin_url('admin-ajax.php') |
| 68 |
) |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
//AJAX |
| 73 |
add_action('wp_ajax_bazz_widget_action', 'bazz_widget_send'); |
| 74 |
add_action('wp_ajax_nopriv_bazz_widget_action', 'bazz_widget_send'); |
| 75 |
function bazz_widget_send() { |
| 76 |
if (isset($_POST['phone'])) {$phone = $_POST['phone'];} |
| 77 |
if (isset($_POST['name'])) {$name = $_POST['name'];} else {$name = 'Клиент не представился';} |
| 78 |
$blog_url = get_home_url(); |
| 79 |
$bazz_options_arr = get_option('bazz_options'); |
| 80 |
$email = $bazz_options_arr['email']; |
| 81 |
$current_time = current_time('G'); |
| 82 |
if ($current_time >= 9 && $current_time <= 21) { |
| 83 |
$text = $bazz_options_arr['day_text']; |
| 84 |
} else { |
| 85 |
$text = $bazz_options_arr['night_text']; |
| 86 |
} |
| 87 |
$to = $email; |
| 88 |
$headers = "Content-type: text/plain; charset =utf-8"; |
| 89 |
$subject = "$blog_url [ИЗ ВИДЖЕТА]"; |
| 90 |
$message = "Телефон - $phone |
| 91 |
Имя - $name"; |
| 92 |
$send = mail($to, $subject, $message, $headers); |
| 93 |
if ($send == 'true'){ |
| 94 |
echo ('<div style="color: #FFFFFF; font-size: 18px; line-height: 1.2; padding-top: 13px;">'.$text.'</div>'); |
| 95 |
wp_die(); |
| 96 |
} else { |
| 97 |
return false; |
| 98 |
wp_die(); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
//HTML layout |
| 103 |
add_action('wp_footer', 'bazz_layout'); |
| 104 |
function bazz_layout() { ?> |
| 105 |
<?php $bazz_options_arr = get_option('bazz_options'); ?> |
| 106 |
<div class="bazz-widget"> |
| 107 |
<div class="bazz-widget-button"> |
| 108 |
<i></i> |
| 109 |
<i><?php echo($bazz_options_arr['button_text']); ?></i> |
| 110 |
</div> |
| 111 |
<div class="bazz-widget-close">+</div> |
| 112 |
<div class="bazz-widget-form"> |
| 113 |
<div class="bazz-widget-form-top"> |
| 114 |
<label>Перезвоним <a href="#" class="bazz-widget-your-name">Вам</a> за<br>00:<span class="bazz_time"><?php echo($bazz_options_arr['time']); ?></span> секунд!</label> |
| 115 |
<input type="text" value="<?php echo plugins_url('', __FILE__); ?>" id="plugin-url" hidden /> |
| 116 |
<input id="bazz-widget-phone" name="bazz-widget-phone" value="" type="tel" placeholder="+7(___)___-__-__" /> |
| 117 |
<a href="#" class="bazz-widget-form-submit"><?php echo($bazz_options_arr['send_text']); ?></a> |
| 118 |
</div> |
| 119 |
<div class="bazz-widget-form-bottom"> |
| 120 |
<label>Пердставьтесь, и мы будем обращаться по имени</label> |
| 121 |
<input id="bazz-widget-name" name="bazz-widget-name" value="" type="text" placeholder="Введите Ваше имя" /> |
| 122 |
<a href="#" class="bazz-widget-name-close"></a> |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
<div class="bazz-widget-inner-circle"></div> |
| 126 |
<div class="bazz-widget-inner-border"></div> |
| 127 |
</div> |
| 128 |
<?php } |
| 129 |
//menu |
| 130 |
add_action('admin_menu','bazz_widget_menu'); |
| 131 |
function bazz_widget_menu() { |
| 132 |
add_options_page('Bazz CallBack Widget settins page', 'Bazz CallBack Widget settings', 'manage_options', 'bazz_menu', 'bazz_menu_page'); |
| 133 |
add_action('admin_init', 'bazz_register_settings'); |
| 134 |
} |
| 135 |
function bazz_register_settings() { |
| 136 |
register_setting('bazz_settings_group', 'bazz_options', 'bazz_sanitize_options'); |
| 137 |
} |
| 138 |
function bazz_sanitize_options($input) { |
| 139 |
$input['email'] = sanitize_email($input['email']); |
| 140 |
$input['time'] = sanitize_text_field($input['time']); |
| 141 |
$input['button_text'] = sanitize_text_field($input['button_text']); |
| 142 |
$input['send_text'] = sanitize_text_field($input['send_text']); |
| 143 |
$input['day_text'] = sanitize_text_field($input['day_text']); |
| 144 |
$input['night_text'] = sanitize_text_field($input['night_text']); |
| 145 |
return $input; |
| 146 |
} |
| 147 |
function bazz_menu_page() { ?> |
| 148 |
<h2>Привет! Это настройки плагина Bazz CallBack Widget</h2> |
| 149 |
<p>Изменяем параметры на свое усмотрение.<br></p> |
| 150 |
<form method="post" action="options.php" id="bazz-settings-form"> |
| 151 |
<?php settings_fields('bazz_settings_group'); ?> |
| 152 |
<?php $bazz_options = get_option('bazz_options'); ?> |
| 153 |
<div class="option-email"> |
| 154 |
<label for="">Отправлять письмо на:<input type="email" name="bazz_options[email]" value="<?php echo esc_attr($bazz_options['email']); ?>" /></label> |
| 155 |
</div> |
| 156 |
<div class="option-timer"> |
| 157 |
<label for="">Таймер обратного отсчета будет запущен на <input type="text" name="bazz_options[time]" value="<?php echo esc_attr($bazz_options['time']); ?>" /> секунд.</label> |
| 158 |
</div> |
| 159 |
<div class="option-text1"> |
| 160 |
<label for="">Текст на круглой синей кнопке:</label> |
| 161 |
<input type="text" name="bazz_options[button_text]" value="<?php echo esc_attr($bazz_options['button_text']); ?>" /> |
| 162 |
</div> |
| 163 |
<div class="option-text2"> |
| 164 |
<label for="">Текст на кнопке отправки формы:</label> |
| 165 |
<input type="text" name="bazz_options[send_text]" value="<?php echo esc_attr($bazz_options['send_text']); ?>" /> |
| 166 |
</div> |
| 167 |
<div class="option-text3"> |
| 168 |
<label for="">Текст-результат в рабочее время (днем):</label> |
| 169 |
<textarea name="bazz_options[day_text]"><?php echo($bazz_options['day_text']); ?></textarea> |
| 170 |
</div> |
| 171 |
<div class="option-text4"> |
| 172 |
<label for="">Текст-результат в НЕ рабочее время (ночью):</label> |
| 173 |
<textarea name="bazz_options[night_text]"><?php echo($bazz_options['night_text']); ?></textarea> |
| 174 |
</div> |
| 175 |
<div> |
| 176 |
<input type="submit" value="Со� |
| 177 |
ранить" /> |
| 178 |
</div> |
| 179 |
</form> |
| 180 |
<?php } |
| 181 |
|
| 182 |
?> |