WP Notification Bars - Version 1.0.2

Version Description

  • Minor code improvements
  • Checked compatibility with WordPress v4.9.5
Download this release

Release Info

Developer roymahfooz
Plugin Icon 128x128 WP Notification Bars
Version 1.0.2
Comparing to
See all releases

Code changes from version 1.0.1 to 1.0.2

admin/class-wp-notification-bars-admin.php CHANGED
@@ -20,560 +20,566 @@
20
  * @subpackage MTSNBF/admin
21
  * @author MyThemeShop
22
  */
23
- class MTSNBF_Admin {
24
-
25
- /**
26
- * The ID of this plugin.
27
- *
28
- * @since 1.0
29
- * @access private
30
- * @var string $plugin_name The ID of this plugin.
31
- */
32
- private $plugin_name;
33
-
34
- /**
35
- * The version of this plugin.
36
- *
37
- * @since 1.0
38
- * @access private
39
- * @var string $version The current version of this plugin.
40
- */
41
- private $version;
42
-
43
- /**
44
- * Slug of the plugin screen.
45
- *
46
- * @since 1.0
47
- *
48
- * @var string
49
- */
50
- private $plugin_screen_hook_suffix = null;
51
-
52
- private $force_bar_post_types;
53
-
54
- /**
55
- * Initialize the class and set its properties.
56
- *
57
- * @since 1.0
58
- * @param string $plugin_name The name of this plugin.
59
- * @param string $version The version of this plugin.
60
- */
61
- public function __construct( $plugin_name, $version ) {
62
-
63
- $this->plugin_name = $plugin_name;
64
- $this->version = $version;
 
 
 
 
 
65
 
66
- }
67
 
68
- /**
69
- * Register the stylesheets for the Dashboard.
70
- *
71
- * @since 1.0
72
- */
73
- public function enqueue_styles() {
74
 
75
- $screen = get_current_screen();
76
- $screen_id = $screen->id;
77
 
78
- $force_bar_post_types = $this->force_bar_post_types;
79
 
80
- if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types ) ) {
81
 
82
- wp_enqueue_style( 'wp-color-picker' );
83
- wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-notification-bars-admin.css', array(), $this->version, 'all' );
84
- if ( 'mts_notification_bar' !== $screen_id ) {
85
- wp_enqueue_style( $this->plugin_name.'_select2', plugin_dir_url( __FILE__ ) . 'css/select2.min.css', array(), $this->version, 'all' );
 
86
  }
87
  }
88
- }
89
 
90
- /**
91
- * Register the JavaScript for the dashboard.
92
- *
93
- * @since 1.0
94
- */
95
- public function enqueue_scripts() {
96
 
97
- $screen = get_current_screen();
98
- $screen_id = $screen->id;
99
 
100
- $force_bar_post_types = $this->force_bar_post_types;
101
 
102
- if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types ) ) {
103
 
104
- wp_enqueue_script( 'wp-color-picker' );
105
 
106
- if ( 'mts_notification_bar' !== $screen_id ) {
 
 
 
 
 
 
 
 
 
107
 
108
  wp_enqueue_script(
109
- $this->plugin_name.'_select2',
110
- plugin_dir_url( __FILE__ ) . 'js/select2.full.min.js',
111
- array('jquery'),
112
- $this->version,
113
- false
 
 
 
 
 
 
 
 
 
 
114
  );
115
  }
 
116
 
117
- wp_enqueue_script(
118
- $this->plugin_name,
119
- plugin_dir_url( __FILE__ ) . 'js/wp-notification-bars-admin.js',
120
- array(
121
- 'jquery',
122
- 'wp-color-picker',
123
- ),
124
- $this->version, false
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  );
126
 
127
- wp_localize_script(
128
- $this->plugin_name,
129
- 'mtsnb_locale',
130
- array(
131
- 'select_placeholder' => __( 'Enter Notification Bar Title', $this->plugin_name ),
132
- )
 
 
 
 
 
 
133
  );
134
- }
135
- }
136
 
137
- //////////////////////
138
- //////// CPT /////////
139
- //////////////////////
140
-
141
- /**
142
- * Register MTS Notification Bar Post Type, attached to 'init'
143
- *
144
- * @since 1.0
145
- */
146
- public function mts_notification_cpt() {
147
- $labels = array(
148
- 'name' => _x( 'Notification Bars', 'post type general name', $this->plugin_name ),
149
- 'singular_name' => _x( 'Notification Bar', 'post type singular name', $this->plugin_name ),
150
- 'menu_name' => _x( 'Notification Bars', 'admin menu', $this->plugin_name ),
151
- 'name_admin_bar' => _x( 'Notification Bar', 'add new on admin bar', $this->plugin_name ),
152
- 'add_new' => _x( 'Add New', 'notification bar', $this->plugin_name ),
153
- 'add_new_item' => __( 'Add New Notification Bar', $this->plugin_name ),
154
- 'new_item' => __( 'New Notification Bar', $this->plugin_name ),
155
- 'edit_item' => __( 'Edit Notification Bar', $this->plugin_name ),
156
- 'view_item' => __( 'View Notification Bar', $this->plugin_name ),
157
- 'all_items' => __( 'All Notification Bars', $this->plugin_name ),
158
- 'search_items' => __( 'Search Notification Bars', $this->plugin_name ),
159
- 'parent_item_colon' => __( 'Parent Notification Bars:', $this->plugin_name ),
160
- 'not_found' => __( 'No notification bars found.', $this->plugin_name ),
161
- 'not_found_in_trash' => __( 'No notification bars found in Trash.', $this->plugin_name )
162
- );
163
-
164
- $args = array(
165
- 'labels' => $labels,
166
- 'public' => false,
167
- 'show_ui' => true,
168
- 'capability_type' => 'post',
169
- 'hierarchical' => false,
170
- 'rewrite' => false,
171
- 'publicly_queryable' => false,
172
- 'menu_position' => 100,
173
- 'menu_icon' => 'dashicons-info',
174
- 'has_archive' => false,
175
- 'supports' => array('title')
176
- );
177
-
178
- register_post_type( 'mts_notification_bar' , $args );
179
-
180
- // Filter supported post types where user ca override bar on single view
181
- $force_bar_supported_post_types = apply_filters( 'mtsnb_force_bar_post_types', array( 'post', 'page' ) );
182
-
183
- if ( ( $key = array_search( 'mts_notification_bar', $force_bar_supported_post_types ) ) !== false ) {
184
-
185
- unset( $force_bar_supported_post_types[ $key ] );
186
  }
187
 
188
- $this->force_bar_post_types = $force_bar_supported_post_types;
189
- }
 
 
 
 
 
 
 
 
 
 
 
190
 
191
- /**
192
- * Add preview button to edit bar page.
193
- *
194
- * @since 1.0
195
- */
196
- public function add_preview_button() {
197
- global $post;
198
- if ( 'mts_notification_bar' === $post->post_type ) {
199
- echo '<div class="misc-pub-section">';
200
- echo '<a href="#" class="button" id="preview-bar"><i class="dashicons dashicons-visibility"></i> '.__( 'Preview Bar', $this->plugin_name ).'</a>';
201
- echo '</div>';
 
 
 
 
202
  }
203
- }
204
 
