PluginProbe
Exit Popup / 3.2
Exit Popup v3.2
3.5 trunk 3.1 3.2 3.3 3.4
exit-popup / exit-popup.php

exit-popup.php in Exit Popup 3.2, at exit-popup.php

427 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Exit Popup
4 Plugin URI: https://www.brontobytes.com/
5 Description: Exit Popup enables you to display a jQuery modal before a visitor leaves your website.
6 Author: Brontobytes
7 Author URI: https://www.brontobytes.com/
8 Version: 3.2
9 License: GPLv2
10 Text Domain: exit-popup
11 Domain Path: /languages
12 */
13
14 if ( ! defined( 'ABSPATH' ) )
15 exit;
16
17 function exit_popup_menu() {
18 add_options_page(__('Exit Popup Settings', 'exit-popup'), __('Exit Popup', 'exit-popup'), 'administrator', 'exit-popup-settings', 'exit_popup_settings_page');
19 }
20 add_action('admin_menu', 'exit_popup_menu');
21
22
23 function my_admin_enqueue($hook_suffix) {
24 if($hook_suffix == 'settings_page_exit-popup-settings') {
25 wp_register_style( 'select2css', '//cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css', false, '1.0', 'all' );
26 wp_register_script( 'select2', '//cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js', array( 'jquery' ), '1.0', true );
27 wp_enqueue_style( 'select2css' );
28 wp_enqueue_script( 'select2' );
29
30 wp_enqueue_style( 'wp-color-picker' );
31
32 }
33 }
34 add_action('admin_enqueue_scripts', 'my_admin_enqueue');
35
36
37 add_filter( 'plugin_action_links', 'exis_popup_settings_plugin_link', 10, 2 );
38
39 function exis_popup_settings_plugin_link( $links, $file )
40 {
41 if ( $file == plugin_basename(dirname(__FILE__) . '/exit-popup.php') )
42 {
43 /*
44 * Insert the link at the beginning
45 */
46 // $in = '<a href="options-general.php?page=cookie-bar-settings">' . __('Settings','mtt') . '</a>';
47 // array_unshift($links, $in);
48
49 /*
50 * Insert at the end
51 */
52 $links[] = '<a href="options-general.php?page=exit-popup-settings">'.__('Settings','mtt').'</a>';
53 }
54 return $links;
55 }
56
57
58 function exit_popup_settings_page() { ?>
59 <style type="text/css" >
60 .wrap {
61 background-color: #ffffff;
62 padding: 30px;
63 border-radius: 20px;
64 }
65
66 .postbox .inside h2, .wrap [class$="icon32"] + h2, .wrap h1, .wrap > h2:first-child {
67 padding: 0px;
68 }
69
70 @media screen and (max-width: 768px) {
71 input[type="text"] {
72 max-width: 200px !important;
73 ; }
74
75 xmp {
76 display: block;
77 white-space: pre-wrap;
78 }
79 }
80
81 </style>
82 <div class="wrap">
83 <h2><?php echo __('Exit Popup Settings', 'exit-popup'); ?></h2>
84 <p><?php echo __('Exit Popup enables you to display a jQuery modal before a visitor leaves your website.', 'exit-popup'); ?></p>
85 <form method="post" action="options.php">
86 <?php
87 settings_fields( 'exit-popup-settings' );
88 do_settings_sections( 'exit-popup-settings' );
89 ?>
90 <table class="form-table">
91 <tr valign="top">
92 <th scope="row"><?php echo __('Cookie expiration (days)', 'exit-popup'); ?></th>
93 <td>
94 <input type="text" size="10" name="exit_popup_cookie_expire" value="<?php echo esc_attr( get_option('exit_popup_cookie_expire') ); ?>" /><br /><small><?php echo __('E.g.: 10', 'exit-popup'); ?></small><br /><small><?php echo __('Enter -1 to have the cookies last for the session.', 'exit-popup'); ?></small>
95 </td>
96 </tr>
97 <tr valign="top">
98 <th scope="row"><?php echo __('Prevent close on click outside of modal box', 'exit-popup'); ?></th>
99 <td>
100 <input type="checkbox" name="exit_popup_click_outside" value="true" <?php echo ( get_option('exit_popup_click_outside') == true ) ? ' checked="checked" />' : ' />'; ?> <br /><small></small>
101 </td>
102 </tr>
103 <tr valign="top">
104 <th scope="row"><?php echo __('Show for logged out users only', 'exit-popup'); ?></th>
105 <td>
106 <input type="checkbox" name="exit_popup_logged_out_users_only" value="true" <?php echo ( get_option('exit_popup_logged_out_users_only') == true ) ? ' checked="checked" />' : ' />'; ?> <br /><small></small>
107 </td>
108 </tr>
109 <tr valign="top">
110 <th scope="row"><?php echo __('Modal width (px or %)', 'exit-popup'); ?></th>
111 <td>
112 <input type="text" size="10" name="exit_popup_modal_width" value="<?php echo esc_attr( get_option('exit_popup_modal_width') ); ?>" /><br /><small><?php echo __('E.g.: 500px or 50%', 'exit-popup'); ?></small>
113 </td>
114 </tr>
115 <tr valign="top">
116 <th scope="row"><?php echo __('Modal height (px or %)', 'exit-popup'); ?></th>
117 <td>
118 <input type="text" size="10" name="exit_popup_modal_height" value="<?php echo esc_attr( get_option('exit_popup_modal_height') ); ?>" /><br /><small><?php echo __('E.g.: 500px or 50%', 'exit-popup'); ?></small>
119 </td>
120 </tr>
121 <tr valign="top">
122 <th scope="row"><?php echo __('Title background colour', 'exit-popup'); ?></th>
123 <td>
124 <input id="exit_popup_popup_title_color" type="text" size="10" name="exit_popup_popup_title_color" value="<?php echo esc_attr( get_option('exit_popup_popup_title_color') ); ?>" /><br />
125 </td>
126 </tr>
127 <tr valign="top">
128 <th scope="row"><?php echo __('Title (Text)', 'exit-popup'); ?></th>
129 <td>
130 <input type="text" size="40" name="exit_popup_popup_title" value="<?php echo esc_attr( get_option('exit_popup_popup_title') ); ?>" /><br /><small><?php echo __('E.g.: Don\'t Leave Yet!', 'exit-popup'); ?></small>
131 </td>
132 </tr>
133 <tr valign="top">
134 <th scope="row"><?php echo __('Footer (Text)', 'exit-popup'); ?></th>
135 <td>
136 <input type="text" size="40" name="exit_popup_popup_footer" value="<?php echo esc_attr( get_option('exit_popup_popup_footer') ); ?>" /><br /><small><?php echo __('E.g.: Thank You!', 'exit-popup'); ?></small><br /><small><?php echo __('This is a clickable text/button that closes the popup when clicked. Leave empty to hide the footer.', 'exit-popup'); ?></small>
137 </td>
138 </tr>
139 <tr valign="top">
140 <th scope="row"><?php echo __('Body (HTML)', 'exit-popup'); ?></th>
141 <td><textarea rows="10" cols="100" name="exit_popup_popup_body"><?php echo esc_html( get_option('exit_popup_popup_body') ); ?></textarea>
142 <small>
143 <xmp>
144 <?php echo __('HTML code example:
145 <style>
146 .discount-box {
147 font-size: 2em;
148 font-weight: bold;
149 display: inline;
150 background: #ec971f;
151 color: #fff;
152 padding: 20px;
153 padding-left: 5px;
154 padding-right: 5px;
155 box-shadow: 10px 0 0 #777, -10px 0 0 #777;
156 align: center;
157 }
158 </style>
159
160 <h4>Best Offer</h4>
161 <p style="padding-top: 20px"></p>
162 <p><span class="discount-box">3 For The Price Of 2!</span></p>
163 <p style="padding-top: 20px"></p>
164 <p><small>The offer is available to all.</small></p>', 'exit-popup'); ?>
165 </xmp>
166 </small>
167 </td>
168 </tr>
169 <?php if( array_key_exists( 'wpml_object_id' , $GLOBALS['wp_filter']) ): // check for WPML ?>
170 <tr valign="top">
171 <th scope="row"><?php _e('Enabled language','exit-popup');?></th>
172 <td>
173 <?php $languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' );
174 $enabled_languages = get_option('exit_popup_languages');
175 foreach ($languages as $key => $value) : ?>
176 <label style="padding-right: 15px;"><input type="checkbox" name="exit_popup_languages[<?php echo $key;?>]" value="<?php echo $key; ?>" <?php checked( $key, $enabled_languages[$key], true); ?> />&nbsp;<?php echo $value['native_name']; ?></label>
177 <?php endforeach; ?>
178 </td>
179 </tr>
180
181 <?php endif; ?>
182 <tr valign="top">
183 <th scope="row"><?php _e('Exclude from Posts/Pages','exit-popup');?></th>
184 <td>
185 <?php
186
187
188
189
190 $ep_post_types = get_post_types();
191
192
193 $selected_posts_to_exclude = get_option('exit-popup-exclude-from-posts') ;
194
195 if(empty($selected_posts_to_exclude)) {
196 $selected_posts_to_exclude = array();
197 }
198
199
200 echo '<label for="exit-popup-exclude-from-posts"></label>';
201 echo '<select id="js-hide-search-multi" name="exit-popup-exclude-from-posts[]" multiple="multiple" class="request-schedule-select" >';
202
203
204 foreach($ep_post_types as $post_type) {
205 if($post_type == 'attachment' || $post_type == 'nav_menu_item' || $post_type == 'revision' || $post_type == 'custom_css'
206 || $post_type == 'customize_changeset' || $post_type == 'oembed_cache' || $post_type == 'user_request' || $post_type == 'wp_block'
207 || $post_type == 'wp_template' || $post_type == 'wp_template_part' || $post_type == 'wp_global_styles' || $post_type == 'wp_navigation'
208
209 ) {
210 break ;
211 }
212
213 $args = array(
214 'post_type' => $post_type,
215 'order' => 'DESC',
216 'post_status' => 'publish',
217 'posts_per_page' => -1
218 );
219
220 $query = new WP_Query($args);
221
222 if ($query->have_posts()) {
223 echo '<optgroup label="' . $post_type . '" >';
224
225
226 while ($query->have_posts()) : $query->the_post();
227 $id = get_the_ID();
228 echo '<option value="' . $id . '" ' . ((in_array($id, $selected_posts_to_exclude)) ? ('selected') : '') . ' . >' . get_the_title() . '</option>';
229
230 endwhile;
231 echo '</optgroup >';
232 }
233 }
234 echo '</select>';
235
236
237
238 ?>
239 </td>
240 </tr>
241 <tr valign="top">
242 <th scope="row"><label for="exit_popup_powered_by"><?php echo __("Show 'Powered by' link",'exit-popup');?></label></th>
243 <td>
244 <input type="checkbox" name="exit_popup_powered_by" value="true" <?php echo ( get_option('exit_popup_powered_by') == true ) ? ' checked="checked" />' : ' />'; ?><br /><small><?php echo __('We are very happy to be able to provide this for free along with other <a href="https://www.brontobytes.com/blog
245 /c/wordpress-plugins/" target="_blank">free WordPress plugins</a>.', 'exit-popup');?> </small>
246 </td>
247 </tr>
248 </table>
249 <script type="text/javascript" >
250 jQuery(document).ready(function(){
251 jQuery("#exit_popup_popup_title_color").wpColorPicker();
252
253 jQuery('#js-hide-search-multi').select2();
254
255
256 });
257
258 </script>
259 <?php
260 submit_button();
261 ?>
262 </form>
263 <p><?php echo __('Plugin developed by ','exit-popup');?><a href="https://www.brontobytes.com/" target="_blank" >Brontobytes</a></p>
264 <a href="https://www.brontobytes.com/" target="_blank"><img width="100" style="vertical-align:middle" src="<?php echo plugins_url( 'images/brontobytes.svg', __FILE__ ) ?>" alt="<?php echo __('Web & VPS hosting provider','exit-popup');?>"></a>
265 </div>
266 <?php }
267
268 function exit_popup_settings() {
269 register_setting( 'exit-popup-settings', 'exit_popup_cookie_expire' );
270 register_setting( 'exit-popup-settings', 'exit_popup_click_outside' );
271 register_setting( 'exit-popup-settings', 'exit_popup_modal_width' );
272 register_setting( 'exit-popup-settings', 'exit_popup_modal_height' );
273 register_setting( 'exit-popup-settings', 'exit_popup_popup_title_color' );
274 register_setting( 'exit-popup-settings', 'exit_popup_popup_title' );
275 register_setting( 'exit-popup-settings', 'exit_popup_popup_body' );
276 register_setting( 'exit-popup-settings', 'exit_popup_popup_footer' );
277 register_setting( 'exit-popup-settings', 'exit_popup_languages' );
278 register_setting( 'exit-popup-settings', 'exit-popup-exclude-from-posts' );
279 register_setting( 'exit-popup-settings', 'exit_popup_powered_by' );
280 register_setting( 'exit-popup-settings', 'exit_popup_logged_out_users_only' );
281
282 }
283 add_action( 'admin_init', 'exit_popup_settings' );
284
285 function exit_popup_deactivation() {
286 delete_option( 'exit_popup_cookie_expire' );
287 delete_option( 'exit_popup_click_outside' );
288 delete_option( 'exit_popup_modal_width' );
289 delete_option( 'exit_popup_modal_height' );
290 delete_option( 'exit_popup_popup_title_color' );
291 delete_option( 'exit_popup_popup_title' );
292 delete_option( 'exit_popup_popup_body' );
293 delete_option( 'exit_popup_popup_footer' );
294 delete_option( 'exit_popup_languages' );
295 delete_option( 'exit_popup_powered_by' );
296 delete_option( 'exit-popup-exclude-from-posts' );
297 delete_option( 'exit_popup_logged_out_users_only' );
298 }
299 register_deactivation_hook( __FILE__, 'exit_popup_deactivation' );
300
301 function exit_popup_dependencies() {
302 wp_register_script( 'js-cookie-js', plugins_url('js/js-cookie.js', __FILE__), array('jquery'), time(), false );
303 wp_enqueue_script( 'js-cookie-js' );
304 wp_register_script( 'exit-popup-js', plugins_url('js/exit-popup.js', __FILE__), array('jquery'), time(), false );
305 wp_enqueue_script( 'exit-popup-js' );
306 wp_register_style( 'exit-popup-css', plugins_url('css/exit-popup.css', __FILE__) );
307 wp_enqueue_style( 'exit-popup-css' );
308 }
309 add_action( 'wp_enqueue_scripts', 'exit_popup_dependencies' );
310
311 function exit_popup() {
312
313
314 $show_for_logged_out_users_only = get_option('exit_popup_logged_out_users_only' , false ) ;
315
316 if(!$show_for_logged_out_users_only ) {
317
318 }
319 else {
320 if(is_user_logged_in()) {
321 return;
322 }
323
324 }
325
326
327
328
329 $selected_posts_to_exclude = get_option('exit-popup-exclude-from-posts') ;
330
331
332 if(empty($selected_posts_to_exclude)) {
333 $selected_posts_to_exclude = array();
334 }
335
336 if (in_array(get_the_ID(), $selected_posts_to_exclude) )
337 {
338 return;
339 }
340
341
342 // Check for language
343 $check_lg = true;
344 if( array_key_exists( 'wpml_object_id' , $GLOBALS['wp_filter']) ) {
345 $epp_lg = get_option('exit_popup_languages');
346
347 $current_lg = ICL_LANGUAGE_CODE;
348
349 $check_lg = false;
350
351 if( in_array($current_lg, $epp_lg) ) $check_lg = true;
352 }
353
354 if($check_lg) { // v3.0
355 //if($check_lg && !isset($_COOKIE['viewedExitPopupWP']) && $_COOKIE['viewedExitPopupWP'] != 'true') {
356
357 if(esc_attr( get_option('exit_popup_click_outside') ) == "true") {
358 $exit_popup_click_outside = "";
359 } else {
360 $exit_popup_click_outside = "
361 $('body').on('click', function() {
362 $('#exitpopup-modal').hide();
363 });
364 ";
365 }
366 ?>
367 <!-- Exit Popup -->
368 <div id='exitpopup-modal'>
369 <div class='underlay'></div>
370 <div class='exitpopup-modal-window' style='width:<?php echo esc_attr( get_option('exit_popup_modal_width') ); if (preg_match('(px|%)', esc_attr( get_option('exit_popup_modal_height') )) !== 1) { echo 'px'; } ?> !important; height:<?php echo esc_attr( get_option('exit_popup_modal_height') ); if (preg_match('(px|%)', esc_attr( get_option('exit_popup_modal_height') )) !== 1) { echo 'px'; } ?> !important;'>
371 <?php $title_background_color = get_option('exit_popup_popup_title_color');
372 if(!empty($title_background_color))
373 {
374
375 // echo $title_background_color . ' ' . strpos($title_background_color, '#' ) . 'yay';
376 if(strpos($title_background_color, '#' ) !== false)
377 {
378 $title_background_color = $title_background_color;
379 }
380 else {
381 $title_background_color = '#' . $title_background_color;
382 }
383 }
384 ?>
385
386 <div class='modal-title' style='background-color:<?php echo esc_attr( $title_background_color ); ?> !important;'>
387 <h3><?php echo esc_html( get_option('exit_popup_popup_title') ); ?></h3>
388 </div>
389 <div class='modal-body'>
390 <?php echo do_shortcode(html_entity_decode(get_option('exit_popup_popup_body'))); ?>
391 </div>
392 <div class='exitpopup-modal-footer'>
393 <p><?php echo esc_html( get_option('exit_popup_popup_footer') ); ?></p>
394 </div>
395 <?php if (get_option('exit_popup_powered_by') == true) { ?> <div style="bottom: -25px;position: absolute;right: 0px;"><a style="font-size:x-small;color:white;text-decoration:none;" target="_blank" href="https://www.brontobytes.com/blog/exit-popup-free-wordpress-plugin/"><?php echo __('Exit Popup for WordPress','exit-popup');?></a></div> <?php } ?>
396 </div>
397 </div>
398
399 <script type='text/javascript'>
400 jQuery(document).ready(function($) {
401 var exit_popup_value = Cookies.get('viewedExitPopupWP'); // v3.0
402 if(!exit_popup_value){ // v3.0
403 var _exitpopup = exitpopup(document.getElementById('exitpopup-modal'), {
404 aggressive: true,
405 timer: 0,
406 sensitivity: 20,
407 delay: 0,
408 sitewide: true,
409 cookieExpire: <?php echo esc_attr( get_option('exit_popup_cookie_expire') ); ?>,
410 callback: function() { console.log('exitpopup fired!'); }
411 });
412
413 <?php echo $exit_popup_click_outside; ?>
414 $('#exitpopup-modal .exitpopup-modal-footer').on('click', function() {
415 $('#exitpopup-modal').hide();
416 });
417 $('#exitpopup-modal .exitpopup-modal-window').on('click', function(e) {
418 e.stopPropagation();
419 });
420 } // v3.0
421 });
422 </script>
423 <!-- End Exit Popup -->
424 <?php
425 }//if viewedExitPopupWP
426 }//function exit_popup
427 add_action( 'wp_footer', 'exit_popup', 10 );