WP Notification Bars - Version 1.0.7

Version Description

  • More security improvements
Download this release

Release Info

Developer pbalazs
Plugin Icon 128x128 WP Notification Bars
Version 1.0.7
Comparing to
See all releases

Code changes from version 1.0.6 to 1.0.7

admin/class-wp-notification-bars-admin.php CHANGED
@@ -1,1011 +1,1134 @@
1
- <?php
2
-
3
- /**
4
- * The dashboard-specific functionality of the plugin.
5
- *
6
- * @link http://mythemeshop.com
7
- * @since 1.0
8
- *
9
- * @package MTSNBF
10
- * @subpackage MTSNBF/admin
11
- */
12
-
13
- /**
14
- * The dashboard-specific functionality of the plugin.
15
- *
16
- * Defines the plugin name, version, and two examples hooks for how to
17
- * enqueue the dashboard-specific stylesheet and JavaScript.
18
- *
19
- * @package MTSNBF
20
- * @subpackage MTSNBF/admin
21
- * @author MyThemeShop
22
- */
23
- // If this file is called directly, abort.
24
- if ( ! defined( 'WPINC' ) ) {
25
- die;
26
- }
27
-
28
- if ( ! class_exists( 'MTSNBF_Admin' ) ) {
29
- class MTSNBF_Admin {
30
-
31
- /**
32
- * The ID of this plugin.
33
- *
34
- * @since 1.0
35
- * @access private
36
- * @var string $plugin_name The ID of this plugin.
37
- */
38
- private $plugin_name;
39
-
40
- /**
41
- * The version of this plugin.
42
- *
43
- * @since 1.0
44
- * @access private
45
- * @var string $version The current version of this plugin.
46
- */
47
- private $version;
48
-
49
- /**
50
- * Slug of the plugin screen.
51
- *
52
- * @since 1.0
53
- *
54
- * @var string
55
- */
56
- private $plugin_screen_hook_suffix = null;
57
-
58
- private $force_bar_post_types;
59
-
60
- /**
61
- * Initialize the class and set its properties.
62
- *
63
- * @since 1.0
64
- * @param string $plugin_name The name of this plugin.
65
- * @param string $version The version of this plugin.
66
- */
67
- public function __construct( $plugin_name, $version ) {
68
-
69
- $this->plugin_name = $plugin_name;
70
- $this->version = $version;
71
-
72
- }
73
-
74
- /**
75
- * Register the stylesheets for the Dashboard.
76
- *
77
- * @since 1.0
78
- */
79
- public function enqueue_styles() {
80
-
81
- $screen = get_current_screen();
82
- $screen_id = $screen->id;
83
-
84
- $force_bar_post_types = $this->force_bar_post_types;
85
-
86
- if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types ) ) {
87
-
88
- wp_enqueue_style( 'wp-color-picker' );
89
- wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-notification-bars-admin.css', array(), $this->version, 'all' );
90
- if ( 'mts_notification_bar' !== $screen_id ) {
91
- wp_enqueue_style( $this->plugin_name.'_select2', plugin_dir_url( __FILE__ ) . 'css/select2.min.css', array(), $this->version, 'all' );
92
- }
93
- }
94
- }
95
-
96
- /**
97
- * Register the JavaScript for the dashboard.
98
- *
99
- * @since 1.0
100
- */
101
- public function enqueue_scripts() {
102
-
103
- $screen = get_current_screen();
104
- $screen_id = $screen->id;
105
-
106
- $force_bar_post_types = $this->force_bar_post_types;
107
-
108
- if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types ) ) {
109
-
110
- wp_enqueue_script( 'wp-color-picker' );
111
-
112
- if ( 'mts_notification_bar' !== $screen_id ) {
113
-
114
- wp_enqueue_script(
115
- $this->plugin_name.'_select2',
116
- plugin_dir_url( __FILE__ ) . 'js/select2.full.min.js',
117
- array('jquery'),
118
- $this->version,
119
- false
120
- );
121
- }
122
-
123
- wp_enqueue_script(
124
- $this->plugin_name,
125
- plugin_dir_url( __FILE__ ) . 'js/wp-notification-bars-admin.js',
126
- array(
127
- 'jquery',
128
- 'wp-color-picker',
129
- ),
130
- $this->version, false
131
- );
132
-
133
- wp_localize_script(
134
- $this->plugin_name,
135
- 'mtsnb_locale',
136
- array(
137
- 'select_placeholder' => __( 'Enter Notification Bar Title', 'wp-notification-bars' ),
138
- )
139
- );
140
- }
141
-
142
- wp_enqueue_script(
143
- $this->plugin_name,
144
- plugin_dir_url( __FILE__ ) . 'js/wp-nb-admin-notices.js',
145
- array(
146
- 'jquery',
147
- ),
148
- $this->version, false
149
- );
150
- }
151
-
152
- //////////////////////
153
- //////// CPT /////////
154
- //////////////////////
155
-
156
- /**
157
- * Register MTS Notification Bar Post Type, attached to 'init'
158
- *
159
- * @since 1.0
160
- */
161
- public function mts_notification_cpt() {
162
- $labels = array(
163
- 'name' => _x( 'Notification Bars', 'post type general name', 'wp-notification-bars' ),
164
- 'singular_name' => _x( 'Notification Bar', 'post type singular name', 'wp-notification-bars' ),
165
- 'menu_name' => _x( 'Notification Bars', 'admin menu', 'wp-notification-bars' ),
166
- 'name_admin_bar' => _x( 'Notification Bar', 'add new on admin bar', 'wp-notification-bars' ),
167
- 'add_new' => _x( 'Add New', 'notification bar', 'wp-notification-bars' ),
168
- 'add_new_item' => __( 'Add New Notification Bar', 'wp-notification-bars' ),
169
- 'new_item' => __( 'New Notification Bar', 'wp-notification-bars' ),
170
- 'edit_item' => __( 'Edit Notification Bar', 'wp-notification-bars' ),
171
- 'view_item' => __( 'View Notification Bar', 'wp-notification-bars' ),
172
- 'all_items' => __( 'All Notification Bars', 'wp-notification-bars' ),
173
- 'search_items' => __( 'Search Notification Bars', 'wp-notification-bars' ),
174
- 'parent_item_colon' => __( 'Parent Notification Bars:', 'wp-notification-bars' ),
175
- 'not_found' => __( 'No notification bars found.', 'wp-notification-bars' ),
176
- 'not_found_in_trash' => __( 'No notification bars found in Trash.', 'wp-notification-bars' )
177
- );
178
-
179
- $args = array(
180
- 'labels' => $labels,
181
- 'public' => false,
182
- 'show_ui' => true,
183
- 'capability_type' => 'post',
184
- 'hierarchical' => false,
185
- 'rewrite' => false,
186
- 'publicly_queryable' => false,
187
- 'menu_position' => 100,
188
- 'menu_icon' => 'dashicons-info',
189
- 'has_archive' => false,
190
- 'supports' => array( 'title' ),
191
- );
192
-
193
- register_post_type( 'mts_notification_bar' , $args );
194
-
195
- // Filter supported post types where user ca override bar on single view
196
- $force_bar_supported_post_types = apply_filters( 'mtsnb_force_bar_post_types', array( 'post', 'page' ) );
197
-
198
- if ( ( $key = array_search( 'mts_notification_bar', $force_bar_supported_post_types ) ) !== false ) {
199
- unset( $force_bar_supported_post_types[ $key ] );
200
- }
201
-
202
- $this->force_bar_post_types = $force_bar_supported_post_types;
203
- }
204
-
205
- /**
206
- * Add preview button to edit bar page.
207
- *
208
- * @since 1.0
209
- */
210
- public function add_preview_button() {
211
- global $post;
212
- if ( 'mts_notification_bar' === $post->post_type ) {
213
- echo '<div class="misc-pub-section">';
214
- echo '<a href="#" class="button" id="preview-bar"><i class="dashicons dashicons-visibility"></i> '.__( 'Preview Bar', 'wp-notification-bars' ).'</a>';
215
- echo '</div>';
216
- }
217
- }
218
-
219
- /**
220
- * Add the Meta Box.
221
- *
222
- * @since 1.0
223
- */
224
- public function add_custom_meta_box() {
225
- add_meta_box(
226
- 'custom_meta_box',
227
- __( 'Settings', 'wp-notification-bars' ),
228
- array( $this, 'show_custom_meta_box' ),
229
- 'mts_notification_bar',
230
- 'normal',
231
- 'high'
232
- );
233
- }
234
-
235
- /**
236
- * The Callback, Meta Box Content.
237
- *
238
- * @since 1.0
239
- */
240
- public function show_custom_meta_box( $post ) {
241
-
242
- $general_options = array(
243
- array(
244
- 'type' => 'select',
245
- 'name' => 'button',
246
- 'label' => __( 'Hide/Close Button', 'wp-notification-bars' ),
247
- 'default' => 'no_button',
248
- 'options' => array(
249
- 'no_button' => __( 'No Button', 'wp-notification-bars' ),
250
- 'toggle_button' => __( 'Toggle Button', 'wp-notification-bars' ),
251
- 'close_button' => __( 'Close Button', 'wp-notification-bars' ),
252
- ),
253
- 'class' => 'mtsnb-has-child-opt',
254
- ),
255
- array(
256
- 'type' => 'number',
257
- 'name' => 'content_width',
258
- 'label' => __( 'Content Width (px)', 'wp-notification-bars' ),
259
- 'default' => '960',
260
- ),
261
- array(
262
- 'type' => 'select',
263
- 'name' => 'css_position',
264
- 'label' => __( 'Notification bar CSS position', 'wp-notification-bars' ),
265
- 'default' => 'fixed',
266
- 'options' => array(
267
- 'fixed' => __( 'Fixed', 'wp-notification-bars' ),
268
- 'absolute' => __( 'Absolute', 'wp-notification-bars' ),
269
- ),
270
- ),
271
- );
272
-
273
- $style_options = array(
274
- array(
275
- 'type' => 'color',
276
- 'name' => 'bg_color',
277
- 'label' => __( 'Background Color', 'wp-notification-bars' ),
278
- 'default' => '#d35151',
279
- ),
280
- array(
281
- 'type' => 'color',
282
- 'name' => 'txt_color',
283
- 'label' => __( 'Text Color', 'wp-notification-bars' ),
284
- 'default' => '#ffffff',
285
- ),
286
- array(
287
- 'type' => 'color',
288
- 'name' => 'link_color',
289
- 'label' => __( 'Link Color/Button Color', 'wp-notification-bars' ),
290
- 'default' => '#f4a700',
291
- ),
292
- array(
293
- 'type' => 'number',
294
- 'name' => 'font_size',
295
- 'label' => __( 'Font size (px)', 'wp-notification-bars' ),
296
- 'default' => '15',
297
- ),
298
- );
299
-
300
- $button_content_type_options = array(
301
- array(
302
- 'type' => 'select',
303
- 'name' => 'basic_link_style',
304
- 'label' => __( 'Link Style', 'wp-notification-bars' ),
305
- 'default' => 'link',
306
- 'options' => array(
307
- 'link' => __( 'Link', 'wp-notification-bars' ),
308
- 'button' => __( 'Button', 'wp-notification-bars' ),
309
- ),
310
- ),
311
- array(
312
- 'type' => 'text',
313
- 'name' => 'basic_text',
314
- 'label' => __( 'Text', 'wp-notification-bars' ),
315
- 'default' => '',
316
- ),
317
- array(
318
- 'type' => 'text',
319
- 'name' => 'basic_link_text',
320
- 'label' => __( 'Link/Button Text', 'wp-notification-bars' ),
321
- 'default' => '',
322
- ),
323
- array(
324
- 'type' => 'text',
325
- 'name' => 'basic_link_url',
326
- 'label' => __( 'Link/Button Url', 'wp-notification-bars' ),
327
- 'default' => '',
328
- ),
329
- );
330
-
331
- $custom_content_type_options = array(
332
- array(
333
- 'type' => 'textarea',
334
- 'name' => 'custom_content',
335
- 'label' => __( 'Add custom content, shortcodes allowed', 'wp-notification-bars' ),
336
- 'default' => '',
337
- ),
338
- );
339
-
340
- // Add an nonce field so we can check for it later.
341
- wp_nonce_field('mtsnb_meta_box', 'mtsnb_meta_box_nonce');
342
- // Use get_post_meta to retrieve an existing value from the database.
343
- $value = get_post_meta( $post->ID, '_mtsnb_data', true );//var_dump($value);
344
- ?>
345
- <div class="mtsnb-tabs clearfix">
346
- <div class="mtsnb-tabs-inner clearfix">
347
- <?php $active_tab = ( isset( $value['active_tab'] ) && !empty( $value['active_tab'] ) ) ? $value['active_tab'] : 'general'; ?>
348
- <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[active_tab]" id="mtsnb_fields_active_tab" value="<?php echo $active_tab; ?>" />
349
- <ul class="mtsnb-tabs-nav" id="main-tabs-nav">
350
- <li>
351
- <a href="#tab-general" <?php if ( $active_tab === 'general' ) echo 'class="active"'; ?>>
352
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-generic"></i><?php _e( 'General', 'wp-notification-bars' ); ?></span>
353
- </a>
354
- </li>
355
- <li>
356
- <a href="#tab-type" <?php if ( $active_tab === 'type' ) echo 'class="active"'; ?>>
357
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-edit"></i><?php _e( 'Content', 'wp-notification-bars' ); ?></span>
358
- </a>
359
- </li>
360
- <li>
361
- <a href="#tab-style" <?php if ( $active_tab === 'style' ) echo 'class="active"'; ?>>
362
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-appearance"></i><?php _e( 'Style', 'wp-notification-bars' ); ?></span>
363
- </a>
364
- </li>
365
- <li>
366
- <a href="#tab-conditions" <?php if ( $active_tab === 'conditions' ) echo 'class="active"'; ?>>
367
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-settings"></i><?php _e( 'Conditions', 'wp-notification-bars' ); ?></span>
368
- </a>
369
- </li>
370
- </ul>
371
- <div class="mtsnb-tabs-wrap" id="main-tabs-wrap">
372
- <div id="tab-general" class="mtsnb-tabs-content <?php if ( $active_tab === 'general' ) echo 'active'; ?>">
373
- <div class="mtsnb-tab-desc"><?php _e( 'Select basic settings like close button type and CSS position of the bar.', 'wp-notification-bars' ); ?></div>
374
- <div class="mtsnb-tab-options clearfix">
375
- <?php
376
- foreach ( $general_options as $option_args ) {
377
- $this->custom_meta_field( $option_args, $value );
378
- }
379
- ?>
380
- </div>
381
- </div>
382
- <div id="tab-type" class="mtsnb-tabs-content <?php if ( $active_tab === 'type' ) echo 'active'; ?>">
383
- <div class="mtsnb-tab-desc"><?php _e( 'Set up notification bar content. Select content type and fill in the fields.', 'wp-notification-bars' ); ?></div>
384
- <div class="mtsnb-tab-options clearfix">
385
- <?php $content_type = ( isset( $value['content_type'] ) && !empty( $value['content_type'] ) ) ? $value['content_type'] : 'button'; ?>
386
- <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[content_type]" id="mtsnb_fields_content_type" value="<?php echo $content_type; ?>" />
387
- <ul class="mtsnb-tabs-nav" id="sub-tabs-nav">
388
- <li><a href="#tab-button" <?php if ( $content_type === 'button' ) echo 'class="active"'; ?>><?php _e( 'Text and Link/Button', 'wp-notification-bars' ); ?></a></li>
389
- <li><a href="#tab-custom" <?php if ( $content_type === 'custom' ) echo 'class="active"'; ?>><?php _e( 'Custom', 'wp-notification-bars' ); ?></a></li>
390
- </ul>
391
- <div class="meta-tabs-wrap" id="sub-tabs-wrap">
392
- <div id="tab-button" class="mtsnb-tabs-content <?php if ( $content_type === 'button' ) echo 'active'; ?>">
393
- <?php
394
- foreach ( $button_content_type_options as $option_args ) {
395
- $this->custom_meta_field( $option_args, $value );
396
- }
397
- ?>
398
- </div>
399
- <div id="tab-custom" class="mtsnb-tabs-content <?php if ( $content_type === 'custom' ) echo 'active'; ?>">
400
- <?php
401
- foreach ( $custom_content_type_options as $option_args ) {
402
- $this->custom_meta_field( $option_args, $value );
403
- }
404
- ?>
405
- </div>
406
- </div>
407
- </div>
408
- </div>
409
- <div id="tab-style" class="mtsnb-tabs-content <?php if ( $active_tab === 'style' ) echo 'active'; ?>">
410
- <div class="mtsnb-tab-desc"><?php _e( 'Change the appearance of the notification bar.', 'wp-notification-bars' ); ?></div>
411
- <div class="mtsnb-tab-options clearfix">
412
- <?php
413
- foreach ( $style_options as $option_args ) {
414
- $this->custom_meta_field( $option_args, $value );
415
- }
416
- ?>
417
- </div>
418
- </div>
419
- <div id="tab-conditions" class="mtsnb-tabs-content <?php if ( $active_tab === 'conditions' ) echo 'active'; ?>">
420
- <div class="mtsnb-tab-desc"><?php _e( 'Choose when and where to display the notification bar.', 'wp-notification-bars' ); ?></div>
421
- <div id="conditions-selector-wrap" class="clearfix">
422
- <div id="conditions-selector">
423
- <ul>
424
- <?php $condition_location_state = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['state'] ) && !empty( $value['conditions']['location']['state'] ) ) ? $value['conditions']['location']['state'] : ''; ?>
425
- <?php $condition_notlocation_state = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['state'] ) && !empty( $value['conditions']['notlocation']['state'] ) ) ? $value['conditions']['notlocation']['state'] : ''; ?>
426
- <?php $condition_location_disabled = empty( $condition_notlocation_state ) ? '' : ' disabled'; ?>
427
- <?php $condition_notlocation_disabled = empty( $condition_location_state ) ? '' : ' disabled'; ?>
428
- <li id="condition-location" data-disable="notlocation" class="condition-checkbox <?php echo $condition_location_state.$condition_location_disabled; ?>">
429
- <?php _e( 'On specific locations', 'wp-notification-bars' ); ?>
430
- <div class="mtsnb-check"></div>
431
- <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_location_state" name="mtsnb_fields[conditions][location][state]" value="<?php echo $condition_location_state; ?>">
432
- </li>
433
- <li id="condition-notlocation" data-disable="location" class="condition-checkbox <?php echo $condition_notlocation_state.$condition_notlocation_disabled; ?>">
434
- <?php _e( 'Not on specific locations', 'wp-notification-bars' ); ?>
435
- <div class="mtsnb-check"></div>
436
- <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_notlocation_state" name="mtsnb_fields[conditions][notlocation][state]" value="<?php echo $condition_notlocation_state; ?>">
437
- </li>
438
- <?php $condition_google_state = isset( $value['conditions'] ) && isset( $value['conditions']['google'] ) && ( isset( $value['conditions']['google']['state'] ) && !empty( $value['conditions']['google']['state'] ) ) ? $value['conditions']['google']['state'] : ''; ?>
439
- <?php $condition_notgoogle_state = isset( $value['conditions'] ) && isset( $value['conditions']['notgoogle'] ) && ( isset( $value['conditions']['notgoogle']['state'] ) && !empty( $value['conditions']['notgoogle']['state'] ) ) ? $value['conditions']['notgoogle']['state'] : ''; ?>
440
- <?php $condition_google_disabled = empty( $condition_notgoogle_state ) ? '' : ' disabled'; ?>
441
- <?php $condition_notgoogle_disabled = empty( $condition_google_state ) ? '' : ' disabled'; ?>
442
- <li id="condition-google" data-disable="notgoogle" class="condition-checkbox <?php echo $condition_google_state.$condition_google_disabled; ?>">
443
- <?php _e( 'From Google', 'wp-notification-bars' ); ?>
444
- <div class="mtsnb-check"></div>
445
- <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_google_state" name="mtsnb_fields[conditions][google][state]" value="<?php echo $condition_google_state; ?>">
446
- </li>
447
- <li id="condition-notgoogle" data-disable="google" class="condition-checkbox <?php echo $condition_notgoogle_state.$condition_notgoogle_disabled; ?>">
448
- <?php _e( 'Not from Google', 'wp-notification-bars' ); ?>
449
- <div class="mtsnb-check"></div>
450
- <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_notgoogle_state" name="mtsnb_fields[conditions][notgoogle][state]" value="<?php echo $condition_notgoogle_state; ?>">
451
- </li>
452
- <?php $condition_facebook_state = isset( $value['conditions'] ) && isset( $value['conditions']['facebook'] ) && ( isset( $value['conditions']['facebook']['state'] ) && !empty( $value['conditions']['facebook']['state'] ) ) ? $value['conditions']['facebook']['state'] : ''; ?>
453
- <?php $condition_notfacebook_state = isset( $value['conditions'] ) && isset( $value['conditions']['notfacebook'] ) && ( isset( $value['conditions']['notfacebook']['state'] ) && !empty( $value['conditions']['notfacebook']['state'] ) ) ? $value['conditions']['notfacebook']['state'] : ''; ?>
454
- <?php $condition_facebook_disabled = empty( $condition_notfacebook_state ) ? '' : ' disabled'; ?>
455
- <?php $condition_notfacebook_disabled = empty( $condition_facebook_state ) ? '' : ' disabled'; ?>
456
- <li id="condition-facebook" data-disable="notfacebook" class="condition-checkbox <?php echo $condition_facebook_state.$condition_facebook_disabled; ?>">
457
- <?php _e( 'From Facebook', 'wp-notification-bars' ); ?>
458
- <div class="mtsnb-check"></div>
459
- <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_facebook_state" name="mtsnb_fields[conditions][facebook][state]" value="<?php echo $condition_facebook_state; ?>">
460
- </li>
461
- <li id="condition-notfacebook" data-disable="facebook" class="condition-checkbox <?php echo $condition_notfacebook_state.$condition_notfacebook_disabled; ?>">
462
- <?php _e( 'Not from Facebook', 'wp-notification-bars' ); ?>
463
- <div class="mtsnb-check"></div>
464
- <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_notfacebook_state" name="mtsnb_fields[conditions][notfacebook][state]" value="<?php echo $condition_notfacebook_state; ?>">
465
- </li>
466
- </ul>
467
- </div>
468
- <div id="conditions-panels">
469
- <div id="condition-location-panel" class="mtsnb-conditions-panel <?php echo $condition_location_state; ?>">
470
- <div class="mtsnb-conditions-panel-title"><?php _e( 'On specific locations', 'wp-notification-bars' ); ?></div>
471
- <div class="mtsnb-conditions-panel-content">
472
- <div class="mtsnb-conditions-panel-desc"><?php _e( 'Show Notification Bar on the following locations', 'wp-notification-bars' ); ?></div>
473
- <div class="mtsnb-conditions-panel-opt">
474
- <?php $location_home = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['home'] ) && !empty( $value['conditions']['location']['home'] ) ) ? $value['conditions']['location']['home'] : '0'; ?>
475
- <?php $location_blog_home = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['blog_home'] ) && !empty( $value['conditions']['location']['blog_home'] ) ) ? $value['conditions']['location']['blog_home'] : '0'; ?>
476
- <?php $location_pages = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['pages'] ) && !empty( $value['conditions']['location']['pages'] ) ) ? $value['conditions']['location']['pages'] : '0'; ?>
477
- <?php $location_posts = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['posts'] ) && !empty( $value['conditions']['location']['posts'] ) ) ? $value['conditions']['location']['posts'] : '0'; ?>
478
- <p>
479
- <label>
480
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][home]" id="mtsnb_fields_conditions_location_home" value="1" <?php checked( $location_home, '1', true ); ?> />
481
- <?php _e( 'Homepage.', 'wp-notification-bars' ); ?>
482
- </label>
483
- </p>
484
- <?php if ( 'page' === get_option('show_on_front') && '0' !== get_option('page_for_posts') && '0' !== get_option('page_on_front') ) { ?>
485
- <p>
486
- <label>
487
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][blog_home]" id="mtsnb_fields_conditions_location_blog_home" value="1" <?php checked( $location_blog_home, '1', true ); ?> />
488
- <?php _e( 'Blog Homepage.', 'wp-notification-bars' ); ?>
489
- </label>
490
- </p>
491
- <?php } ?>
492
- <p>
493
- <label>
494
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][pages]" id="mtsnb_fields_conditions_location_pages" value="1" <?php checked( $location_pages, '1', true ); ?> />
495
- <?php _e( 'Pages.', 'wp-notification-bars' ); ?>
496
- </label>
497
- </p>
498
- <p>
499
- <label>
500
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][posts]" id="mtsnb_fields_conditions_location_posts" value="1" <?php checked( $location_posts, '1', true ); ?> />
501
- <?php _e( 'Posts.', 'wp-notification-bars' ); ?>
502
- </label>
503
- </p>
504
- </div>
505
- </div>
506
- </div>
507
- <div id="condition-notlocation-panel" class="mtsnb-conditions-panel <?php echo $condition_notlocation_state; ?>">
508
- <div class="mtsnb-conditions-panel-title"><?php _e( 'Not on specific locations', 'wp-notification-bars' ); ?></div>
509
- <div class="mtsnb-conditions-panel-content">
510
- <div class="mtsnb-conditions-panel-desc"><?php _e( 'Hide Notification Bar on the following locations', 'wp-notification-bars' ); ?></div>
511
- <div class="mtsnb-conditions-panel-opt">
512
- <?php $notlocation_home = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['home'] ) && !empty( $value['conditions']['notlocation']['home'] ) ) ? $value['conditions']['notlocation']['home'] : '0'; ?>
513
- <?php $notlocation_blog_home = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['blog_home'] ) && !empty( $value['conditions']['notlocation']['blog_home'] ) ) ? $value['conditions']['notlocation']['blog_home'] : '0'; ?>
514
- <?php $notlocation_pages = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['pages'] ) && !empty( $value['conditions']['notlocation']['pages'] ) ) ? $value['conditions']['notlocation']['pages'] : '0'; ?>
515
- <?php $notlocation_posts = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['posts'] ) && !empty( $value['conditions']['notlocation']['posts'] ) ) ? $value['conditions']['notlocation']['posts'] : '0'; ?>
516
- <p>
517
- <label>
518
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][home]" id="mtsnb_fields_conditions_notlocation_home" value="1" <?php checked( $notlocation_home, '1', true ); ?> />
519
- <?php _e( 'Homepage.', 'wp-notification-bars' ); ?>
520
- </label>
521
- </p>
522
- <?php if ( 'page' === get_option('show_on_front') && '0' !== get_option('page_for_posts') && '0' !== get_option('page_on_front') ) { ?>
523
- <p>
524
- <label>
525
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][blog_home]" id="mtsnb_fields_conditions_notlocation_blog_home" value="1" <?php checked( $notlocation_blog_home, '1', true ); ?> />
526
- <?php _e( 'Blog Homepage.', 'wp-notification-bars' ); ?>
527
- </label>
528
- </p>
529
- <?php } ?>
530
- <p>
531
- <label>
532
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][pages]" id="mtsnb_fields_conditions_notlocation_pages" value="1" <?php checked( $notlocation_pages, '1', true ); ?> />
533
- <?php _e( 'Pages.', 'wp-notification-bars' ); ?>
534
- </label>
535
- </p>
536
- <p>
537
- <label>
538
- <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][posts]" id="mtsnb_fields_conditions_notlocation_posts" value="1" <?php checked( $notlocation_posts, '1', true ); ?> />
539
- <?php _e( 'Posts.', 'wp-notification-bars' ); ?>
540
- </label>
541
- </p>
542
- </div>
543
- </div>
544
- </div>
545
- <div id="condition-google-panel" class="mtsnb-conditions-panel <?php echo $condition_google_state; ?>">
546
- <div class="mtsnb-conditions-panel-title"><?php _e( 'From Google', 'wp-notification-bars' ); ?></div>
547
- <div class="mtsnb-conditions-panel-content">
548
- <div class="mtsnb-conditions-panel-desc">
549
- <p>
550
- <label>
551
- <?php _e( 'Show Notification Bar if visitor arrived via Google search engine.', 'wp-notification-bars' ); ?>
552
- </label>
553
- </p>
554
- </div>
555
- </div>
556
- </div>
557
- <div id="condition-notgoogle-panel" class="mtsnb-conditions-panel <?php echo $condition_notgoogle_state; ?>">
558
- <div class="mtsnb-conditions-panel-title"><?php _e( 'Not from Google', 'wp-notification-bars' ); ?></div>
559
- <div class="mtsnb-conditions-panel-content">
560
- <div class="mtsnb-conditions-panel-desc">
561
- <p>
562
- <label>
563
- <?php _e( 'Hide Notification Bar if visitor arrived via Google search engine.', 'wp-notification-bars' ); ?>
564
- </label>
565
- </p>
566
- </div>
567
- </div>
568
- </div>
569
- <div id="condition-facebook-panel" class="mtsnb-conditions-panel <?php echo $condition_facebook_state; ?>">
570
- <div class="mtsnb-conditions-panel-title"><?php _e( 'From Facebook', 'wp-notification-bars' ); ?></div>
571
- <div class="mtsnb-conditions-panel-content">
572
- <div class="mtsnb-conditions-panel-desc">
573
- <p>
574
- <label>
575
- <?php _e( 'Show Notification Bar if visitor arrived from Facebook.', 'wp-notification-bars' ); ?>
576
- </label>
577
- </p>
578
- </div>
579
- </div>
580
- </div>
581
- <div id="condition-notfacebook-panel" class="mtsnb-conditions-panel <?php echo $condition_notfacebook_state; ?>">
582
- <div class="mtsnb-conditions-panel-title"><?php _e( 'Not from Facebook', 'wp-notification-bars' ); ?></div>
583
- <div class="mtsnb-conditions-panel-content">
584
- <div class="mtsnb-conditions-panel-desc">
585
- <p>
586
- <label>
587
- <?php _e( 'Hide Notification Bar if visitor arrived from Facebook.', 'wp-notification-bars' ); ?>
588
- </label>
589
- </p>
590
- </div>
591
- </div>
592
- </div>
593
- </div>
594
- </div>
595
- </div>
596
- </div>
597
- </div>
598
- </div>
599
- <?php
600
- }
601
-
602
- /**
603
- * Helper function for common fields
604
- *
605
- * @since 1.0
606
- */
607
- public function custom_meta_field( $args, $value, $b = false ) {
608
-
609
- $type = isset( $args['type'] ) ? $args['type'] : '';
610
- $name = isset( $args['name'] ) ? $args['name'] : '';
611
- $name = $b ? 'b_'.$name : $name;
612
- $label = isset( $args['label'] ) ? $args['label'] : '';
613
- $options = isset( $args['options'] ) ? $args['options'] : array();
614
- $default = isset( $args['default'] ) ? $args['default'] : '';
615
- $min = isset( $args['min'] ) ? $args['min'] : '0';
616
-
617
- $class = isset( $args['class'] ) ? $args['class'] : '';
618
-
619
- // Option value
620
- $opt_val = isset( $value[ $name ] ) ? $value[ $name ] : $default;
621
-
622
- ?>
623
- <div id="mtsnb_fields_<?php echo sanitize_html_class( $name );?>_row" class="form-row">
624
- <label class="form-label" for="mtsnb_fields_<?php echo sanitize_html_class( $name );?>"><?php echo esc_html( $label ); ?></label>
625
- <div class="form-option <?php echo esc_attr( $class ); ?>">
626
- <?php
627
- switch ( $type ) {
628
-
629
- case 'text':
630
- ?>
631
- <input type="text" name="mtsnb_fields[<?php echo sanitize_html_class( $name );?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name );?>" value="<?php echo esc_attr( $opt_val );?>" />
632
- <?php
633
- break;
634
- case 'select':
635
- ?>
636
- <select name="mtsnb_fields[<?php echo sanitize_html_class( $name );?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>">
637
- <?php foreach ( $options as $val => $label ) { ?>
638
- <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $opt_val, $val, true); ?>><?php echo esc_html( $label ); ?></option>
639
- <?php } ?>
640
- </select>
641
- <?php
642
- break;
643
- case 'number':
644
- ?>
645
- <input type="number" step="1" min="<?php echo (int) $min; ?>" name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" value="<?php echo esc_attr( $opt_val ); ?>" class="small-text"/>
646
- <?php
647
- break;
648
- case 'color':
649
- ?>
650
- <input type="text" name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" value="<?php echo esc_attr( $opt_val );?>" class="mtsnb-color-picker" />
651
- <?php
652
- break;
653
- case 'textarea':
654
- ?>
655
- <textarea name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" class="mtsnb-textarea"><?php echo esc_textarea( $opt_val ); ?></textarea>
656
- <?php
657
- break;
658
- case 'checkbox':
659
- ?>
660
- <input type="checkbox" name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" value="1" <?php checked( $opt_val, '1', true ); ?> />
661
- <?php
662
- break;
663
- case 'info':
664
- ?>
665
- <small class="mtsnb-option-info">
666
- <?php echo wp_kses_post( $default ); ?>
667
- </small>
668
- <?php
669
- break;
670
- }
671
- ?>
672
- </div>
673
- </div>
674
- <?php
675
- }
676
-
677
- /**
678
- * Save the Data
679
- *
680
- * @since 1.0
681
- */
682
- public function save_custom_meta( $post_id ) {
683
- // Check if our nonce is set.
684
- if ( ! isset( $_POST['mtsnb_meta_box_nonce'] ) ) {
685
- return;
686
- }
687
- // Verify that the nonce is valid.
688
- if ( ! wp_verify_nonce( $_POST['mtsnb_meta_box_nonce'], 'mtsnb_meta_box' ) ) {
689
- return;
690
- }
691
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
692
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
693
- return;
694
- }
695
- // Check the user's permissions.
696
- if ( isset( $_POST['post_type'] ) && 'mts_notification_bar' == $_POST['post_type'] ) {
697
-
698
- if ( ! current_user_can( 'edit_page', $post_id ) ) {
699
- return;
700
- }
701
-
702
- } else {
703
-
704
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
705
- return;
706
- }
707
- }
708
-
709
- /* OK, it's safe for us to save the data now. */
710
- if ( ! isset( $_POST['mtsnb_fields'] ) ) {
711
- return;
712
- }
713
-
714
- $my_data = $_POST['mtsnb_fields'];
715
-
716
- // Update the meta field in the database.
717
- update_post_meta( $post_id, '_mtsnb_data', $my_data );
718
- }
719
-
720
- /**
721
- * Deactivate plugin if pro is active
722
- *
723
- * @since 1.0
724
- */
725
- public function check_version() {
726
-
727
- if ( defined( 'MTSNB_PLUGIN_BASE' ) ) {
728
-
729
- if ( is_plugin_active( MTSNB_PLUGIN_BASE ) || class_exists('MTSNB') ) {
730
-
731
- deactivate_plugins( MTSNBF_PLUGIN_BASE );
732
- add_action( 'admin_notices', array( $this, 'disabled_notice' ) );
733
- if ( isset( $_GET['activate'] ) ) {
734
- unset( $_GET['activate'] );
735
- }
736
- }
737
- }
738
- }
739
-
740
- public function wp_notification_bar_admin_notice() {
741
- global $current_user ;
742
- $user_id = $current_user->ID;
743
- /* Check that the user hasn't already clicked to ignore the message */
744
- /* Only show the notice 2 days after plugin activation */
745
- if ( ! get_user_meta($user_id, 'wp_notification_bar_ignore_notice') && time() >= (get_option( 'wp_notification_bar_activated', 0 ) + (2 * 24 * 60 * 60)) ) {
746
- echo '<div class="updated notice-info wp-notification-bar-notice" id="wpnotificationbar-notice" style="position:relative;">';
747
- echo __( '<p>Like WP Notification Bar plugin? You will LOVE <a target="_blank" href="https://mythemeshop.com/plugins/wp-notification-bar/?utm_source=WP+Notification+Bars&utm_medium=Notification+Link&utm_content=WP+Notification+Bar+Pro+LP&utm_campaign=WordPressOrg"><strong>WP Notification Bar Pro!</strong></a></p><a class="notice-dismiss mtsnb-notice-dismiss" data-ignore="0" href="#"></a>', 'wp-notification-bars');
748
- echo "</div>";
749
- }
750
- /* Other notice appears right after activating */
751
- /* And it gets hidden after showing 3 times */
752
- if ( ! get_user_meta($user_id, 'wp_notification_bar_ignore_notice_2') && get_option('wp_notification_bar_notice_views', 0) < 3 && get_option( 'wp_notification_bar_activated', 0 ) ) {
753
- $views = get_option('wp_notification_bar_notice_views', 0);
754
- update_option( 'wp_notification_bar_notice_views', ($views + 1) );
755
- echo '<div class="updated notice-info wp-notification-bar-notice" id="wpnotificationbar-notice2" style="position:relative;">';
756
- echo '<p>';
757
- _e( 'Thank you for trying WP Notification Bar. We hope you will like it.', 'wp-notification-bars');
758
- echo '</p>';
759
- echo '<a class="notice-dismiss mtsnb-notice-dismiss" data-ignore="1" href="#"></a>';
760
- echo "</div>";
761
- }
762
- }
763
-
764
- public function wp_notification_bar_admin_notice_ignore() {
765
- global $current_user;
766
- $user_id = $current_user->ID;
767
- /* If user clicks to ignore the notice, add that to their user meta */
768
- if ( isset($_POST['dismiss']) ) {
769
- if ( '0' == $_POST['dismiss'] ) {
770
- add_user_meta($user_id, 'wp_notification_bar_ignore_notice', '1', true);
771
- } elseif ( '1' == $_POST['dismiss'] ) {
772
- add_user_meta($user_id, 'wp_notification_bar_ignore_notice_2', '1', true);
773
- }
774
- }
775
- }
776
-
777
- /**
778
- * Deactivation notice
779
- *
780
- * @since 1.0
781
- */
782
- public function disabled_notice() {
783
- ?>
784
- <div class="updated">
785
- <p><?php _e( 'Free version of WP Notification Bars plugin disabled. Pro version is active!', 'wp-notification-bars' ); ?></p>
786
- </div>
787
- <?php
788
- }
789
-
790
- /**
791
- * Notification Bar update messages
792
- *
793
- * @since 1.0
794
- *
795
- * @param array $messages
796
- * @return array $messages
797
- */
798
- public function mtsnb_update_messages( $messages ) {
799
-
800
- global $post;
801
-
802
- $post_ID = $post->ID;
803
- $post_type = get_post_type( $post_ID );
804
-
805
- if ('mts_notification_bar' == $post_type ) {
806
-
807
- $messages['mts_notification_bar'] = array(
808
- 0 => '', // Unused. Messages start at index 1.
809
- 1 => __( 'Notification Bar updated.', 'wp-notification-bars' ),
810
- 2 => __( 'Custom field updated.', 'wp-notification-bars' ),
811
- 3 => __( 'Custom field deleted.', 'wp-notification-bars' ),
812
- 4 => __( 'Notification Bar updated.', 'wp-notification-bars' ),
813
- 5 => isset($_GET['revision']) ? sprintf( __('Notification Bar restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
814
- 6 => __( 'Notification Bar published.', 'wp-notification-bars' ),
815
- 7 => __( 'Notification Bar saved.', 'wp-notification-bars' ),
816
- 8 => __( 'Notification Bar submitted.', 'wp-notification-bars'),
817
- 9 => sprintf( __( 'Notification Bar scheduled for: <strong>%1$s</strong>.', 'wp-notification-bars' ), date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) ) ),
818
- 10 => __( 'Notification Bar draft updated.', 'wp-notification-bars' ),
819
- );
820
- }
821
-
822
- return $messages;
823
- }
824
-
825
-
826
- /**
827
- * Single post view bar select
828
- *
829
- * @since 1.0.1
830
- */
831
- public function mtsnb_select_metabox_insert() {
832
-
833
- $force_bar_post_types = $this->force_bar_post_types;
834
-
835
- if ( $force_bar_post_types && is_array( $force_bar_post_types ) ) {
836
-
837
- foreach ( $force_bar_post_types as $screen ) {
838
-
839
- add_meta_box(
840
- 'mtsnb_single_bar_metabox',
841
- __( 'Notification Bar', 'wp-notification-bars' ),
842
- array( $this, 'mtsnb_select_metabox_content' ),
843
- $screen,
844
- 'side',
845
- 'default'
846
- );
847
- }
848
- }
849
- }
850
- public function mtsnb_select_metabox_content( $post ) {
851
-
852
- // Add an nonce field so we can check for it later.
853
- wp_nonce_field('mtsnb_select_metabox_save', 'mtsnb_select_metabox_nonce');
854
-
855
- /*
856
- * Use get_post_meta() to retrieve an existing value
857
- * from the database and use the value for the form.
858
- */
859
- $bar = get_post_meta( $post->ID, '_mtsnb_override_bar', true );
860
-
861
- $processed_item_ids = '';
862
- if ( !empty( $bar ) ) {
863
- // Some entries may be arrays themselves!
864
- $processed_item_ids = array();
865
- foreach ($bar as $this_id) {
866
- if (is_array($this_id)) {
867
- $processed_item_ids = array_merge( $processed_item_ids, $this_id );
868
- } else {
869
- $processed_item_ids[] = $this_id;
870
- }
871
- }
872
-
873
- if (is_array($processed_item_ids) && !empty($processed_item_ids)) {
874
- $processed_item_ids = implode(',', $processed_item_ids);
875
- } else {
876
- $processed_item_ids = '';
877
- }
878
- }
879
- ?>
880
- <p>
881
- <label for="mtsnb_override_bar_field"><?php _e( 'Select Notification Bar (optional):', 'wp-notification-bars' ); ?></label><br />
882
- <input style="width: 400px;" type="hidden" id="mtsnb_override_bar_field" name="mtsnb_override_bar_field" class="mtsnb-bar-select" value="<?php echo $processed_item_ids; ?>" />
883
- </p>
884
- <p>
885
- <i><?php _e( 'Selected notification bar will override any other bar.', 'wp-notification-bars' ); ?></i>
886
- </p>
887
- <?php
888
- }
889
-
890
- public function mtsnb_select_metabox_save( $post_id ) {
891
-
892
- // Check if our nonce is set.
893
- if ( ! isset( $_POST['mtsnb_select_metabox_nonce'] ) ) {
894
- return;
895
- }
896
- // Verify that the nonce is valid.
897
- if ( ! wp_verify_nonce( $_POST['mtsnb_select_metabox_nonce'], 'mtsnb_select_metabox_save' ) ) {
898
- return;
899
- }
900
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
901
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
902
- return;
903
- }
904
-
905
- // Check the user's permissions.
906
- if ( 'page' == $_POST['post_type'] ) {
907
-
908
- if ( ! current_user_can( 'edit_page', $post_id ) )
909
- return;
910
-
911
- } else {
912
-
913
- if ( ! current_user_can( 'edit_post', $post_id ) )
914
- return;
915
- }
916
-
917
- /* OK, its safe for us to save the data now. */
918
- if ( ! isset( $_POST['mtsnb_override_bar_field'] ) ) {
919
- return;
920
- }
921
-
922
- $val = $_POST['mtsnb_override_bar_field'];
923
-
924
- if (strpos($val, ',') === false) {
925
- // No comma, must be single value - still needs to be in an array for now
926
- $post_ids = array( $val );
927
- } else {
928
- // There is a comma so it's explodable
929
- $post_ids = explode(',', $val);
930
- }
931
-
932
- // Update the meta field in the database.
933
- update_post_meta( $post_id, '_mtsnb_override_bar', $post_ids );
934
- }
935
-
936
- /**
937
- * Bar select ajax function
938
- *
939
- * @since 1.0.1
940
- */
941
- public function mtsnb_get_bars() {
942
-
943
- $result = array();
944
-
945
- $search = $_REQUEST['q'];
946
-
947
- $ads_query = array(
948
- 'posts_per_page' => -1,
949
- 'post_status' => array('publish'),
950
- 'post_type' => 'mts_notification_bar',
951
- 'order' => 'ASC',
952
- 'orderby' => 'title',
953
- 'suppress_filters' => false,
954
- 's'=> $search
955
- );
956
- $posts = get_posts( $ads_query );
957
-
958
- // We'll return a JSON-encoded result.
959
- foreach ( $posts as $this_post ) {
960
- $post_title = $this_post->post_title;
961
- $id = $this_post->ID;
962
-
963
- $result[] = array(
964
- 'id' => $id,
965
- 'title' => $post_title,
966
- );
967
- }
968
-
969
- echo json_encode( $result );
970
-
971
- die();
972
- }
973
-
974
- public function mtsnb_get_bar_titles() {
975
- $result = array();
976
-
977
- if (isset($_REQUEST['post_ids'])) {
978
- $post_ids = $_REQUEST['post_ids'];
979
- if (strpos($post_ids, ',') === false) {
980
- // There is no comma, so we can't explode, but we still want an array
981
- $post_ids = array( $post_ids );
982
- } else {
983
- // There is a comma, so it must be explodable
984
- $post_ids = explode(',', $post_ids);
985
- }
986
- } else {
987
- $post_ids = array();
988
- }
989
-
990
- if (is_array($post_ids) && ! empty($post_ids)) {
991
-
992
- $posts = get_posts(array(
993
- 'posts_per_page' => -1,
994
- 'post_status' => array('publish'),
995
- 'post__in' => $post_ids,
996
- 'post_type' => 'mts_notification_bar'
997
- ));
998
- foreach ( $posts as $this_post ) {
999
- $result[] = array(
1000
- 'id' => $this_post->ID,
1001
- 'title' => $this_post->post_title,
1002
- );
1003
- }
1004
- }
1005
-
1006
- echo json_encode( $result );
1007
-
1008
- die();
1009
- }
1010
- }
1011
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * The dashboard-specific functionality of the plugin.
5
+ *
6
+ * @link http://mythemeshop.com
7
+ * @since 1.0
8
+ *
9
+ * @package MTSNBF
10
+ * @subpackage MTSNBF/admin
11
+ */
12
+
13
+ /**
14
+ * The dashboard-specific functionality of the plugin.
15
+ *
16
+ * Defines the plugin name, version, and two examples hooks for how to
17
+ * enqueue the dashboard-specific stylesheet and JavaScript.
18
+ *
19
+ * @package MTSNBF
20
+ * @subpackage MTSNBF/admin
21
+ * @author MyThemeShop
22
+ */
23
+ // If this file is called directly, abort.
24
+ if ( ! defined( 'WPINC' ) ) {
25
+ die;
26
+ }
27
+
28
+ if ( ! class_exists( 'MTSNBF_Admin' ) ) {
29
+ class MTSNBF_Admin {
30
+
31
+ /**
32
+ * The ID of this plugin.
33
+ *
34
+ * @since 1.0
35
+ * @access private
36
+ * @var string $plugin_name The ID of this plugin.
37
+ */
38
+ private $plugin_name;
39
+
40
+ /**
41
+ * The version of this plugin.
42
+ *
43
+ * @since 1.0
44
+ * @access private
45
+ * @var string $version The current version of this plugin.
46
+ */
47
+ private $version;
48
+
49
+ /**
50
+ * Post types where user can override bar on single view.
51
+ *
52
+ * @var [type]
53
+ */
54
+ private $force_bar_post_types;
55
+
56
+ /**
57
+ * Initialize the class and set its properties.
58
+ *
59
+ * @since 1.0
60
+ * @param string $plugin_name The name of this plugin.
61
+ * @param string $version The version of this plugin.
62
+ */
63
+ public function __construct( $plugin_name, $version ) {
64
+ $this->plugin_name = $plugin_name;
65
+ $this->version = $version;
66
+ }
67
+
68
+ /**
69
+ * Register the stylesheets for the Dashboard.
70
+ *
71
+ * @since 1.0
72
+ */
73
+ public function enqueue_styles() {
74
+ $screen = get_current_screen();
75
+ $screen_id = $screen->id;
76
+
77
+ $force_bar_post_types = $this->force_bar_post_types;
78
+
79
+ if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types, true ) ) {
80
+
81
+ wp_enqueue_style( 'wp-color-picker' );
82
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-notification-bars-admin.css', array(), $this->version, 'all' );
83
+ if ( 'mts_notification_bar' !== $screen_id ) {
84
+ wp_enqueue_style( $this->plugin_name . '_select2', plugin_dir_url( __FILE__ ) . 'css/select2.min.css', array(), $this->version, 'all' );
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Register the JavaScript for the dashboard.
91
+ *
92
+ * @since 1.0
93
+ */
94
+ public function enqueue_scripts() {
95
+
96
+ $screen = get_current_screen();
97
+ $screen_id = $screen->id;
98
+
99
+ $force_bar_post_types = $this->force_bar_post_types;
100
+
101
+ if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types, true ) ) {
102
+
103
+ wp_enqueue_script( 'wp-color-picker' );
104
+
105
+ if ( 'mts_notification_bar' !== $screen_id ) {
106
+
107
+ wp_enqueue_script(
108
+ $this->plugin_name . '_select2',
109
+ plugin_dir_url( __FILE__ ) . 'js/select2.full.min.js',
110
+ array( 'jquery' ),
111
+ $this->version,
112
+ false
113
+ );
114
+ }
115
+
116
+ wp_enqueue_script(
117
+ $this->plugin_name,
118
+ plugin_dir_url( __FILE__ ) . 'js/wp-notification-bars-admin.js',
119
+ array(
120
+ 'jquery',
121
+ 'wp-color-picker',
122
+ ),
123
+ $this->version,
124
+ false
125
+ );
126
+
127
+ wp_localize_script(
128
+ $this->plugin_name,
129
+ 'mtsnb_locale',
130
+ array(
131
+ 'select_placeholder' => __( 'Enter Notification Bar Title', 'wp-notification-bars' ),
132
+ )
133
+ );
134
+ }
135
+
136
+ wp_enqueue_script(
137
+ $this->plugin_name,
138
+ plugin_dir_url( __FILE__ ) . 'js/wp-nb-admin-notices.js',
139
+ array(
140
+ 'jquery',
141
+ ),
142
+ $this->version,
143
+ false
144
+ );
145
+ }
146
+
147
+ //
148
+ // CPT /////////
149
+ //
150
+
151
+ /**
152
+ * Register MTS Notification Bar Post Type, attached to 'init'
153
+ *
154
+ * @since 1.0
155
+ */
156
+ public function mts_notification_cpt() {
157
+ $labels = array(
158
+ 'name' => _x( 'Notification Bars', 'post type general name', 'wp-notification-bars' ),
159
+ 'singular_name' => _x( 'Notification Bar', 'post type singular name', 'wp-notification-bars' ),
160
+ 'menu_name' => _x( 'Notification Bars', 'admin menu', 'wp-notification-bars' ),
161
+ 'name_admin_bar' => _x( 'Notification Bar', 'add new on admin bar', 'wp-notification-bars' ),
162
+ 'add_new' => _x( 'Add New', 'notification bar', 'wp-notification-bars' ),
163
+ 'add_new_item' => __( 'Add New Notification Bar', 'wp-notification-bars' ),
164
+ 'new_item' => __( 'New Notification Bar', 'wp-notification-bars' ),
165
+ 'edit_item' => __( 'Edit Notification Bar', 'wp-notification-bars' ),
166
+ 'view_item' => __( 'View Notification Bar', 'wp-notification-bars' ),
167
+ 'all_items' => __( 'All Notification Bars', 'wp-notification-bars' ),
168
+ 'search_items' => __( 'Search Notification Bars', 'wp-notification-bars' ),
169
+ 'parent_item_colon' => __( 'Parent Notification Bars:', 'wp-notification-bars' ),
170
+ 'not_found' => __( 'No notification bars found.', 'wp-notification-bars' ),
171
+ 'not_found_in_trash' => __( 'No notification bars found in Trash.', 'wp-notification-bars' ),
172
+ );
173
+
174
+ $args = array(
175
+ 'labels' => $labels,
176
+ 'public' => false,
177
+ 'show_ui' => true,
178
+ 'capability_type' => 'post',
179
+ 'hierarchical' => false,
180
+ 'rewrite' => false,
181
+ 'publicly_queryable' => false,
182
+ 'menu_position' => 100,
183
+ 'menu_icon' => 'dashicons-info',
184
+ 'has_archive' => false,
185
+ 'supports' => array( 'title' ),
186
+ );
187
+
188
+ register_post_type( 'mts_notification_bar', $args );
189
+
190
+ // Filter supported post types where user can override bar on single view.
191
+ $force_bar_supported_post_types = apply_filters( 'mtsnb_force_bar_post_types', array( 'post', 'page' ) );
192
+
193
+ $key = array_search( 'mts_notification_bar', $force_bar_supported_post_types, true );
194
+ if ( false !== $key ) {
195
+ unset( $force_bar_supported_post_types[ $key ] );
196
+ }
197
+
198
+ $this->force_bar_post_types = $force_bar_supported_post_types;
199
+ }
200
+
201
+ /**
202
+ * Add preview button to edit bar page.
203
+ *
204
+ * @since 1.0
205
+ */
206
+ public function add_preview_button() {
207
+ global $post;
208
+ if ( 'mts_notification_bar' === $post->post_type ) {
209
+ echo '<div class="misc-pub-section">';
210
+ echo '<a href="#" class="button" id="preview-bar"><i class="dashicons dashicons-visibility"></i> ' . esc_html__( 'Preview Bar', 'wp-notification-bars' ) . '</a>';
211
+ echo '</div>';
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Add the Meta Box.
217
+ *
218
+ * @since 1.0
219
+ */
220
+ public function add_custom_meta_box() {
221
+ add_meta_box(
222
+ 'custom_meta_box',
223
+ __( 'Settings', 'wp-notification-bars' ),
224
+ array( $this, 'show_custom_meta_box' ),
225
+ 'mts_notification_bar',
226
+ 'normal',
227
+ 'high'
228
+ );
229
+ }
230
+
231
+ /**
232
+ * The Callback, Meta Box Content.
233
+ *
234
+ * @since 1.0
235
+ */
236
+ public function show_custom_meta_box( $post ) {
237
+
238
+ $general_options = array(
239
+ array(
240
+ 'type' => 'select',
241
+ 'name' => 'button',
242
+ 'label' => __( 'Hide/Close Button', 'wp-notification-bars' ),
243
+ 'default' => 'no_button',
244
+ 'options' => array(
245
+ 'no_button' => __( 'No Button', 'wp-notification-bars' ),
246
+ 'toggle_button' => __( 'Toggle Button', 'wp-notification-bars' ),
247
+ 'close_button' => __( 'Close Button', 'wp-notification-bars' ),
248
+ ),
249
+ 'class' => 'mtsnb-has-child-opt',
250
+ ),
251
+ array(
252
+ 'type' => 'number',
253
+ 'name' => 'content_width',
254
+ 'label' => __( 'Content Width (px)', 'wp-notification-bars' ),
255
+ 'default' => '960',
256
+ ),
257
+ array(
258
+ 'type' => 'select',
259
+ 'name' => 'css_position',
260
+ 'label' => __( 'Notification bar CSS position', 'wp-notification-bars' ),
261
+ 'default' => 'fixed',
262
+ 'options' => array(
263
+ 'fixed' => __( 'Fixed', 'wp-notification-bars' ),
264
+ 'absolute' => __( 'Absolute', 'wp-notification-bars' ),
265
+ ),
266
+ ),
267
+ );
268
+
269
+ $style_options = array(
270
+ array(
271
+ 'type' => 'color',
272
+ 'name' => 'bg_color',
273
+ 'label' => __( 'Background Color', 'wp-notification-bars' ),
274
+ 'default' => '#d35151',
275
+ ),
276
+ array(
277
+ 'type' => 'color',
278
+ 'name' => 'txt_color',
279
+ 'label' => __( 'Text Color', 'wp-notification-bars' ),
280
+ 'default' => '#ffffff',
281
+ ),
282
+ array(
283
+ 'type' => 'color',
284
+ 'name' => 'link_color',
285
+ 'label' => __( 'Link Color/Button Color', 'wp-notification-bars' ),
286
+ 'default' => '#f4a700',
287
+ ),
288
+ array(
289
+ 'type' => 'number',
290
+ 'name' => 'font_size',
291
+ 'label' => __( 'Font size (px)', 'wp-notification-bars' ),
292
+ 'default' => '15',
293
+ ),
294
+ );
295
+
296
+ $button_content_type_options = array(
297
+ array(
298
+ 'type' => 'select',
299
+ 'name' => 'basic_link_style',
300
+ 'label' => __( 'Link Style', 'wp-notification-bars' ),
301
+ 'default' => 'link',
302
+ 'options' => array(
303
+ 'link' => __( 'Link', 'wp-notification-bars' ),
304
+ 'button' => __( 'Button', 'wp-notification-bars' ),
305
+ ),
306
+ ),
307
+ array(
308
+ 'type' => 'text',
309
+ 'name' => 'basic_text',
310
+ 'label' => __( 'Text', 'wp-notification-bars' ),
311
+ 'default' => '',
312
+ ),
313
+ array(
314
+ 'type' => 'text',
315
+ 'name' => 'basic_link_text',
316
+ 'label' => __( 'Link/Button Text', 'wp-notification-bars' ),
317
+ 'default' => '',
318
+ ),
319
+ array(
320
+ 'type' => 'text',
321
+ 'name' => 'basic_link_url',
322
+ 'label' => __( 'Link/Button Url', 'wp-notification-bars' ),
323
+ 'default' => '',
324
+ ),
325
+ );
326
+
327
+ $custom_content_type_options = array(
328
+ array(
329
+ 'type' => 'textarea',
330
+ 'name' => 'custom_content',
331
+ 'label' => __( 'Add custom content, shortcodes allowed', 'wp-notification-bars' ),
332
+ 'default' => '',
333
+ ),
334
+ );
335
+
336
+ // Add an nonce field so we can check for it later.
337
+ wp_nonce_field( 'mtsnb_meta_box', 'mtsnb_meta_box_nonce' );
338
+ // Use get_post_meta to retrieve an existing value from the database.
339
+ $value = get_post_meta( $post->ID, '_mtsnb_data', true );
340
+ ?>
341
+ <div class="mtsnb-tabs clearfix">
342
+ <div class="mtsnb-tabs-inner clearfix">
343
+ <?php $active_tab = ( isset( $value['active_tab'] ) && ! empty( $value['active_tab'] ) ) ? $value['active_tab'] : 'general'; ?>
344
+ <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[active_tab]" id="mtsnb_fields_active_tab" value="<?php echo esc_attr( $active_tab ); ?>" />
345
+ <ul class="mtsnb-tabs-nav" id="main-tabs-nav">
346
+ <li>
347
+ <a href="#tab-general" <?php $this->active_class( $active_tab, 'general', true ); ?>>
348
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-generic"></i><?php esc_html_e( 'General', 'wp-notification-bars' ); ?></span>
349
+ </a>
350
+ </li>
351
+ <li>
352
+ <a href="#tab-type" <?php $this->active_class( $active_tab, 'type', true ); ?>>
353
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-edit"></i><?php esc_html_e( 'Content', 'wp-notification-bars' ); ?></span>
354
+ </a>
355
+ </li>
356
+ <li>
357
+ <a href="#tab-style" <?php $this->active_class( $active_tab, 'style', true ); ?>>
358
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-appearance"></i><?php esc_html_e( 'Style', 'wp-notification-bars' ); ?></span>
359
+ </a>
360
+ </li>
361
+ <li>
362
+ <a href="#tab-conditions" <?php $this->active_class( $active_tab, 'conditions', true ); ?>>
363
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-settings"></i><?php esc_html_e( 'Conditions', 'wp-notification-bars' ); ?></span>
364
+ </a>
365
+ </li>
366
+ </ul>
367
+ <div class="mtsnb-tabs-wrap" id="main-tabs-wrap">
368
+ <div id="tab-general" class="mtsnb-tabs-content <?php $this->active_class( $active_tab, 'general', false ); ?>">
369
+ <div class="mtsnb-tab-desc"><?php esc_html_e( 'Select basic settings like close button type and CSS position of the bar.', 'wp-notification-bars' ); ?></div>
370
+ <div class="mtsnb-tab-options clearfix">
371
+ <?php
372
+ foreach ( $general_options as $option_args ) {
373
+ $this->custom_meta_field( $option_args, $value );
374
+ }
375
+ ?>
376
+ </div>
377
+ </div>
378
+ <div id="tab-type" class="mtsnb-tabs-content <?php $this->active_class( $active_tab, 'type', false ); ?>">
379
+ <div class="mtsnb-tab-desc"><?php esc_html_e( 'Set up notification bar content. Select content type and fill in the fields.', 'wp-notification-bars' ); ?></div>
380
+ <div class="mtsnb-tab-options clearfix">
381
+ <?php $content_type = ( isset( $value['content_type'] ) && ! empty( $value['content_type'] ) ) ? $value['content_type'] : 'button'; ?>
382
+ <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[content_type]" id="mtsnb_fields_content_type" value="<?php echo esc_attr( $content_type ); ?>" />
383
+ <ul class="mtsnb-tabs-nav" id="sub-tabs-nav">
384
+ <li><a href="#tab-button" <?php $this->active_class( $content_type, 'button', true ); ?>><?php esc_html_e( 'Text and Link/Button', 'wp-notification-bars' ); ?></a></li>
385
+ <li><a href="#tab-custom" <?php $this->active_class( $content_type, 'custom', true ); ?>><?php esc_html_e( 'Custom', 'wp-notification-bars' ); ?></a></li>
386
+ </ul>
387
+ <div class="meta-tabs-wrap" id="sub-tabs-wrap">
388
+ <div id="tab-button" class="mtsnb-tabs-content <?php $this->active_class( $content_type, 'button', false ); ?>">
389
+ <?php
390
+ foreach ( $button_content_type_options as $option_args ) {
391
+ $this->custom_meta_field( $option_args, $value );
392
+ }
393
+ ?>
394
+ </div>
395
+ <div id="tab-custom" class="mtsnb-tabs-content <?php $this->active_class( $content_type, 'custom', false ); ?>">
396
+ <?php
397
+ foreach ( $custom_content_type_options as $option_args ) {
398
+ $this->custom_meta_field( $option_args, $value );
399
+ }
400
+ ?>
401
+ </div>
402
+ </div>
403
+ </div>
404
+ </div>
405
+ <div id="tab-style" class="mtsnb-tabs-content <?php $this->active_class( $active_tab, 'style', false ); ?>">
406
+ <div class="mtsnb-tab-desc"><?php esc_html_e( 'Change the appearance of the notification bar.', 'wp-notification-bars' ); ?></div>
407
+ <div class="mtsnb-tab-options clearfix">
408
+ <?php
409
+ foreach ( $style_options as $option_args ) {
410
+ $this->custom_meta_field( $option_args, $value );
411
+ }
412
+ ?>
413
+ </div>
414
+ </div>
415
+ <div id="tab-conditions" class="mtsnb-tabs-content <?php $this->active_class( $active_tab, 'conditions', false ); ?>">
416
+ <div class="mtsnb-tab-desc"><?php esc_html_e( 'Choose when and where to display the notification bar.', 'wp-notification-bars' ); ?></div>
417
+ <div id="conditions-selector-wrap" class="clearfix">
418
+ <div id="conditions-selector">
419
+ <ul>
420
+ <?php $condition_location_state = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['state'] ) && ! empty( $value['conditions']['location']['state'] ) ) ? $value['conditions']['location']['state'] : ''; ?>
421
+ <?php $condition_notlocation_state = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['state'] ) && ! empty( $value['conditions']['notlocation']['state'] ) ) ? $value['conditions']['notlocation']['state'] : ''; ?>
422
+ <?php $condition_location_disabled = empty( $condition_notlocation_state ) ? '' : ' disabled'; ?>
423
+ <?php $condition_notlocation_disabled = empty( $condition_location_state ) ? '' : ' disabled'; ?>
424
+ <li id="condition-location" data-disable="notlocation" class="condition-checkbox <?php echo esc_attr( $condition_location_state . $condition_location_disabled ); ?>">
425
+ <?php esc_html_e( 'On specific locations', 'wp-notification-bars' ); ?>
426
+ <div class="mtsnb-check"></div>
427
+ <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_location_state" name="mtsnb_fields[conditions][location][state]" value="<?php echo esc_attr( $condition_location_state ); ?>">
428
+ </li>
429
+ <li id="condition-notlocation" data-disable="location" class="condition-checkbox <?php echo esc_attr( $condition_notlocation_state . $condition_notlocation_disabled ); ?>">
430
+ <?php esc_html_e( 'Not on specific locations', 'wp-notification-bars' ); ?>
431
+ <div class="mtsnb-check"></div>
432
+ <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_notlocation_state" name="mtsnb_fields[conditions][notlocation][state]" value="<?php echo esc_attr( $condition_notlocation_state ); ?>">
433
+ </li>
434
+ <?php $condition_google_state = isset( $value['conditions'] ) && isset( $value['conditions']['google'] ) && ( isset( $value['conditions']['google']['state'] ) && ! empty( $value['conditions']['google']['state'] ) ) ? $value['conditions']['google']['state'] : ''; ?>
435
+ <?php $condition_notgoogle_state = isset( $value['conditions'] ) && isset( $value['conditions']['notgoogle'] ) && ( isset( $value['conditions']['notgoogle']['state'] ) && ! empty( $value['conditions']['notgoogle']['state'] ) ) ? $value['conditions']['notgoogle']['state'] : ''; ?>
436
+ <?php $condition_google_disabled = empty( $condition_notgoogle_state ) ? '' : ' disabled'; ?>
437
+ <?php $condition_notgoogle_disabled = empty( $condition_google_state ) ? '' : ' disabled'; ?>
438
+ <li id="condition-google" data-disable="notgoogle" class="condition-checkbox <?php echo esc_attr( $condition_google_state . $condition_google_disabled ); ?>">
439
+ <?php esc_html_e( 'From Google', 'wp-notification-bars' ); ?>
440
+ <div class="mtsnb-check"></div>
441
+ <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_google_state" name="mtsnb_fields[conditions][google][state]" value="<?php echo esc_attr( $condition_google_state ); ?>">
442
+ </li>
443
+ <li id="condition-notgoogle" data-disable="google" class="condition-checkbox <?php echo esc_attr( $condition_notgoogle_state . $condition_notgoogle_disabled ); ?>">
444
+ <?php esc_html_e( 'Not from Google', 'wp-notification-bars' ); ?>
445
+ <div class="mtsnb-check"></div>
446
+ <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_notgoogle_state" name="mtsnb_fields[conditions][notgoogle][state]" value="<?php echo esc_attr( $condition_notgoogle_state ); ?>">
447
+ </li>
448
+ <?php $condition_facebook_state = isset( $value['conditions'] ) && isset( $value['conditions']['facebook'] ) && ( isset( $value['conditions']['facebook']['state'] ) && ! empty( $value['conditions']['facebook']['state'] ) ) ? $value['conditions']['facebook']['state'] : ''; ?>
449
+ <?php $condition_notfacebook_state = isset( $value['conditions'] ) && isset( $value['conditions']['notfacebook'] ) && ( isset( $value['conditions']['notfacebook']['state'] ) && ! empty( $value['conditions']['notfacebook']['state'] ) ) ? $value['conditions']['notfacebook']['state'] : ''; ?>
450
+ <?php $condition_facebook_disabled = empty( $condition_notfacebook_state ) ? '' : ' disabled'; ?>
451
+ <?php $condition_notfacebook_disabled = empty( $condition_facebook_state ) ? '' : ' disabled'; ?>
452
+ <li id="condition-facebook" data-disable="notfacebook" class="condition-checkbox <?php echo esc_attr( $condition_facebook_state . $condition_facebook_disabled ); ?>">
453
+ <?php esc_html_e( 'From Facebook', 'wp-notification-bars' ); ?>
454
+ <div class="mtsnb-check"></div>
455
+ <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_facebook_state" name="mtsnb_fields[conditions][facebook][state]" value="<?php echo esc_attr( $condition_facebook_state ); ?>">
456
+ </li>
457
+ <li id="condition-notfacebook" data-disable="facebook" class="condition-checkbox <?php echo esc_attr( $condition_notfacebook_state . $condition_notfacebook_disabled ); ?>">
458
+ <?php esc_html_e( 'Not from Facebook', 'wp-notification-bars' ); ?>
459
+ <div class="mtsnb-check"></div>
460
+ <input type="hidden" class="mtsnb-condition-checkbox-input" id="mtsnb_fields_conditions_notfacebook_state" name="mtsnb_fields[conditions][notfacebook][state]" value="<?php echo esc_attr( $condition_notfacebook_state ); ?>">
461
+ </li>
462
+ </ul>
463
+ </div>
464
+ <div id="conditions-panels">
465
+ <div id="condition-location-panel" class="mtsnb-conditions-panel <?php echo esc_attr( $condition_location_state ); ?>">
466
+ <div class="mtsnb-conditions-panel-title"><?php esc_html_e( 'On specific locations', 'wp-notification-bars' ); ?></div>
467
+ <div class="mtsnb-conditions-panel-content">
468
+ <div class="mtsnb-conditions-panel-desc"><?php esc_html_e( 'Show Notification Bar on the following locations', 'wp-notification-bars' ); ?></div>
469
+ <div class="mtsnb-conditions-panel-opt">
470
+ <?php $location_home = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['home'] ) && ! empty( $value['conditions']['location']['home'] ) ) ? $value['conditions']['location']['home'] : '0'; ?>
471
+ <?php $location_blog_home = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['blog_home'] ) && ! empty( $value['conditions']['location']['blog_home'] ) ) ? $value['conditions']['location']['blog_home'] : '0'; ?>
472
+ <?php $location_pages = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['pages'] ) && ! empty( $value['conditions']['location']['pages'] ) ) ? $value['conditions']['location']['pages'] : '0'; ?>
473
+ <?php $location_posts = isset( $value['conditions'] ) && isset( $value['conditions']['location'] ) && ( isset( $value['conditions']['location']['posts'] ) && ! empty( $value['conditions']['location']['posts'] ) ) ? $value['conditions']['location']['posts'] : '0'; ?>
474
+ <p>
475
+ <label>
476
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][home]" id="mtsnb_fields_conditions_location_home" value="1" <?php checked( $location_home, '1', true ); ?> />
477
+ <?php esc_html_e( 'Homepage.', 'wp-notification-bars' ); ?>
478
+ </label>
479
+ </p>
480
+ <?php if ( 'page' === get_option( 'show_on_front' ) && '0' !== get_option( 'page_for_posts' ) && '0' !== get_option( 'page_on_front' ) ) { ?>
481
+ <p>
482
+ <label>
483
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][blog_home]" id="mtsnb_fields_conditions_location_blog_home" value="1" <?php checked( $location_blog_home, '1', true ); ?> />
484
+ <?php esc_html_e( 'Blog Homepage.', 'wp-notification-bars' ); ?>
485
+ </label>
486
+ </p>
487
+ <?php } ?>
488
+ <p>
489
+ <label>
490
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][pages]" id="mtsnb_fields_conditions_location_pages" value="1" <?php checked( $location_pages, '1', true ); ?> />
491
+ <?php esc_html_e( 'Pages.', 'wp-notification-bars' ); ?>
492
+ </label>
493
+ </p>
494
+ <p>
495
+ <label>
496
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][location][posts]" id="mtsnb_fields_conditions_location_posts" value="1" <?php checked( $location_posts, '1', true ); ?> />
497
+ <?php esc_html_e( 'Posts.', 'wp-notification-bars' ); ?>
498
+ </label>
499
+ </p>
500
+ </div>
501
+ </div>
502
+ </div>
503
+ <div id="condition-notlocation-panel" class="mtsnb-conditions-panel <?php echo esc_attr( $condition_notlocation_state ); ?>">
504
+ <div class="mtsnb-conditions-panel-title"><?php esc_html_e( 'Not on specific locations', 'wp-notification-bars' ); ?></div>
505
+ <div class="mtsnb-conditions-panel-content">
506
+ <div class="mtsnb-conditions-panel-desc"><?php esc_html_e( 'Hide Notification Bar on the following locations', 'wp-notification-bars' ); ?></div>
507
+ <div class="mtsnb-conditions-panel-opt">
508
+ <?php $notlocation_home = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['home'] ) && ! empty( $value['conditions']['notlocation']['home'] ) ) ? $value['conditions']['notlocation']['home'] : '0'; ?>
509
+ <?php $notlocation_blog_home = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['blog_home'] ) && ! empty( $value['conditions']['notlocation']['blog_home'] ) ) ? $value['conditions']['notlocation']['blog_home'] : '0'; ?>
510
+ <?php $notlocation_pages = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['pages'] ) && ! empty( $value['conditions']['notlocation']['pages'] ) ) ? $value['conditions']['notlocation']['pages'] : '0'; ?>
511
+ <?php $notlocation_posts = isset( $value['conditions'] ) && isset( $value['conditions']['notlocation'] ) && ( isset( $value['conditions']['notlocation']['posts'] ) && ! empty( $value['conditions']['notlocation']['posts'] ) ) ? $value['conditions']['notlocation']['posts'] : '0'; ?>
512
+ <p>
513
+ <label>
514
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][home]" id="mtsnb_fields_conditions_notlocation_home" value="1" <?php checked( $notlocation_home, '1', true ); ?> />
515
+ <?php esc_html_e( 'Homepage.', 'wp-notification-bars' ); ?>
516
+ </label>
517
+ </p>
518
+ <?php if ( 'page' === get_option( 'show_on_front' ) && '0' !== get_option( 'page_for_posts' ) && '0' !== get_option( 'page_on_front' ) ) { ?>
519
+ <p>
520
+ <label>
521
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][blog_home]" id="mtsnb_fields_conditions_notlocation_blog_home" value="1" <?php checked( $notlocation_blog_home, '1', true ); ?> />
522
+ <?php esc_html_e( 'Blog Homepage.', 'wp-notification-bars' ); ?>
523
+ </label>
524
+ </p>
525
+ <?php } ?>
526
+ <p>
527
+ <label>
528
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][pages]" id="mtsnb_fields_conditions_notlocation_pages" value="1" <?php checked( $notlocation_pages, '1', true ); ?> />
529
+ <?php esc_html_e( 'Pages.', 'wp-notification-bars' ); ?>
530
+ </label>
531
+ </p>
532
+ <p>
533
+ <label>
534
+ <input type="checkbox" class="mtsnb-checkbox" name="mtsnb_fields[conditions][notlocation][posts]" id="mtsnb_fields_conditions_notlocation_posts" value="1" <?php checked( $notlocation_posts, '1', true ); ?> />
535
+ <?php esc_html_e( 'Posts.', 'wp-notification-bars' ); ?>
536
+ </label>
537
+ </p>
538
+ </div>
539
+ </div>
540
+ </div>
541
+ <div id="condition-google-panel" class="mtsnb-conditions-panel <?php echo esc_attr( $condition_google_state ); ?>">
542
+ <div class="mtsnb-conditions-panel-title"><?php esc_html_e( 'From Google', 'wp-notification-bars' ); ?></div>
543
+ <div class="mtsnb-conditions-panel-content">
544
+ <div class="mtsnb-conditions-panel-desc">
545
+ <p>
546
+ <label>
547
+ <?php esc_html_e( 'Show Notification Bar if visitor arrived via Google search engine.', 'wp-notification-bars' ); ?>
548
+ </label>
549
+ </p>
550
+ </div>
551
+ </div>
552
+ </div>
553
+ <div id="condition-notgoogle-panel" class="mtsnb-conditions-panel <?php echo esc_attr( $condition_notgoogle_state ); ?>">
554
+ <div class="mtsnb-conditions-panel-title"><?php esc_html_e( 'Not from Google', 'wp-notification-bars' ); ?></div>
555
+ <div class="mtsnb-conditions-panel-content">
556
+ <div class="mtsnb-conditions-panel-desc">
557
+ <p>
558
+ <label>
559
+ <?php esc_html_e( 'Hide Notification Bar if visitor arrived via Google search engine.', 'wp-notification-bars' ); ?>
560
+ </label>
561
+ </p>
562
+ </div>
563
+ </div>
564
+ </div>
565
+ <div id="condition-facebook-panel" class="mtsnb-conditions-panel <?php echo esc_attr( $condition_facebook_state ); ?>">
566
+ <div class="mtsnb-conditions-panel-title"><?php esc_html_e( 'From Facebook', 'wp-notification-bars' ); ?></div>
567
+ <div class="mtsnb-conditions-panel-content">
568
+ <div class="mtsnb-conditions-panel-desc">
569
+ <p>
570
+ <label>
571
+ <?php esc_html_e( 'Show Notification Bar if visitor arrived from Facebook.', 'wp-notification-bars' ); ?>
572
+ </label>
573
+ </p>
574
+ </div>
575
+ </div>
576
+ </div>
577
+ <div id="condition-notfacebook-panel" class="mtsnb-conditions-panel <?php echo esc_attr( $condition_notfacebook_state ); ?>">
578
+ <div class="mtsnb-conditions-panel-title"><?php esc_html_e( 'Not from Facebook', 'wp-notification-bars' ); ?></div>
579
+ <div class="mtsnb-conditions-panel-content">
580
+ <div class="mtsnb-conditions-panel-desc">
581
+ <p>
582
+ <label>
583
+ <?php esc_html_e( 'Hide Notification Bar if visitor arrived from Facebook.', 'wp-notification-bars' ); ?>
584
+ </label>
585
+ </p>
586
+ </div>
587
+ </div>
588
+ </div>
589
+ </div>
590
+ </div>
591
+ </div>
592
+ </div>
593
+ </div>
594
+ </div>
595
+ <?php
596
+ }
597
+
598
+ /**
599
+ * Echo class="active" if the condition is met.
600
+ *
601
+ * @param mixed $variable Variable.
602
+ * @param mixed $match Matching value.
603
+ * @param boolean $add_attribute Add class attribute name too, or just its value.
604
+ * @return void
605
+ */
606
+ private function active_class( $variable, $match, $add_attribute = false ) {
607
+ $class = '';
608
+ if ( $variable === $match ) {
609
+ $class = ' active';
610
+ }
611
+ if ( $add_attribute ) {
612
+ $class = ' class="' . $class . '"';
613
+ }
614
+
615
+ echo wp_kses_post( $class );
616
+ }
617
+
618
+ /**
619
+ * Helper function for common fields
620
+ *
621
+ * @since 1.0
622
+ */
623
+ public function custom_meta_field( $args, $value, $b = false ) {
624
+
625
+ $type = isset( $args['type'] ) ? $args['type'] : '';
626
+ $name = isset( $args['name'] ) ? $args['name'] : '';
627
+ $name = $b ? 'b_' . $name : $name;
628
+ $label = isset( $args['label'] ) ? $args['label'] : '';
629
+ $options = isset( $args['options'] ) ? $args['options'] : array();
630
+ $default = isset( $args['default'] ) ? $args['default'] : '';
631
+ $min = isset( $args['min'] ) ? $args['min'] : '0';
632
+
633
+ $class = isset( $args['class'] ) ? $args['class'] : '';
634
+
635
+ // Option value
636
+ $opt_val = isset( $value[ $name ] ) ? $value[ $name ] : $default;
637
+
638
+ ?>
639
+ <div id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>_row" class="form-row">
640
+ <label class="form-label" for="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>"><?php echo esc_html( $label ); ?></label>
641
+ <div class="form-option <?php echo esc_attr( $class ); ?>">
642
+ <?php
643
+ switch ( $type ) {
644
+
645
+ case 'text':
646
+ ?>
647
+ <input type="text" name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" value="<?php echo esc_attr( $opt_val ); ?>" />
648
+ <?php
649
+ break;
650
+ case 'select':
651
+ ?>
652
+ <select name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>">
653
+ <?php foreach ( $options as $val => $label ) { ?>
654
+ <option value="<?php echo esc_attr( $val ); ?>" <?php selected( $opt_val, $val, true ); ?>><?php echo esc_html( $label ); ?></option>
655
+ <?php } ?>
656
+ </select>
657
+ <?php
658
+ break;
659
+ case 'number':
660
+ ?>
661
+ <input type="number" step="1" min="<?php echo (int) $min; ?>" name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" value="<?php echo esc_attr( $opt_val ); ?>" class="small-text"/>
662
+ <?php
663
+ break;
664
+ case 'color':
665
+ ?>
666
+ <input type="text" name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" value="<?php echo esc_attr( $opt_val ); ?>" class="mtsnb-color-picker" />
667
+ <?php
668
+ break;
669
+ case 'textarea':
670
+ ?>
671
+ <textarea name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" class="mtsnb-textarea"><?php echo esc_textarea( $opt_val ); ?></textarea>
672
+ <?php
673
+ break;
674
+ case 'checkbox':
675
+ ?>
676
+ <input type="checkbox" name="mtsnb_fields[<?php echo sanitize_html_class( $name ); ?>]" id="mtsnb_fields_<?php echo sanitize_html_class( $name ); ?>" value="1" <?php checked( $opt_val, '1', true ); ?> />
677
+ <?php
678
+ break;
679
+ case 'info':
680
+ ?>
681
+ <small class="mtsnb-option-info">
682
+ <?php echo wp_kses_post( $default ); ?>
683
+ </small>
684
+ <?php
685
+ break;
686
+ }
687
+ ?>
688
+ </div>
689
+ </div>
690
+ <?php
691
+ }
692
+
693
+ /**
694
+ * Save the Data
695
+ *
696
+ * @since 1.0
697
+ */
698
+ public function save_custom_meta( $post_id ) {
699
+ // Check if our nonce is set.
700
+ if ( ! isset( $_POST['mtsnb_meta_box_nonce'] ) ) {
701
+ return;
702
+ }
703
+ // Verify that the nonce is valid.
704
+ if ( ! wp_verify_nonce( $_POST['mtsnb_meta_box_nonce'], 'mtsnb_meta_box' ) ) {
705
+ return;
706
+ }
707
+ // If this is an autosave, our form has not been submitted, so we don't want to do anything.
708
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
709
+ return;
710
+ }
711
+ // Check the user's permissions.
712
+ if ( isset( $_POST['post_type'] ) && 'mts_notification_bar' === $_POST['post_type'] ) {
713
+
714
+ if ( ! current_user_can( 'edit_page', $post_id ) ) {
715
+ return;
716
+ }
717
+ } else {
718
+
719
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
720
+ return;
721
+ }
722
+ }
723
+
724
+ /* OK, it's safe for us to save the data now. */
725
+ if ( ! isset( $_POST['mtsnb_fields'] ) ) {
726
+ return;
727
+ }
728
+
729
+ $my_data = $_POST['mtsnb_fields'];
730
+
731
+ // Sanitize fields.
732
+ $my_data = $this->sanitize_data( $my_data );
733
+
734
+ // Update the meta field in the database.
735
+ update_post_meta( $post_id, '_mtsnb_data', $my_data );
736
+ }
737
+
738
+ /**
739
+ * Sanitize meta fields recursively.
740
+ *
741
+ * @param mixed $value Original value.
742
+ *
743
+ * @return mixed Sanitized value.
744
+ */
745
+ public function sanitize_meta( $value ) {
746
+ if ( defined( 'MTSNBF_UNFILTERED_HTML' ) && MTSNBF_UNFILTERED_HTML ) {
747
+ return $value;
748
+ }
749
+
750
+ if ( is_string( $value ) ) {
751
+ return wp_kses_post( $value );
752
+ } elseif ( is_array( $value ) ) {
753
+ return array_map( array( $this, 'sanitize_meta' ), $value );
754
+ }
755
+
756
+ return $value;
757
+ }
758
+
759
+ public function sanitize_data( $data ) {
760
+ if ( defined( 'MTSNBF_UNFILTERED_HTML' ) && MTSNBF_UNFILTERED_HTML ) {
761
+ return $data;
762
+ }
763
+
764
+ $sanitized_data = array();
765
+ $sanitize_map = array(
766
+ 'active_tab' => 'sanitize_text_field',
767
+ 'button' => 'sanitize_text_field',
768
+ 'content_width' => 'absint',
769
+ 'css_position' => 'sanitize_text_field',
770
+ 'content_type' => 'sanitize_text_field',
771
+ 'basic_link_style' => 'sanitize_text_field',
772
+ 'basic_text' => 'wp_kses_post',
773
+ 'basic_link_url' => 'esc_url',
774
+ 'custom_content' => 'wp_kses_post',
775
+ 'bg_color' => 'sanitize_hex_color',
776
+ 'txt_color' => 'sanitize_hex_color',
777
+ 'link_color' => 'sanitize_hex_color',
778
+ 'font_size' => 'absint',
779
+ );
780
+
781
+ foreach ( $data as $key => $value ) {
782
+ if ( is_array( $value ) ) {
783
+ $sanitized_data[ $key ] = $this->sanitize_data( $value );
784
+ } elseif ( isset( $sanitize_map[ $key ] ) ) {
785
+ $sanitized_data[ $key ] = call_user_func( $sanitize_map[ $key ], $value );
786
+ } else {
787
+ $sanitized_data[ $key ] = $value;
788
+ }
789
+ }
790
+
791
+ return $sanitized_data;
792
+ }
793
+
794
+ /**
795
+ * Deactivate plugin if pro is active.
796
+ *
797
+ * @since 1.0
798
+ */
799
+ public function check_version() {
800
+
801
+ if ( defined( 'MTSNB_PLUGIN_BASE' ) ) {
802
+
803
+ if ( is_plugin_active( MTSNB_PLUGIN_BASE ) || class_exists( 'MTSNB' ) ) {
804
+
805
+ deactivate_plugins( MTSNBF_PLUGIN_BASE );
806
+ add_action( 'admin_notices', array( $this, 'disabled_notice' ) );
807
+ if ( isset( $_GET['activate'] ) ) {
808
+ unset( $_GET['activate'] );
809
+ }
810
+ }
811
+ }
812
+ }
813
+
814
+ /**
815
+ * Show admin notice.
816
+ *
817
+ * @return void
818
+ */
819
+ public function wp_notification_bar_admin_notice() {
820
+ global $current_user;
821
+ $user_id = $current_user->ID;
822
+ /*
823
+ Check that the user hasn't already clicked to ignore the message */
824
+ /* Only show the notice 2 days after plugin activation */
825
+ if ( ! get_user_meta( $user_id, 'wp_notification_bar_ignore_notice' ) && time() >= ( get_option( 'wp_notification_bar_activated', 0 ) + ( 2 * 24 * 60 * 60 ) ) ) {
826
+ echo '<div class="updated notice-info wp-notification-bar-notice" id="wpnotificationbar-notice" style="position:relative;">';
827
+ echo '<p>';
828
+ // Translators: placeholder is a link to the plugin home page, with "WP Notification Bar Pro" as the anchor text.
829
+ printf( esc_html__( 'Like WP Notification Bar plugin? You will LOVE %s!', 'wp-notification-bars' ), '<a target="_blank" href="https://mythemeshop.com/plugins/wp-notification-bar/?utm_source=WP+Notification+Bars&utm_medium=Notification+Link&utm_content=WP+Notification+Bar+Pro+LP&utm_campaign=WordPressOrg"><strong>WP Notification Bar Pro</strong></a>' );
830
+ echo '</p>';
831
+ echo '<a class="notice-dismiss mtsnb-notice-dismiss" data-ignore="0" data-nonce="' . esc_attr( wp_create_nonce( 'mtsnb_dismiss_notice' ) ) . '" href="#"></a>';
832
+ echo '</div>';
833
+ }
834
+ /*
835
+ Other notice appears right after activating */
836
+ /* And it gets hidden after showing 3 times */
837
+ if ( ! get_user_meta( $user_id, 'wp_notification_bar_ignore_notice_2' ) && get_option( 'wp_notification_bar_notice_views', 0 ) < 3 && get_option( 'wp_notification_bar_activated', 0 ) ) {
838
+ $views = get_option( 'wp_notification_bar_notice_views', 0 );
839
+ update_option( 'wp_notification_bar_notice_views', ( $views + 1 ) );
840
+ echo '<div class="updated notice-info wp-notification-bar-notice" id="wpnotificationbar-notice2" style="position:relative;">';
841
+ echo '<p>';
842
+ esc_html_e( 'Thank you for trying WP Notification Bar. We hope you will like it.', 'wp-notification-bars' );
843
+ echo '</p>';
844
+ echo '<a class="notice-dismiss mtsnb-notice-dismiss" data-ignore="1" data-nonce="' . esc_attr( wp_create_nonce( 'mtsnb_dismiss_notice' ) ) . '" href="#"></a>';
845
+ echo '</div>';
846
+ }
847
+ }
848
+
849
+ /**
850
+ * Ajax handler to ignore an admin notice.
851
+ *
852
+ * @return void
853
+ */
854
+ public function wp_notification_bar_admin_notice_ignore() {
855
+ global $current_user;
856
+ $user_id = $current_user->ID;
857
+ /* If user clicks to ignore the notice, add that to their user meta */
858
+ if ( isset( $_POST['dismiss'] ) ) {
859
+ // Check if our nonce is set.
860
+ if ( ! isset( $_POST['mtsnb_notice_nonce'] ) ) {
861
+ return;
862
+ }
863
+ // Verify that the nonce is valid.
864
+ if ( ! wp_verify_nonce( $_POST['mtsnb_notice_nonce'], 'mtsnb_dismiss_notice' ) ) {
865
+ return;
866
+ }
867
+
868
+ if ( '0' == $_POST['dismiss'] ) {
869
+ add_user_meta( $user_id, 'wp_notification_bar_ignore_notice', '1', true );
870
+ } elseif ( '1' == $_POST['dismiss'] ) {
871
+ add_user_meta( $user_id, 'wp_notification_bar_ignore_notice_2', '1', true );
872
+ }
873
+ }
874
+ }
875
+
876
+ /**
877
+ * Deactivation notice.
878
+ *
879
+ * @since 1.0
880
+ */
881
+ public function disabled_notice() {
882
+ ?>
883
+ <div class="updated">
884
+ <p><?php esc_html_e( 'Free version of WP Notification Bars plugin disabled. Pro version is active!', 'wp-notification-bars' ); ?></p>
885
+ </div>
886
+ <?php
887
+ }
888
+
889
+ /**
890
+ * Notification Bar update messages.
891
+ *
892
+ * @since 1.0
893
+ *
894
+ * @param array $messages
895
+ * @return array $messages
896
+ */
897
+ public function mtsnb_update_messages( $messages ) {
898
+
899
+ global $post;
900
+
901
+ $post_ID = $post->ID;
902
+ $post_type = get_post_type( $post_ID );
903
+
904
+ if ( 'mts_notification_bar' === $post_type ) {
905
+
906
+ $messages['mts_notification_bar'] = array(
907
+ 0 => '', // Unused. Messages start at index 1.
908
+ 1 => __( 'Notification Bar updated.', 'wp-notification-bars' ),
909
+ 2 => __( 'Custom field updated.', 'wp-notification-bars' ),
910
+ 3 => __( 'Custom field deleted.', 'wp-notification-bars' ),
911
+ 4 => __( 'Notification Bar updated.', 'wp-notification-bars' ),
912
+ // Translators: %s: date and time of the revision.
913
+ 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Notification Bar restored to revision from %s' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, // phpcs:ignore WordPress.Security.NonceVerification
914
+ 6 => __( 'Notification Bar published.', 'wp-notification-bars' ),
915
+ 7 => __( 'Notification Bar saved.', 'wp-notification-bars' ),
916
+ 8 => __( 'Notification Bar submitted.', 'wp-notification-bars' ),
917
+ // Translators: %s: date and time of the scheduled publication.
918
+ 9 => sprintf( esc_html__( 'Notification Bar scheduled for: %1$s.', 'wp-notification-bars' ), '<strong>' . date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) ) . '</strong>' ),
919
+ 10 => __( 'Notification Bar draft updated.', 'wp-notification-bars' ),
920
+ );
921
+ }
922
+
923
+ return $messages;
924
+ }
925
+
926
+ /**
927
+ * Single post view bar select.
928
+ *
929
+ * @since 1.0.1
930
+ */
931
+ public function mtsnb_select_metabox_insert() {
932
+
933
+ $force_bar_post_types = $this->force_bar_post_types;
934
+
935
+ if ( $force_bar_post_types && is_array( $force_bar_post_types ) ) {
936
+
937
+ foreach ( $force_bar_post_types as $screen ) {
938
+
939
+ add_meta_box(
940
+ 'mtsnb_single_bar_metabox',
941
+ __( 'Notification Bar', 'wp-notification-bars' ),
942
+ array( $this, 'mtsnb_select_metabox_content' ),
943
+ $screen,
944
+ 'side',
945
+ 'default'
946
+ );
947
+ }
948
+ }
949
+ }
950
+
951
+ /**
952
+ * Post Meta box contents: select notification bar.
953
+ *
954
+ * @param WP_Post $post Post object.
955
+ */
956
+ public function mtsnb_select_metabox_content( $post ) {
957
+
958
+ // Add a nonce field so we can check for it later.
959
+ wp_nonce_field( 'mtsnb_select_metabox_save', 'mtsnb_select_metabox_nonce' );
960
+
961
+ /*
962
+ * Use get_post_meta() to retrieve an existing value
963
+ * from the database and use the value for the form.
964
+ */
965
+ $bar = get_post_meta( $post->ID, '_mtsnb_override_bar', true );
966
+
967
+ $processed_item_ids = '';
968
+ if ( ! empty( $bar ) ) {
969
+ // Some entries may be arrays themselves!
970
+ $processed_item_ids = array();
971
+ foreach ( $bar as $this_id ) {
972
+ if ( is_array( $this_id ) ) {
973
+ $processed_item_ids = array_merge( $processed_item_ids, $this_id );
974
+ } else {
975
+ $processed_item_ids[] = $this_id;
976
+ }
977
+ }
978
+
979
+ if ( is_array( $processed_item_ids ) && ! empty( $processed_item_ids ) ) {
980
+ $processed_item_ids = implode( ',', $processed_item_ids );
981
+ } else {
982
+ $processed_item_ids = '';
983
+ }
984
+ }
985
+ ?>
986
+ <p>
987
+ <label for="mtsnb_override_bar_field"><?php esc_html_e( 'Select Notification Bar (optional):', 'wp-notification-bars' ); ?></label><br />
988
+ <input style="width: 400px;" type="hidden" id="mtsnb_override_bar_field" name="mtsnb_override_bar_field" class="mtsnb-bar-select" value="<?php echo esc_attr( $processed_item_ids ); ?>" />
989
+ </p>
990
+ <p>
991
+ <i><?php esc_html_e( 'Selected notification bar will override any other bar.', 'wp-notification-bars' ); ?></i>
992
+ </p>
993
+ <?php
994
+ }
995
+
996
+ /**
997
+ * Save meta box data.
998
+ *
999
+ * @param int $post_id Post ID.
1000
+ */
1001
+ public function mtsnb_select_metabox_save( $post_id ) {
1002
+
1003
+ // Check if our nonce is set.
1004
+ if ( ! isset( $_POST['mtsnb_select_metabox_nonce'] ) ) {
1005
+ return;
1006
+ }
1007
+ // Verify that the nonce is valid.
1008
+ if ( ! wp_verify_nonce( $_POST['mtsnb_select_metabox_nonce'], 'mtsnb_select_metabox_save' ) ) {
1009
+ return;
1010
+ }
1011
+ // If this is an autosave, our form has not been submitted, so we don't want to do anything.
1012
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
1013
+ return;
1014
+ }
1015
+
1016
+ // Check the user's permissions.
1017
+ if ( 'page' === $_POST['post_type'] ) {
1018
+
1019
+ if ( ! current_user_can( 'edit_page', $post_id ) ) {
1020
+ return;
1021
+ }
1022
+ } else {
1023
+
1024
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
1025
+ return;
1026
+ }
1027
+ }
1028
+
1029
+ /* OK, its safe for us to save the data now. */
1030
+ if ( ! isset( $_POST['mtsnb_override_bar_field'] ) ) {
1031
+ return;
1032
+ }
1033
+
1034
+ $val = $_POST['mtsnb_override_bar_field'];
1035
+
1036
+ if ( strpos( $val, ',' ) === false ) {
1037
+ // No comma, must be single value - still needs to be in an array for now
1038
+ $post_ids = array( $val );
1039
+ } else {
1040
+ // There is a comma so it's explodable
1041
+ $post_ids = explode( ',', $val );
1042
+ }
1043
+
1044
+ // Update the meta field in the database.
1045
+ update_post_meta( $post_id, '_mtsnb_override_bar', $post_ids );
1046
+ }
1047
+
1048
+ /**
1049
+ * Bar select ajax function.
1050
+ *
1051
+ * @since 1.0.1
1052
+ */
1053
+ public function mtsnb_get_bars() {
1054
+
1055
+ $result = array();
1056
+
1057
+ $search = $_REQUEST['q']; // phpcs:ignore WordPress.Security.NonceVerification
1058
+
1059
+ $ads_query = array(
1060
+ 'posts_per_page' => -1,
1061
+ 'post_status' => array( 'publish' ),
1062
+ 'post_type' => 'mts_notification_bar',
1063
+ 'order' => 'ASC',
1064
+ 'orderby' => 'title',
1065
+ 'suppress_filters' => false,
1066
+ 's' => $search,
1067
+ );
1068
+ $posts = get_posts( $ads_query );
1069
+
1070
+ // We'll return a JSON-encoded result.
1071
+ foreach ( $posts as $this_post ) {
1072
+ $post_title = $this_post->post_title;
1073
+ $id = $this_post->ID;
1074
+
1075
+ $result[] = array(
1076
+ 'id' => $id,
1077
+ 'title' => $post_title,
1078
+ );
1079
+ }
1080
+
1081
+ echo wp_json_encode( $result );
1082
+
1083
+ die();
1084
+ }
1085
+
1086
+ /**
1087
+ * Bar titles ajax function.
1088
+ *
1089
+ * @since 1.0.1
1090
+ */
1091
+ public function mtsnb_get_bar_titles() {
1092
+ if ( ! current_user_can( 'edit_posts' ) ) {
1093
+ die( '0' );
1094
+ }
1095
+
1096
+ $result = array();
1097
+
1098
+ if ( isset( $_REQUEST['post_ids'] ) ) {
1099
+ $post_ids = $_REQUEST['post_ids'];
1100
+ if ( strpos( $post_ids, ',' ) === false ) {
1101
+ // There is no comma, so we can't explode, but we still want an array
1102
+ $post_ids = array( $post_ids );
1103
+ } else {
1104
+ // There is a comma, so it must be explodable
1105
+ $post_ids = explode( ',', $post_ids );
1106
+ }
1107
+ } else {
1108
+ $post_ids = array();
1109
+ }
1110
+
1111
+ if ( is_array( $post_ids ) && ! empty( $post_ids ) ) {
1112
+
1113
+ $posts = get_posts(
1114
+ array(
1115
+ 'posts_per_page' => -1,
1116
+ 'post_status' => array( 'publish' ),
1117
+ 'post__in' => $post_ids,
1118
+ 'post_type' => 'mts_notification_bar',
1119
+ )
1120
+ );
1121
+ foreach ( $posts as $this_post ) {
1122
+ $result[] = array(
1123
+ 'id' => $this_post->ID,
1124
+ 'title' => $this_post->post_title,
1125
+ );
1126
+ }
1127
+ }
1128
+
1129
+ echo wp_json_encode( $result );
1130
+
1131
+ die();
1132
+ }
1133
+ }
1134
+ }
admin/css/wp-notification-bars-admin.css CHANGED
@@ -1,86 +1,86 @@
1
- /**
2
- * Plugin Name: WP Notification Bars by MyThemeShop
3
- * Author URI: https://mythemeshop.com/
4
- */
5
- .mtsnb-tabs *, .mtsnb-tabs *:before, .mtsnb-tabs *:after { box-sizing: border-box }
6
- .clearfix:before, .clearfix:after { content: " "; display: table; }
7
- .clearfix:after { clear: both }
8
- .clearfix { *zoom: 1 }
9
- .mtsnb-tabs label, .mtsnb-tabs p { font-size: 15px }
10
- .utm-text { min-width: 150px; float: left; }
11
- .mtsnb-remove-utm-tag { position: absolute; right: 15px; top: 5px; }
12
- .mtsnb-tabs p { color: #7f7f7f }
13
- .mtsnb-tabs input[type="text"]:not(.wp-color-picker), .mtsnb-tabs input[type="number"], .mtsnb-tabs select, .mtsnb-tabs textarea { font-size: 15px; color: #aaaaaa; line-height: 22px; height: auto; padding: 9px 20px; background: #ffffff; margin: 0; border: 1px solid #eaebec; outline: none!important; box-shadow: none!important; }
14
- .mtsnb-tabs button, .mtsnb-tabs .button:not(.wp-picker-clear, .mtsnb-load-palette), .mtsnb-tabs input[type="submit"] { font-size: 15px!important; padding: 9px 20px!important; height: auto!important; line-height: 22px!important; outline: none!important; }
15
- .mtsnb-tabs button:focus, .mtsnb-tabs .button:focus, .mtsnb-tabs input[type="submit"]:focus { outline: none!important; box-shadow: none!important; }
16
- .mtsnb-tabs input[type="text"], .mtsnb-tabs input[type="number"], .mtsnb-tabs select, .mtsnb-tabs textarea { width: 100% }
17
- .mtsnb-tabs select { height: auto }
18
- .mtsnb-tabs textarea { width: 100%; max-width: 100%; height: 200px; }
19
- .mtsnb-tabs input:focus, .mtsnb-tabs select:focus, .mtsnb-tabs textarea:focus, .select2-container--default.select2-container--focus .select2-selection--multiple { border-color: #a4e3fa; color: #666666; outline: none; }
20
- /*Tabs*/
21
- .mtsnb-tabs { padding: 20px; font-size: 16px; }
22
- .mtsnb-tabs-inner { background: #fdfdfd }
23
- .mtsnb-tabs-nav { float: left; margin: 0; }
24
- #main-tabs-nav { width: 100%; padding-right: 0; }
25
- #main-tabs-wrap { }
26
- .mtsnb-tabs-nav li, #conditions-selector li { float: left; display: inline-block; width: 100%; clear: left; margin: 0; }
27
- #main-tabs-nav li { width: 25%; display: block; clear: none; border-right: 1px solid #34aad5; }
28
- #main-tabs-nav li:last-child { border-right: 0 }
29
- .mtsnb-tabs-nav li a, #conditions-selector li { float: left; width: 100%; background: #45bbe6; color: #fff; padding: 15px; font-size: 15px; text-decoration: none; outline: none !important; position: relative; }
30
- .mtsnb-tabs-nav li a:hover, .mtsnb-tabs-nav li a.active { background: #0074A2 }
31
- .mtsnb-tabs-nav li a:focus { color: #fff; box-shadow: none; }
32
- .mtsnb-tabs-nav li a.active { pointer-events: none }
33
- #sub-tabs-nav li a, #conditions-selector li { padding-right: 60px; font-weight: bold; background: #ffffff; border: 1px solid #eaebec; margin: -1px 0 0 -1px; color: #aaaaaa; position: relative; cursor: pointer; }
34
- #sub-tabs-nav li a.active, #sub-tabs-nav li a:hover, #conditions-selector li.active, #conditions-selector li:hover { background: #45BBE6; border-color: #45BBE6; border-left-color: #45bbe6; color: #fff; }
35
- #sub-tabs-nav li a.active:after, #conditions-selector li.active:after { content: ''; position: absolute; border-style: solid; border-width: 9px 0 9px 9px; border-color: rgba(0, 0, 0, 0) #45BBE6; display: block; width: 0; z-index: 1; right: -9px; top: 50%; margin-top: -9px; }
36
- #sub-tabs-nav li a.active:before, #conditions-selector li.active:before { content: ''; position: absolute; border-style: solid; border-width: 9px 0 9px 9px; border-color: rgba(0, 0, 0, 0) #45BBE6; display: block; width: 0; z-index: 0; right: -10px; top: 50%; margin-top: -9px; }
37
- #conditions-selector li { padding-left: 50px; padding-right: 25px; }
38
- .mtsnb-tab-title { display: block }
39
- .mtsnb-tab-title { font-size: 16px; font-weight: bold; text-transform: uppercase; text-align: center; }
40
- .mtsnb-tab-title .dashicons { margin-right: 8px }
41
- /*tab content*/
42
- .mtsnb-tabs-content { display: none; float: left; width: 100%; clear: both; }
43
- .mtsnb-tabs-content.active { display: block }
44
- .mtsnb-ab-slider-label { margin-bottom: 5px }
45
- .mtsnb-tab-desc { border-width: 0 1px 0 1px; border-style: solid; border-color: #eaebec; background: #ffffff; line-height: 24px; color: #666666; padding: 30px 26px; }
46
- .mtsnb-tab-options, #conditions-selector-wrap { padding: 30px; border: 1px solid #eaebec; }
47
- .mtsnb-tab-options { padding-top: 10px; }
48
- #tab-type .mtsnb-tab-options, #tab-conditions .mtsnb-tab-options, #conditions-selector-wrap { padding: 0 }
49
- #tab-type .meta-tabs-wrap, #tab-conditions .meta-tabs-wrap { padding-top: 30px }
50
- #sub-tabs-wrap { overflow: hidden }
51
- .form-row { float: left; width: 100%; clear: both; margin: 15px 0; padding: 0; }
52
- #tab-type .mtsnb-tab-options .form-row { padding: 0 30px }
53
- .form-label { float: left; width: 25%; color: #7f7f7f; padding-right: 20px; padding-top: 12px; }
54
- .form-label:hover { color: #666666 }
55
- .form-option { float: left; width: 75%; }
56
- .clear-image { margin: 0 10px; vertical-align: bottom; }
57
- #preview-bar { width: 100%; padding: 10px; height: auto; text-align: center; }
58
- .mtsnb-tabs .wp-color-result, .mtsnb-tabs .wp-picker-container .button { height: auto }
59
- .mtsnb-tabs .wp-picker-container .button, .mtsnb-tabs .wp-color-result:after { line-height: 26px }
60
- .mtsnb-tabs .wp-picker-container input[type=text].wp-color-picker { width: 70px }
61
- .mtsnb-submit { pointer-events: none }
62
- .mtsnb-tabs input[type=checkbox] { margin-top: 12px }
63
- /*conditions*/
64
- /*checkboxes*/
65
- #conditions-selector { float: left }
66
- #conditions-selector ul { margin: 0 }
67
- #conditions-selector .mtsnb-check, #conditions-selector .mtsnb-check:after { position: absolute; border-radius: 50%; }
68
- #conditions-selector .mtsnb-check { top: 15px; left: 15px; width: 17px; height: 17px; border: 1px solid #cccccc; }
69
- #conditions-selector .mtsnb-check:after { content: ""; top: 3px; left: 3px; width: 9px; height: 9px; background: #cccccc; }
70
- #conditions-selector .condition-checkbox.active .mtsnb-check, #conditions-selector .condition-checkbox:hover .mtsnb-check { border-color: #FFFFFF;}
71
- #conditions-selector .condition-checkbox.active .mtsnb-check:after, #conditions-selector .condition-checkbox:hover .mtsnb-check:after { background: #FFFFFF;}
72
- #conditions-selector ul li.disabled { color: #dcdcdc; pointer-events: none; }
73
- #conditions-selector .condition-checkbox.disabled .mtsnb-check { border-color: #dcdcdc }
74
- #conditions-selector .condition-checkbox.disabled .mtsnb-check:after { background: #dcdcdc }
75
- /*panels*/
76
- #conditions-panels { overflow: hidden }
77
- .mtsnb-conditions-panel { padding: 15px; display: none; }
78
- .mtsnb-conditions-panel.active { display: block }
79
- .mtsnb-conditions-panel-title, .mtsnb-conditions-panel-content { padding: 15px }
80
- .mtsnb-conditions-panel-title { color: #666666; font-size: 18px; font-weight: 700; }
81
- .mtsnb-conditions-panel-desc input[type="number"] { width: 90px }
82
- .mtsnb-conditions-panel-opt { margin-top: 15px; padding-left: 15px; padding-right: 15px; }
83
- .text-center { text-align: center }
84
- .mtsnb-colors-loader { margin-bottom: 12px }
85
- .mtsnb-small-select { width: auto!important; padding: 5px!important; margin: -3px 5px 0 5px!important; }
86
- .mtsnb-bar-select { max-width: 100% }
1
+ /**
2
+ * Plugin Name: WP Notification Bars by MyThemeShop
3
+ * Author URI: https://mythemeshop.com/
4
+ */
5
+ .mtsnb-tabs *, .mtsnb-tabs *:before, .mtsnb-tabs *:after { box-sizing: border-box }
6
+ .clearfix:before, .clearfix:after { content: " "; display: table; }
7
+ .clearfix:after { clear: both }
8
+ .clearfix { *zoom: 1 }
9
+ .mtsnb-tabs label, .mtsnb-tabs p { font-size: 15px }
10
+ .utm-text { min-width: 150px; float: left; }
11
+ .mtsnb-remove-utm-tag { position: absolute; right: 15px; top: 5px; }
12
+ .mtsnb-tabs p { color: #7f7f7f }
13
+ .mtsnb-tabs input[type="text"]:not(.wp-color-picker), .mtsnb-tabs input[type="number"], .mtsnb-tabs select, .mtsnb-tabs textarea { font-size: 15px; color: #aaaaaa; line-height: 22px; height: auto; padding: 9px 20px; background: #ffffff; margin: 0; border: 1px solid #eaebec; outline: none!important; box-shadow: none!important; }
14
+ .mtsnb-tabs button, .mtsnb-tabs .button:not(.wp-picker-clear, .mtsnb-load-palette), .mtsnb-tabs input[type="submit"] { font-size: 15px!important; padding: 9px 20px!important; height: auto!important; line-height: 22px!important; outline: none!important; }
15
+ .mtsnb-tabs button:focus, .mtsnb-tabs .button:focus, .mtsnb-tabs input[type="submit"]:focus { outline: none!important; box-shadow: none!important; }
16
+ .mtsnb-tabs input[type="text"], .mtsnb-tabs input[type="number"], .mtsnb-tabs select, .mtsnb-tabs textarea { width: 100% }
17
+ .mtsnb-tabs select { height: auto }
18
+ .mtsnb-tabs textarea { width: 100%; max-width: 100%; height: 200px; }
19
+ .mtsnb-tabs input:focus, .mtsnb-tabs select:focus, .mtsnb-tabs textarea:focus, .select2-container--default.select2-container--focus .select2-selection--multiple { border-color: #a4e3fa; color: #666666; outline: none; }
20
+ /*Tabs*/
21
+ .mtsnb-tabs { padding: 20px; font-size: 16px; }
22
+ .mtsnb-tabs-inner { background: #fdfdfd }
23
+ .mtsnb-tabs-nav { float: left; margin: 0; }
24
+ #main-tabs-nav { width: 100%; padding-right: 0; }
25
+ #main-tabs-wrap { }
26
+ .mtsnb-tabs-nav li, #conditions-selector li { float: left; display: inline-block; width: 100%; clear: left; margin: 0; }
27
+ #main-tabs-nav li { width: 25%; display: block; clear: none; border-right: 1px solid #34aad5; }
28
+ #main-tabs-nav li:last-child { border-right: 0 }
29
+ .mtsnb-tabs-nav li a, #conditions-selector li { float: left; width: 100%; background: #45bbe6; color: #fff; padding: 15px; font-size: 15px; text-decoration: none; outline: none !important; position: relative; }
30
+ .mtsnb-tabs-nav li a:hover, .mtsnb-tabs-nav li a.active { background: #0074A2 }
31
+ .mtsnb-tabs-nav li a:focus { color: #fff; box-shadow: none; }
32
+ .mtsnb-tabs-nav li a.active { pointer-events: none }
33
+ #sub-tabs-nav li a, #conditions-selector li { padding-right: 60px; font-weight: bold; background: #ffffff; border: 1px solid #eaebec; margin: -1px 0 0 -1px; color: #aaaaaa; position: relative; cursor: pointer; }
34
+ #sub-tabs-nav li a.active, #sub-tabs-nav li a:hover, #conditions-selector li.active, #conditions-selector li:hover { background: #45BBE6; border-color: #45BBE6; border-left-color: #45bbe6; color: #fff; }
35
+ #sub-tabs-nav li a.active:after, #conditions-selector li.active:after { content: ''; position: absolute; border-style: solid; border-width: 9px 0 9px 9px; border-color: rgba(0, 0, 0, 0) #45BBE6; display: block; width: 0; z-index: 1; right: -9px; top: 50%; margin-top: -9px; }
36
+ #sub-tabs-nav li a.active:before, #conditions-selector li.active:before { content: ''; position: absolute; border-style: solid; border-width: 9px 0 9px 9px; border-color: rgba(0, 0, 0, 0) #45BBE6; display: block; width: 0; z-index: 0; right: -10px; top: 50%; margin-top: -9px; }
37
+ #conditions-selector li { padding-left: 50px; padding-right: 25px; }
38
+ .mtsnb-tab-title { display: block }
39
+ .mtsnb-tab-title { font-size: 16px; font-weight: bold; text-transform: uppercase; text-align: center; }
40
+ .mtsnb-tab-title .dashicons { margin-right: 8px }
41
+ /*tab content*/
42
+ .mtsnb-tabs-content { display: none; float: left; width: 100%; clear: both; }
43
+ .mtsnb-tabs-content.active { display: block }
44
+ .mtsnb-ab-slider-label { margin-bottom: 5px }
45
+ .mtsnb-tab-desc { border-width: 0 1px 0 1px; border-style: solid; border-color: #eaebec; background: #ffffff; line-height: 24px; color: #666666; padding: 30px 26px; }
46
+ .mtsnb-tab-options, #conditions-selector-wrap { padding: 30px; border: 1px solid #eaebec; }
47
+ .mtsnb-tab-options { padding-top: 10px; }
48
+ #tab-type .mtsnb-tab-options, #tab-conditions .mtsnb-tab-options, #conditions-selector-wrap { padding: 0 }
49
+ #tab-type .meta-tabs-wrap, #tab-conditions .meta-tabs-wrap { padding-top: 30px }
50
+ #sub-tabs-wrap { overflow: hidden }
51
+ .form-row { float: left; width: 100%; clear: both; margin: 15px 0; padding: 0; }
52
+ #tab-type .mtsnb-tab-options .form-row { padding: 0 30px }
53
+ .form-label { float: left; width: 25%; color: #7f7f7f; padding-right: 20px; padding-top: 12px; }
54
+ .form-label:hover { color: #666666 }
55
+ .form-option { float: left; width: 75%; }
56
+ .clear-image { margin: 0 10px; vertical-align: bottom; }
57
+ #preview-bar { width: 100%; padding: 10px; height: auto; text-align: center; }
58
+ .mtsnb-tabs .wp-color-result, .mtsnb-tabs .wp-picker-container .button { height: auto }
59
+ .mtsnb-tabs .wp-picker-container .button, .mtsnb-tabs .wp-color-result:after { line-height: 26px }
60
+ .mtsnb-tabs .wp-picker-container input[type=text].wp-color-picker { width: 70px }
61
+ .mtsnb-submit { pointer-events: none }
62
+ .mtsnb-tabs input[type=checkbox] { margin-top: 12px }
63
+ /*conditions*/
64
+ /*checkboxes*/
65
+ #conditions-selector { float: left }
66
+ #conditions-selector ul { margin: 0 }
67
+ #conditions-selector .mtsnb-check, #conditions-selector .mtsnb-check:after { position: absolute; border-radius: 50%; }
68
+ #conditions-selector .mtsnb-check { top: 15px; left: 15px; width: 17px; height: 17px; border: 1px solid #cccccc; }
69
+ #conditions-selector .mtsnb-check:after { content: ""; top: 3px; left: 3px; width: 9px; height: 9px; background: #cccccc; }
70
+ #conditions-selector .condition-checkbox.active .mtsnb-check, #conditions-selector .condition-checkbox:hover .mtsnb-check { border-color: #FFFFFF;}
71
+ #conditions-selector .condition-checkbox.active .mtsnb-check:after, #conditions-selector .condition-checkbox:hover .mtsnb-check:after { background: #FFFFFF;}
72
+ #conditions-selector ul li.disabled { color: #dcdcdc; pointer-events: none; }
73
+ #conditions-selector .condition-checkbox.disabled .mtsnb-check { border-color: #dcdcdc }
74
+ #conditions-selector .condition-checkbox.disabled .mtsnb-check:after { background: #dcdcdc }
75
+ /*panels*/
76
+ #conditions-panels { overflow: hidden }
77
+ .mtsnb-conditions-panel { padding: 15px; display: none; }
78
+ .mtsnb-conditions-panel.active { display: block }
79
+ .mtsnb-conditions-panel-title, .mtsnb-conditions-panel-content { padding: 15px }
80
+ .mtsnb-conditions-panel-title { color: #666666; font-size: 18px; font-weight: 700; }
81
+ .mtsnb-conditions-panel-desc input[type="number"] { width: 90px }
82
+ .mtsnb-conditions-panel-opt { margin-top: 15px; padding-left: 15px; padding-right: 15px; }
83
+ .text-center { text-align: center }
84
+ .mtsnb-colors-loader { margin-bottom: 12px }
85
+ .mtsnb-small-select { width: auto!important; padding: 5px!important; margin: -3px 5px 0 5px!important; }
86
+ .mtsnb-bar-select { max-width: 100% }
admin/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
admin/js/wp-nb-admin-notices.js CHANGED
@@ -1,15 +1,24 @@
1
- jQuery(document).on('click', '.mtsnb-notice-dismiss', function(e){
2
- e.preventDefault();
3
- var $this = jQuery(this);
4
- jQuery.ajax({
5
- type: "POST",
6
- url: ajaxurl,
7
- data: {
8
- action: 'mts_dismiss_nb_notice',
9
- dismiss: jQuery(this).data('ignore')
10
- }
11
- }).done(function() {
12
- $this.parent().remove();
13
- });
14
- return false;
15
- });
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).on(
2
+ 'click',
3
+ '.mtsnb-notice-dismiss',
4
+ function(e){
5
+ e.preventDefault();
6
+ var $this = jQuery( this );
7
+ jQuery.ajax(
8
+ {
9
+ type: "POST",
10
+ url: ajaxurl,
11
+ data: {
12
+ action: 'mts_dismiss_nb_notice',
13
+ dismiss: jQuery( this ).data( 'ignore' ),
14
+ mtsnb_notice_nonce: jQuery( this ).data( 'nonce' )
15
+ }
16
+ }
17
+ ).done(
18
+ function() {
19
+ $this.parent().remove();
20
+ }
21
+ );
22
+ return false;
23
+ }
24
+ );
admin/js/wp-notification-bars-admin.js CHANGED
@@ -1,168 +1,208 @@
1
- /**
2
- * Plugin Name: WP Notification Bars by MyThemeShop
3
- * Author URI: https://mythemeshop.com/
4
- */
5
- (function( $ ) {
6
-
7
- 'use strict';
8
-
9
- $(function() {
10
-
11
- // Tabs
12
- $(document).on('click', '.mtsnb-tabs-nav a', function(e){
13
- e.preventDefault();
14
- var $this = $(this),
15
- target = $this.attr('href');
16
- if ( !$this.hasClass('active') ) {
17
- $this.parent().parent().find('a.active').removeClass('active');
18
- $this.addClass('active');
19
- $this.parent().parent().next().children().siblings().removeClass('active');
20
- $this.parent().parent().next().find( target ).addClass('active');
21
- $this.parent().parent().prev().val( target.replace('#tab-',''));
22
- }
23
- });
24
-
25
- // Display conditions manager
26
- $(document).on('click', '.condition-checkbox', function(e){
27
- var $this = $(this),
28
- panel = '#'+$this.attr('id')+'-panel',
29
- disable = $this.data('disable');
30
- if ( !$this.hasClass('disabled') ) {
31
- if ( $this.hasClass('active') ) {
32
- $this.removeClass('active');
33
- $this.find('input').val('');
34
- $(panel).removeClass('active');
35
- if ( disable ) {
36
- $('#condition-'+disable).removeClass('disabled');
37
- }
38
- } else {
39
- $this.addClass('active');
40
- $(panel).addClass('active');
41
- $this.find('input').val('active');
42
- if ( disable ) {
43
- $('#condition-'+disable).addClass('disabled');
44
- }
45
- }
46
- }
47
- });
48
-
49
- // Preview Bar Button
50
- $(document).on('click', '#preview-bar', function(e){
51
- e.preventDefault();
52
- $('.mtsnb').remove();
53
- $('body').css({ "padding-top": "0", "padding-bottom": "0" }).removeClass('has-mtsnb');
54
- var form_data = $('form#post').serialize();
55
- var data = {
56
- action: 'preview_bar',
57
- form_data: form_data,
58
- };
59
-
60
- $.post( ajaxurl, data, function(response) {
61
-
62
- if ( response ) {
63
- $('body').prepend( response );
64
- }
65
- }).done(function(result){
66
- $( document ).trigger('mtsnbPreviewLoaded');
67
- });
68
-
69
- });
70
-
71
- // Preview Bar
72
- $( document ).on( 'mtsnbPreviewLoaded', function( event ) {
73
-
74
- var barHeight;
75
-
76
- if ( $('.mtsnb').length > 0 ) {
77
- barHeight = $('.mtsnb').outerHeight();
78
- $('body').css('padding-top', barHeight).addClass('has-mtsnb');
79
- }
80
-
81
- $(document).on('click', '.mtsnb-hide', function(e) {
82
-
83
- e.preventDefault();
84
-
85
- var $this = $(this);
86
-
87
- if ( !$this.hasClass('active') ) {
88
- $this.closest('.mtsnb').removeClass('mtsnb-shown').addClass('mtsnb-hidden');
89
- $('body').css('padding-top', 0);
90
- }
91
- });
92
-
93
- // Show Button
94
- $(document).on('click', '.mtsnb-show', function(e) {
95
-
96
- e.preventDefault();
97
-
98
- var $this = $(this);
99
- if ( !$this.hasClass('active') ) {
100
- barHeight = $('.mtsnb').outerHeight();
101
- $this.closest('.mtsnb').removeClass('mtsnb-hidden').addClass('mtsnb-shown');
102
- $('body').css('padding-top', barHeight);
103
- }
104
- });
105
- });
106
-
107
- // Color option
108
- $('.mtsnb-color-picker').wpColorPicker();
109
-
110
- // Bar select
111
- function mtsnbProcessPostSelectDataForSelect2( ajaxData, page, query ) {
112
-
113
- var items=[];
114
-
115
- for (var thisId in ajaxData) {
116
- var newItem = {
117
- 'id': ajaxData[thisId]['id'],
118
- 'text': ajaxData[thisId]['title']
119
- };
120
- items.push(newItem);
121
- }
122
- return { results: items };
123
- }
124
-
125
- $('input.mtsnb-bar-select').each(function() {
126
-
127
- var $this = $(this);
128
-
129
- $this.select2( {
130
- placeholder: mtsnb_locale.select_placeholder,
131
- multiple: true,
132
- maximumSelectionSize: 1,
133
- minimumInputLength: 2,
134
- ajax: {
135
- url: ajaxurl,
136
- dataType: 'json',
137
- data: function (term, page) {
138
- return {
139
- q: term,
140
- action: 'mtsnb_get_bars',
141
- };
142
- },
143
- results: mtsnbProcessPostSelectDataForSelect2
144
- },
145
- initSelection: function(element, callback) {
146
-
147
- var ids=$(element).val();
148
- if ( ids !== "" ) {
149
- $.ajax({
150
- url: ajaxurl,
151
- dataType: "json",
152
- data: {
153
- action: 'mtsnb_get_bar_titles',
154
- post_ids: ids
155
- },
156
-
157
- }).done(function(response) {console.log(response);
158
-
159
- var processedData = mtsnbProcessPostSelectDataForSelect2( response );
160
- callback( processedData.results );
161
- });
162
- }
163
- },
164
- });
165
- });
166
- });
167
-
168
- })( jQuery );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Plugin Name: WP Notification Bars by MyThemeShop
3
+ * Author URI: https://mythemeshop.com/
4
+ */
5
+ (function( $ ) {
6
+
7
+ 'use strict';
8
+
9
+ $(
10
+ function() {
11
+
12
+ // Tabs
13
+ $( document ).on(
14
+ 'click',
15
+ '.mtsnb-tabs-nav a',
16
+ function(e){
17
+ e.preventDefault();
18
+ var $this = $( this ),
19
+ target = $this.attr( 'href' );
20
+ if ( ! $this.hasClass( 'active' ) ) {
21
+ $this.parent().parent().find( 'a.active' ).removeClass( 'active' );
22
+ $this.addClass( 'active' );
23
+ $this.parent().parent().next().children().siblings().removeClass( 'active' );
24
+ $this.parent().parent().next().find( target ).addClass( 'active' );
25
+ $this.parent().parent().prev().val( target.replace( '#tab-','' ) );
26
+ }
27
+ }
28
+ );
29
+
30
+ // Display conditions manager
31
+ $( document ).on(
32
+ 'click',
33
+ '.condition-checkbox',
34
+ function(e){
35
+ var $this = $( this ),
36
+ panel = '#' + $this.attr( 'id' ) + '-panel',
37
+ disable = $this.data( 'disable' );
38
+ if ( ! $this.hasClass( 'disabled' ) ) {
39
+ if ( $this.hasClass( 'active' ) ) {
40
+ $this.removeClass( 'active' );
41
+ $this.find( 'input' ).val( '' );
42
+ $( panel ).removeClass( 'active' );
43
+ if ( disable ) {
44
+ $( '#condition-' + disable ).removeClass( 'disabled' );
45
+ }
46
+ } else {
47
+ $this.addClass( 'active' );
48
+ $( panel ).addClass( 'active' );
49
+ $this.find( 'input' ).val( 'active' );
50
+ if ( disable ) {
51
+ $( '#condition-' + disable ).addClass( 'disabled' );
52
+ }
53
+ }
54
+ }
55
+ }
56
+ );
57
+
58
+ // Preview Bar Button
59
+ $( document ).on(
60
+ 'click',
61
+ '#preview-bar',
62
+ function(e){
63
+ e.preventDefault();
64
+ $( '.mtsnb' ).remove();
65
+ $( 'body' ).css( { "padding-top": "0", "padding-bottom": "0" } ).removeClass( 'has-mtsnb' );
66
+ var form_data = $( 'form#post' ).serialize();
67
+ var data = {
68
+ action: 'preview_bar',
69
+ form_data: form_data,
70
+ mtsnb_meta_box_nonce: $( '#mtsnb_meta_box_nonce' ).val()
71
+ };
72
+
73
+ $.post(
74
+ ajaxurl,
75
+ data,
76
+ function(response) {
77
+
78
+ if ( response ) {
79
+ $( 'body' ).prepend( response );
80
+ }
81
+ }
82
+ ).done(
83
+ function(result){
84
+ $( document ).trigger( 'mtsnbPreviewLoaded' );
85
+ }
86
+ );
87
+
88
+ }
89
+ );
90
+
91
+ // Preview Bar
92
+ $( document ).on(
93
+ 'mtsnbPreviewLoaded',
94
+ function( event ) {
95
+
96
+ var barHeight;
97
+
98
+ if ( $( '.mtsnb' ).length > 0 ) {
99
+ barHeight = $( '.mtsnb' ).outerHeight();
100
+ $( 'body' ).css( 'padding-top', barHeight ).addClass( 'has-mtsnb' );
101
+ }
102
+
103
+ $( document ).on(
104
+ 'click',
105
+ '.mtsnb-hide',
106
+ function(e) {
107
+
108
+ e.preventDefault();
109
+
110
+ var $this = $( this );
111
+
112
+ if ( ! $this.hasClass( 'active' ) ) {
113
+ $this.closest( '.mtsnb' ).removeClass( 'mtsnb-shown' ).addClass( 'mtsnb-hidden' );
114
+ $( 'body' ).css( 'padding-top', 0 );
115
+ }
116
+ }
117
+ );
118
+
119
+ // Show Button
120
+ $( document ).on(
121
+ 'click',
122
+ '.mtsnb-show',
123
+ function(e) {
124
+
125
+ e.preventDefault();
126
+
127
+ var $this = $( this );
128
+ if ( ! $this.hasClass( 'active' ) ) {
129
+ barHeight = $( '.mtsnb' ).outerHeight();
130
+ $this.closest( '.mtsnb' ).removeClass( 'mtsnb-hidden' ).addClass( 'mtsnb-shown' );
131
+ $( 'body' ).css( 'padding-top', barHeight );
132
+ }
133
+ }
134
+ );
135
+ }
136
+ );
137
+
138
+ // Color option
139
+ $( '.mtsnb-color-picker' ).wpColorPicker();
140
+
141
+ // Bar select
142
+ function mtsnbProcessPostSelectDataForSelect2( ajaxData, page, query ) {
143
+
144
+ var items = [];
145
+
146
+ for (var thisId in ajaxData) {
147
+ var newItem = {
148
+ 'id': ajaxData[thisId]['id'],
149
+ 'text': ajaxData[thisId]['title']
150
+ };
151
+ items.push( newItem );
152
+ }
153
+ return { results: items };
154
+ }
155
+
156
+ $( 'input.mtsnb-bar-select' ).each(
157
+ function() {
158
+
159
+ var $this = $( this );
160
+
161
+ $this.select2(
162
+ {
163
+ placeholder: mtsnb_locale.select_placeholder,
164
+ multiple: true,
165
+ maximumSelectionSize: 1,
166
+ minimumInputLength: 2,
167
+ ajax: {
168
+ url: ajaxurl,
169
+ dataType: 'json',
170
+ data: function (term, page) {
171
+ return {
172
+ q: term,
173
+ action: 'mtsnb_get_bars',
174
+ };
175
+ },
176
+ results: mtsnbProcessPostSelectDataForSelect2
177
+ },
178
+ initSelection: function(element, callback) {
179
+
180
+ var ids = $( element ).val();
181
+ if ( ids !== "" ) {
182
+ $.ajax(
183
+ {
184
+ url: ajaxurl,
185
+ dataType: "json",
186
+ data: {
187
+ action: 'mtsnb_get_bar_titles',
188
+ post_ids: ids
189
+ },
190
+
191
+ }
192
+ ).done(
193
+ function(response) {console.log( response );
194
+
195
+ var processedData = mtsnbProcessPostSelectDataForSelect2( response );
196
+ callback( processedData.results );
197
+ }
198
+ );
199
+ }
200
+ },
201
+ }
202
+ );
203
+ }
204
+ );
205
+ }
206
+ );
207
+
208
+ })( jQuery );
includes/class-wp-notification-bars-activator.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
-
3
- /**
4
- * Fired during plugin activation
5
- *
6
- * @link http://mythemeshop.com
7
- * @since 1.0
8
- *
9
- * @package MTSNBF
10
- * @subpackage MTSNBF/includes
11
- */
12
-
13
- /**
14
- * Fired during plugin activation.
15
- *
16
- * This class defines all code necessary to run during the plugin's activation.
17
- *
18
- * @since 1.0
19
- * @package MTSNBF
20
- * @subpackage MTSNBF/includes
21
- * @author MyThemeShop
22
- */
23
- // If this file is called directly, abort.
24
- if ( ! defined( 'WPINC' ) ) {
25
- die;
26
- }
27
- class MTSNBF_Activator {
28
-
29
- /**
30
- * Short Description. (use period)
31
- *
32
- * Long Description.
33
- *
34
- * @since 1.0
35
- */
36
- public static function activate() {
37
-
38
- if ( false == get_option( 'mtsnb_stats' ) ) {
39
-
40
- add_option( 'mtsnb_stats', array() );
41
- }
42
- }
43
-
44
- }
1
+ <?php
2
+
3
+ /**
4
+ * Fired during plugin activation
5
+ *
6
+ * @link http://mythemeshop.com
7
+ * @since 1.0
8
+ *
9
+ * @package MTSNBF
10
+ * @subpackage MTSNBF/includes
11
+ */
12
+
13
+ /**
14
+ * Fired during plugin activation.
15
+ *
16
+ * This class defines all code necessary to run during the plugin's activation.
17
+ *
18
+ * @since 1.0
19
+ * @package MTSNBF
20
+ * @subpackage MTSNBF/includes
21
+ * @author MyThemeShop
22
+ */
23
+ // If this file is called directly, abort.
24
+ if ( ! defined( 'WPINC' ) ) {
25
+ die;
26
+ }
27
+ class MTSNBF_Activator {
28
+
29
+ /**
30
+ * Short Description. (use period)
31
+ *
32
+ * Long Description.
33
+ *
34
+ * @since 1.0
35
+ */
36
+ public static function activate() {
37
+
38
+ if ( false == get_option( 'mtsnb_stats' ) ) {
39
+
40
+ add_option( 'mtsnb_stats', array() );
41
+ }
42
+ }
43
+
44
+ }
includes/class-wp-notification-bars-deactivator.php CHANGED
@@ -1,40 +1,40 @@
1
- <?php
2
-
3
- /**
4
- * Fired during plugin deactivation
5
- *
6
- * @link http://mythemeshop.com
7
- * @since 1.0
8
- *
9
- * @package MTSNBF
10
- * @subpackage MTSNBF/includes
11
- */
12
-
13
- /**
14
- * Fired during plugin deactivation.
15
- *
16
- * This class defines all code necessary to run during the plugin's deactivation.
17
- *
18
- * @since 1.0
19
- * @package MTSNBF
20
- * @subpackage MTSNBF/includes
21
- * @author MyThemeShop
22
- */
23
- // If this file is called directly, abort.
24
- if ( ! defined( 'WPINC' ) ) {
25
- die;
26
- }
27
- class MTSNBF_Deactivator {
28
-
29
- /**
30
- * Short Description. (use period)
31
- *
32
- * Long Description.
33
- *
34
- * @since 1.0
35
- */
36
- public static function deactivate() {
37
-
38
- }
39
-
40
- }
1
+ <?php
2
+
3
+ /**
4
+ * Fired during plugin deactivation
5
+ *
6
+ * @link http://mythemeshop.com
7
+ * @since 1.0
8
+ *
9
+ * @package MTSNBF
10
+ * @subpackage MTSNBF/includes
11
+ */
12
+
13
+ /**
14
+ * Fired during plugin deactivation.
15
+ *
16
+ * This class defines all code necessary to run during the plugin's deactivation.
17
+ *
18
+ * @since 1.0
19
+ * @package MTSNBF
20
+ * @subpackage MTSNBF/includes
21
+ * @author MyThemeShop
22
+ */
23
+ // If this file is called directly, abort.
24
+ if ( ! defined( 'WPINC' ) ) {
25
+ die;
26
+ }
27
+ class MTSNBF_Deactivator {
28
+
29
+ /**
30
+ * Short Description. (use period)
31
+ *
32
+ * Long Description.
33
+ *
34
+ * @since 1.0
35
+ */
36
+ public static function deactivate() {
37
+
38
+ }
39
+
40
+ }
includes/class-wp-notification-bars-i18n.php CHANGED
@@ -1,67 +1,68 @@
1
- <?php
2
-
3
- /**
4
- * Define the internationalization functionality
5
- *
6
- * Loads and defines the internationalization files for this plugin
7
- * so that it is ready for translation.
8
- *
9
- * @link http://mythemeshop.com
10
- * @since 1.0
11
- *
12
- * @package MTSNBF
13
- * @subpackage MTSNBF/includes
14
- */
15
-
16
- /**
17
- * Define the internationalization functionality.
18
- *
19
- * Loads and defines the internationalization files for this plugin
20
- * so that it is ready for translation.
21
- *
22
- * @since 1.0
23
- * @package MTSNBF
24
- * @subpackage MTSNBF/includes
25
- * @author MyThemeShop
26
- */
27
- // If this file is called directly, abort.
28
- if ( ! defined( 'WPINC' ) ) {
29
- die;
30
- }
31
- class MTSNBF_i18n {
32
-
33
- /**
34
- * The domain specified for this plugin.
35
- *
36
- * @since 1.0
37
- * @access private
38
- * @var string $domain The domain identifier for this plugin.
39
- */
40
- private $domain;
41
-
42
- /**
43
- * Load the plugin text domain for translation.
44
- *
45
- * @since 1.0
46
- */
47
- public function load_plugin_textdomain() {
48
-
49
- load_plugin_textdomain(
50
- $this->domain,
51
- false,
52
- dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
53
- );
54
-
55
- }
56
-
57
- /**
58
- * Set the domain equal to that of the specified domain.
59
- *
60
- * @since 1.0
61
- * @param string $domain The domain that represents the locale of this plugin.
62
- */
63
- public function set_domain( $domain ) {
64
- $this->domain = $domain;
65
- }
66
-
67
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * Define the internationalization functionality
5
+ *
6
+ * Loads and defines the internationalization files for this plugin
7
+ * so that it is ready for translation.
8
+ *
9
+ * @link http://mythemeshop.com
10
+ * @since 1.0
11
+ *
12
+ * @package MTSNBF
13
+ * @subpackage MTSNBF/includes
14
+ */
15
+
16
+ /**
17
+ * Define the internationalization functionality.
18
+ *
19
+ * Loads and defines the internationalization files for this plugin
20
+ * so that it is ready for translation.
21
+ *
22
+ * @since 1.0
23
+ * @package MTSNBF
24
+ * @subpackage MTSNBF/includes
25
+ * @author MyThemeShop
26
+ */
27
+
28
+ // If this file is called directly, abort.
29
+ if ( ! defined( 'WPINC' ) ) {
30
+ die;
31
+ }
32
+ class MTSNBF_i18n {
33
+
34
+ /**
35
+ * The domain specified for this plugin.
36
+ *
37
+ * @since 1.0
38
+ * @access private
39
+ * @var string $domain The domain identifier for this plugin.
40
+ */
41
+ private $domain;
42
+
43
+ /**
44
+ * Load the plugin text domain for translation.
45
+ *
46
+ * @since 1.0
47
+ */
48
+ public function load_plugin_textdomain() {
49
+
50
+ load_plugin_textdomain(
51
+ $this->domain,
52
+ false,
53
+ dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
54
+ );
55
+
56
+ }
57
+
58
+ /**
59
+ * Set the domain equal to that of the specified domain.
60
+ *
61
+ * @since 1.0
62
+ * @param string $domain The domain that represents the locale of this plugin.
63
+ */
64
+ public function set_domain( $domain ) {
65
+ $this->domain = $domain;
66
+ }
67
+
68
+ }
includes/class-wp-notification-bars-loader.php CHANGED
@@ -1,133 +1,134 @@
1
- <?php
2
-
3
- /**
4
- * Register all actions and filters for the plugin
5
- *
6
- * @link http://mythemeshop.com
7
- * @since 1.0
8
- *
9
- * @package MTSNBF
10
- * @subpackage MTSNBF/includes
11
- */
12
-
13
- /**
14
- * Register all actions and filters for the plugin.
15
- *
16
- * Maintain a list of all hooks that are registered throughout
17
- * the plugin, and register them with the WordPress API. Call the
18
- * run function to execute the list of actions and filters.
19
- *
20
- * @package MTSNBF
21
- * @subpackage MTSNBF/includes
22
- * @author MyThemeShop
23
- */
24
- // If this file is called directly, abort.
25
- if ( ! defined( 'WPINC' ) ) {
26
- die;
27
- }
28
- class MTSNBF_Loader {
29
-
30
- /**
31
- * The array of actions registered with WordPress.
32
- *
33
- * @since 1.0
34
- * @access protected
35
- * @var array $actions The actions registered with WordPress to fire when the plugin loads.
36
- */
37
- protected $actions;
38
-
39
- /**
40
- * The array of filters registered with WordPress.
41
- *
42
- * @since 1.0
43
- * @access protected
44
- * @var array $filters The filters registered with WordPress to fire when the plugin loads.
45
- */
46
- protected $filters;
47
-
48
- /**
49
- * Initialize the collections used to maintain the actions and filters.
50
- *
51
- * @since 1.0
52
- */
53
- public function __construct() {
54
-
55
- $this->actions = array();
56
- $this->filters = array();
57
-
58
- }
59
-
60
- /**
61
- * Add a new action to the collection to be registered with WordPress.
62
- *
63
- * @since 1.0
64
- * @param string $hook The name of the WordPress action that is being registered.
65
- * @param object $component A reference to the instance of the object on which the action is defined.
66
- * @param string $callback The name of the function definition on the $component.
67
- * @param int Optional $priority The priority at which the function should be fired.
68
- * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
69
- */
70
- public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
71
- $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
72
- }
73
-
74
- /**
75
- * Add a new filter to the collection to be registered with WordPress.
76
- *
77
- * @since 1.0
78
- * @param string $hook The name of the WordPress filter that is being registered.
79
- * @param object $component A reference to the instance of the object on which the filter is defined.
80
- * @param string $callback The name of the function definition on the $component.
81
- * @param int Optional $priority The priority at which the function should be fired.
82
- * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
83
- */
84
- public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
85
- $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
86
- }
87
-
88
- /**
89
- * A utility function that is used to register the actions and hooks into a single
90
- * collection.
91
- *
92
- * @since 1.0
93
- * @access private
94
- * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
95
- * @param string $hook The name of the WordPress filter that is being registered.
96
- * @param object $component A reference to the instance of the object on which the filter is defined.
97
- * @param string $callback The name of the function definition on the $component.
98
- * @param int Optional $priority The priority at which the function should be fired.
99
- * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
100
- * @return type The collection of actions and filters registered with WordPress.
101
- */
102
- private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
103
-
104
- $hooks[] = array(
105
- 'hook' => $hook,
106
- 'component' => $component,
107
- 'callback' => $callback,
108
- 'priority' => $priority,
109
- 'accepted_args' => $accepted_args
110
- );
111
-
112
- return $hooks;
113
-
114
- }
115
-
116
- /**
117
- * Register the filters and actions with WordPress.
118
- *
119
- * @since 1.0
120
- */
121
- public function run() {
122
-
123
- foreach ( $this->filters as $hook ) {
124
- add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
125
- }
126
-
127
- foreach ( $this->actions as $hook ) {
128
- add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
129
- }
130
-
131
- }
132
-
133
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * Register all actions and filters for the plugin
5
+ *
6
+ * @link http://mythemeshop.com
7
+ * @since 1.0
8
+ *
9
+ * @package MTSNBF
10
+ * @subpackage MTSNBF/includes
11
+ */
12
+
13
+ /**
14
+ * Register all actions and filters for the plugin.
15
+ *
16
+ * Maintain a list of all hooks that are registered throughout
17
+ * the plugin, and register them with the WordPress API. Call the
18
+ * run function to execute the list of actions and filters.
19
+ *
20
+ * @package MTSNBF
21
+ * @subpackage MTSNBF/includes
22
+ * @author MyThemeShop
23
+ */
24
+
25
+ // If this file is called directly, abort.
26
+ if ( ! defined( 'WPINC' ) ) {
27
+ die;
28
+ }
29
+ class MTSNBF_Loader {
30
+
31
+ /**
32
+ * The array of actions registered with WordPress.
33
+ *
34
+ * @since 1.0
35
+ * @access protected
36
+ * @var array $actions The actions registered with WordPress to fire when the plugin loads.
37
+ */
38
+ protected $actions;
39
+
40
+ /**
41
+ * The array of filters registered with WordPress.
42
+ *
43
+ * @since 1.0
44
+ * @access protected
45
+ * @var array $filters The filters registered with WordPress to fire when the plugin loads.
46
+ */
47
+ protected $filters;
48
+
49
+ /**
50
+ * Initialize the collections used to maintain the actions and filters.
51
+ *
52
+ * @since 1.0
53
+ */
54
+ public function __construct() {
55
+
56
+ $this->actions = array();
57
+ $this->filters = array();
58
+
59
+ }
60
+
61
+ /**
62
+ * Add a new action to the collection to be registered with WordPress.
63
+ *
64
+ * @since 1.0
65
+ * @param string $hook The name of the WordPress action that is being registered.
66
+ * @param object $component A reference to the instance of the object on which the action is defined.
67
+ * @param string $callback The name of the function definition on the $component.
68
+ * @param int Optional $priority The priority at which the function should be fired.
69
+ * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
70
+ */
71
+ public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
72
+ $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
73
+ }
74
+
75
+ /**
76
+ * Add a new filter to the collection to be registered with WordPress.
77
+ *
78
+ * @since 1.0
79
+ * @param string $hook The name of the WordPress filter that is being registered.
80
+ * @param object $component A reference to the instance of the object on which the filter is defined.
81
+ * @param string $callback The name of the function definition on the $component.
82
+ * @param int Optional $priority The priority at which the function should be fired.
83
+ * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
84
+ */
85
+ public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
86
+ $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
87
+ }
88
+
89
+ /**
90
+ * A utility function that is used to register the actions and hooks into a single
91
+ * collection.
92
+ *
93
+ * @since 1.0
94
+ * @access private
95
+ * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
96
+ * @param string $hook The name of the WordPress filter that is being registered.
97
+ * @param object $component A reference to the instance of the object on which the filter is defined.
98
+ * @param string $callback The name of the function definition on the $component.
99
+ * @param int Optional $priority The priority at which the function should be fired.
100
+ * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
101
+ * @return type The collection of actions and filters registered with WordPress.
102
+ */
103
+ private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
104
+
105
+ $hooks[] = array(
106
+ 'hook' => $hook,
107
+ 'component' => $component,
108
+ 'callback' => $callback,
109
+ 'priority' => $priority,
110
+ 'accepted_args' => $accepted_args,
111
+ );
112
+
113
+ return $hooks;
114
+
115
+ }
116
+
117
+ /**
118
+ * Register the filters and actions with WordPress.
119
+ *
120
+ * @since 1.0
121
+ */
122
+ public function run() {
123
+
124
+ foreach ( $this->filters as $hook ) {
125
+ add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
126
+ }
127
+
128
+ foreach ( $this->actions as $hook ) {
129
+ add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
130
+ }
131
+
132
+ }
133
+
134
+ }
includes/class-wp-notification-bars-shared.php CHANGED
@@ -20,11 +20,13 @@
20
  * @subpackage MTSNBF/public
21
  * @author MyThemeShop
22
  */
23
- // If this file is called directly, abort.
24
- if ( ! defined( 'WPINC' ) ) {
25
- die;
26
- }
27
- if( !class_exists( 'MTSNBF_Shared' )) {
 
 
28
  class MTSNBF_Shared {
29
 
30
  /**
@@ -67,13 +69,13 @@
67
  * Initialize the class and set its properties.
68
  *
69
  * @since 1.0
70
- * @param string $plugin_name The name of the plugin.
71
- * @param string $version The version of this plugin.
72
  */
73
  public function __construct( $plugin_name, $version ) {
74
 
75
  $this->plugin_name = $plugin_name;
76
- $this->version = $version;
77
 
78
  }
79
 
@@ -84,7 +86,9 @@
84
  */
85
  public function get_notification_bar_data() {
86
 
87
- if ( is_admin() ) return;
 
 
88
 
89
  $bar_id = false;
90
  $bar_data = false;
@@ -94,11 +98,11 @@
94
  global $post;
95
  $bar = get_post_meta( $post->ID, '_mtsnb_override_bar', true );
96
 
97
- if ( $bar && !empty( $bar ) ) {
98
 
99
  $bar_id = isset( $bar[0] ) ? $bar[0] : false;
100
 
101
- if ( $bar_id && !empty( $bar_id ) ) {
102
 
103
  $meta_values = get_post_meta( $bar_id, '_mtsnb_data', true );
104
 
@@ -111,16 +115,16 @@
111
  }
112
 
113
  $args = array(
114
- 'post_type' => 'mts_notification_bar',
115
  'posts_per_page' => -1,
116
- 'post_status' => 'publish',
117
  );
118
 
119
  $all_bars = get_posts( $args );
120
- foreach( $all_bars as $post ) :
121
- setup_postdata( $post );
122
 
123
- $bar_id = $post->ID;
124
  $meta_values = get_post_meta( $bar_id, '_mtsnb_data', true );
125
 
126
  $passed_location_conditions = $this->test_location( $meta_values );
@@ -134,7 +138,8 @@
134
  break;
135
  }
136
 
137
- endforeach; wp_reset_postdata();
 
138
  }
139
 
140
  /**
@@ -146,14 +151,13 @@
146
 
147
  if ( is_admin() ) {// Needed for Notification Bar preview on admin side
148
 
149
- $screen = get_current_screen();
150
  $screen_id = $screen->id;
151
 
152
  if ( 'mts_notification_bar' === $screen_id ) {
153
 
154
- wp_enqueue_style( $this->plugin_name.'admin', MTSNBF_PLUGIN_URL . 'public/css/wp-notification-bars-public.css', array(), $this->version, 'all' );
155
  }
156
-
157
  } else {
158
 
159
  if ( $this->bar_id && $this->bar_data ) {
@@ -170,7 +174,7 @@
170
  */
171
  public function enqueue_scripts() {
172
 
173
- if ( !is_admin() && $this->bar_id && $this->bar_data ) {
174
 
175
  wp_enqueue_script( $this->plugin_name, MTSNBF_PLUGIN_URL . 'public/js/wp-notification-bars-public.js', array( 'jquery' ), $this->version, false );
176
  }
@@ -200,8 +204,8 @@
200
  $button_close_icon = '<span>+</span>';
201
  $button_open_icon = '<span>+</span>';
202
 
203
- $style = 'background-color:'.$meta_values['bg_color'].';color:'.$meta_values['txt_color'].';';
204
- $btn_style = 'background-color:'.$meta_values['bg_color'].';color:'.$meta_values['txt_color'].';';
205
 
206
  $shadow = '-webkit-box-shadow: 0 3px 4px rgba(0, 0, 0, 0.05);box-shadow: 0 3px 4px rgba(0, 0, 0, 0.05);';
207
 
@@ -211,23 +215,26 @@
211
  $screen_position_class = 'mtsnb-top';
212
  $css_position_class = isset( $meta_values['css_position'] ) ? 'mtsnb-' . sanitize_html_class( $meta_values['css_position'] ) : 'mtsnb-fixed';
213
  ?>
214
- <div class="mtsnb mtsnb-shown <?php echo $screen_position_class . ' ' . $css_position_class; ?>" id="mtsnb-<?php echo absint( $bar_id ); ?>" data-mtsnb-id="<?php echo absint( $bar_id ); ?>" style="<?php echo esc_attr( $style );?>">
215
  <style type="text/css">
216
- .mtsnb { position: <?php echo sanitize_html_class( $meta_values['css_position'] );?>; <?php echo $shadow; ?>}
217
- .mtsnb .mtsnb-container { width: <?php echo $width; ?>px; font-size: <?php echo (int) $meta_values['font_size']; ?>px;}
218
  .mtsnb a { color: <?php echo sanitize_hex_color( $meta_values['link_color'] ); ?>;}
219
  .mtsnb .mtsnb-button { background-color: <?php echo sanitize_hex_color( $meta_values['link_color'] ); ?>;}
220
  </style>
221
  <div class="mtsnb-container-outer">
222
  <div class="mtsnb-container mtsnb-clearfix">
223
- <?php do_action('before_mtsnb_content'); ?>
224
  <?php $this->bar_content( $meta_values ); ?>
225
- <?php do_action('after_mtsnb_content'); ?>
226
  </div>
227
  <?php if ( 'no_button' !== $button_type ) { ?>
228
- <?php if ( 'toggle_button' === $button_type ) {?><a href="#" class="mtsnb-show" style="<?php echo $btn_style; ?>"><?php echo $button_open_icon; ?></a><?php } ?>
229
- <a href="#" class="mtsnb-hide" style="<?php echo esc_attr( $style ); ?>"><?php echo $button_close_icon; ?></a>
230
- <?php } ?>
 
 
 
231
  </div>
232
  </div>
233
  <?php
@@ -246,17 +253,10 @@
246
  switch ( $options['content_type'] ) {
247
 
248
  case 'button':
 
249
 
250
- $text = wp_kses_post( $options['basic_text'] );
251
- $link_text = wp_kses_post( $options['basic_link_text'] );
252
- $link_url = esc_url( $options['basic_link_url'] );
253
- $link_style = sanitize_html_class( $options['basic_link_style'] );
254
-
255
- echo '<span class="mtsnb-text">'.$text.'</span><a href="'.$link_url.'" class="mtsnb-'.$link_style.'">'.$link_text.'</a>';
256
-
257
- break;
258
  case 'custom':
259
-
260
  echo '<div class="mtsnb-custom-content">';
261
  if ( defined( 'MTSNBF_UNFILTERED_HTML' ) && MTSNBF_UNFILTERED_HTML ) {
262
  echo do_shortcode( html_entity_decode( $options['custom_content'] ) );
@@ -265,7 +265,7 @@
265
  }
266
  echo '</div>';
267
 
268
- break;
269
  }
270
 
271
  echo '</div>';
@@ -278,13 +278,19 @@
278
  */
279
  public function preview_bar() {
280
 
 
 
281
  $data = $_POST['form_data'];
282
 
283
  parse_str( $data, $options );
284
 
285
- $id = $options['post_ID'];
286
  $meta_values = $options['mtsnb_fields'];
287
 
 
 
 
 
288
  // fix slashes
289
  foreach ( $meta_values as $key => $value ) {
290
 
@@ -309,14 +315,18 @@
309
 
310
  $no_condition = (bool) ( empty( $meta_values['conditions']['google']['state'] ) && empty( $meta_values['conditions']['notgoogle']['state'] ) && empty( $meta_values['conditions']['facebook']['state'] ) && empty( $meta_values['conditions']['notfacebook']['state'] ) );
311
 
312
- if ( $no_condition ) return true; // not set, can be displayed
 
 
313
 
314
  $referer = $this->get_referrer();
315
 
316
  // Show for google
317
- if ( !empty( $meta_values['conditions']['google']['state'] ) ) {
318
 
319
- if ( empty( $referer ) ) return false; // not set, don't display
 
 
320
  $is_search_engine = $this->test_searchengine( $referer );
321
 
322
  if ( $is_search_engine ) {
@@ -328,9 +338,11 @@
328
  }
329
 
330
  // Don't show for google
331
- if ( !empty( $meta_values['conditions']['notgoogle']['state'] ) ) {
332
 
333
- if ( empty( $referer ) ) return true; // not set, display
 
 
334
  $is_search_engine = $this->test_searchengine( $referer );
335
 
336
  if ( $is_search_engine ) {
@@ -342,9 +354,11 @@
342
  }
343
 
344
  // Show for facebook
345
- if ( !empty( $meta_values['conditions']['facebook']['state'] ) ) {
346
 
347
- if ( empty( $referer ) ) return false; // not set, don't display
 
 
348
 
349
  if ( false !== strpos( $referer, 'facebook.' ) ) {
350
 
@@ -355,9 +369,11 @@
355
  }
356
 
357
  // Don't show for facebook
358
- if ( !empty( $meta_values['conditions']['notfacebook']['state'] ) ) {
359
 
360
- if ( empty( $referer ) ) return true; // not set, display
 
 
361
 
362
  if ( false !== strpos( $referer, 'facebook.' ) ) {
363
 
@@ -377,29 +393,31 @@
377
 
378
  $no_condition = (bool) ( empty( $meta_values['conditions']['location']['state'] ) && empty( $meta_values['conditions']['notlocation']['state'] ) );
379
 
380
- if ( $no_condition ) return true; // not set, can be displayed
 
 
381
 
382
  // Enable on locations
383
- if ( !empty( $meta_values['conditions']['location']['state'] ) ) {
384
 
385
  if (
386
- 'page' === get_option('show_on_front') &&
387
- '0' !== get_option('page_for_posts') &&
388
- '0' !== get_option('page_on_front') &&
389
  ( ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['location']['blog_home'] ) ) )
390
  ) {
391
 
392
  return true;
393
 
394
- } else if ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) {
395
 
396
  return true;
397
 
398
- } else if ( is_single() && isset( $meta_values['conditions']['location']['posts'] ) ) {
399
 
400
  return true;
401
 
402
- } else if ( is_page() && isset( $meta_values['conditions']['location']['pages'] ) ) {
403
 
404
  return true;
405
  }
@@ -408,26 +426,26 @@
408
  }
409
 
410
  // Disable on locations
411
- if ( !empty( $meta_values['conditions']['notlocation']['state'] ) ) {
412
 
413
  if (
414
- 'page' === get_option('show_on_front') &&
415
- '0' !== get_option('page_for_posts') &&
416
- '0' !== get_option('page_on_front') &&
417
  ( ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['notlocation']['blog_home'] ) ) )
418
  ) {
419
 
420
  return false;
421
 
422
- } else if ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) {
423
 
424
  return false;
425
 
426
- } else if ( is_single() && isset( $meta_values['conditions']['notlocation']['posts'] ) ) {
427
 
428
  return false;
429
 
430
- } else if ( is_page() && isset( $meta_values['conditions']['notlocation']['pages'] ) ) {
431
 
432
  return false;
433
  }
@@ -450,7 +468,7 @@
450
 
451
  foreach ( $patterns as $url ) {
452
  if ( false !== stripos( $referrer, $url ) ) {
453
- if ( $url == '.google.' ) {
454
  if ( $this->is_googlesearch( $referrer ) ) {
455
  $response = true;
456
  } else {
@@ -474,18 +492,18 @@
474
  $response = true;
475
 
476
  // Get the query strings and check its a web source.
477
- $qs = parse_url( $referrer, PHP_URL_QUERY );
478
  $qget = array();
479
 
480
  foreach ( explode( '&', $qs ) as $keyval ) {
481
  $kv = explode( '=', $keyval );
482
- if ( count( $kv ) == 2 ) {
483
  $qget[ trim( $kv[0] ) ] = trim( $kv[1] );
484
  }
485
  }
486
 
487
  if ( isset( $qget['source'] ) ) {
488
- $response = $qget['source'] == 'web';
489
  }
490
 
491
  return $response;
@@ -500,9 +518,9 @@
500
 
501
  $referer = wp_unslash( $_SERVER['HTTP_REFERER'] );
502
 
503
- if ( $referer && !empty( $referer ) ) {
504
 
505
- $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );// maybe not needed
506
  setcookie( 'mtsnb_referrer', esc_url( $referer ), 0, COOKIEPATH, COOKIE_DOMAIN, $secure ); // session
507
 
508
  } else {
20
  * @subpackage MTSNBF/public
21
  * @author MyThemeShop
22
  */
23
+
24
+ // If this file is called directly, abort.
25
+ if ( ! defined( 'WPINC' ) ) {
26
+ die;
27
+ }
28
+
29
+ if ( ! class_exists( 'MTSNBF_Shared' ) ) {
30
  class MTSNBF_Shared {
31
 
32
  /**
69
  * Initialize the class and set its properties.
70
  *
71
  * @since 1.0
72
+ * @param string $plugin_name The name of the plugin.
73
+ * @param string $version The version of this plugin.
74
  */
75
  public function __construct( $plugin_name, $version ) {
76
 
77
  $this->plugin_name = $plugin_name;
78
+ $this->version = $version;
79
 
80
  }
81
 
86
  */
87
  public function get_notification_bar_data() {
88
 
89
+ if ( is_admin() ) {
90
+ return;
91
+ }
92
 
93
  $bar_id = false;
94
  $bar_data = false;
98
  global $post;
99
  $bar = get_post_meta( $post->ID, '_mtsnb_override_bar', true );
100
 
101
+ if ( $bar && ! empty( $bar ) ) {
102
 
103
  $bar_id = isset( $bar[0] ) ? $bar[0] : false;
104
 
105
+ if ( $bar_id && ! empty( $bar_id ) ) {
106
 
107
  $meta_values = get_post_meta( $bar_id, '_mtsnb_data', true );
108
 
115
  }
116
 
117
  $args = array(
118
+ 'post_type' => 'mts_notification_bar',
119
  'posts_per_page' => -1,
120
+ 'post_status' => 'publish',
121
  );
122
 
123
  $all_bars = get_posts( $args );
124
+ foreach ( $all_bars as $bar ) :
125
+ setup_postdata( $bar );
126
 
127
+ $bar_id = $bar->ID;
128
  $meta_values = get_post_meta( $bar_id, '_mtsnb_data', true );
129
 
130
  $passed_location_conditions = $this->test_location( $meta_values );
138
  break;
139
  }
140
 
141
+ endforeach;
142
+ wp_reset_postdata();
143
  }
144
 
145
  /**
151
 
152
  if ( is_admin() ) {// Needed for Notification Bar preview on admin side
153
 
154
+ $screen = get_current_screen();
155
  $screen_id = $screen->id;
156
 
157
  if ( 'mts_notification_bar' === $screen_id ) {
158
 
159
+ wp_enqueue_style( $this->plugin_name . 'admin', MTSNBF_PLUGIN_URL . 'public/css/wp-notification-bars-public.css', array(), $this->version, 'all' );
160
  }
 
161
  } else {
162
 
163
  if ( $this->bar_id && $this->bar_data ) {
174
  */
175
  public function enqueue_scripts() {
176
 
177
+ if ( ! is_admin() && $this->bar_id && $this->bar_data ) {
178
 
179
  wp_enqueue_script( $this->plugin_name, MTSNBF_PLUGIN_URL . 'public/js/wp-notification-bars-public.js', array( 'jquery' ), $this->version, false );
180
  }
204
  $button_close_icon = '<span>+</span>';
205
  $button_open_icon = '<span>+</span>';
206
 
207
+ $style = 'background-color:' . $meta_values['bg_color'] . ';color:' . $meta_values['txt_color'] . ';';
208
+ $btn_style = 'background-color:' . $meta_values['bg_color'] . ';color:' . $meta_values['txt_color'] . ';';
209
 
210
  $shadow = '-webkit-box-shadow: 0 3px 4px rgba(0, 0, 0, 0.05);box-shadow: 0 3px 4px rgba(0, 0, 0, 0.05);';
211
 
215
  $screen_position_class = 'mtsnb-top';
216
  $css_position_class = isset( $meta_values['css_position'] ) ? 'mtsnb-' . sanitize_html_class( $meta_values['css_position'] ) : 'mtsnb-fixed';
217
  ?>
218
+ <div class="mtsnb mtsnb-shown <?php echo esc_attr( $screen_position_class . ' ' . $css_position_class ); ?>" id="mtsnb-<?php echo esc_attr( $bar_id ); ?>" data-mtsnb-id="<?php echo esc_attr( $bar_id ); ?>" style="<?php echo esc_attr( $style ); ?>">
219
  <style type="text/css">
220
+ .mtsnb { position: <?php echo sanitize_html_class( $meta_values['css_position'] ); ?>; <?php echo esc_html( $shadow ); ?>}
221
+ .mtsnb .mtsnb-container { width: <?php echo esc_html( $width ); ?>px; font-size: <?php echo esc_html( $meta_values['font_size'] ); ?>px;}
222
  .mtsnb a { color: <?php echo sanitize_hex_color( $meta_values['link_color'] ); ?>;}
223
  .mtsnb .mtsnb-button { background-color: <?php echo sanitize_hex_color( $meta_values['link_color'] ); ?>;}
224
  </style>
225
  <div class="mtsnb-container-outer">
226
  <div class="mtsnb-container mtsnb-clearfix">
227
+ <?php do_action( 'before_mtsnb_content' ); ?>
228
  <?php $this->bar_content( $meta_values ); ?>
229
+ <?php do_action( 'after_mtsnb_content' ); ?>
230
  </div>
231
  <?php if ( 'no_button' !== $button_type ) { ?>
232
+ <?php
233
+ if ( 'toggle_button' === $button_type ) {
234
+ ?>
235
+ <a href="#" class="mtsnb-show" style="<?php echo esc_attr( $btn_style ); ?>"><?php echo wp_kses_post( $button_open_icon ); ?></a><?php } ?>
236
+ <a href="#" class="mtsnb-hide" style="<?php echo esc_attr( $style ); ?>"><?php echo wp_kses_post( $button_close_icon ); ?></a>
237
+ <?php } ?>
238
  </div>
239
  </div>
240
  <?php
253
  switch ( $options['content_type'] ) {
254
 
255
  case 'button':
256
+ echo '<span class="mtsnb-text">' . wp_kses_post( $options['basic_text'] ) . '</span><a href="' . esc_url( $options['basic_link_url'] ) . '" class="mtsnb-' . esc_attr( $options['basic_link_style'] ) . '">' . wp_kses_post( $options['basic_link_text'] ) . '</a>';
257
 
258
+ break;
 
 
 
 
 
 
 
259
  case 'custom':
 
260
  echo '<div class="mtsnb-custom-content">';
261
  if ( defined( 'MTSNBF_UNFILTERED_HTML' ) && MTSNBF_UNFILTERED_HTML ) {
262
  echo do_shortcode( html_entity_decode( $options['custom_content'] ) );
265
  }
266
  echo '</div>';
267
 
268
+ break;
269
  }
270
 
271
  echo '</div>';
278
  */
279
  public function preview_bar() {
280
 
281
+ check_ajax_referer( 'mtsnb_meta_box', 'mtsnb_meta_box_nonce' );
282
+
283
  $data = $_POST['form_data'];
284
 
285
  parse_str( $data, $options );
286
 
287
+ $id = $options['post_ID'];
288
  $meta_values = $options['mtsnb_fields'];
289
 
290
+ if ( ! current_user_can( 'edit_post', $id ) ) {
291
+ die( '0' );
292
+ }
293
+
294
  // fix slashes
295
  foreach ( $meta_values as $key => $value ) {
296
 
315
 
316
  $no_condition = (bool) ( empty( $meta_values['conditions']['google']['state'] ) && empty( $meta_values['conditions']['notgoogle']['state'] ) && empty( $meta_values['conditions']['facebook']['state'] ) && empty( $meta_values['conditions']['notfacebook']['state'] ) );
317
 
318
+ if ( $no_condition ) {
319
+ return true; // not set, can be displayed
320
+ }
321
 
322
  $referer = $this->get_referrer();
323
 
324
  // Show for google
325
+ if ( ! empty( $meta_values['conditions']['google']['state'] ) ) {
326
 
327
+ if ( empty( $referer ) ) {
328
+ return false; // not set, don't display
329
+ }
330
  $is_search_engine = $this->test_searchengine( $referer );
331
 
332
  if ( $is_search_engine ) {
338
  }
339
 
340
  // Don't show for google
341
+ if ( ! empty( $meta_values['conditions']['notgoogle']['state'] ) ) {
342
 
343
+ if ( empty( $referer ) ) {
344
+ return true; // not set, display
345
+ }
346
  $is_search_engine = $this->test_searchengine( $referer );
347
 
348
  if ( $is_search_engine ) {
354
  }
355
 
356
  // Show for facebook
357
+ if ( ! empty( $meta_values['conditions']['facebook']['state'] ) ) {
358
 
359
+ if ( empty( $referer ) ) {
360
+ return false; // not set, don't display
361
+ }
362
 
363
  if ( false !== strpos( $referer, 'facebook.' ) ) {
364
 
369
  }
370
 
371
  // Don't show for facebook
372
+ if ( ! empty( $meta_values['conditions']['notfacebook']['state'] ) ) {
373
 
374
+ if ( empty( $referer ) ) {
375
+ return true; // not set, display
376
+ }
377
 
378
  if ( false !== strpos( $referer, 'facebook.' ) ) {
379
 
393
 
394
  $no_condition = (bool) ( empty( $meta_values['conditions']['location']['state'] ) && empty( $meta_values['conditions']['notlocation']['state'] ) );
395
 
396
+ if ( $no_condition ) {
397
+ return true; // not set, can be displayed
398
+ }
399
 
400
  // Enable on locations
401
+ if ( ! empty( $meta_values['conditions']['location']['state'] ) ) {
402
 
403
  if (
404
+ 'page' === get_option( 'show_on_front' ) &&
405
+ '0' !== get_option( 'page_for_posts' ) &&
406
+ '0' !== get_option( 'page_on_front' ) &&
407
  ( ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['location']['blog_home'] ) ) )
408
  ) {
409
 
410
  return true;
411
 
412
+ } elseif ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) {
413
 
414
  return true;
415
 
416
+ } elseif ( is_single() && isset( $meta_values['conditions']['location']['posts'] ) ) {
417
 
418
  return true;
419
 
420
+ } elseif ( is_page() && isset( $meta_values['conditions']['location']['pages'] ) ) {
421
 
422
  return true;
423
  }
426
  }
427
 
428
  // Disable on locations
429
+ if ( ! empty( $meta_values['conditions']['notlocation']['state'] ) ) {
430
 
431
  if (
432
+ 'page' === get_option( 'show_on_front' ) &&
433
+ '0' !== get_option( 'page_for_posts' ) &&
434
+ '0' !== get_option( 'page_on_front' ) &&
435
  ( ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['notlocation']['blog_home'] ) ) )
436
  ) {
437
 
438
  return false;
439
 
440
+ } elseif ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) {
441
 
442
  return false;
443
 
444
+ } elseif ( is_single() && isset( $meta_values['conditions']['notlocation']['posts'] ) ) {
445
 
446
  return false;
447
 
448
+ } elseif ( is_page() && isset( $meta_values['conditions']['notlocation']['pages'] ) ) {
449
 
450
  return false;
451
  }
468
 
469
  foreach ( $patterns as $url ) {
470
  if ( false !== stripos( $referrer, $url ) ) {
471
+ if ( '.google.' === $url ) {
472
  if ( $this->is_googlesearch( $referrer ) ) {
473
  $response = true;
474
  } else {
492
  $response = true;
493
 
494
  // Get the query strings and check its a web source.
495
+ $qs = wp_parse_url( $referrer, PHP_URL_QUERY );
496
  $qget = array();
497
 
498
  foreach ( explode( '&', $qs ) as $keyval ) {
499
  $kv = explode( '=', $keyval );
500
+ if ( count( $kv ) === 2 ) {
501
  $qget[ trim( $kv[0] ) ] = trim( $kv[1] );
502
  }
503
  }
504
 
505
  if ( isset( $qget['source'] ) ) {
506
+ $response = ( 'web' === $qget['source'] );
507
  }
508
 
509
  return $response;
518
 
519
  $referer = wp_unslash( $_SERVER['HTTP_REFERER'] );
520
 
521
+ if ( $referer && ! empty( $referer ) ) {
522
 
523
+ $secure = ( 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME ) );// maybe not needed
524
  setcookie( 'mtsnb_referrer', esc_url( $referer ), 0, COOKIEPATH, COOKIE_DOMAIN, $secure ); // session
525
 
526
  } else {
includes/class-wp-notification-bars.php CHANGED
@@ -1,262 +1,262 @@
1
- <?php
2
-
3
- /**
4
- * The file that defines the core plugin class
5
- *
6
- * A class definition that includes attributes and functions used across both the
7
- * public-facing side of the site and the dashboard.
8
- *
9
- * @link http://mythemeshop.com
10
- * @since 1.0
11
- *
12
- * @package MTSNBF
13
- * @subpackage MTSNBF/includes
14
- */
15
-
16
- /**
17
- * The core plugin class.
18
- *
19
- * This is used to define internationalization, dashboard-specific hooks, and
20
- * public-facing site hooks.
21
- *
22
- * Also maintains the unique identifier of this plugin as well as the current
23
- * version of the plugin.
24
- *
25
- * @since 1.0
26
- * @package MTSNBF
27
- * @subpackage MTSNBF/includes
28
- * @author MyThemeShop
29
- */
30
- class MTSNBF {
31
-
32
- /**
33
- * The loader that's responsible for maintaining and registering all hooks that power
34
- * the plugin.
35
- *
36
- * @since 1.0
37
- * @access protected
38
- * @var MTSNBF_Loader $loader Maintains and registers all hooks for the plugin.
39
- */
40
- protected $loader;
41
-
42
- /**
43
- * The unique identifier of this plugin.
44
- *
45
- * @since 1.0
46
- * @access protected
47
- * @var string $plugin_name The string used to uniquely identify this plugin.
48
- */
49
- protected $plugin_name;
50
-
51
- /**
52
- * The current version of the plugin.
53
- *
54
- * @since 1.0
55
- * @access protected
56
- * @var string $version The current version of the plugin.
57
- */
58
- protected $version;
59
-
60
- /**
61
- * Define the core functionality of the plugin.
62
- *
63
- * Set the plugin name and the plugin version that can be used throughout the plugin.
64
- * Load the dependencies, define the locale, and set the hooks for the Dashboard and
65
- * the public-facing side of the site.
66
- *
67
- * @since 1.0
68
- */
69
- public function __construct() {
70
-
71
- $this->plugin_name = 'wp-notification-bars';
72
- $this->version = '1.0.6';
73
-
74
- $this->load_dependencies();
75
- $this->set_locale();
76
- $this->define_admin_hooks();
77
- $this->define_public_hooks();
78
- $this->define_shared_hooks();
79
- }
80
-
81
- /**
82
- * Load the required dependencies for this plugin.
83
- *
84
- * Include the following files that make up the plugin:
85
- *
86
- * - MTSNBF_Loader. Orchestrates the hooks of the plugin.
87
- * - MTSNBF_i18n. Defines internationalization functionality.
88
- * - MTSNBF_Admin. Defines all hooks for the dashboard.
89
- * - MTSNBF_Public. Defines all hooks for the public side of the site.
90
- *
91
- * Create an instance of the loader which will be used to register the hooks
92
- * with WordPress.
93
- *
94
- * @since 1.0
95
- * @access private
96
- */
97
- private function load_dependencies() {
98
-
99
- /**
100
- * The class responsible for orchestrating the actions and filters of the
101
- * core plugin.
102
- */
103
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-notification-bars-loader.php';
104
-
105
- /**
106
- * The class responsible for defining internationalization functionality
107
- * of the plugin.
108
- */
109
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-notification-bars-i18n.php';
110
-
111
- /**
112
- * The class responsible for defining all actions that occur in the Dashboard.
113
- */
114
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-notification-bars-admin.php';
115
-
116
- /**
117
- * The class responsible for defining all actions that occur in the public-facing
118
- * side of the site.
119
- */
120
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-notification-bars-public.php';
121
-
122
- /**
123
- * The class responsible for defining all actions that occur in both sides of the site.
124
- */
125
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-notification-bars-shared.php';
126
-
127
- $this->loader = new MTSNBF_Loader();
128
- }
129
-
130
- /**
131
- * Define the locale for this plugin for internationalization.
132
- *
133
- * Uses the MTSNBF_i18n class in order to set the domain and to register the hook
134
- * with WordPress.
135
- *
136
- * @since 1.0
137
- * @access private
138
- */
139
- private function set_locale() {
140
-
141
- $plugin_i18n = new MTSNBF_i18n();
142
- $plugin_i18n->set_domain( $this->get_plugin_name() );
143
-
144
- $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
145
- }
146
-
147
- /**
148
- * Register all of the hooks related to the dashboard functionality
149
- * of the plugin.
150
- *
151
- * @since 1.0
152
- * @access private
153
- */
154
- private function define_admin_hooks() {
155
-
156
- $plugin_admin = new MTSNBF_Admin( $this->get_plugin_name(), $this->get_version() );
157
-
158
- $this->loader->add_action( 'admin_init', $plugin_admin, 'check_version' );
159
-
160
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
161
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
162
-
163
- /* Display a notice */
164
- $this->loader->add_action( 'admin_notices', $plugin_admin, 'wp_notification_bar_admin_notice' );
165
- $this->loader->add_action( 'wp_ajax_mts_dismiss_nb_notice', $plugin_admin, 'wp_notification_bar_admin_notice_ignore' );
166
-
167
- // Register our post type
168
- $this->loader->add_action( 'init', $plugin_admin, 'mts_notification_cpt' );
169
-
170
- // Metaboxes
171
- $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'add_custom_meta_box' );
172
- $this->loader->add_action( 'save_post', $plugin_admin, 'save_custom_meta' );
173
-
174
- // Add preview button to poblish metabox
175
- $this->loader->add_action( 'post_submitbox_misc_actions', $plugin_admin, 'add_preview_button' );
176
-
177
- $this->loader->add_filter( 'post_updated_messages', $plugin_admin, 'mtsnb_update_messages' );
178
-
179
- // Force notification bar metabox
180
- $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'mtsnb_select_metabox_insert' );
181
- $this->loader->add_action( 'save_post', $plugin_admin, 'mtsnb_select_metabox_save' );
182
- $this->loader->add_action( 'wp_ajax_mtsnb_get_bars', $plugin_admin, 'mtsnb_get_bars' );
183
- $this->loader->add_action( 'wp_ajax_mtsnb_get_bar_titles', $plugin_admin, 'mtsnb_get_bar_titles' );
184
- }
185
-
186
- /**
187
- * Register all of the hooks related to the public-facing functionality
188
- * of the plugin.
189
- *
190
- * @since 1.0
191
- * @access private
192
- */
193
- private function define_public_hooks() {
194
-
195
- $plugin_public = new MTSNBF_Public( $this->get_plugin_name(), $this->get_version() );
196
- }
197
-
198
- /**
199
- * Register all of the hooks related to both public and dashboard functionality
200
- * of the plugin.
201
- *
202
- * @since 1.0
203
- * @access private
204
- */
205
- private function define_shared_hooks() {
206
-
207
- $plugin_shared = new MTSNBF_Shared( $this->get_plugin_name(), $this->get_version() );
208
-
209
- // get/set bar settings
210
- $this->loader->add_action( 'wp', $plugin_shared, 'get_notification_bar_data' );
211
- // Display bar on front end
212
- $this->loader->add_action( 'wp_footer', $plugin_shared, 'display_bar' );
213
- // Ajax Preview on backend
214
- $this->loader->add_action( 'wp_ajax_preview_bar', $plugin_shared, 'preview_bar' );
215
-
216
- $this->loader->add_action( 'wp_enqueue_scripts', $plugin_shared, 'enqueue_styles', -1 );
217
- $this->loader->add_action( 'wp_enqueue_scripts', $plugin_shared, 'enqueue_scripts' );
218
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_shared, 'enqueue_styles' );
219
- $this->loader->add_action( 'admin_enqueue_scripts', $plugin_shared, 'enqueue_scripts' );
220
- }
221
-
222
- /**
223
- * Run the loader to execute all of the hooks with WordPress.
224
- *
225
- * @since 1.0
226
- */
227
- public function run() {
228
- $this->loader->run();
229
- }
230
-
231
- /**
232
- * The name of the plugin used to uniquely identify it within the context of
233
- * WordPress and to define internationalization functionality.
234
- *
235
- * @since 1.0
236
- * @return string The name of the plugin.
237
- */
238
- public function get_plugin_name() {
239
- return $this->plugin_name;
240
- }
241
-
242
- /**
243
- * The reference to the class that orchestrates the hooks with the plugin.
244
- *
245
- * @since 1.0
246
- * @return MTSNBF_Loader Orchestrates the hooks of the plugin.
247
- */
248
- public function get_loader() {
249
- return $this->loader;
250
- }
251
-
252
- /**
253
- * Retrieve the version number of the plugin.
254
- *
255
- * @since 1.0
256
- * @return string The version number of the plugin.
257
- */
258
- public function get_version() {
259
- return $this->version;
260
- }
261
-
262
- }
1
+ <?php
2
+
3
+ /**
4
+ * The file that defines the core plugin class
5
+ *
6
+ * A class definition that includes attributes and functions used across both the
7
+ * public-facing side of the site and the dashboard.
8
+ *
9
+ * @link http://mythemeshop.com
10
+ * @since 1.0
11
+ *
12
+ * @package MTSNBF
13
+ * @subpackage MTSNBF/includes
14
+ */
15
+
16
+ /**
17
+ * The core plugin class.
18
+ *
19
+ * This is used to define internationalization, dashboard-specific hooks, and
20
+ * public-facing site hooks.
21
+ *
22
+ * Also maintains the unique identifier of this plugin as well as the current
23
+ * version of the plugin.
24
+ *
25
+ * @since 1.0
26
+ * @package MTSNBF
27
+ * @subpackage MTSNBF/includes
28
+ * @author MyThemeShop
29
+ */
30
+ class MTSNBF {
31
+
32
+ /**
33
+ * The loader that's responsible for maintaining and registering all hooks that power
34
+ * the plugin.
35
+ *
36
+ * @since 1.0
37
+ * @access protected
38
+ * @var MTSNBF_Loader $loader Maintains and registers all hooks for the plugin.
39
+ */
40
+ protected $loader;
41
+
42
+ /**
43
+ * The unique identifier of this plugin.
44
+ *
45
+ * @since 1.0
46
+ * @access protected
47
+ * @var string $plugin_name The string used to uniquely identify this plugin.
48
+ */
49
+ protected $plugin_name;
50
+
51
+ /**
52
+ * The current version of the plugin.
53
+ *
54
+ * @since 1.0
55
+ * @access protected
56
+ * @var string $version The current version of the plugin.
57
+ */
58
+ protected $version;
59
+
60
+ /**
61
+ * Define the core functionality of the plugin.
62
+ *
63
+ * Set the plugin name and the plugin version that can be used throughout the plugin.
64
+ * Load the dependencies, define the locale, and set the hooks for the Dashboard and
65
+ * the public-facing side of the site.
66
+ *
67
+ * @since 1.0
68
+ */
69
+ public function __construct() {
70
+
71
+ $this->plugin_name = 'wp-notification-bars';
72
+ $this->version = '1.0.7';
73
+
74
+ $this->load_dependencies();
75
+ $this->set_locale();
76
+ $this->define_admin_hooks();
77
+ $this->define_public_hooks();
78
+ $this->define_shared_hooks();
79
+ }
80
+
81
+ /**
82
+ * Load the required dependencies for this plugin.
83
+ *
84
+ * Include the following files that make up the plugin:
85
+ *
86
+ * - MTSNBF_Loader. Orchestrates the hooks of the plugin.
87
+ * - MTSNBF_i18n. Defines internationalization functionality.
88
+ * - MTSNBF_Admin. Defines all hooks for the dashboard.
89
+ * - MTSNBF_Public. Defines all hooks for the public side of the site.
90
+ *
91
+ * Create an instance of the loader which will be used to register the hooks
92
+ * with WordPress.
93
+ *
94
+ * @since 1.0
95
+ * @access private
96
+ */
97
+ private function load_dependencies() {
98
+
99
+ /**
100
+ * The class responsible for orchestrating the actions and filters of the
101
+ * core plugin.
102
+ */
103
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-notification-bars-loader.php';
104
+
105
+ /**
106
+ * The class responsible for defining internationalization functionality
107
+ * of the plugin.
108
+ */
109
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-notification-bars-i18n.php';
110
+
111
+ /**
112
+ * The class responsible for defining all actions that occur in the Dashboard.
113
+ */
114
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-notification-bars-admin.php';
115
+
116
+ /**
117
+ * The class responsible for defining all actions that occur in the public-facing
118
+ * side of the site.
119
+ */
120
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-notification-bars-public.php';
121
+
122
+ /**
123
+ * The class responsible for defining all actions that occur in both sides of the site.
124
+ */
125
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-notification-bars-shared.php';
126
+
127
+ $this->loader = new MTSNBF_Loader();
128
+ }
129
+
130
+ /**
131
+ * Define the locale for this plugin for internationalization.
132
+ *
133
+ * Uses the MTSNBF_i18n class in order to set the domain and to register the hook
134
+ * with WordPress.
135
+ *
136
+ * @since 1.0
137
+ * @access private
138
+ */
139
+ private function set_locale() {
140
+
141
+ $plugin_i18n = new MTSNBF_i18n();
142
+ $plugin_i18n->set_domain( $this->get_plugin_name() );
143
+
144
+ $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
145
+ }
146
+
147
+ /**
148
+ * Register all of the hooks related to the dashboard functionality
149
+ * of the plugin.
150
+ *
151
+ * @since 1.0
152
+ * @access private
153
+ */
154
+ private function define_admin_hooks() {
155
+
156
+ $plugin_admin = new MTSNBF_Admin( $this->get_plugin_name(), $this->get_version() );
157
+
158
+ $this->loader->add_action( 'admin_init', $plugin_admin, 'check_version' );
159
+
160
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
161
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
162
+
163
+ /* Display a notice */
164
+ $this->loader->add_action( 'admin_notices', $plugin_admin, 'wp_notification_bar_admin_notice' );
165
+ $this->loader->add_action( 'wp_ajax_mts_dismiss_nb_notice', $plugin_admin, 'wp_notification_bar_admin_notice_ignore' );
166
+
167
+ // Register our post type
168
+ $this->loader->add_action( 'init', $plugin_admin, 'mts_notification_cpt' );
169
+
170
+ // Metaboxes
171
+ $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'add_custom_meta_box' );
172
+ $this->loader->add_action( 'save_post', $plugin_admin, 'save_custom_meta' );
173
+
174
+ // Add preview button to poblish metabox
175
+ $this->loader->add_action( 'post_submitbox_misc_actions', $plugin_admin, 'add_preview_button' );
176
+
177
+ $this->loader->add_filter( 'post_updated_messages', $plugin_admin, 'mtsnb_update_messages' );
178
+
179
+ // Force notification bar metabox
180
+ $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'mtsnb_select_metabox_insert' );
181
+ $this->loader->add_action( 'save_post', $plugin_admin, 'mtsnb_select_metabox_save' );
182
+ $this->loader->add_action( 'wp_ajax_mtsnb_get_bars', $plugin_admin, 'mtsnb_get_bars' );
183
+ $this->loader->add_action( 'wp_ajax_mtsnb_get_bar_titles', $plugin_admin, 'mtsnb_get_bar_titles' );
184
+ }
185
+
186
+ /**
187
+ * Register all of the hooks related to the public-facing functionality
188
+ * of the plugin.
189
+ *
190
+ * @since 1.0
191
+ * @access private
192
+ */
193
+ private function define_public_hooks() {
194
+
195
+ $plugin_public = new MTSNBF_Public( $this->get_plugin_name(), $this->get_version() );
196
+ }
197
+
198
+ /**
199
+ * Register all of the hooks related to both public and dashboard functionality
200
+ * of the plugin.
201
+ *
202
+ * @since 1.0
203
+ * @access private
204
+ */
205
+ private function define_shared_hooks() {
206
+
207
+ $plugin_shared = new MTSNBF_Shared( $this->get_plugin_name(), $this->get_version() );
208
+
209
+ // get/set bar settings
210
+ $this->loader->add_action( 'wp', $plugin_shared, 'get_notification_bar_data' );
211
+ // Display bar on front end
212
+ $this->loader->add_action( 'wp_footer', $plugin_shared, 'display_bar' );
213
+ // Ajax Preview on backend
214
+ $this->loader->add_action( 'wp_ajax_preview_bar', $plugin_shared, 'preview_bar' );
215
+
216
+ $this->loader->add_action( 'wp_enqueue_scripts', $plugin_shared, 'enqueue_styles', -1 );
217
+ $this->loader->add_action( 'wp_enqueue_scripts', $plugin_shared, 'enqueue_scripts' );
218
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_shared, 'enqueue_styles' );
219
+ $this->loader->add_action( 'admin_enqueue_scripts', $plugin_shared, 'enqueue_scripts' );
220
+ }
221
+
222
+ /**
223
+ * Run the loader to execute all of the hooks with WordPress.
224
+ *
225
+ * @since 1.0
226
+ */
227
+ public function run() {
228
+ $this->loader->run();
229
+ }
230
+
231
+ /**
232
+ * The name of the plugin used to uniquely identify it within the context of
233
+ * WordPress and to define internationalization functionality.
234
+ *
235
+ * @since 1.0
236
+ * @return string The name of the plugin.
237
+ */
238
+ public function get_plugin_name() {
239
+ return $this->plugin_name;
240
+ }
241
+
242
+ /**
243
+ * The reference to the class that orchestrates the hooks with the plugin.
244
+ *
245
+ * @since 1.0
246
+ * @return MTSNBF_Loader Orchestrates the hooks of the plugin.
247
+ */
248
+ public function get_loader() {
249
+ return $this->loader;
250
+ }
251
+
252
+ /**
253
+ * Retrieve the version number of the plugin.
254
+ *
255
+ * @since 1.0
256
+ * @return string The version number of the plugin.
257
+ */
258
+ public function get_version() {
259
+ return $this->version;
260
+ }
261
+
262
+ }
includes/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
public/class-wp-notification-bars-public.php CHANGED
@@ -1,61 +1,61 @@
1
- <?php
2
- /**
3
- * The public-facing functionality of the plugin.
4
- *
5
- * @link https://mythemeshop.com
6
- * @since 1.0
7
- *
8
- * @package MTSNBF
9
- * @subpackage MTSNBF/public
10
- */
11
-
12
- /**
13
- * The public-facing functionality of the plugin.
14
- *
15
- * Defines the plugin name, version, and two examples hooks for how to
16
- * enqueue the dashboard-specific stylesheet and JavaScript.
17
- *
18
- * @package MTSNBF
19
- * @subpackage MTSNBF/public
20
- * @author MyThemeShop
21
- */
22
- // If this file is called directly, abort.
23
- if ( ! defined( 'WPINC' ) ) {
24
- die;
25
- }
26
- if( !class_exists( 'MTSNBF_Public' )){
27
-
28
- class MTSNBF_Public {
29
-
30
- /**
31
- * The ID of this plugin.
32
- *
33
- * @since 1.0
34
- * @access private
35
- * @var string $plugin_name The ID of this plugin.
36
- */
37
- private $plugin_name;
38
-
39
- /**
40
- * The version of this plugin.
41
- *
42
- * @since 1.0
43
- * @access private
44
- * @var string $version The current version of this plugin.
45
- */
46
- private $version;
47
-
48
- /**
49
- * Initialize the class and set its properties.
50
- *
51
- * @since 1.0
52
- * @param string $plugin_name The name of the plugin.
53
- * @param string $version The version of this plugin.
54
- */
55
- public function __construct( $plugin_name, $version ) {
56
-
57
- $this->plugin_name = $plugin_name;
58
- $this->version = $version;
59
- }
60
- }
61
- }
1
+ <?php
2
+ /**
3
+ * The public-facing functionality of the plugin.
4
+ *
5
+ * @link https://mythemeshop.com
6
+ * @since 1.0
7
+ *
8
+ * @package MTSNBF
9
+ * @subpackage MTSNBF/public
10
+ */
11
+
12
+ /**
13
+ * The public-facing functionality of the plugin.
14
+ *
15
+ * Defines the plugin name, version, and two examples hooks for how to
16
+ * enqueue the dashboard-specific stylesheet and JavaScript.
17
+ *
18
+ * @package MTSNBF
19
+ * @subpackage MTSNBF/public
20
+ * @author MyThemeShop
21
+ */
22
+ // If this file is called directly, abort.
23
+ if ( ! defined( 'WPINC' ) ) {
24
+ die;
25
+ }
26
+ if ( ! class_exists( 'MTSNBF_Public' ) ) {
27
+
28
+ class MTSNBF_Public {
29
+
30
+ /**
31
+ * The ID of this plugin.
32
+ *
33
+ * @since 1.0
34
+ * @access private
35
+ * @var string $plugin_name The ID of this plugin.
36
+ */
37
+ private $plugin_name;
38
+
39
+ /**
40
+ * The version of this plugin.
41
+ *
42
+ * @since 1.0
43
+ * @access private
44
+ * @var string $version The current version of this plugin.
45
+ */
46
+ private $version;
47
+
48
+ /**
49
+ * Initialize the class and set its properties.
50
+ *
51
+ * @since 1.0
52
+ * @param string $plugin_name The name of the plugin.
53
+ * @param string $version The version of this plugin.
54
+ */
55
+ public function __construct( $plugin_name, $version ) {
56
+
57
+ $this->plugin_name = $plugin_name;
58
+ $this->version = $version;
59
+ }
60
+ }
61
+ }
public/index.php CHANGED
@@ -1 +1 @@
1
- <?php // Silence is golden
1
+ <?php // Silence is golden
public/js/wp-notification-bars-public.js CHANGED
@@ -1,47 +1,57 @@
1
- /**
2
- * Plugin Name: WP Notification Bars by MyThemeShop
3
- * Author URI: https://mythemeshop.com/
4
- */
5
- (function( $ ) {
6
-
7
- 'use strict';
8
-
9
- $(function() {
10
-
11
- var barHeight;
12
-
13
- // Show notification bar
14
- if ( $('.mtsnb').length > 0 ) {
15
- barHeight = $('.mtsnb').outerHeight();
16
- $('body').css('padding-top', barHeight).addClass('has-mtsnb');
17
- }
18
-
19
- // Hide Button
20
- $(document).on('click', '.mtsnb-hide', function(e) {
21
-
22
- e.preventDefault();
23
-
24
- var $this = $(this);
25
-
26
- if ( !$this.hasClass('active') ) {
27
- $this.closest('.mtsnb').removeClass('mtsnb-shown').addClass('mtsnb-hidden');
28
- $('body').css('padding-top', 0);
29
- }
30
- });
31
-
32
- // Show Button
33
- $(document).on('click', '.mtsnb-show', function(e) {
34
-
35
- e.preventDefault();
36
-
37
- var $this = $(this);
38
-
39
- if ( !$this.hasClass('active') ) {
40
- barHeight = $('.mtsnb').outerHeight();
41
- $this.closest('.mtsnb').removeClass('mtsnb-hidden').addClass('mtsnb-shown');
42
- $('body').css('padding-top', barHeight);
43
- }
44
- });
45
- });
46
-
47
- })( jQuery );
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Plugin Name: WP Notification Bars by MyThemeShop
3
+ * Author URI: https://mythemeshop.com/
4
+ */
5
+ (function( $ ) {
6
+
7
+ 'use strict';
8
+
9
+ $(
10
+ function() {
11
+
12
+ var barHeight;
13
+
14
+ // Show notification bar
15
+ if ( $( '.mtsnb' ).length > 0 ) {
16
+ barHeight = $( '.mtsnb' ).outerHeight();
17
+ $( 'body' ).css( 'padding-top', barHeight ).addClass( 'has-mtsnb' );
18
+ }
19
+
20
+ // Hide Button
21
+ $( document ).on(
22
+ 'click',
23
+ '.mtsnb-hide',
24
+ function(e) {
25
+
26
+ e.preventDefault();
27
+
28
+ var $this = $( this );
29
+
30
+ if ( ! $this.hasClass( 'active' ) ) {
31
+ $this.closest( '.mtsnb' ).removeClass( 'mtsnb-shown' ).addClass( 'mtsnb-hidden' );
32
+ $( 'body' ).css( 'padding-top', 0 );
33
+ }
34
+ }
35
+ );
36
+
37
+ // Show Button
38
+ $( document ).on(
39
+ 'click',
40
+ '.mtsnb-show',
41
+ function(e) {
42
+
43
+ e.preventDefault();
44
+
45
+ var $this = $( this );
46
+
47
+ if ( ! $this.hasClass( 'active' ) ) {
48
+ barHeight = $( '.mtsnb' ).outerHeight();
49
+ $this.closest( '.mtsnb' ).removeClass( 'mtsnb-hidden' ).addClass( 'mtsnb-shown' );
50
+ $( 'body' ).css( 'padding-top', barHeight );
51
+ }
52
+ }
53
+ );
54
+ }
55
+ );
56
+
57
+ })( jQuery );
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: mythemeshop
3
  Creator's website link: http://mythemeshop.com/plugins/wp-notification-bars/
4
  Tags: notification, alert, notification bar, welcome google visitor, welcome facebook visitor, attention bar, floating bar, message, notice, sticky header, offer bar, hello bar
5
  Requires at least: 3.0.1
6
- Tested up to: 4.9.8
7
- Stable tag: 1.0.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -74,6 +74,9 @@ Please disable all plugins and check if backup is working properly. Then you can
74
 
75
  == Changelog ==
76
 
 
 
 
77
  = 1.0.6 =
78
  * Fixed security issues and hardened overall plugin security
79
  * Fixed plugin locale in gettext calls
3
  Creator's website link: http://mythemeshop.com/plugins/wp-notification-bars/
4
  Tags: notification, alert, notification bar, welcome google visitor, welcome facebook visitor, attention bar, floating bar, message, notice, sticky header, offer bar, hello bar
5
  Requires at least: 3.0.1
6
+ Tested up to: 5.8.2
7
+ Stable tag: 1.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
74
 
75
  == Changelog ==
76
 
77
+ = 1.0.7 =
78
+ * More security improvements
79
+
80
  = 1.0.6 =
81
  * Fixed security issues and hardened overall plugin security
82
  * Fixed plugin locale in gettext calls
uninstall.php CHANGED
@@ -1,31 +1,31 @@
1
- <?php
2
-
3
- /**
4
- * Fired when the plugin is uninstalled.
5
- *
6
- * When populating this file, consider the following flow
7
- * of control:
8
- *
9
- * - This method should be static
10
- * - Check if the $_REQUEST content actually is the plugin name
11
- * - Run an admin referrer check to make sure it goes through authentication
12
- * - Verify the output of $_GET makes sense
13
- * - Repeat with other user roles. Best directly by using the links/query string parameters.
14
- * - Repeat things for multisite. Once for a single site in the network, once sitewide.
15
- *
16
- * This file may be updated more in future version of the Boilerplate; however, this is the
17
- * general skeleton and outline for how the file should work.
18
- *
19
- * For more information, see the following discussion:
20
- * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
21
- *
22
- * @link https://mythemeshop.com
23
- * @since 1.0
24
- *
25
- * @package MTSNBF
26
- */
27
-
28
- // If uninstall not called from WordPress, then exit.
29
- if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
30
- exit;
31
- }
1
+ <?php
2
+
3
+ /**
4
+ * Fired when the plugin is uninstalled.
5
+ *
6
+ * When populating this file, consider the following flow
7
+ * of control:
8
+ *
9
+ * - This method should be static
10
+ * - Check if the $_REQUEST content actually is the plugin name
11
+ * - Run an admin referrer check to make sure it goes through authentication
12
+ * - Verify the output of $_GET makes sense
13
+ * - Repeat with other user roles. Best directly by using the links/query string parameters.
14
+ * - Repeat things for multisite. Once for a single site in the network, once sitewide.
15
+ *
16
+ * This file may be updated more in future version of the Boilerplate; however, this is the
17
+ * general skeleton and outline for how the file should work.
18
+ *
19
+ * For more information, see the following discussion:
20
+ * https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
21
+ *
22
+ * @link https://mythemeshop.com
23
+ * @since 1.0
24
+ *
25
+ * @package MTSNBF
26
+ */
27
+
28
+ // If uninstall not called from WordPress, then exit.
29
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
30
+ exit;
31
+ }
wp-notification-bars.php CHANGED
@@ -1,72 +1,75 @@
1
- <?php
2
- /**
3
- * @wordpress-plugin
4
- * Plugin Name: WP Notification Bars
5
- * Plugin URI: https://mythemeshop.com/plugins/wp-notification-bars/
6
- * Description: WP Notification Bars is a custom notification and alert bar plugin for WordPress which is perfect for marketing promotions, alerts, increasing click throughs to other pages and so much more.
7
- * Version: 1.0.6
8
- * Author: MyThemeShop
9
- * Author URI: https://mythemeshop.com/
10
- * Text Domain: wp-notification-bars
11
- * Domain Path: /languages
12
- */
13
-
14
- // If this file is called directly, abort.
15
- if ( ! defined( 'WPINC' ) ) {
16
- die;
17
- }
18
-
19
- // Plugin directory
20
- if ( !defined( 'MTSNBF_PLUGIN_DIR') )
21
- define( 'MTSNBF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
22
-
23
- if ( !defined( 'MTSNBF_PLUGIN_URL') )
24
- define( 'MTSNBF_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
25
-
26
- if ( !defined( 'MTSNBF_PLUGIN_BASE') )
27
- define( 'MTSNBF_PLUGIN_BASE', plugin_basename(__FILE__) );
28
-
29
- /**
30
- * The code that runs during plugin activation.
31
- * This action is documented in includes/class-wp-notification-bars-activator.php
32
- */
33
- function activate_mts_notification_bar_f() {
34
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-notification-bars-activator.php';
35
- MTSNBF_Activator::activate();
36
- update_option('wp_notification_bar_activated', time());
37
- }
38
-
39
- /**
40
- * The code that runs during plugin deactivation.
41
- * This action is documented in includes/class-wp-notification-bars-deactivator.php
42
- */
43
- function deactivate_mts_notification_bar_f() {
44
- require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-notification-bars-deactivator.php';
45
- MTSNBF_Deactivator::deactivate();
46
- }
47
-
48
- register_activation_hook( __FILE__, 'activate_mts_notification_bar_f' );
49
- register_deactivation_hook( __FILE__, 'deactivate_mts_notification_bar_f' );
50
-
51
- /**
52
- * The core plugin class that is used to define internationalization,
53
- * dashboard-specific hooks, and public-facing site hooks.
54
- */
55
- require plugin_dir_path( __FILE__ ) . 'includes/class-wp-notification-bars.php';
56
-
57
- /**
58
- * Begins execution of the plugin.
59
- *
60
- * Since everything within the plugin is registered via hooks,
61
- * then kicking off the plugin from this point in the file does
62
- * not affect the page life cycle.
63
- *
64
- * @since 1.0
65
- */
66
- function run_mts_notification_bar_f() {
67
-
68
- $plugin = new MTSNBF();
69
- $plugin->run();
70
-
71
- }
72
- run_mts_notification_bar_f();
 
 
 
1
+ <?php
2
+ /**
3
+ * @wordpress-plugin
4
+ * Plugin Name: WP Notification Bars
5
+ * Plugin URI: https://mythemeshop.com/plugins/wp-notification-bars/
6
+ * Description: WP Notification Bars is a custom notification and alert bar plugin for WordPress which is perfect for marketing promotions, alerts, increasing click throughs to other pages and so much more.
7
+ * Version: 1.0.7
8
+ * Author: MyThemeShop
9
+ * Author URI: https://mythemeshop.com/
10
+ * Text Domain: wp-notification-bars
11
+ * Domain Path: /languages
12
+ */
13
+
14
+ // If this file is called directly, abort.
15
+ if ( ! defined( 'WPINC' ) ) {
16
+ die;
17
+ }
18
+
19
+ // Plugin directory
20
+ if ( ! defined( 'MTSNBF_PLUGIN_DIR' ) ) {
21
+ define( 'MTSNBF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
22
+ }
23
+
24
+ if ( ! defined( 'MTSNBF_PLUGIN_URL' ) ) {
25
+ define( 'MTSNBF_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
26
+ }
27
+
28
+ if ( ! defined( 'MTSNBF_PLUGIN_BASE' ) ) {
29
+ define( 'MTSNBF_PLUGIN_BASE', plugin_basename( __FILE__ ) );
30
+ }
31
+
32
+ /**
33
+ * The code that runs during plugin activation.
34
+ * This action is documented in includes/class-wp-notification-bars-activator.php
35
+ */
36
+ function activate_mts_notification_bar_f() {
37
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-notification-bars-activator.php';
38
+ MTSNBF_Activator::activate();
39
+ update_option( 'wp_notification_bar_activated', time() );
40
+ }
41
+
42
+ /**
43
+ * The code that runs during plugin deactivation.
44
+ * This action is documented in includes/class-wp-notification-bars-deactivator.php
45
+ */
46
+ function deactivate_mts_notification_bar_f() {
47
+ require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-notification-bars-deactivator.php';
48
+ MTSNBF_Deactivator::deactivate();
49
+ }
50
+
51
+ register_activation_hook( __FILE__, 'activate_mts_notification_bar_f' );
52
+ register_deactivation_hook( __FILE__, 'deactivate_mts_notification_bar_f' );
53
+
54
+ /**
55
+ * The core plugin class that is used to define internationalization,
56
+ * dashboard-specific hooks, and public-facing site hooks.
57
+ */
58
+ require plugin_dir_path( __FILE__ ) . 'includes/class-wp-notification-bars.php';
59
+
60
+ /**
61
+ * Begins execution of the plugin.
62
+ *
63
+ * Since everything within the plugin is registered via hooks,
64
+ * then kicking off the plugin from this point in the file does
65
+ * not affect the page life cycle.
66
+ *
67
+ * @since 1.0
68
+ */
69
+ function run_mts_notification_bar_f() {
70
+
71
+ $plugin = new MTSNBF();
72
+ $plugin->run();
73
+
74
+ }
75
+ run_mts_notification_bar_f();