205
- /**
206
- * Add the Meta Box
207
- *
208
- * @since 1.0
209
- */
210
- public function add_custom_meta_box() {
211
-
212
- add_meta_box(
213
- 'custom_meta_box',
214
- __( 'Settings', $this->plugin_name ),
215
- array( $this, 'show_custom_meta_box' ),
216
- 'mts_notification_bar',
217
- 'normal',
218
- 'high'
219
- );
220
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
- /**
223
- * The Callback, Meta Box Content
224
- *
225
- * @since 1.0
226
- */
227
- public function show_custom_meta_box( $post ) {
228
-
229
- $general_options = array(
230
- array(
231
- 'type' => 'select',
232
- 'name' => 'button',
233
- 'label' => __( 'Hide/Close Button', $this->plugin_name ),
234
- 'default'=> 'no_button',
235
- 'options' => array(
236
- 'no_button' => __( 'No Button', $this->plugin_name ),
237
- 'toggle_button' => __( 'Toggle Button', $this->plugin_name ),
238
- 'close_button' => __( 'Close Button', $this->plugin_name ),
 
 
 
 
 
 
 
 
 
 
 
239
  ),
240
- 'class' => 'mtsnb-has-child-opt'
241
- ),
242
- array(
243
- 'type' => 'number',
244
- 'name' => 'content_width',
245
- 'label' => __( 'Content Width (px)', $this->plugin_name ),
246
- 'default'=> '960'
247
- ),
248
- array(
249
- 'type' => 'select',
250
- 'name' => 'css_position',
251
- 'label' => __( 'Notification bar CSS position', $this->plugin_name ),
252
- 'default'=> 'fixed',
253
- 'options' => array(
254
- 'fixed' => __( 'Fixed', $this->plugin_name ),
255
- 'absolute' => __( 'Absolute', $this->plugin_name ),
256
- )
257
- ),
258
- );
259
-
260
- $style_options = array(
261
- array(
262
- 'type' => 'color',
263
- 'name' => 'bg_color',
264
- 'label' => __( 'Background Color', $this->plugin_name ),
265
- 'default'=> '#d35151'
266
- ),
267
- array(
268
- 'type' => 'color',
269
- 'name' => 'txt_color',
270
- 'label' => __( 'Text Color', $this->plugin_name ),
271
- 'default'=> '#ffffff'
272
- ),
273
- array(
274
- 'type' => 'color',
275
- 'name' => 'link_color',
276
- 'label' => __( 'Link Color/Button Color', $this->plugin_name ),
277
- 'default'=> '#f4a700'
278
- ),
279
- array(
280
- 'type' => 'number',
281
- 'name' => 'font_size',
282
- 'label' => __( 'Font size (px)', $this->plugin_name ),
283
- 'default'=> '15'
284
- ),
285
- );
286
-
287
- $button_content_type_options = array(
288
- array(
289
- 'type' => 'select',
290
- 'name' => 'basic_link_style',
291
- 'label' => __( 'Link Style', $this->plugin_name ),
292
- 'default'=> 'link',
293
- 'options' => array(
294
- 'link' => __( 'Link', $this->plugin_name ),
295
- 'button' => __( 'Button', $this->plugin_name ),
296
- )
297
- ),
298
- array(
299
- 'type' => 'text',
300
- 'name' => 'basic_text',
301
- 'label' => __( 'Text', $this->plugin_name ),
302
- 'default'=> ''
303
- ),
304
- array(
305
- 'type' => 'text',
306
- 'name' => 'basic_link_text',
307
- 'label' => __( 'Link/Button Text', $this->plugin_name ),
308
- 'default'=> ''
309
- ),
310
- array(
311
- 'type' => 'text',
312
- 'name' => 'basic_link_url',
313
- 'label' => __( 'Link/Button Url', $this->plugin_name ),
314
- 'default'=> ''
315
- ),
316
- );
317
-
318
- $custom_content_type_options = array(
319
- array(
320
- 'type' => 'textarea',
321
- 'name' => 'custom_content',
322
- 'label' => __( 'Add custom content, shortcodes allowed', $this->plugin_name ),
323
- 'default'=> ''
324
- ),
325
- );
326
-
327
- // Add an nonce field so we can check for it later.
328
- wp_nonce_field('mtsnb_meta_box', 'mtsnb_meta_box_nonce');
329
- // Use get_post_meta to retrieve an existing value from the database.
330
- $value = get_post_meta( $post->ID, '_mtsnb_data', true );//var_dump($value);
331
- ?>
332
- <div class="mtsnb-tabs clearfix">
333
- <div class="mtsnb-tabs-inner clearfix">
334
- <?php $active_tab = ( isset( $value['active_tab'] ) && !empty( $value['active_tab'] ) ) ? $value['active_tab'] : 'general'; ?>
335
- <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[active_tab]" id="mtsnb_fields_active_tab" value="<?php echo $active_tab; ?>" />
336
- <ul class="mtsnb-tabs-nav" id="main-tabs-nav">
337
- <li>
338
- <a href="#tab-general" <?php if ( $active_tab === 'general' ) echo 'class="active"'; ?>>
339
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-generic"></i><?php _e( 'General', $this->plugin_name ); ?></span>
340
- </a>
341
- </li>
342
- <li>
343
- <a href="#tab-type" <?php if ( $active_tab === 'type' ) echo 'class="active"'; ?>>
344
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-edit"></i><?php _e( 'Content', $this->plugin_name ); ?></span>
345
- </a>
346
- </li>
347
- <li>
348
- <a href="#tab-style" <?php if ( $active_tab === 'style' ) echo 'class="active"'; ?>>
349
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-appearance"></i><?php _e( 'Style', $this->plugin_name ); ?></span>
350
- </a>
351
- </li>
352
- <li>
353
- <a href="#tab-conditions" <?php if ( $active_tab === 'conditions' ) echo 'class="active"'; ?>>
354
- <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-settings"></i><?php _e( 'Conditions', $this->plugin_name ); ?></span>
355
- </a>
356
- </li>
357
- </ul>
358
- <div class="mtsnb-tabs-wrap" id="main-tabs-wrap">
359
- <div id="tab-general" class="mtsnb-tabs-content <?php if ( $active_tab === 'general' ) echo 'active'; ?>">
360
- <div class="mtsnb-tab-desc"><?php _e( 'Select basic settings like close button type and CSS position of the bar.', $this->plugin_name ); ?></div>
361
- <div class="mtsnb-tab-options clearfix">
362
  <?php
363
- foreach ( $general_options as $option_args ) {
364
  $this->custom_meta_field( $option_args, $value );
365
  }
366
  ?>
367
- </div>
368
- </div>
369
- <div id="tab-type" class="mtsnb-tabs-content <?php if ( $active_tab === 'type' ) echo 'active'; ?>">
370
- <div class="mtsnb-tab-desc"><?php _e( 'Set up notification bar content. Select content type and fill in the fields.', $this->plugin_name ); ?></div>
371
- <div class="mtsnb-tab-options clearfix">
372
- <?php $content_type = ( isset( $value['content_type'] ) && !empty( $value['content_type'] ) ) ? $value['content_type'] : 'button'; ?>
373
- <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[content_type]" id="mtsnb_fields_content_type" value="<?php echo $content_type; ?>" />
374
- <ul class="mtsnb-tabs-nav" id="sub-tabs-nav">
375
- <li><a href="#tab-button" <?php if ( $content_type === 'button' ) echo 'class="active"'; ?>><?php _e( 'Text and Link/Button', $this->plugin_name ); ?></a></li>
376
- <li><a href="#tab-custom" <?php if ( $content_type === 'custom' ) echo 'class="active"'; ?>><?php _e( 'Custom', $this->plugin_name ); ?></a></li>
377
- </ul>
378
- <div class="meta-tabs-wrap" id="sub-tabs-wrap">
379
- <div id="tab-button" class="mtsnb-tabs-content <?php if ( $content_type === 'button' ) echo 'active'; ?>">
380
- <?php
381
- foreach ( $button_content_type_options as $option_args ) {
382
- $this->custom_meta_field( $option_args, $value );
383
- }
384
- ?>
385
- </div>
386
- <div id="tab-custom" class="mtsnb-tabs-content <?php if ( $content_type === 'custom' ) echo 'active'; ?>">
387
- <?php
388
- foreach ( $custom_content_type_options as $option_args ) {
389
- $this->custom_meta_field( $option_args, $value );
390
- }
391
- ?>
392
- </div>
393
  </div>
394
  </div>
395
- </div>
396
- <div id="tab-style" class="mtsnb-tabs-content <?php if ( $active_tab === 'style' ) echo 'active'; ?>">
397
- <div class="mtsnb-tab-desc"><?php _e( 'Change the appearance of the notification bar.', $this->plugin_name ); ?></div>
398
- <div class="mtsnb-tab-options clearfix">
399
- <?php
400
- foreach ( $style_options as $option_args ) {
401
- $this->custom_meta_field( $option_args, $value );
402
- }
403
- ?>
404
- </div>
405
- </div>
406
- <div id="tab-conditions" class="mtsnb-tabs-content <?php if ( $active_tab === 'conditions' ) echo 'active'; ?>">
407
- <div class="mtsnb-tab-desc"><?php _e( 'Choose when and where to display the notification bar.', $this->plugin_name ); ?></div>
408
- <div id="conditions-selector-wrap" class="clearfix">
409
- <div id="conditions-selector">
410
- <ul>
411
- <?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'] : ''; ?>
412
- <?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'] : ''; ?>
413
- <?php $condition_location_disabled = empty( $condition_notlocation_state ) ? '' : ' disabled'; ?>
414
- <?php $condition_notlocation_disabled = empty( $condition_location_state ) ? '' : ' disabled'; ?>
415
- <li id="condition-location" data-disable="notlocation" class="condition-checkbox <?php echo $condition_location_state.$condition_location_disabled; ?>">
416
- <?php _e( 'On specific locations', $this->plugin_name ); ?>
417
- <div class="mtsnb-check"></div>
418
- <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; ?>">
419
- </li>
420
- <li id="condition-notlocation" data-disable="location" class="condition-checkbox <?php echo $condition_notlocation_state.$condition_notlocation_disabled; ?>">
421
- <?php _e( 'Not on specific locations', $this->plugin_name ); ?>
422
- <div class="mtsnb-check"></div>
423
- <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; ?>">
424
- </li>
425
- <?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'] : ''; ?>
426
- <?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'] : ''; ?>
427
- <?php $condition_google_disabled = empty( $condition_notgoogle_state ) ? '' : ' disabled'; ?>
428
- <?php $condition_notgoogle_disabled = empty( $condition_google_state ) ? '' : ' disabled'; ?>
429
- <li id="condition-google" data-disable="notgoogle" class="condition-checkbox <?php echo $condition_google_state.$condition_google_disabled; ?>">
430
- <?php _e( 'From Google', $this->plugin_name ); ?>
431
- <div class="mtsnb-check"></div>
432
- <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; ?>">
433
- </li>
434
- <li id="condition-notgoogle" data-disable="google" class="condition-checkbox <?php echo $condition_notgoogle_state.$condition_notgoogle_disabled; ?>">
435
- <?php _e( 'Not from Google', $this->plugin_name ); ?>
436
- <div class="mtsnb-check"></div>
437
- <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; ?>">
438
- </li>
439
- <?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'] : ''; ?>
440
- <?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'] : ''; ?>
441
- <?php $condition_facebook_disabled = empty( $condition_notfacebook_state ) ? '' : ' disabled'; ?>
442
- <?php $condition_notfacebook_disabled = empty( $condition_facebook_state ) ? '' : ' disabled'; ?>
443
- <li id="condition-facebook" data-disable="notfacebook" class="condition-checkbox <?php echo $condition_facebook_state.$condition_facebook_disabled; ?>">
444
- <?php _e( 'From Facebook', $this->plugin_name ); ?>
445
- <div class="mtsnb-check"></div>
446
- <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; ?>">
447
- </li>
448
- <li id="condition-notfacebook" data-disable="facebook" class="condition-checkbox <?php echo $condition_notfacebook_state.$condition_notfacebook_disabled; ?>">
449
- <?php _e( 'Not from Facebook', $this->plugin_name ); ?>
450
- <div class="mtsnb-check"></div>
451
- <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; ?>">
452
- </li>
453
- </ul>
454
- </div>
455
- <div id="conditions-panels">
456
- <div id="condition-location-panel" class="mtsnb-conditions-panel <?php echo $condition_location_state; ?>">
457
- <div class="mtsnb-conditions-panel-title"><?php _e( 'On specific locations', $this->plugin_name ); ?></div>
458
- <div class="mtsnb-conditions-panel-content">
459
- <div class="mtsnb-conditions-panel-desc"><?php _e( 'Show Notification Bar on the following locations', $this->plugin_name ); ?></div>
460
- <div class="mtsnb-conditions-panel-opt">
461
- <?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'; ?>
462
- <?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'; ?>
463
- <?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'; ?>
464
- <?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'; ?>
465
- <p>
466
- <label>
467
- <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 ); ?> />
468
- <?php _e( 'Homepage.', $this->plugin_name ); ?>
469
- </label>
470
- </p>
471
- <?php if ( 'page' === get_option('show_on_front') && '0' !== get_option('page_for_posts') && '0' !== get_option('page_on_front') ) { ?>
472
  <p>
473
  <label>
474
- <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 ); ?> />
475
- <?php _e( 'Blog Homepage.', $this->plugin_name ); ?>
476
  </label>
477
  </p>
478
- <?php } ?>
479
- <p>
480
- <label>
481
- <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 ); ?> />
482
- <?php _e( 'Pages.', $this->plugin_name ); ?>
483
- </label>
484
- </p>
485
- <p>
486
- <label>
487
- <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 ); ?> />
488
- <?php _e( 'Posts.', $this->plugin_name ); ?>
489
- </label>
490
- </p>
491
  </div>
492
  </div>
493
- </div>
494
- <div id="condition-notlocation-panel" class="mtsnb-conditions-panel <?php echo $condition_notlocation_state; ?>">
495
- <div class="mtsnb-conditions-panel-title"><?php _e( 'Not on specific locations', $this->plugin_name ); ?></div>
496
- <div class="mtsnb-conditions-panel-content">
497
- <div class="mtsnb-conditions-panel-desc"><?php _e( 'Hide Notification Bar on the following locations', $this->plugin_name ); ?></div>
498
- <div class="mtsnb-conditions-panel-opt">
499
- <?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'; ?>
500
- <?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'; ?>
501
- <?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'; ?>
502
- <?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'; ?>
503
- <p>
504
- <label>
505
- <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 ); ?> />
506
- <?php _e( 'Homepage.', $this->plugin_name ); ?>
507
- </label>
508
- </p>
509
- <?php if ( 'page' === get_option('show_on_front') && '0' !== get_option('page_for_posts') && '0' !== get_option('page_on_front') ) { ?>
510
  <p>
511
  <label>
512
- <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 ); ?> />
513
- <?php _e( 'Blog Homepage.', $this->plugin_name ); ?>
514
  </label>
515
  </p>
516
- <?php } ?>
517
- <p>
518
- <label>
519
- <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 ); ?> />
520
- <?php _e( 'Pages.', $this->plugin_name ); ?>
521
- </label>
522
- </p>
523
- <p>
524
- <label>
525
- <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 ); ?> />
526
- <?php _e( 'Posts.', $this->plugin_name ); ?>
527
- </label>
528
- </p>
 
 
 
 
 
 
 
 
529
  </div>
530
  </div>
531
- </div>
532
- <div id="condition-google-panel" class="mtsnb-conditions-panel <?php echo $condition_google_state; ?>">
533
- <div class="mtsnb-conditions-panel-title"><?php _e( 'From Google', $this->plugin_name ); ?></div>
534
- <div class="mtsnb-conditions-panel-content">
535
- <div class="mtsnb-conditions-panel-desc">
536
- <p>
537
- <label>
538
- <?php _e( 'Show Notification Bar if visitor arrived via Google search engine.', $this->plugin_name ); ?>
539
- </label>
540
- </p>
541
  </div>
542
  </div>
543
- </div>
544
- <div id="condition-notgoogle-panel" class="mtsnb-conditions-panel <?php echo $condition_notgoogle_state; ?>">
545
- <div class="mtsnb-conditions-panel-title"><?php _e( 'Not from Google', $this->plugin_name ); ?></div>
546
- <div class="mtsnb-conditions-panel-content">
547
- <div class="mtsnb-conditions-panel-desc">
548
- <p>
549
- <label>
550
- <?php _e( 'Hide Notification Bar if visitor arrived via Google search engine.', $this->plugin_name ); ?>
551
- </label>
552
- </p>
553
  </div>
554
  </div>
555
- </div>
556
- <div id="condition-facebook-panel" class="mtsnb-conditions-panel <?php echo $condition_facebook_state; ?>">
557
- <div class="mtsnb-conditions-panel-title"><?php _e( 'From Facebook', $this->plugin_name ); ?></div>
558
- <div class="mtsnb-conditions-panel-content">
559
- <div class="mtsnb-conditions-panel-desc">
560
- <p>
561
- <label>
562
- <?php _e( 'Show Notification Bar if visitor arrived from Facebook.', $this->plugin_name ); ?>
563
- </label>
564
- </p>
565
  </div>
566
  </div>
567
- </div>
568
- <div id="condition-notfacebook-panel" class="mtsnb-conditions-panel <?php echo $condition_notfacebook_state; ?>">
569
- <div class="mtsnb-conditions-panel-title"><?php _e( 'Not from Facebook', $this->plugin_name ); ?></div>
570
- <div class="mtsnb-conditions-panel-content">
571
- <div class="mtsnb-conditions-panel-desc">
572
- <p>
573
- <label>
574
- <?php _e( 'Hide Notification Bar if visitor arrived from Facebook.', $this->plugin_name ); ?>
575
- </label>
576
- </p>
577
  </div>
578
  </div>
579
  </div>
@@ -582,379 +588,379 @@ class MTSNBF_Admin {
582
  </div>
583
  </div>
584
  </div>
585
- </div>
586
- <?php
587
- }
588
-
589
- /**
590
- * Helper function for common fields
591
- *
592
- * @since 1.0
593
- */
594
- public function custom_meta_field( $args, $value, $b = false ) {
595
-
596
- $type = isset( $args['type'] ) ? $args['type'] : '';
597
- $name = isset( $args['name'] ) ? $args['name'] : '';
598
- $name = $b ? 'b_'.$name : $name;
599
- $label = isset( $args['label'] ) ? $args['label'] : '';
600
- $options = isset( $args['options'] ) ? $args['options'] : array();
601
- $default = isset( $args['default'] ) ? $args['default'] : '';
602
- $min = isset( $args['min'] ) ? $args['min'] : '0';
603
-
604
- $class = isset( $args['class'] ) ? $args['class'] : '';
605
-
606
- // Option value
607
- $opt_val = isset( $value[ $name ] ) ? $value[ $name ] : $default;
608
-
609
- ?>
610
- <div id="mtsnb_fields_<?php echo $name;?>_row" class="form-row">
611
- <label class="form-label" for="mtsnb_fields_<?php echo $name;?>"><?php echo $label; ?></label>
612
- <div class="form-option <?php echo $class; ?>">
613
  <?php
614
- switch ( $type ) {
615
 
616
- case 'text':
617
- ?>
618
- <input type="text" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="<?php echo esc_attr( $opt_val );?>" />
619
- <?php
620
- break;
621
- case 'select':
622
- ?>
623
- <select name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>">
624
- <?php foreach ( $options as $val => $label ) { ?>
625
- <option value="<?php echo $val; ?>" <?php selected( $opt_val, $val, true); ?>><?php echo $label ?></option>
626
- <?php } ?>
627
- </select>
628
- <?php
629
- break;
630
- case 'number':
631
- ?>
632
- <input type="number" step="1" min="<?php echo $min;?>" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="<?php echo $opt_val;?>" class="small-text"/>
633
- <?php
634
- break;
635
- case 'color':
636
- ?>
637
- <input type="text" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="<?php echo $opt_val;?>" class="mtsnb-color-picker" />
638
- <?php
639
- break;
640
- case 'textarea':
641
- ?>
642
- <textarea name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" class="mtsnb-textarea"><?php echo esc_textarea( $opt_val );?></textarea>
643
- <?php
644
- break;
645
- case 'checkbox':
646
- ?>
647
- <input type="checkbox" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="1" <?php checked( $opt_val, '1', true ); ?> />
648
  <?php
649
- break;
650
- case 'info':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
  ?>
652
- <small class="mtsnb-option-info">
653
- <?php echo $default; ?>
654
- </small>
655
- <?php
656
- break;
657
- }
658
- ?>
659
  </div>
660
- </div>
661
- <?php
662
- }
663
-
664
- /**
665
- * Save the Data
666
- *
667
- * @since 1.0
668
- */
669
- public function save_custom_meta( $post_id ) {
670
- // Check if our nonce is set.
671
- if ( ! isset( $_POST['mtsnb_meta_box_nonce'] ) ) {
672
- return;
673
- }
674
- // Verify that the nonce is valid.
675
- if ( ! wp_verify_nonce( $_POST['mtsnb_meta_box_nonce'], 'mtsnb_meta_box' ) ) {
676
- return;
677
- }
678
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
679
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
680
- return;
681
  }
682
- // Check the user's permissions.
683
- if ( isset( $_POST['post_type'] ) && 'mts_notification_bar' == $_POST['post_type'] ) {
684
 
685
- if ( ! current_user_can( 'edit_page', $post_id ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
686
  return;
687
  }
 
 
688
 
689
- } else {
 
 
690
 
691
- if ( ! current_user_can( 'edit_post', $post_id ) ) {
692
- return;
 
 
 
693
  }
694
- }
695
 
696
- /* OK, it's safe for us to save the data now. */
697
- if ( ! isset( $_POST['mtsnb_fields'] ) ) {
698
- return;
699
- }
700
 
701
- $my_data = $_POST['mtsnb_fields'];
702
 
703
- // Update the meta field in the database.
704
- update_post_meta( $post_id, '_mtsnb_data', $my_data );
705
- }
706
 
707
- /**
708
- * Deactivate plugin if pro is active
709
- *
710
- * @since 1.0
711
- */
712
- public function check_version() {
713
 
714
- if ( defined( 'MTSNB_PLUGIN_BASE' ) ) {
715
 
716
- if ( is_plugin_active( MTSNB_PLUGIN_BASE ) || class_exists('MTSNB') ) {
717
 
718
- deactivate_plugins( MTSNBF_PLUGIN_BASE );
719
- add_action( 'admin_notices', array( $this, 'disabled_notice' ) );
720
- if ( isset( $_GET['activate'] ) ) {
721
- unset( $_GET['activate'] );
 
722
  }
723
  }
724
  }
725
- }
726
 
727
- /**
728
- * Deactivation notice
729
- *
730
- * @since 1.0
731
- */
732
- public function disabled_notice() {
733
- ?>
734
- <div class="updated">
735
- <p><?php _e( 'Free version of WP Notification Bars plugin disabled. Pro version is active!', $this->plugin_name ); ?></p>
736
- </div>
737
- <?php
738
- }
739
 
740
- /**
741
- * Notification Bar update messages
742
- *
743
- * @since 1.0
744
- *
745
- * @param array $messages
746
- * @return array $messages
747
- */
748
- public function mtsnb_update_messages( $messages ) {
749
-
750
- global $post;
751
-
752
- $post_ID = $post->ID;
753
- $post_type = get_post_type( $post_ID );
754
-
755
- if ('mts_notification_bar' == $post_type ) {
756
-
757
- $messages['mts_notification_bar'] = array(
758
- 0 => '', // Unused. Messages start at index 1.
759
- 1 => __( 'Notification Bar updated.', $this->plugin_name ),
760
- 2 => __( 'Custom field updated.', $this->plugin_name ),
761
- 3 => __( 'Custom field deleted.', $this->plugin_name ),
762
- 4 => __( 'Notification Bar updated.', $this->plugin_name ),
763
- 5 => isset($_GET['revision']) ? sprintf( __('Notification Bar restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
764
- 6 => __( 'Notification Bar published.', $this->plugin_name ),
765
- 7 => __( 'Notification Bar saved.', $this->plugin_name ),
766
- 8 => __( 'Notification Bar submitted.', $this->plugin_name),
767
- 9 => sprintf( __('Notification Bar scheduled for: <strong>%1$s</strong>.', $this->plugin_name ), date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) ) ),
768
- 10 => __('Notification Bar draft updated.', $this->plugin_name ),
769
- );
 
 
 
770
  }
771
 
772
- return $messages;
773
- }
774
 
 
 
 
 
 
 
775
 
776
- /**
777
- * Single post view bar select
778
- *
779
- * @since 1.0.1
780
- */
781
- public function mtsnb_select_metabox_insert() {
782
-
783
- $force_bar_post_types = $this->force_bar_post_types;
784
 
785
- if ( $force_bar_post_types && is_array( $force_bar_post_types ) ) {
786
 
787
- foreach ( $force_bar_post_types as $screen ) {
788
 
789
- add_meta_box(
790
- 'mtsnb_single_bar_metabox',
791
- __( 'Notification Bar', $this->plugin_name ),
792
- array( $this, 'mtsnb_select_metabox_content' ),
793
- $screen,
794
- 'side',
795
- 'default'
796
- );
 
797
  }
798
  }
799
- }
800
- public function mtsnb_select_metabox_content( $post ) {
801
-
802
- // Add an nonce field so we can check for it later.
803
- wp_nonce_field('mtsnb_select_metabox_save', 'mtsnb_select_metabox_nonce');
804
-
805
- /*
806
- * Use get_post_meta() to retrieve an existing value
807
- * from the database and use the value for the form.
808
- */
809
- $bar = get_post_meta( $post->ID, '_mtsnb_override_bar', true );
810
-
811
- $processed_item_ids = '';
812
- if ( !empty( $bar ) ) {
813
- // Some entries may be arrays themselves!
814
- $processed_item_ids = array();
815
- foreach ($bar as $this_id) {
816
- if (is_array($this_id)) {
817
- $processed_item_ids = array_merge( $processed_item_ids, $this_id );
818
- } else {
819
- $processed_item_ids[] = $this_id;
820
  }
821
- }
822
 
823
- if (is_array($processed_item_ids) && !empty($processed_item_ids)) {
824
- $processed_item_ids = implode(',', $processed_item_ids);
825
- } else {
826
- $processed_item_ids = '';
 
827
  }
828
- }
829
- ?>
830
- <p>
831
- <label for="mtsnb_override_bar_field"><?php _e( 'Select Notification Bar (optional):', $this->plugin_name ); ?></label><br />
832
- <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; ?>" />
833
- </p>
834
- <p>
835
- <i><?php _e( 'Selected notification bar will override any other bar.', $this->plugin_name ); ?></i>
836
- </p>
837
- <?php
838
- }
839
-
840
- public function mtsnb_select_metabox_save( $post_id ) {
841
-
842
- // Check if our nonce is set.
843
- if ( ! isset( $_POST['mtsnb_select_metabox_nonce'] ) ) {
844
- return;
845
- }
846
- // Verify that the nonce is valid.
847
- if ( ! wp_verify_nonce( $_POST['mtsnb_select_metabox_nonce'], 'mtsnb_select_metabox_save' ) ) {
848
- return;
849
- }
850
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
851
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
852
- return;
853
  }
854
 
855
- // Check the user's permissions.
856
- if ( 'page' == $_POST['post_type'] ) {
857
 
858
- if ( ! current_user_can( 'edit_page', $post_id ) )
 
859
  return;
860
-
861
- } else {
862
-
863
- if ( ! current_user_can( 'edit_post', $post_id ) )
864
  return;
865
- }
866
-
867
- /* OK, its safe for us to save the data now. */
868
- if ( ! isset( $_POST['mtsnb_override_bar_field'] ) ) {
869
- return;
870
- }
871
 
872
- $val = $_POST['mtsnb_override_bar_field'];
 
873
 
874
- if (strpos($val, ',') === false) {
875
- // No comma, must be single value - still needs to be in an array for now
876
- $post_ids = array( $val );
877
- } else {
878
- // There is a comma so it's explodable
879
- $post_ids = explode(',', $val);
880
- }
881
 
882
- // Update the meta field in the database.
883
- update_post_meta( $post_id, '_mtsnb_override_bar', $post_ids );
884
- }
885
-
886
- /**
887
- * Bar select ajax function
888
- *
889
- * @since 1.0.1
890
- */
891
- public function mtsnb_get_bars() {
892
-
893
- $result = array();
894
-
895
- $search = $_REQUEST['q'];
896
-
897
- $ads_query = array(
898
- 'posts_per_page' => -1,
899
- 'post_status' => array('publish'),
900
- 'post_type' => 'mts_notification_bar',
901
- 'order' => 'ASC',
902
- 'orderby' => 'title',
903
- 'suppress_filters' => false,
904
- 's'=> $search
905
- );
906
- $posts = get_posts( $ads_query );
907
-
908
- // We'll return a JSON-encoded result.
909
- foreach ( $posts as $this_post ) {
910
- $post_title = $this_post->post_title;
911
- $id = $this_post->ID;
912
-
913
- $result[] = array(
914
- 'id' => $id,
915
- 'title' => $post_title,
916
- );
917
- }
918
 
919
- echo json_encode( $result );
 
 
920
 
921
- die();
922
- }
 
 
923
 
924
- public function mtsnb_get_bar_titles() {
925
- $result = array();
926
 
927
- if (isset($_REQUEST['post_ids'])) {
928
- $post_ids = $_REQUEST['post_ids'];
929
- if (strpos($post_ids, ',') === false) {
930
- // There is no comma, so we can't explode, but we still want an array
931
- $post_ids = array( $post_ids );
932
  } else {
933
- // There is a comma, so it must be explodable
934
- $post_ids = explode(',', $post_ids);
935
  }
936
- } else {
937
- $post_ids = array();
 
938
  }
939
 
940
- if (is_array($post_ids) && ! empty($post_ids)) {
 
 
 
 
 
 
 
941
 
942
- $posts = get_posts(array(
 
 
943
  'posts_per_page' => -1,
944
  'post_status' => array('publish'),
945
- 'post__in' => $post_ids,
946
- 'post_type' => 'mts_notification_bar'
947
- ));
 
 
 
 
 
 
948
  foreach ( $posts as $this_post ) {
 
 
 
949
  $result[] = array(
950
- 'id' => $this_post->ID,
951
- 'title' => $this_post->post_title,
952
  );
953
  }
 
 
 
 
954
  }
955
 
956
- echo json_encode( $result );
 
957
 
958
- die();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
959
  }
960
- }
20
  * @subpackage MTSNBF/admin
21
  * @author MyThemeShop
22
  */
23
+ // If this file is called directly, abort.
24
+ if ( ! defined( 'WPINC' ) ) {
25
+ die;
26
+ }
27
+ if( !class_exists( 'MTSNBF_Admin' ) ){
28
+ class MTSNBF_Admin {
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
+ * Slug of the plugin screen.
50
+ *
51
+ * @since 1.0
52
+ *
53
+ * @var string
54
+ */
55
+ private $plugin_screen_hook_suffix = null;
56
+
57
+ private $force_bar_post_types;
58
+
59
+ /**
60
+ * Initialize the class and set its properties.
61
+ *
62
+ * @since 1.0
63
+ * @param string $plugin_name The name of this plugin.
64
+ * @param string $version The version of this plugin.
65
+ */
66
+ public function __construct( $plugin_name, $version ) {
67
+
68
+ $this->plugin_name = $plugin_name;
69
+ $this->version = $version;
70
 
71
+ }
72
 
73
+ /**
74
+ * Register the stylesheets for the Dashboard.
75
+ *
76
+ * @since 1.0
77
+ */
78
+ public function enqueue_styles() {
79
 
80
+ $screen = get_current_screen();
81
+ $screen_id = $screen->id;
82
 
83
+ $force_bar_post_types = $this->force_bar_post_types;
84
 
85
+ if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types ) ) {
86
 
87
+ wp_enqueue_style( 'wp-color-picker' );
88
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wp-notification-bars-admin.css', array(), $this->version, 'all' );
89
+ if ( 'mts_notification_bar' !== $screen_id ) {
90
+ wp_enqueue_style( $this->plugin_name.'_select2', plugin_dir_url( __FILE__ ) . 'css/select2.min.css', array(), $this->version, 'all' );
91
+ }
92
  }
93
  }
 
94
 
95
+ /**
96
+ * Register the JavaScript for the dashboard.
97
+ *
98
+ * @since 1.0
99
+ */
100
+ public function enqueue_scripts() {
101
 
102
+ $screen = get_current_screen();
103
+ $screen_id = $screen->id;
104
 
105
+ $force_bar_post_types = $this->force_bar_post_types;
106
 
107
+ if ( 'mts_notification_bar' === $screen_id || in_array( $screen_id, $force_bar_post_types ) ) {
108
 
109
+ wp_enqueue_script( 'wp-color-picker' );
110
 
111
+ if ( 'mts_notification_bar' !== $screen_id ) {
112
+
113
+ wp_enqueue_script(
114
+ $this->plugin_name.'_select2',
115
+ plugin_dir_url( __FILE__ ) . 'js/select2.full.min.js',
116
+ array('jquery'),
117
+ $this->version,
118
+ false
119
+ );
120
+ }
121
 
122
  wp_enqueue_script(
123
+ $this->plugin_name,
124
+ plugin_dir_url( __FILE__ ) . 'js/wp-notification-bars-admin.js',
125
+ array(
126
+ 'jquery',
127
+ 'wp-color-picker',
128
+ ),
129
+ $this->version, false
130
+ );
131
+
132
+ wp_localize_script(
133
+ $this->plugin_name,
134
+ 'mtsnb_locale',
135
+ array(
136
+ 'select_placeholder' => __( 'Enter Notification Bar Title', $this->plugin_name ),
137
+ )
138
  );
139
  }
140
+ }
141
 
142
+ //////////////////////
143
+ //////// CPT /////////
144
+ //////////////////////
145
+
146
+ /**
147
+ * Register MTS Notification Bar Post Type, attached to 'init'
148
+ *
149
+ * @since 1.0
150
+ */
151
+ public function mts_notification_cpt() {
152
+ $labels = array(
153
+ 'name' => _x( 'Notification Bars', 'post type general name', $this->plugin_name ),
154
+ 'singular_name' => _x( 'Notification Bar', 'post type singular name', $this->plugin_name ),
155
+ 'menu_name' => _x( 'Notification Bars', 'admin menu', $this->plugin_name ),
156
+ 'name_admin_bar' => _x( 'Notification Bar', 'add new on admin bar', $this->plugin_name ),
157
+ 'add_new' => _x( 'Add New', 'notification bar', $this->plugin_name ),
158
+ 'add_new_item' => __( 'Add New Notification Bar', $this->plugin_name ),
159
+ 'new_item' => __( 'New Notification Bar', $this->plugin_name ),
160
+ 'edit_item' => __( 'Edit Notification Bar', $this->plugin_name ),
161
+ 'view_item' => __( 'View Notification Bar', $this->plugin_name ),
162
+ 'all_items' => __( 'All Notification Bars', $this->plugin_name ),
163
+ 'search_items' => __( 'Search Notification Bars', $this->plugin_name ),
164
+ 'parent_item_colon' => __( 'Parent Notification Bars:', $this->plugin_name ),
165
+ 'not_found' => __( 'No notification bars found.', $this->plugin_name ),
166
+ 'not_found_in_trash' => __( 'No notification bars found in Trash.', $this->plugin_name )
167
  );
168
 
169
+ $args = array(
170
+ 'labels' => $labels,
171
+ 'public' => false,
172
+ 'show_ui' => true,
173
+ 'capability_type' => 'post',
174
+ 'hierarchical' => false,
175
+ 'rewrite' => false,
176
+ 'publicly_queryable' => false,
177
+ 'menu_position' => 100,
178
+ 'menu_icon' => 'dashicons-info',
179
+ 'has_archive' => false,
180
+ 'supports' => array('title')
181
  );
 
 
182
 
183
+ register_post_type( 'mts_notification_bar' , $args );
184
+
185
+ // Filter supported post types where user ca override bar on single view
186
+ $force_bar_supported_post_types = apply_filters( 'mtsnb_force_bar_post_types', array( 'post', 'page' ) );
187
+
188
+ if ( ( $key = array_search( 'mts_notification_bar', $force_bar_supported_post_types ) ) !== false ) {
189
+
190
+ unset( $force_bar_supported_post_types[ $key ] );
191
+ }
192
+
193
+ $this->force_bar_post_types = $force_bar_supported_post_types;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  }
195
 
196
+ /**
197
+ * Add preview button to edit bar page.
198
+ *
199
+ * @since 1.0
200
+ */
201
+ public function add_preview_button() {
202
+ global $post;
203
+ if ( 'mts_notification_bar' === $post->post_type ) {
204
+ echo '<div class="misc-pub-section">';
205
+ echo '<a href="#" class="button" id="preview-bar"><i class="dashicons dashicons-visibility"></i> '.__( 'Preview Bar', $this->plugin_name ).'</a>';
206
+ echo '</div>';
207
+ }
208
+ }
209
 
210
+ /**
211
+ * Add the Meta Box
212
+ *
213
+ * @since 1.0
214
+ */
215
+ public function add_custom_meta_box() {
216
+
217
+ add_meta_box(
218
+ 'custom_meta_box',
219
+ __( 'Settings', $this->plugin_name ),
220
+ array( $this, 'show_custom_meta_box' ),
221
+ 'mts_notification_bar',
222
+ 'normal',
223
+ 'high'
224
+ );
225
  }
 
226
 
227
+ /**
228
+ * The Callback, Meta Box Content
229
+ *
230
+ * @since 1.0
231
+ */
232
+ public function show_custom_meta_box( $post ) {
233
+
234
+ $general_options = array(
235
+ array(
236
+ 'type' => 'select',
237
+ 'name' => 'button',
238
+ 'label' => __( 'Hide/Close Button', $this->plugin_name ),
239
+ 'default'=> 'no_button',
240
+ 'options' => array(
241
+ 'no_button' => __( 'No Button', $this->plugin_name ),
242
+ 'toggle_button' => __( 'Toggle Button', $this->plugin_name ),
243
+ 'close_button' => __( 'Close Button', $this->plugin_name ),
244
+ ),
245
+ 'class' => 'mtsnb-has-child-opt'
246
+ ),
247
+ array(
248
+ 'type' => 'number',
249
+ 'name' => 'content_width',
250
+ 'label' => __( 'Content Width (px)', $this->plugin_name ),
251
+ 'default'=> '960'
252
+ ),
253
+ array(
254
+ 'type' => 'select',
255
+ 'name' => 'css_position',
256
+ 'label' => __( 'Notification bar CSS position', $this->plugin_name ),
257
+ 'default'=> 'fixed',
258
+ 'options' => array(
259
+ 'fixed' => __( 'Fixed', $this->plugin_name ),
260
+ 'absolute' => __( 'Absolute', $this->plugin_name ),
261
+ )
262
+ ),
263
+ );
264
+
265
+ $style_options = array(
266
+ array(
267
+ 'type' => 'color',
268
+ 'name' => 'bg_color',
269
+ 'label' => __( 'Background Color', $this->plugin_name ),
270
+ 'default'=> '#d35151'
271
+ ),
272
+ array(
273
+ 'type' => 'color',
274
+ 'name' => 'txt_color',
275
+ 'label' => __( 'Text Color', $this->plugin_name ),
276
+ 'default'=> '#ffffff'
277
+ ),
278
+ array(
279
+ 'type' => 'color',
280
+ 'name' => 'link_color',
281
+ 'label' => __( 'Link Color/Button Color', $this->plugin_name ),
282
+ 'default'=> '#f4a700'
283
+ ),
284
+ array(
285
+ 'type' => 'number',
286
+ 'name' => 'font_size',
287
+ 'label' => __( 'Font size (px)', $this->plugin_name ),
288
+ 'default'=> '15'
289
+ ),
290
+ );
291
 
292
+ $button_content_type_options = array(
293
+ array(
294
+ 'type' => 'select',
295
+ 'name' => 'basic_link_style',
296
+ 'label' => __( 'Link Style', $this->plugin_name ),
297
+ 'default'=> 'link',
298
+ 'options' => array(
299
+ 'link' => __( 'Link', $this->plugin_name ),
300
+ 'button' => __( 'Button', $this->plugin_name ),
301
+ )
302
+ ),
303
+ array(
304
+ 'type' => 'text',
305
+ 'name' => 'basic_text',
306
+ 'label' => __( 'Text', $this->plugin_name ),
307
+ 'default'=> ''
308
+ ),
309
+ array(
310
+ 'type' => 'text',
311
+ 'name' => 'basic_link_text',
312
+ 'label' => __( 'Link/Button Text', $this->plugin_name ),
313
+ 'default'=> ''
314
+ ),
315
+ array(
316
+ 'type' => 'text',
317
+ 'name' => 'basic_link_url',
318
+ 'label' => __( 'Link/Button Url', $this->plugin_name ),
319
+ 'default'=> ''
320
  ),
321
+ );
322
+
323
+ $custom_content_type_options = array(
324
+ array(
325
+ 'type' => 'textarea',
326
+ 'name' => 'custom_content',
327
+ 'label' => __( 'Add custom content, shortcodes allowed', $this->plugin_name ),
328
+ 'default'=> ''
329
+ ),
330
+ );
331
+
332
+ // Add an nonce field so we can check for it later.
333
+ wp_nonce_field('mtsnb_meta_box', 'mtsnb_meta_box_nonce');
334
+ // Use get_post_meta to retrieve an existing value from the database.
335
+ $value = get_post_meta( $post->ID, '_mtsnb_data', true );//var_dump($value);
336
+ ?>
337
+ <div class="mtsnb-tabs clearfix">
338
+ <div class="mtsnb-tabs-inner clearfix">
339
+ <?php $active_tab = ( isset( $value['active_tab'] ) && !empty( $value['active_tab'] ) ) ? $value['active_tab'] : 'general'; ?>
340
+ <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[active_tab]" id="mtsnb_fields_active_tab" value="<?php echo $active_tab; ?>" />
341
+ <ul class="mtsnb-tabs-nav" id="main-tabs-nav">
342
+ <li>
343
+ <a href="#tab-general" <?php if ( $active_tab === 'general' ) echo 'class="active"'; ?>>
344
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-generic"></i><?php _e( 'General', $this->plugin_name ); ?></span>
345
+ </a>
346
+ </li>
347
+ <li>
348
+ <a href="#tab-type" <?php if ( $active_tab === 'type' ) echo 'class="active"'; ?>>
349
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-edit"></i><?php _e( 'Content', $this->plugin_name ); ?></span>
350
+ </a>
351
+ </li>
352
+ <li>
353
+ <a href="#tab-style" <?php if ( $active_tab === 'style' ) echo 'class="active"'; ?>>
354
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-appearance"></i><?php _e( 'Style', $this->plugin_name ); ?></span>
355
+ </a>
356
+ </li>
357
+ <li>
358
+ <a href="#tab-conditions" <?php if ( $active_tab === 'conditions' ) echo 'class="active"'; ?>>
359
+ <span class="mtsnb-tab-title"><i class="dashicons dashicons-admin-settings"></i><?php _e( 'Conditions', $this->plugin_name ); ?></span>
360
+ </a>
361
+ </li>
362
+ </ul>
363
+ <div class="mtsnb-tabs-wrap" id="main-tabs-wrap">
364
+ <div id="tab-general" class="mtsnb-tabs-content <?php if ( $active_tab === 'general' ) echo 'active'; ?>">
365
+ <div class="mtsnb-tab-desc"><?php _e( 'Select basic settings like close button type and CSS position of the bar.', $this->plugin_name ); ?></div>
366
+ <div class="mtsnb-tab-options clearfix">
367
+ <?php
368
+ foreach ( $general_options as $option_args ) {
369
+ $this->custom_meta_field( $option_args, $value );
370
+ }
371
+ ?>
372
+ </div>
373
+ </div>
374
+ <div id="tab-type" class="mtsnb-tabs-content <?php if ( $active_tab === 'type' ) echo 'active'; ?>">
375
+ <div class="mtsnb-tab-desc"><?php _e( 'Set up notification bar content. Select content type and fill in the fields.', $this->plugin_name ); ?></div>
376
+ <div class="mtsnb-tab-options clearfix">
377
+ <?php $content_type = ( isset( $value['content_type'] ) && !empty( $value['content_type'] ) ) ? $value['content_type'] : 'button'; ?>
378
+ <input type="hidden" class="mtsnb-tab-option" name="mtsnb_fields[content_type]" id="mtsnb_fields_content_type" value="<?php echo $content_type; ?>" />
379
+ <ul class="mtsnb-tabs-nav" id="sub-tabs-nav">
380
+ <li><a href="#tab-button" <?php if ( $content_type === 'button' ) echo 'class="active"'; ?>><?php _e( 'Text and Link/Button', $this->plugin_name ); ?></a></li>
381
+ <li><a href="#tab-custom" <?php if ( $content_type === 'custom' ) echo 'class="active"'; ?>><?php _e( 'Custom', $this->plugin_name ); ?></a></li>
382
+ </ul>
383
+ <div class="meta-tabs-wrap" id="sub-tabs-wrap">
384
+ <div id="tab-button" class="mtsnb-tabs-content <?php if ( $content_type === 'button' ) echo 'active'; ?>">
385
+ <?php
386
+ foreach ( $button_content_type_options as $option_args ) {
387
+ $this->custom_meta_field( $option_args, $value );
388
+ }
389
+ ?>
390
+ </div>
391
+ <div id="tab-custom" class="mtsnb-tabs-content <?php if ( $content_type === 'custom' ) echo 'active'; ?>">
392
+ <?php
393
+ foreach ( $custom_content_type_options as $option_args ) {
394
+ $this->custom_meta_field( $option_args, $value );
395
+ }
396
+ ?>
397
+ </div>
398
+ </div>
399
+ </div>
400
+ </div>
401
+ <div id="tab-style" class="mtsnb-tabs-content <?php if ( $active_tab === 'style' ) echo 'active'; ?>">
402
+ <div class="mtsnb-tab-desc"><?php _e( 'Change the appearance of the notification bar.', $this->plugin_name ); ?></div>
403
+ <div class="mtsnb-tab-options clearfix">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  <?php
405
+ foreach ( $style_options as $option_args ) {
406
  $this->custom_meta_field( $option_args, $value );
407
  }
408
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  </div>
410
  </div>
411
+ <div id="tab-conditions" class="mtsnb-tabs-content <?php if ( $active_tab === 'conditions' ) echo 'active'; ?>">
412
+ <div class="mtsnb-tab-desc"><?php _e( 'Choose when and where to display the notification bar.', $this->plugin_name ); ?></div>
413
+ <div id="conditions-selector-wrap" class="clearfix">
414
+ <div id="conditions-selector">
415
+ <ul>
416
+ <?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'] : ''; ?>
417
+ <?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'] : ''; ?>
418
+ <?php $condition_location_disabled = empty( $condition_notlocation_state ) ? '' : ' disabled'; ?>
419
+ <?php $condition_notlocation_disabled = empty( $condition_location_state ) ? '' : ' disabled'; ?>
420
+ <li id="condition-location" data-disable="notlocation" class="condition-checkbox <?php echo $condition_location_state.$condition_location_disabled; ?>">
421
+ <?php _e( 'On specific locations', $this->plugin_name ); ?>
422
+ <div class="mtsnb-check"></div>
423
+ <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; ?>">
424
+ </li>
425
+ <li id="condition-notlocation" data-disable="location" class="condition-checkbox <?php echo $condition_notlocation_state.$condition_notlocation_disabled; ?>">
426
+ <?php _e( 'Not on specific locations', $this->plugin_name ); ?>
427
+ <div class="mtsnb-check"></div>
428
+ <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; ?>">
429
+ </li>
430
+ <?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'] : ''; ?>
431
+ <?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'] : ''; ?>
432
+ <?php $condition_google_disabled = empty( $condition_notgoogle_state ) ? '' : ' disabled'; ?>
433
+ <?php $condition_notgoogle_disabled = empty( $condition_google_state ) ? '' : ' disabled'; ?>
434
+ <li id="condition-google" data-disable="notgoogle" class="condition-checkbox <?php echo $condition_google_state.$condition_google_disabled; ?>">
435
+ <?php _e( 'From Google', $this->plugin_name ); ?>
436
+ <div class="mtsnb-check"></div>
437
+ <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; ?>">
438
+ </li>
439
+ <li id="condition-notgoogle" data-disable="google" class="condition-checkbox <?php echo $condition_notgoogle_state.$condition_notgoogle_disabled; ?>">
440
+ <?php _e( 'Not from Google', $this->plugin_name ); ?>
441
+ <div class="mtsnb-check"></div>
442
+ <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; ?>">
443
+ </li>
444
+ <?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'] : ''; ?>
445
+ <?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'] : ''; ?>
446
+ <?php $condition_facebook_disabled = empty( $condition_notfacebook_state ) ? '' : ' disabled'; ?>
447
+ <?php $condition_notfacebook_disabled = empty( $condition_facebook_state ) ? '' : ' disabled'; ?>
448
+ <li id="condition-facebook" data-disable="notfacebook" class="condition-checkbox <?php echo $condition_facebook_state.$condition_facebook_disabled; ?>">
449
+ <?php _e( 'From Facebook', $this->plugin_name ); ?>
450
+ <div class="mtsnb-check"></div>
451
+ <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; ?>">
452
+ </li>
453
+ <li id="condition-notfacebook" data-disable="facebook" class="condition-checkbox <?php echo $condition_notfacebook_state.$condition_notfacebook_disabled; ?>">
454
+ <?php _e( 'Not from Facebook', $this->plugin_name ); ?>
455
+ <div class="mtsnb-check"></div>
456
+ <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; ?>">
457
+ </li>
458
+ </ul>
459
+ </div>
460
+ <div id="conditions-panels">
461
+ <div id="condition-location-panel" class="mtsnb-conditions-panel <?php echo $condition_location_state; ?>">
462
+ <div class="mtsnb-conditions-panel-title"><?php _e( 'On specific locations', $this->plugin_name ); ?></div>
463
+ <div class="mtsnb-conditions-panel-content">
464
+ <div class="mtsnb-conditions-panel-desc"><?php _e( 'Show Notification Bar on the following locations', $this->plugin_name ); ?></div>
465
+ <div class="mtsnb-conditions-panel-opt">
466
+ <?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'; ?>
467
+ <?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'; ?>
468
+ <?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'; ?>
469
+ <?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'; ?>
470
+ <p>
471
+ <label>
472
+ <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 ); ?> />
473
+ <?php _e( 'Homepage.', $this->plugin_name ); ?>
474
+ </label>
475
+ </p>
476
+ <?php if ( 'page' === get_option('show_on_front') && '0' !== get_option('page_for_posts') && '0' !== get_option('page_on_front') ) { ?>
477
+ <p>
478
+ <label>
479
+ <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 ); ?> />
480
+ <?php _e( 'Blog Homepage.', $this->plugin_name ); ?>
481
+ </label>
482
+ </p>
483
+ <?php } ?>
 
 
 
 
484
  <p>
485
  <label>
486
+ <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 ); ?> />
487
+ <?php _e( 'Pages.', $this->plugin_name ); ?>
488
  </label>
489
  </p>
490
+ <p>
491
+ <label>
492
+ <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 ); ?> />
493
+ <?php _e( 'Posts.', $this->plugin_name ); ?>
494
+ </label>
495
+ </p>
496
+ </div>
 
 
 
 
 
 
497
  </div>
498
  </div>
499
+ <div id="condition-notlocation-panel" class="mtsnb-conditions-panel <?php echo $condition_notlocation_state; ?>">
500
+ <div class="mtsnb-conditions-panel-title"><?php _e( 'Not on specific locations', $this->plugin_name ); ?></div>
501
+ <div class="mtsnb-conditions-panel-content">
502
+ <div class="mtsnb-conditions-panel-desc"><?php _e( 'Hide Notification Bar on the following locations', $this->plugin_name ); ?></div>
503
+ <div class="mtsnb-conditions-panel-opt">
504
+ <?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'; ?>
505
+ <?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'; ?>
506
+ <?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'; ?>
507
+ <?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'; ?>
 
 
 
 
 
 
 
 
508
  <p>
509
  <label>
510
+ <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 ); ?> />
511
+ <?php _e( 'Homepage.', $this->plugin_name ); ?>
512
  </label>
513
  </p>
514
+ <?php if ( 'page' === get_option('show_on_front') && '0' !== get_option('page_for_posts') && '0' !== get_option('page_on_front') ) { ?>
515
+ <p>
516
+ <label>
517
+ <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 ); ?> />
518
+ <?php _e( 'Blog Homepage.', $this->plugin_name ); ?>
519
+ </label>
520
+ </p>
521
+ <?php } ?>
522
+ <p>
523
+ <label>
524
+ <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 ); ?> />
525
+ <?php _e( 'Pages.', $this->plugin_name ); ?>
526
+ </label>
527
+ </p>
528
+ <p>
529
+ <label>
530
+ <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 ); ?> />
531
+ <?php _e( 'Posts.', $this->plugin_name ); ?>
532
+ </label>
533
+ </p>
534
+ </div>
535
  </div>
536
  </div>
537
+ <div id="condition-google-panel" class="mtsnb-conditions-panel <?php echo $condition_google_state; ?>">
538
+ <div class="mtsnb-conditions-panel-title"><?php _e( 'From Google', $this->plugin_name ); ?></div>
539
+ <div class="mtsnb-conditions-panel-content">
540
+ <div class="mtsnb-conditions-panel-desc">
541
+ <p>
542
+ <label>
543
+ <?php _e( 'Show Notification Bar if visitor arrived via Google search engine.', $this->plugin_name ); ?>
544
+ </label>
545
+ </p>
546
+ </div>
547
  </div>
548
  </div>
549
+ <div id="condition-notgoogle-panel" class="mtsnb-conditions-panel <?php echo $condition_notgoogle_state; ?>">
550
+ <div class="mtsnb-conditions-panel-title"><?php _e( 'Not from Google', $this->plugin_name ); ?></div>
551
+ <div class="mtsnb-conditions-panel-content">
552
+ <div class="mtsnb-conditions-panel-desc">
553
+ <p>
554
+ <label>
555
+ <?php _e( 'Hide Notification Bar if visitor arrived via Google search engine.', $this->plugin_name ); ?>
556
+ </label>
557
+ </p>
558
+ </div>
559
  </div>
560
  </div>
561
+ <div id="condition-facebook-panel" class="mtsnb-conditions-panel <?php echo $condition_facebook_state; ?>">
562
+ <div class="mtsnb-conditions-panel-title"><?php _e( 'From Facebook', $this->plugin_name ); ?></div>
563
+ <div class="mtsnb-conditions-panel-content">
564
+ <div class="mtsnb-conditions-panel-desc">
565
+ <p>
566
+ <label>
567
+ <?php _e( 'Show Notification Bar if visitor arrived from Facebook.', $this->plugin_name ); ?>
568
+ </label>
569
+ </p>
570
+ </div>
571
  </div>
572
  </div>
573
+ <div id="condition-notfacebook-panel" class="mtsnb-conditions-panel <?php echo $condition_notfacebook_state; ?>">
574
+ <div class="mtsnb-conditions-panel-title"><?php _e( 'Not from Facebook', $this->plugin_name ); ?></div>
575
+ <div class="mtsnb-conditions-panel-content">
576
+ <div class="mtsnb-conditions-panel-desc">
577
+ <p>
578
+ <label>
579
+ <?php _e( 'Hide Notification Bar if visitor arrived from Facebook.', $this->plugin_name ); ?>
580
+ </label>
581
+ </p>
582
+ </div>
583
  </div>
584
  </div>
585
  </div>
588
  </div>
589
  </div>
590
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
  <?php
592
+ }
593
 
594
+ /**
595
+ * Helper function for common fields
596
+ *
597
+ * @since 1.0
598
+ */
599
+ public function custom_meta_field( $args, $value, $b = false ) {
600
+
601
+ $type = isset( $args['type'] ) ? $args['type'] : '';
602
+ $name = isset( $args['name'] ) ? $args['name'] : '';
603
+ $name = $b ? 'b_'.$name : $name;
604
+ $label = isset( $args['label'] ) ? $args['label'] : '';
605
+ $options = isset( $args['options'] ) ? $args['options'] : array();
606
+ $default = isset( $args['default'] ) ? $args['default'] : '';
607
+ $min = isset( $args['min'] ) ? $args['min'] : '0';
608
+
609
+ $class = isset( $args['class'] ) ? $args['class'] : '';
610
+
611
+ // Option value
612
+ $opt_val = isset( $value[ $name ] ) ? $value[ $name ] : $default;
613
+
614
+ ?>
615
+ <div id="mtsnb_fields_<?php echo $name;?>_row" class="form-row">
616
+ <label class="form-label" for="mtsnb_fields_<?php echo $name;?>"><?php echo $label; ?></label>
617
+ <div class="form-option <?php echo $class; ?>">
 
 
 
 
 
 
 
 
618
  <?php
619
+ switch ( $type ) {
620
+
621
+ case 'text':
622
+ ?>
623
+ <input type="text" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="<?php echo esc_attr( $opt_val );?>" />
624
+ <?php
625
+ break;
626
+ case 'select':
627
+ ?>
628
+ <select name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>">
629
+ <?php foreach ( $options as $val => $label ) { ?>
630
+ <option value="<?php echo $val; ?>" <?php selected( $opt_val, $val, true); ?>><?php echo $label ?></option>
631
+ <?php } ?>
632
+ </select>
633
+ <?php
634
+ break;
635
+ case 'number':
636
+ ?>
637
+ <input type="number" step="1" min="<?php echo $min;?>" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="<?php echo $opt_val;?>" class="small-text"/>
638
+ <?php
639
+ break;
640
+ case 'color':
641
+ ?>
642
+ <input type="text" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="<?php echo $opt_val;?>" class="mtsnb-color-picker" />
643
+ <?php
644
+ break;
645
+ case 'textarea':
646
+ ?>
647
+ <textarea name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" class="mtsnb-textarea"><?php echo esc_textarea( $opt_val );?></textarea>
648
+ <?php
649
+ break;
650
+ case 'checkbox':
651
+ ?>
652
+ <input type="checkbox" name="mtsnb_fields[<?php echo $name;?>]" id="mtsnb_fields_<?php echo $name;?>" value="1" <?php checked( $opt_val, '1', true ); ?> />
653
+ <?php
654
+ break;
655
+ case 'info':
656
+ ?>
657
+ <small class="mtsnb-option-info">
658
+ <?php echo $default; ?>
659
+ </small>
660
+ <?php
661
+ break;
662
+ }
663
  ?>
664
+ </div>
 
 
 
 
 
 
665
  </div>
666
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667
  }
 
 
668
 
669
+ /**
670
+ * Save the Data
671
+ *
672
+ * @since 1.0
673
+ */
674
+ public function save_custom_meta( $post_id ) {
675
+ // Check if our nonce is set.
676
+ if ( ! isset( $_POST['mtsnb_meta_box_nonce'] ) ) {
677
+ return;
678
+ }
679
+ // Verify that the nonce is valid.
680
+ if ( ! wp_verify_nonce( $_POST['mtsnb_meta_box_nonce'], 'mtsnb_meta_box' ) ) {
681
+ return;
682
+ }
683
+ // If this is an autosave, our form has not been submitted, so we don't want to do anything.
684
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
685
  return;
686
  }
687
+ // Check the user's permissions.
688
+ if ( isset( $_POST['post_type'] ) && 'mts_notification_bar' == $_POST['post_type'] ) {
689
 
690
+ if ( ! current_user_can( 'edit_page', $post_id ) ) {
691
+ return;
692
+ }
693
 
694
+ } else {
695
+
696
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
697
+ return;
698
+ }
699
  }
 
700
 
701
+ /* OK, it's safe for us to save the data now. */
702
+ if ( ! isset( $_POST['mtsnb_fields'] ) ) {
703
+ return;
704
+ }
705
 
706
+ $my_data = $_POST['mtsnb_fields'];
707
 
708
+ // Update the meta field in the database.
709
+ update_post_meta( $post_id, '_mtsnb_data', $my_data );
710
+ }
711
 
712
+ /**
713
+ * Deactivate plugin if pro is active
714
+ *
715
+ * @since 1.0
716
+ */
717
+ public function check_version() {
718
 
719
+ if ( defined( 'MTSNB_PLUGIN_BASE' ) ) {
720
 
721
+ if ( is_plugin_active( MTSNB_PLUGIN_BASE ) || class_exists('MTSNB') ) {
722
 
723
+ deactivate_plugins( MTSNBF_PLUGIN_BASE );
724
+ add_action( 'admin_notices', array( $this, 'disabled_notice' ) );
725
+ if ( isset( $_GET['activate'] ) ) {
726
+ unset( $_GET['activate'] );
727
+ }
728
  }
729
  }
730
  }
 
731
 
732
+ /**
733
+ * Deactivation notice
734
+ *
735
+ * @since 1.0
736
+ */
737
+ public function disabled_notice() {
738
+ ?>
739
+ <div class="updated">
740
+ <p><?php _e( 'Free version of WP Notification Bars plugin disabled. Pro version is active!', $this->plugin_name ); ?></p>
741
+ </div>
742
+ <?php
743
+ }
744
 
745
+ /**
746
+ * Notification Bar update messages
747
+ *
748
+ * @since 1.0
749
+ *
750
+ * @param array $messages
751
+ * @return array $messages
752
+ */
753
+ public function mtsnb_update_messages( $messages ) {
754
+
755
+ global $post;
756
+
757
+ $post_ID = $post->ID;
758
+ $post_type = get_post_type( $post_ID );
759
+
760
+ if ('mts_notification_bar' == $post_type ) {
761
+
762
+ $messages['mts_notification_bar'] = array(
763
+ 0 => '', // Unused. Messages start at index 1.
764
+ 1 => __( 'Notification Bar updated.', $this->plugin_name ),
765
+ 2 => __( 'Custom field updated.', $this->plugin_name ),
766
+ 3 => __( 'Custom field deleted.', $this->plugin_name ),
767
+ 4 => __( 'Notification Bar updated.', $this->plugin_name ),
768
+ 5 => isset($_GET['revision']) ? sprintf( __('Notification Bar restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
769
+ 6 => __( 'Notification Bar published.', $this->plugin_name ),
770
+ 7 => __( 'Notification Bar saved.', $this->plugin_name ),
771
+ 8 => __( 'Notification Bar submitted.', $this->plugin_name),
772
+ 9 => sprintf( __('Notification Bar scheduled for: <strong>%1$s</strong>.', $this->plugin_name ), date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) ) ),
773
+ 10 => __('Notification Bar draft updated.', $this->plugin_name ),
774
+ );
775
+ }
776
+
777
+ return $messages;
778
  }
779
 
 
 
780
 
781
+ /**
782
+ * Single post view bar select
783
+ *
784
+ * @since 1.0.1
785
+ */
786
+ public function mtsnb_select_metabox_insert() {
787
 
788
+ $force_bar_post_types = $this->force_bar_post_types;
 
 
 
 
 
 
 
789
 
790
+ if ( $force_bar_post_types && is_array( $force_bar_post_types ) ) {
791
 
792
+ foreach ( $force_bar_post_types as $screen ) {
793
 
794
+ add_meta_box(
795
+ 'mtsnb_single_bar_metabox',
796
+ __( 'Notification Bar', $this->plugin_name ),
797
+ array( $this, 'mtsnb_select_metabox_content' ),
798
+ $screen,
799
+ 'side',
800
+ 'default'
801
+ );
802
+ }
803
  }
804
  }
805
+ public function mtsnb_select_metabox_content( $post ) {
806
+
807
+ // Add an nonce field so we can check for it later.
808
+ wp_nonce_field('mtsnb_select_metabox_save', 'mtsnb_select_metabox_nonce');
809
+
810
+ /*
811
+ * Use get_post_meta() to retrieve an existing value
812
+ * from the database and use the value for the form.
813
+ */
814
+ $bar = get_post_meta( $post->ID, '_mtsnb_override_bar', true );
815
+
816
+ $processed_item_ids = '';
817
+ if ( !empty( $bar ) ) {
818
+ // Some entries may be arrays themselves!
819
+ $processed_item_ids = array();
820
+ foreach ($bar as $this_id) {
821
+ if (is_array($this_id)) {
822
+ $processed_item_ids = array_merge( $processed_item_ids, $this_id );
823
+ } else {
824
+ $processed_item_ids[] = $this_id;
825
+ }
826
  }
 
827
 
828
+ if (is_array($processed_item_ids) && !empty($processed_item_ids)) {
829
+ $processed_item_ids = implode(',', $processed_item_ids);
830
+ } else {
831
+ $processed_item_ids = '';
832
+ }
833
  }
834
+ ?>
835
+ <p>
836
+ <label for="mtsnb_override_bar_field"><?php _e( 'Select Notification Bar (optional):', $this->plugin_name ); ?></label><br />
837
+ <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; ?>" />
838
+ </p>
839
+ <p>
840
+ <i><?php _e( 'Selected notification bar will override any other bar.', $this->plugin_name ); ?></i>
841
+ </p>
842
+ <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
843
  }
844
 
845
+ public function mtsnb_select_metabox_save( $post_id ) {
 
846
 
847
+ // Check if our nonce is set.
848
+ if ( ! isset( $_POST['mtsnb_select_metabox_nonce'] ) ) {
849
  return;
850
+ }
851
+ // Verify that the nonce is valid.
852
+ if ( ! wp_verify_nonce( $_POST['mtsnb_select_metabox_nonce'], 'mtsnb_select_metabox_save' ) ) {
 
853
  return;
854
+ }
855
+ // If this is an autosave, our form has not been submitted, so we don't want to do anything.
856
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
857
+ return;
858
+ }
 
859
 
860
+ // Check the user's permissions.
861
+ if ( 'page' == $_POST['post_type'] ) {
862
 
863
+ if ( ! current_user_can( 'edit_page', $post_id ) )
864
+ return;
 
 
 
 
 
865
 
866
+ } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
867
 
868
+ if ( ! current_user_can( 'edit_post', $post_id ) )
869
+ return;
870
+ }
871
 
872
+ /* OK, its safe for us to save the data now. */
873
+ if ( ! isset( $_POST['mtsnb_override_bar_field'] ) ) {
874
+ return;
875
+ }
876
 
877
+ $val = $_POST['mtsnb_override_bar_field'];
 
878
 
879
+ if (strpos($val, ',') === false) {
880
+ // No comma, must be single value - still needs to be in an array for now
881
+ $post_ids = array( $val );
 
 
882
  } else {
883
+ // There is a comma so it's explodable
884
+ $post_ids = explode(',', $val);
885
  }
886
+
887
+ // Update the meta field in the database.
888
+ update_post_meta( $post_id, '_mtsnb_override_bar', $post_ids );
889
  }
890
 
891
+ /**
892
+ * Bar select ajax function
893
+ *
894
+ * @since 1.0.1
895
+ */
896
+ public function mtsnb_get_bars() {
897
+
898
+ $result = array();
899
 
900
+ $search = $_REQUEST['q'];
901
+
902
+ $ads_query = array(
903
  'posts_per_page' => -1,
904
  'post_status' => array('publish'),
905
+ 'post_type' => 'mts_notification_bar',
906
+ 'order' => 'ASC',
907
+ 'orderby' => 'title',
908
+ 'suppress_filters' => false,
909
+ 's'=> $search
910
+ );
911
+ $posts = get_posts( $ads_query );
912
+
913
+ // We'll return a JSON-encoded result.
914
  foreach ( $posts as $this_post ) {
915
+ $post_title = $this_post->post_title;
916
+ $id = $this_post->ID;
917
+
918
  $result[] = array(
919
+ 'id' => $id,
920
+ 'title' => $post_title,
921
  );
922
  }
923
+
924
+ echo json_encode( $result );
925
+
926
+ die();
927
  }
928
 
929
+ public function mtsnb_get_bar_titles() {
930
+ $result = array();
931
 
932
+ if (isset($_REQUEST['post_ids'])) {
933
+ $post_ids = $_REQUEST['post_ids'];
934
+ if (strpos($post_ids, ',') === false) {
935
+ // There is no comma, so we can't explode, but we still want an array
936
+ $post_ids = array( $post_ids );
937
+ } else {
938
+ // There is a comma, so it must be explodable
939
+ $post_ids = explode(',', $post_ids);
940
+ }
941
+ } else {
942
+ $post_ids = array();
943
+ }
944
+
945
+ if (is_array($post_ids) && ! empty($post_ids)) {
946
+
947
+ $posts = get_posts(array(
948
+ 'posts_per_page' => -1,
949
+ 'post_status' => array('publish'),
950
+ 'post__in' => $post_ids,
951
+ 'post_type' => 'mts_notification_bar'
952
+ ));
953
+ foreach ( $posts as $this_post ) {
954
+ $result[] = array(
955
+ 'id' => $this_post->ID,
956
+ 'title' => $this_post->post_title,
957
+ );
958
+ }
959
+ }
960
+
961
+ echo json_encode( $result );
962
+
963
+ die();
964
+ }
965
  }
966
+ }
admin/css/select2.min.css CHANGED
File without changes
admin/js/select2.full.min.js CHANGED
File without changes
includes/class-wp-notification-bars-activator.php CHANGED
@@ -20,6 +20,10 @@
20
  * @subpackage MTSNBF/includes
21
  * @author MyThemeShop
22
  */
 
 
 
 
23
  class MTSNBF_Activator {
24
 
25
  /**
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
  /**
includes/class-wp-notification-bars-deactivator.php CHANGED
@@ -20,6 +20,10 @@
20
  * @subpackage MTSNBF/includes
21
  * @author MyThemeShop
22
  */
 
 
 
 
23
  class MTSNBF_Deactivator {
24
 
25
  /**
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
  /**
includes/class-wp-notification-bars-i18n.php CHANGED
@@ -24,6 +24,10 @@
24
  * @subpackage MTSNBF/includes
25
  * @author MyThemeShop
26
  */
 
 
 
 
27
  class MTSNBF_i18n {
28
 
29
  /**
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
  /**
includes/class-wp-notification-bars-loader.php CHANGED
@@ -21,6 +21,10 @@
21
  * @subpackage MTSNBF/includes
22
  * @author MyThemeShop
23
  */
 
 
 
 
24
  class MTSNBF_Loader {
25
 
26
  /**
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
  /**
includes/class-wp-notification-bars-shared.php CHANGED
@@ -20,491 +20,497 @@
20
  * @subpackage MTSNBF/public
21
  * @author MyThemeShop
22
  */
23
- class MTSNBF_Shared {
24
-
25
- /**
26
- * The ID of this plugin.
27
- *
28
- * @since 1.0
29
- * @access private
30
- * @var string $plugin_name The ID of this plugin.
31
- */
32
- private $plugin_name;
33
-
34
- /**
35
- * The version of this plugin.
36
- *
37
- * @since 1.0
38
- * @access private
39
- * @var string $version The current version of this plugin.
40
- */
41
- private $version;
42
-
43
- /**
44
- * Notification bar id
45
- *
46
- * @since 1.0
47
- *
48
- * @var boolean
49
- */
50
- private $bar_id = false;
51
-
52
- /**
53
- * Bar settings.
54
- *
55
- * @since 1.0
56
- *
57
- * @var boolean
58
- */
59
- private $bar_data = false;
60
-
61
- /**
62
- * Initialize the class and set its properties.
63
- *
64
- * @since 1.0
65
- * @param string $plugin_name The name of the plugin.
66
- * @param string $version The version of this plugin.
67
- */
68
- public function __construct( $plugin_name, $version ) {
69
-
70
- $this->plugin_name = $plugin_name;
71
- $this->version = $version;
 
 
 
 
 
72
 
73
- }
74
 
75
- /**
76
- * Check if Notification Bar should be displayed on front end
77
- *
78
- * @since 1.0
79
- */
80
- public function get_notification_bar_data() {
81
 
82
- if ( is_admin() ) return;
83
 
84
- $bar_id = false;
85
- $bar_data = false;
86
 
87
- if ( is_singular() && in_array( get_post_type(), apply_filters( 'mtsnb_force_bar_post_types', array( 'post', 'page' ) ) ) ) {
88
 
89
- global $post;
90
- $bar = get_post_meta( $post->ID, '_mtsnb_override_bar', true );
91
 
92
- if ( $bar && !empty( $bar ) ) {
93
 
94
- $bar_id = isset( $bar[0] ) ? $bar[0] : false;
95
 
96
- if ( $bar_id && !empty( $bar_id ) ) {
97
 
98
- $meta_values = get_post_meta( $bar_id, '_mtsnb_data', true );
99
 
100
- $this->bar_id = $bar_id;
101
- $this->bar_data = $meta_values;
102
 
103
- return;
 
104
  }
105
  }
106
- }
107
 
108
- $args = array(
109
- 'post_type' => 'mts_notification_bar',
110
- 'posts_per_page' => -1,
111
- 'post_status' => 'publish',
112
- );
113
 
114
- $all_bars = get_posts( $args );
115
- foreach( $all_bars as $post ) :
116
- setup_postdata( $post );
117
 
118
- $bar_id = $post->ID;
119
- $meta_values = get_post_meta( $bar_id, '_mtsnb_data', true );
120
 
121
- $passed_location_conditions = $this->test_location( $meta_values );
122
- $passed_referrer_conditions = $this->test_referrer( $meta_values );
123
 
124
- if ( $passed_location_conditions && $passed_referrer_conditions ) {
125
-
126
- $this->bar_id = $bar_id;
127
- $this->bar_data = $meta_values;
128
 
129
- break;
130
- }
131
 
132
- endforeach; wp_reset_postdata();
133
- }
134
 
135
- /**
136
- * Register the stylesheets for the public-facing side of the site.
137
- *
138
- * @since 1.0
139
- */
140
- public function enqueue_styles() {
141
 
142
- if ( is_admin() ) {// Needed for Notification Bar preview on admin side
 
 
 
 
 
143
 
144
- $screen = get_current_screen();
145
- $screen_id = $screen->id;
146
 
147
- if ( 'mts_notification_bar' === $screen_id ) {
 
148
 
149
- wp_enqueue_style( $this->plugin_name.'admin', MTSNBF_PLUGIN_URL . 'public/css/wp-notification-bars-public.css', array(), $this->version, 'all' );
150
- }
151
 
152
- } else {
 
153
 
154
- if ( $this->bar_id && $this->bar_data ) {
155
 
156
- wp_enqueue_style( $this->plugin_name, MTSNBF_PLUGIN_URL . 'public/css/wp-notification-bars-public.css', array(), $this->version, 'all' );
 
 
 
157
  }
158
  }
159
- }
160
 
161
- /**
162
- * Register the stylesheets for the public-facing side of the site.
163
- *
164
- * @since 1.0
165
- */
166
- public function enqueue_scripts() {
167
 
168
- if ( !is_admin() && $this->bar_id && $this->bar_data ) {
169
 
170
- wp_enqueue_script( $this->plugin_name, MTSNBF_PLUGIN_URL . 'public/js/wp-notification-bars-public.js', array( 'jquery' ), $this->version, false );
 
171
  }
172
- }
173
 
174
- /**
175
- * Display Notification Bar on front end
176
- *
177
- * @since 1.0
178
- */
179
- public function display_bar() {
180
 
181
- if ( $this->bar_id && $this->bar_data ) {
182
 
183
- $this->bar_output( $this->bar_id, $this->bar_data );
 
184
  }
185
- }
186
 
187
- /**
188
- * Notification bar output.
189
- *
190
- * @since 1.0
191
- */
192
- public function bar_output( $bar_id, $meta_values ) {
193
-
194
- $button_type = $meta_values['button'];
195
- $button_close_icon = '<span>+</span>';
196
- $button_open_icon = '<span>+</span>';
197
-
198
- $style = 'background-color:'.$meta_values['bg_color'].';color:'.$meta_values['txt_color'].';';
199
- $btn_style = 'background-color:'.$meta_values['bg_color'].';color:'.$meta_values['txt_color'].';';
200
-
201
- $shadow = '-webkit-box-shadow: 0 3px 4px rgba(0, 0, 0, 0.05);box-shadow: 0 3px 4px rgba(0, 0, 0, 0.05);';
202
-
203
- $width = ( isset( $meta_values['content_width'] ) && !empty( $meta_values['content_width'] ) ) ? $meta_values['content_width'] : '960';
204
- $width = (int)$width+120;
205
-
206
- $screen_position_class = 'mtsnb-top';
207
- $css_position_class = isset( $meta_values['css_position'] ) ? ' mtsnb-'.$meta_values['css_position'] : ' mtsnb-fixed';
208
- ?>
209
- <div class="mtsnb mtsnb-shown <?php echo $screen_position_class.$css_position_class; ?>" id="mtsnb-<?php echo $bar_id; ?>" data-mtsnb-id="<?php echo $bar_id; ?>" style="<?php echo $style;?>">
210
- <style type="text/css">
211
- .mtsnb { position: <?php echo $meta_values['css_position'];?>; <?php echo $shadow;?>}
212
- .mtsnb .mtsnb-container { width: <?php echo $width;?>px; font-size: <?php echo $meta_values['font_size'];?>px;}
213
- .mtsnb a { color: <?php echo $meta_values['link_color'];?>;}
214
- .mtsnb .mtsnb-button { background-color: <?php echo $meta_values['link_color'];?>;}
215
- </style>
216
- <div class="mtsnb-container-outer">
217
- <div class="mtsnb-container mtsnb-clearfix">
218
- <?php do_action('before_mtsnb_content'); ?>
219
- <?php $this->bar_content( $meta_values ); ?>
220
- <?php do_action('after_mtsnb_content'); ?>
 
 
 
 
 
221
  </div>
222
- <?php if ( 'no_button' !== $button_type ) { ?>
223
- <?php if ( 'toggle_button' === $button_type ) {?><a href="#" class="mtsnb-show" style="<?php echo $btn_style; ?>"><?php echo $button_open_icon; ?></a><?php } ?>
224
- <a href="#" class="mtsnb-hide" style="<?php echo $style; ?>"><?php echo $button_close_icon; ?></a>
225
- <?php } ?>
226
  </div>
227
- </div>
228
- <?php
229
- }
230
 
231
- /**
232
- * Notification bar content.
233
- *
234
- * @since 1.0
235
- */
236
- public function bar_content( $options ) {
237
 
238
- // Output
239
- echo '<div class="mtsnb-'.$options['content_type'].'-type mtsnb-content">';
240
 
241
- switch ( $options['content_type'] ) {
242
 
243
- case 'button':
244
 
245
- $text = wp_kses_post( $options['basic_text'] );
246
- $link_text = wp_kses_post( $options['basic_link_text'] );
247
- $link_url = esc_url( $options['basic_link_url'] );
248
- $link_style = $options['basic_link_style'];
249
 
250
- echo '<span class="mtsnb-text">'.$text.'</span><a href="'.$link_url.'" class="mtsnb-'.$link_style.'">'.$link_text.'</a>';
251
 
252
- break;
253
- case 'custom':
254
 
255
- echo '<div class="mtsnb-custom-content">';
256
- echo do_shortcode( html_entity_decode( $options['custom_content'] ) );
257
- echo '</div>';
258
 
259
- break;
 
 
 
260
  }
261
 
262
- echo '</div>';
263
- }
 
 
 
 
264
 
265
- /**
266
- * Notification bar admin preview.
267
- *
268
- * @since 1.0
269
- */
270
- public function preview_bar() {
271
-
272
- $data = $_POST['form_data'];
273
 
274
- parse_str( $data, $options );
275
 
276
- $id = $options['post_ID'];
277
- $meta_values = $options['mtsnb_fields'];
278
 
279
- // fix slashes
280
- foreach ( $meta_values as $key => $value ) {
281
 
282
- if ( is_string( $value ) ) {
283
 
284
- $meta_values[ $key ] = stripslashes( $value );
 
285
  }
 
 
 
 
286
  }
287
 
288
- $this->bar_output( $id, $meta_values );
289
 
290
- die();
291
- }
 
 
 
 
 
 
292
 
293
-
294
- /**
295
- * Tests if bar can be displayed based on referrer settings
296
- *
297
- * @since 1.0
298
- */
299
- public function test_referrer( $meta_values ) {
300
 
301
- $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'] ) );
302
 
303
- if ( $no_condition ) return true; // not set, can be displayed
 
304
 
305
- $referer = $this->get_referrer();
 
306
 
307
- // Show for google
308
- if ( !empty( $meta_values['conditions']['google']['state'] ) ) {
309
-
310
- if ( !$referer || empty( $referer ) ) return false; // not set, don't display
311
- $is_search_engine = $this->test_searchengine( $referer );
312
 
313
- if ( $is_search_engine ) {
 
314
 
315
- return true;// referrer is google search engine, display
316
  }
317
 
318
- return false;
319
- }
320
 
321
- // Don't show for google
322
- if ( !empty( $meta_values['conditions']['notgoogle']['state'] ) ) {
323
 
324
- if ( !$referer || empty( $referer ) ) return true; // not set, display
325
- $is_search_engine = $this->test_searchengine( $referer );
326
 
327
- if ( $is_search_engine ) {
 
328
 
329
- return false;// referrer is google search engine, don't display
330
  }
331
 
332
- return true;
333
- }
 
 
334
 
335
- // Show for facebook
336
- if ( !empty( $meta_values['conditions']['facebook']['state'] ) ) {
337
-
338
- if ( !$referer || empty( $referer ) ) return false; // not set, don't display
339
-
340
- if ( false !== strpos( $referer, 'facebook.' ) ) {
341
 
342
- return true;// refetrer is facebook, display
 
 
 
343
  }
344
 
345
- return false;
346
- }
347
 
348
- // Don't show for facebook
349
- if ( !empty( $meta_values['conditions']['notfacebook']['state'] ) ) {
350
 
351
- if ( !$referer || empty( $referer ) ) return true; // not set, display
352
-
353
- if ( false !== strpos( $referer, 'facebook.' ) ) {
354
 
355
- return false;// refetrer is facebook, don't display
356
- }
357
 
358
- return true;
 
359
  }
360
- }
361
 
362
- /**
363
- * Tests if bar can be displayed based on location settings
364
- *
365
- * @since 1.0
366
- */
367
- public function test_location( $meta_values ) {
368
 
369
- $no_condition = (bool) ( empty( $meta_values['conditions']['location']['state'] ) && empty( $meta_values['conditions']['notlocation']['state'] ) );
370
 
371
- if ( $no_condition ) return true; // not set, can be displayed
372
 
373
- // Enable on locations
374
- if ( !empty( $meta_values['conditions']['location']['state'] ) ) {
375
 
376
- if (
377
- 'page' === get_option('show_on_front') &&
378
- '0' !== get_option('page_for_posts') &&
379
- '0' !== get_option('page_on_front') &&
380
- ( ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['location']['blog_home'] ) ) )
381
- ) {
382
 
383
- return true;
384
 
385
- } else if ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) {
386
 
387
- return true;
388
 
389
- } else if ( is_single() && isset( $meta_values['conditions']['location']['posts'] ) ) {
390
 
391
- return true;
392
 
393
- } else if ( is_page() && isset( $meta_values['conditions']['location']['pages'] ) ) {
394
 
395
- return true;
 
 
 
396
  }
397
 
398
- return false;
399
- }
400
 
401
- // Disable on locations
402
- if ( !empty( $meta_values['conditions']['notlocation']['state'] ) ) {
 
 
 
 
403
 
404
- if (
405
- 'page' === get_option('show_on_front') &&
406
- '0' !== get_option('page_for_posts') &&
407
- '0' !== get_option('page_on_front') &&
408
- ( ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['notlocation']['blog_home'] ) ) )
409
- ) {
410
 
411
- return false;
412
 
413
- } else if ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) {
414
 
415
- return false;
416
 
417
- } else if ( is_single() && isset( $meta_values['conditions']['notlocation']['posts'] ) ) {
418
 
419
- return false;
420
 
421
- } else if ( is_page() && isset( $meta_values['conditions']['notlocation']['pages'] ) ) {
 
422
 
423
- return false;
424
  }
425
-
426
- return true;
427
  }
428
- }
429
 
430
- /**
431
- * Tests if the current referrer is a search engine.
432
- *
433
- * @since 1.0
434
- */
435
- public function test_searchengine( $referrer ) {
436
- $response = false;
437
-
438
- $patterns = array(
439
- '.google.',
440
- );
441
-
442
- foreach ( $patterns as $url ) {
443
- if ( false !== stripos( $referrer, $url ) ) {
444
- if ( $url == '.google.' ) {
445
- if ( $this->is_googlesearch( $referrer ) ) {
446
- $response = true;
 
 
 
447
  } else {
448
- $response = false;
449
  }
450
- } else {
451
- $response = true;
452
  }
453
- break;
454
  }
 
455
  }
456
- return $response;
457
- }
458
 
459
- /**
460
- * Checks if the referrer is a google web-source.
461
- *
462
- * @since 1.0
463
- */
464
- public function is_googlesearch( $referrer = '' ) {
465
- $response = true;
466
-
467
- // Get the query strings and check its a web source.
468
- $qs = parse_url( $referrer, PHP_URL_QUERY );
469
- $qget = array();
470
-
471
- foreach ( explode( '&', $qs ) as $keyval ) {
472
- $kv = explode( '=', $keyval );
473
- if ( count( $kv ) == 2 ) {
474
- $qget[ trim( $kv[0] ) ] = trim( $kv[1] );
 
475
  }
476
- }
477
 
478
- if ( isset( $qget['source'] ) ) {
479
- $response = $qget['source'] == 'web';
480
- }
481
 
482
- return $response;
483
- }
484
 
485
- /**
486
- * Get referrer
487
- *
488
- * @since 1.0
489
- */
490
- public function get_referrer() {
491
 
492
- $referer = wp_unslash( $_SERVER['HTTP_REFERER'] );
493
 
494
- if ( $referer && !empty( $referer ) ) {
495
 
496
- $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );// maybe not needed
497
- setcookie( 'mtsnb_referrer', esc_url( $referer ), 0, COOKIEPATH, COOKIE_DOMAIN, $secure ); // session
498
 
499
- } else {
500
 
501
- if ( isset( $_COOKIE['mtsnb_referrer'] ) ) {
502
 
503
- // Stored referrer url
504
- $referer = $_COOKIE['mtsnb_referrer'];
 
505
  }
506
- }
507
 
508
- return $referer;
 
509
  }
510
- }
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
+ /**
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
+ * Notification bar id
50
+ *
51
+ * @since 1.0
52
+ *
53
+ * @var boolean
54
+ */
55
+ private $bar_id = false;
56
+
57
+ /**
58
+ * Bar settings.
59
+ *
60
+ * @since 1.0
61
+ *
62
+ * @var boolean
63
+ */
64
+ private $bar_data = false;
65
+
66
+ /**
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
 
80
+ /**
81
+ * Check if Notification Bar should be displayed on front end
82
+ *
83
+ * @since 1.0
84
+ */
85
+ public function get_notification_bar_data() {
86
 
87
+ if ( is_admin() ) return;
88
 
89
+ $bar_id = false;
90
+ $bar_data = false;
91
 
92
+ if ( is_singular() && in_array( get_post_type(), apply_filters( 'mtsnb_force_bar_post_types', array( 'post', 'page' ) ) ) ) {
93
 
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
 
105
+ $this->bar_id = $bar_id;
106
+ $this->bar_data = $meta_values;
107
 
108
+ return;
109
+ }
110
  }
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 );
127
+ $passed_referrer_conditions = $this->test_referrer( $meta_values );
128
 
129
+ if ( $passed_location_conditions && $passed_referrer_conditions ) {
 
 
 
130
 
131
+ $this->bar_id = $bar_id;
132
+ $this->bar_data = $meta_values;
133
 
134
+ break;
135
+ }
136
 
137
+ endforeach; wp_reset_postdata();
138
+ }
 
 
 
 
139
 
140
+ /**
141
+ * Register the stylesheets for the public-facing side of the site.
142
+ *
143
+ * @since 1.0
144
+ */
145
+ public function enqueue_styles() {
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 ) {
160
+
161
+ wp_enqueue_style( $this->plugin_name, MTSNBF_PLUGIN_URL . 'public/css/wp-notification-bars-public.css', array(), $this->version, 'all' );
162
+ }
163
  }
164
  }
 
165
 
166
+ /**
167
+ * Register the stylesheets for the public-facing side of the site.
168
+ *
169
+ * @since 1.0
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
+ }
177
  }
 
178
 
179
+ /**
180
+ * Display Notification Bar on front end
181
+ *
182
+ * @since 1.0
183
+ */
184
+ public function display_bar() {
185
 
186
+ if ( $this->bar_id && $this->bar_data ) {
187
 
188
+ $this->bar_output( $this->bar_id, $this->bar_data );
189
+ }
190
  }
 
191
 
192
+ /**
193
+ * Notification bar output.
194
+ *
195
+ * @since 1.0
196
+ */
197
+ public function bar_output( $bar_id, $meta_values ) {
198
+
199
+ $button_type = $meta_values['button'];
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
+
208
+ $width = ( isset( $meta_values['content_width'] ) && !empty( $meta_values['content_width'] ) ) ? $meta_values['content_width'] : '960';
209
+ $width = (int)$width+120;
210
+
211
+ $screen_position_class = 'mtsnb-top';
212
+ $css_position_class = isset( $meta_values['css_position'] ) ? ' mtsnb-'.$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 $bar_id; ?>" data-mtsnb-id="<?php echo $bar_id; ?>" style="<?php echo $style;?>">
215
+ <style type="text/css">
216
+ .mtsnb { position: <?php echo $meta_values['css_position'];?>; <?php echo $shadow;?>}
217
+ .mtsnb .mtsnb-container { width: <?php echo $width;?>px; font-size: <?php echo $meta_values['font_size'];?>px;}
218
+ .mtsnb a { color: <?php echo $meta_values['link_color'];?>;}
219
+ .mtsnb .mtsnb-button { background-color: <?php echo $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 $style; ?>"><?php echo $button_close_icon; ?></a>
230
+ <?php } ?>
231
  </div>
 
 
 
 
232
  </div>
233
+ <?php
234
+ }
 
235
 
236
+ /**
237
+ * Notification bar content.
238
+ *
239
+ * @since 1.0
240
+ */
241
+ public function bar_content( $options ) {
242
 
243
+ // Output
244
+ echo '<div class="mtsnb-'.$options['content_type'].'-type mtsnb-content">';
245
 
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 = $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
+ echo do_shortcode( html_entity_decode( $options['custom_content'] ) );
262
+ echo '</div>';
263
 
264
+ break;
265
+ }
266
+
267
+ echo '</div>';
268
  }
269
 
270
+ /**
271
+ * Notification bar admin preview.
272
+ *
273
+ * @since 1.0
274
+ */
275
+ public function preview_bar() {
276
 
277
+ $data = $_POST['form_data'];
 
 
 
 
 
 
 
278
 
279
+ parse_str( $data, $options );
280
 
281
+ $id = $options['post_ID'];
282
+ $meta_values = $options['mtsnb_fields'];
283
 
284
+ // fix slashes
285
+ foreach ( $meta_values as $key => $value ) {
286
 
287
+ if ( is_string( $value ) ) {
288
 
289
+ $meta_values[ $key ] = stripslashes( $value );
290
+ }
291
  }
292
+
293
+ $this->bar_output( $id, $meta_values );
294
+
295
+ die();
296
  }
297
 
 
298
 
299
+ /**
300
+ * Tests if bar can be displayed based on referrer settings
301
+ *
302
+ * @since 1.0
303
+ */
304
+ public function test_referrer( $meta_values ) {
305
+
306
+ $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'] ) );
307
 
308
+ if ( $no_condition ) return true; // not set, can be displayed
 
 
 
 
 
 
309
 
310
+ $referer = $this->get_referrer();
311
 
312
+ // Show for google
313
+ if ( !empty( $meta_values['conditions']['google']['state'] ) ) {
314
 
315
+ if ( !$referer || empty( $referer ) ) return false; // not set, don't display
316
+ $is_search_engine = $this->test_searchengine( $referer );
317
 
318
+ if ( $is_search_engine ) {
 
 
 
 
319
 
320
+ return true;// referrer is google search engine, display
321
+ }
322
 
323
+ return false;
324
  }
325
 
326
+ // Don't show for google
327
+ if ( !empty( $meta_values['conditions']['notgoogle']['state'] ) ) {
328
 
329
+ if ( !$referer || empty( $referer ) ) return true; // not set, display
330
+ $is_search_engine = $this->test_searchengine( $referer );
331
 
332
+ if ( $is_search_engine ) {
 
333
 
334
+ return false;// referrer is google search engine, don't display
335
+ }
336
 
337
+ return true;
338
  }
339
 
340
+ // Show for facebook
341
+ if ( !empty( $meta_values['conditions']['facebook']['state'] ) ) {
342
+
343
+ if ( !$referer || empty( $referer ) ) return false; // not set, don't display
344
 
345
+ if ( false !== strpos( $referer, 'facebook.' ) ) {
 
 
 
 
 
346
 
347
+ return true;// refetrer is facebook, display
348
+ }
349
+
350
+ return false;
351
  }
352
 
353
+ // Don't show for facebook
354
+ if ( !empty( $meta_values['conditions']['notfacebook']['state'] ) ) {
355
 
356
+ if ( !$referer || empty( $referer ) ) return true; // not set, display
 
357
 
358
+ if ( false !== strpos( $referer, 'facebook.' ) ) {
 
 
359
 
360
+ return false;// refetrer is facebook, don't display
361
+ }
362
 
363
+ return true;
364
+ }
365
  }
 
366
 
367
+ /**
368
+ * Tests if bar can be displayed based on location settings
369
+ *
370
+ * @since 1.0
371
+ */
372
+ public function test_location( $meta_values ) {
373
 
374
+ $no_condition = (bool) ( empty( $meta_values['conditions']['location']['state'] ) && empty( $meta_values['conditions']['notlocation']['state'] ) );
375
 
376
+ if ( $no_condition ) return true; // not set, can be displayed
377
 
378
+ // Enable on locations
379
+ if ( !empty( $meta_values['conditions']['location']['state'] ) ) {
380
 
381
+ if (
382
+ 'page' === get_option('show_on_front') &&
383
+ '0' !== get_option('page_for_posts') &&
384
+ '0' !== get_option('page_on_front') &&
385
+ ( ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['location']['blog_home'] ) ) )
386
+ ) {
387
 
388
+ return true;
389
 
390
+ } else if ( is_front_page() && isset( $meta_values['conditions']['location']['home'] ) ) {
391
 
392
+ return true;
393
 
394
+ } else if ( is_single() && isset( $meta_values['conditions']['location']['posts'] ) ) {
395
 
396
+ return true;
397
 
398
+ } else if ( is_page() && isset( $meta_values['conditions']['location']['pages'] ) ) {
399
 
400
+ return true;
401
+ }
402
+
403
+ return false;
404
  }
405
 
406
+ // Disable on locations
407
+ if ( !empty( $meta_values['conditions']['notlocation']['state'] ) ) {
408
 
409
+ if (
410
+ 'page' === get_option('show_on_front') &&
411
+ '0' !== get_option('page_for_posts') &&
412
+ '0' !== get_option('page_on_front') &&
413
+ ( ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) || ( is_home() && isset( $meta_values['conditions']['notlocation']['blog_home'] ) ) )
414
+ ) {
415
 
416
+ return false;
 
 
 
 
 
417
 
418
+ } else if ( is_front_page() && isset( $meta_values['conditions']['notlocation']['home'] ) ) {
419
 
420
+ return false;
421
 
422
+ } else if ( is_single() && isset( $meta_values['conditions']['notlocation']['posts'] ) ) {
423
 
424
+ return false;
425
 
426
+ } else if ( is_page() && isset( $meta_values['conditions']['notlocation']['pages'] ) ) {
427
 
428
+ return false;
429
+ }
430
 
431
+ return true;
432
  }
 
 
433
  }
 
434
 
435
+ /**
436
+ * Tests if the current referrer is a search engine.
437
+ *
438
+ * @since 1.0
439
+ */
440
+ public function test_searchengine( $referrer ) {
441
+ $response = false;
442
+
443
+ $patterns = array(
444
+ '.google.',
445
+ );
446
+
447
+ foreach ( $patterns as $url ) {
448
+ if ( false !== stripos( $referrer, $url ) ) {
449
+ if ( $url == '.google.' ) {
450
+ if ( $this->is_googlesearch( $referrer ) ) {
451
+ $response = true;
452
+ } else {
453
+ $response = false;
454
+ }
455
  } else {
456
+ $response = true;
457
  }
458
+ break;
 
459
  }
 
460
  }
461
+ return $response;
462
  }
 
 
463
 
464
+ /**
465
+ * Checks if the referrer is a google web-source.
466
+ *
467
+ * @since 1.0
468
+ */
469
+ public function is_googlesearch( $referrer = '' ) {
470
+ $response = true;
471
+
472
+ // Get the query strings and check its a web source.
473
+ $qs = parse_url( $referrer, PHP_URL_QUERY );
474
+ $qget = array();
475
+
476
+ foreach ( explode( '&', $qs ) as $keyval ) {
477
+ $kv = explode( '=', $keyval );
478
+ if ( count( $kv ) == 2 ) {
479
+ $qget[ trim( $kv[0] ) ] = trim( $kv[1] );
480
+ }
481
  }
 
482
 
483
+ if ( isset( $qget['source'] ) ) {
484
+ $response = $qget['source'] == 'web';
485
+ }
486
 
487
+ return $response;
488
+ }
489
 
490
+ /**
491
+ * Get referrer
492
+ *
493
+ * @since 1.0
494
+ */
495
+ public function get_referrer() {
496
 
497
+ $referer = wp_unslash( $_SERVER['HTTP_REFERER'] );
498
 
499
+ if ( $referer && !empty( $referer ) ) {
500
 
501
+ $secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );// maybe not needed
502
+ setcookie( 'mtsnb_referrer', esc_url( $referer ), 0, COOKIEPATH, COOKIE_DOMAIN, $secure ); // session
503
 
504
+ } else {
505
 
506
+ if ( isset( $_COOKIE['mtsnb_referrer'] ) ) {
507
 
508
+ // Stored referrer url
509
+ $referer = $_COOKIE['mtsnb_referrer'];
510
+ }
511
  }
 
512
 
513
+ return $referer;
514
+ }
515
  }
516
+ }
includes/class-wp-notification-bars.php CHANGED
@@ -69,7 +69,7 @@ class MTSNBF {
69
  public function __construct() {
70
 
71
  $this->plugin_name = 'wp-notification-bars';
72
- $this->version = '1.0.1';
73
 
74
  $this->load_dependencies();
75
  $this->set_locale();
69
  public function __construct() {
70
 
71
  $this->plugin_name = 'wp-notification-bars';
72
+ $this->version = '1.0.2';
73
 
74
  $this->load_dependencies();
75
  $this->set_locale();
languages/wp-notification-bars.mo CHANGED
File without changes
public/class-wp-notification-bars-public.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /**
4
  * The public-facing functionality of the plugin.
5
  *
@@ -20,36 +19,43 @@
20
  * @subpackage MTSNBF/public
21
  * @author MyThemeShop
22
  */
23
- class MTSNBF_Public {
 
 
 
 
 
 
24
 
25
- /**
26
- * The ID of this plugin.
27
- *
28
- * @since 1.0
29
- * @access private
30
- * @var string $plugin_name The ID of this plugin.
31
- */
32
- private $plugin_name;
33
 
34
- /**
35
- * The version of this plugin.
36
- *
37
- * @since 1.0
38
- * @access private
39
- * @var string $version The current version of this plugin.
40
- */
41
- private $version;
42
 
43
- /**
44
- * Initialize the class and set its properties.
45
- *
46
- * @since 1.0
47
- * @param string $plugin_name The name of the plugin.
48
- * @param string $version The version of this plugin.
49
- */
50
- public function __construct( $plugin_name, $version ) {
51
 
52
- $this->plugin_name = $plugin_name;
53
- $this->version = $version;
 
54
  }
55
  }
1
  <?php
 
2
  /**
3
  * The public-facing functionality of the plugin.
4
  *
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
  }
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.1
7
- Stable tag: 1.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -73,6 +73,9 @@ Please disable all plugins and check if backup is working properly. Then you can
73
  4. Conditions Settings
74
 
75
  == Changelog ==
 
 
 
76
 
77
  = 1.0.1 =
78
  * Added ability to choose notification bar on single post and page
@@ -81,4 +84,4 @@ Please disable all plugins and check if backup is working properly. Then you can
81
  * Allowed html in "Text and Link/Button" content type
82
 
83
  = 1.0 =
84
- * Official plugin release.
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.5
7
+ Stable tag: 1.0.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
73
  4. Conditions Settings
74
 
75
  == Changelog ==
76
+ = 1.0.2 =
77
+ * Minor code improvements
78
+ * Checked compatibility with WordPress v4.9.5
79
 
80
  = 1.0.1 =
81
  * Added ability to choose notification bar on single post and page
84
  * Allowed html in "Text and Link/Button" content type
85
 
86
  = 1.0 =
87
+ * Official plugin release.
wp-notification-bars.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin Name: WP Notification Bars
6
  * Plugin URI: https://mythemeshop.com/plugins/wp-notification-bars/
7
  * 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.
8
- * Version: 1.0.1
9
  * Author: MyThemeShop
10
  * Author URI: https://mythemeshop.com/
11
  * Text Domain: wp-notification-bars
@@ -69,4 +69,4 @@ function run_mts_notification_bar_f() {
69
  $plugin->run();
70
 
71
  }
72
- run_mts_notification_bar_f();
5
  * Plugin Name: WP Notification Bars
6
  * Plugin URI: https://mythemeshop.com/plugins/wp-notification-bars/
7
  * 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.
8
+ * Version: 1.0.2
9
  * Author: MyThemeShop
10
  * Author URI: https://mythemeshop.com/
11
  * Text Domain: wp-notification-bars
69
  $plugin->run();
70
 
71
  }
72
+ run_mts_notification_bar_f();