Insert Headers And Footers - Version 1.3.1

Version Description

  • 2021-12-01
  • Enhancement : Code Optimization.
  • Enhancement : Add compatibility of Mozilla Firefox on dashboard settings.
  • Compatibility : Compatible with WordPress 5.8.
  • Compatibility : Compatible with PHP 8.0.
Download this release

Release Info

Developer WPBrigade
Plugin Icon wp plugin Insert Headers And Footers
Version 1.3.1
Comparing to
See all releases

Code changes from version 1.3.0 to 1.3.1

asset/js/script.js CHANGED
@@ -1,7 +1,9 @@
1
  (function($) {
2
  $(window).on('load', function() {
3
- wp.codeEditor.initialize($('[id="wpheaderandfooter_basics[wp_header_textarea]"]'));
4
- wp.codeEditor.initialize($('[id="wpheaderandfooter_basics[wp_body_textarea]"]'));
5
- wp.codeEditor.initialize($('[id="wpheaderandfooter_basics[wp_footer_textarea]"]'));
 
 
6
  });
7
  })(jQuery);
1
  (function($) {
2
  $(window).on('load', function() {
3
+ $.ready.then(function(){
4
+ wp.codeEditor.initialize($('[id="wpheaderandfooter_basics[wp_header_textarea]"]'));
5
+ wp.codeEditor.initialize($('[id="wpheaderandfooter_basics[wp_body_textarea]"]'));
6
+ wp.codeEditor.initialize($('[id="wpheaderandfooter_basics[wp_footer_textarea]"]'));
7
+ });
8
  });
9
  })(jQuery);
classes/class-settings-api.php CHANGED
@@ -1,13 +1,18 @@
1
  <?php
2
-
3
  /**
4
  * WP Header and Footer Settings API wrapper class
 
 
5
  */
 
6
  if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
 
 
 
7
  class WPHeaderAndFooter_Settings_API {
8
 
9
  /**
10
- * settings sections array
11
  *
12
  * @var array
13
  */
@@ -20,6 +25,9 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
20
  */
21
  protected $settings_fields = array();
22
 
 
 
 
23
  public function __construct() {
24
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
25
  }
@@ -27,7 +35,7 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
27
  /**
28
  * Enqueue scripts and styles
29
  */
30
- function admin_enqueue_scripts() {
31
  wp_enqueue_style( 'wp-color-picker' );
32
 
33
  wp_enqueue_media();
@@ -38,9 +46,9 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
38
  /**
39
  * Set settings sections
40
  *
41
- * @param array $sections setting sections array
42
  */
43
- function set_sections( $sections ) {
44
  $this->settings_sections = $sections;
45
 
46
  return $this;
@@ -49,9 +57,9 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
49
  /**
50
  * Add a single section
51
  *
52
- * @param array $section
53
  */
54
- function add_section( $section ) {
55
  $this->settings_sections[] = $section;
56
 
57
  return $this;
@@ -60,15 +68,21 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
60
  /**
61
  * Set settings fields
62
  *
63
- * @param array $fields settings fields array
64
  */
65
- function set_fields( $fields ) {
66
  $this->settings_fields = $fields;
67
 
68
  return $this;
69
  }
70
 
71
- function add_field( $section, $field ) {
 
 
 
 
 
 
72
  $defaults = array(
73
  'name' => '',
74
  'label' => '',
@@ -90,16 +104,16 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
90
  * This function gets the initiated settings sections and fields. Then
91
  * registers them to WordPress and ready for use.
92
  */
93
- function admin_init() {
94
- // register settings sections
95
  foreach ( $this->settings_sections as $section ) {
96
- if ( false == get_option( $section['id'] ) ) {
97
  add_option( $section['id'] );
98
  }
99
 
100
  if ( isset( $section['desc'] ) && ! empty( $section['desc'] ) ) {
101
  $section['desc'] = '<div class="inside">' . $section['desc'] . '</div>';
102
- $callback = call_user_func( array( $this, 'get_description' ), $section['desc'] );
103
  } elseif ( isset( $section['callback'] ) ) {
104
  $callback = $section['callback'];
105
  } else {
@@ -109,7 +123,7 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
109
  add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
110
  }
111
 
112
- // register settings fields
113
  foreach ( $this->settings_fields as $section => $field ) {
114
  foreach ( $field as $option ) {
115
 
@@ -140,7 +154,7 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
140
  }
141
  }
142
 
143
- // creates our settings in the options table
144
  foreach ( $this->settings_sections as $section ) {
145
  register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) );
146
  }
@@ -149,7 +163,7 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
149
  /**
150
  * Get field description for display
151
  *
152
- * @param array $args settings field args
153
  */
154
  public function get_field_description( $args ) {
155
  if ( ! empty( $args['desc'] ) ) {
@@ -164,9 +178,9 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
164
  /**
165
  * Displays a text field for a settings field
166
  *
167
- * @param array $args settings field args
168
  */
169
- function callback_text( $args ) {
170
 
171
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
172
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
@@ -176,24 +190,24 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
176
  $html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
177
  $html .= $this->get_field_description( $args );
178
 
179
- echo $html;
180
  }
181
 
182
  /**
183
  * Displays a url field for a settings field
184
  *
185
- * @param array $args settings field args
186
  */
187
- function callback_url( $args ) {
188
  $this->callback_text( $args );
189
  }
190
 
191
  /**
192
  * Displays a number field for a settings field
193
  *
194
- * @param array $args settings field args
195
  */
196
- function callback_number( $args ) {
197
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
198
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
199
  $type = isset( $args['type'] ) ? $args['type'] : 'number';
@@ -205,15 +219,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
205
  $html = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
206
  $html .= $this->get_field_description( $args );
207
 
208
- echo $html;
209
  }
210
 
211
  /**
212
  * Displays a checkbox for a settings field
213
  *
214
- * @param array $args settings field args
215
  */
216
- function callback_checkbox( $args ) {
217
 
218
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
219
 
@@ -224,15 +238,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
224
  $html .= sprintf( '%1$s</label>', $args['desc'] );
225
  $html .= '</fieldset>';
226
 
227
- echo $html;
228
  }
229
 
230
  /**
231
  * Displays a multicheckbox a settings field
232
  *
233
- * @param array $args settings field args
234
  */
235
- function callback_multicheck( $args ) {
236
 
237
  $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
238
  $html = '<fieldset>';
@@ -247,15 +261,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
247
  $html .= $this->get_field_description( $args );
248
  $html .= '</fieldset>';
249
 
250
- echo $html;
251
  }
252
 
253
  /**
254
  * Displays a multicheckbox a settings field
255
  *
256
- * @param array $args settings field args
257
  */
258
- function callback_radio( $args ) {
259
 
260
  $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
261
  $html = '<fieldset>';
@@ -269,15 +283,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
269
  $html .= $this->get_field_description( $args );
270
  $html .= '</fieldset>';
271
 
272
- echo $html;
273
  }
274
 
275
  /**
276
  * Displays a selectbox for a settings field
277
  *
278
- * @param array $args settings field args
279
  */
280
- function callback_select( $args ) {
281
 
282
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
283
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
@@ -290,15 +304,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
290
  $html .= sprintf( '</select>' );
291
  $html .= $this->get_field_description( $args );
292
 
293
- echo $html;
294
  }
295
 
296
  /**
297
  * Displays a textarea for a settings field
298
  *
299
- * @param array $args settings field args
300
  */
301
- function callback_textarea( $args ) {
302
 
303
  $value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
304
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
@@ -307,30 +321,29 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
307
  $html = sprintf( '<textarea rows="5" cols="100" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
308
  $html .= $this->get_field_description( $args );
309
 
310
- echo $html;
311
  }
312
 
313
  /**
314
  * Displays a textarea for a settings field
315
  *
316
- * @param array $args settings field args
317
- * @return string
318
  */
319
- function callback_html( $args ) {
320
- echo $this->get_field_description( $args );
321
  }
322
 
323
  /**
324
  * Displays a rich text textarea for a settings field
325
  *
326
- * @param array $args settings field args
327
  */
328
- function callback_wysiwyg( $args ) {
329
 
330
  $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
331
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : '500px';
332
 
333
- echo '<div style="max-width: ' . $size . ';">';
334
 
335
  $editor_settings = array(
336
  'teeny' => true,
@@ -346,15 +359,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
346
 
347
  echo '</div>';
348
 
349
- echo $this->get_field_description( $args );
350
  }
351
 
352
  /**
353
  * Displays a file upload field for a settings field
354
  *
355
- * @param array $args settings field args
356
  */
357
- function callback_file( $args ) {
358
 
359
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
360
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
@@ -365,15 +378,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
365
  $html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
366
  $html .= $this->get_field_description( $args );
367
 
368
- echo $html;
369
  }
370
 
371
  /**
372
  * Displays a password field for a settings field
373
  *
374
- * @param array $args settings field args
375
  */
376
- function callback_password( $args ) {
377
 
378
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
379
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
@@ -381,15 +394,15 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
381
  $html = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
382
  $html .= $this->get_field_description( $args );
383
 
384
- echo $html;
385
  }
386
 
387
  /**
388
  * Displays a color picker field for a settings field
389
  *
390
- * @param array $args settings field args
391
  */
392
- function callback_color( $args ) {
393
 
394
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
395
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
@@ -397,15 +410,18 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
397
  $html = sprintf( '<input type="text" class="%1$s-text wp-color-picker-field" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, $args['std'] );
398
  $html .= $this->get_field_description( $args );
399
 
400
- echo $html;
401
  }
402
 
403
  /**
404
  * Sanitize callback for Settings API
405
  *
 
406
  * @return mixed
407
  */
408
- function sanitize_options( $options ) {
 
 
409
 
410
  if ( ! $options ) {
411
  return $options;
@@ -414,36 +430,41 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
414
  foreach ( $options as $option_slug => $option_value ) {
415
  $sanitize_callback = $this->get_sanitize_callback( $option_slug );
416
 
417
- // If callback is set, call it
418
  if ( $sanitize_callback ) {
419
  $options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
420
  continue;
421
  }
 
 
 
422
  }
423
 
 
 
424
  return $options;
425
  }
426
 
427
  /**
428
  * Get sanitization callback for given option slug
429
  *
430
- * @param string $slug option slug
431
  *
432
  * @return mixed string or bool false
433
  */
434
- function get_sanitize_callback( $slug = '' ) {
435
  if ( empty( $slug ) ) {
436
  return false;
437
  }
438
 
439
- // Iterate over registered fields and see if we can find proper callback
440
  foreach ( $this->settings_fields as $section => $options ) {
441
  foreach ( $options as $option ) {
442
- if ( $option['name'] != $slug ) {
443
  continue;
444
  }
445
 
446
- // Return the callback name
447
  return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
448
  }
449
  }
@@ -454,12 +475,12 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
454
  /**
455
  * Get the value of a settings field
456
  *
457
- * @param string $option settings field name
458
- * @param string $section the section name this field belongs to
459
- * @param string $default default text if it's not found
460
- * @return string
461
  */
462
- function get_option( $option, $section, $default = '' ) {
463
 
464
  $options = get_option( $section );
465
 
@@ -475,23 +496,18 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
475
  *
476
  * Shows all the settings section labels as tab
477
  */
478
- function show_navigation() {
479
  $html = '<h2 class="nav-tab-wrapper">';
480
 
481
  $count = count( $this->settings_sections );
482
 
483
- // don't show the navigation if only one section exists
484
- if ( $count === 1 ) {
485
- // return;
486
- }
487
-
488
  foreach ( $this->settings_sections as $tab ) {
489
  $html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab">%2$s</a>', $tab['id'], $tab['title'] );
490
  }
491
 
492
  $html .= '</h2>';
493
 
494
- echo $html;
495
  }
496
 
497
  /**
@@ -499,11 +515,11 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
499
  *
500
  * This function displays every sections in a different form
501
  */
502
- function show_forms() {
503
  ?>
504
  <div class="header-and-footer-setting">
505
  <?php foreach ( $this->settings_sections as $form ) { ?>
506
- <div id="<?php echo $form['id']; ?>" class="group" style="display: none;">
507
  <form method="post" action="options.php">
508
  <?php
509
  do_action( 'wsa_form_top_' . $form['id'], $form );
@@ -550,24 +566,24 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
550
  <ul class="plugins_lists">
551
  <li>
552
  <a href="https://wpbrigade.com/wordpress/plugins/loginpress-pro/?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" data-count="none" target="_blank" title="<?php esc_html_e( 'Customize your login screen', 'wp-headers-and-footers' ); ?>">
553
- <?php esc_html_e( 'LoginPress - Login Customizer', 'wp-headers-and-footers' ) ?>
554
  </a>
555
  </li>
556
 
557
  <li>
558
  <a href="https://analytify.io/ref/73/?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" target="_blank" title="<?php esc_html_e( 'Share with your facebook friends about this awesome plugin.', 'wp-headers-and-footers' ); ?>">
559
- <?php esc_html_e( 'Google Analytics by Analytify', 'wp-headers-and-footers' ) ?>
560
  </a>
561
  </li>
562
 
563
  <li>
564
  <a href="https://simplesocialbuttons.com?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" target="_blank" title="<?php esc_html_e( 'Socialize your Website', 'wp-headers-and-footers' ); ?>">
565
- <?php esc_html_e( 'Simple Social Buttons', 'wp-headers-and-footers' ) ?>
566
  </a>
567
  </li>
568
- <li>
569
  <a href="http://wpbrigade.com/recommend/maintenance-mode?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" target="_blank" title="<?php esc_html_e( 'Socialize your Website', 'wp-headers-and-footers' ); ?>">
570
- <?php esc_html_e( 'Under Construction & Maintenance mode', 'wp-headers-and-footers' ) ?>
571
  </a>
572
  </li>
573
  </ul>
@@ -582,7 +598,7 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
582
  *
583
  * This code uses localstorage for displaying active tabs
584
  */
585
- function script() {
586
  ?>
587
  <script>
588
  jQuery(document).ready(function($) {
@@ -654,10 +670,13 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
654
  });
655
  </script>
656
  <?php
657
- $this->_style_fix();
658
  }
659
 
660
- function _style_fix() {
 
 
 
661
  global $wp_version;
662
 
663
  if ( version_compare( $wp_version, '3.8', '<=' ) ) :
@@ -672,33 +691,37 @@ if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
672
  }
673
 
674
  /**
675
- * Get Section Description
676
- * @param string $desc [description]
677
- *
678
- * @since 1.2.0
679
- */
680
- function get_description( $desc ) {
 
681
  return $desc;
682
  }
683
 
684
  /**
685
- * Prints out all settings sections added to a particular settings page
686
- *
687
- * @since 1.2.1
688
- */
689
- function do_settings_sections( $page ) {
 
690
  global $wp_settings_sections, $wp_settings_fields;
691
 
692
- if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
693
- return;
 
694
 
695
- foreach ( (array) $wp_settings_sections[$page] as $section ) {
696
- echo "<h3>{$section['title']}</h3>\n";
697
- echo $section['callback'] ;
698
- if ( !isset($wp_settings_fields) || !isset($wp_settings_fields[$page]) || !isset($wp_settings_fields[$page][$section['id']]) )
699
- continue;
 
700
  echo '<table class="form-table">';
701
- do_settings_fields($page, $section['id']);
702
  echo '</table>';
703
  }
704
  }
1
  <?php
 
2
  /**
3
  * WP Header and Footer Settings API wrapper class
4
+ *
5
+ * @package wp-headers-and-footers
6
  */
7
+
8
  if ( ! class_exists( 'WPHeaderAndFooter_Settings_API' ) ) :
9
+ /**
10
+ * Class WPHeaderAndFooter_Settings_API
11
+ */
12
  class WPHeaderAndFooter_Settings_API {
13
 
14
  /**
15
+ * Settings sections array
16
  *
17
  * @var array
18
  */
25
  */
26
  protected $settings_fields = array();
27
 
28
+ /**
29
+ * The WPHeaderAndFooter_Settings_API constructor
30
+ */
31
  public function __construct() {
32
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
33
  }
35
  /**
36
  * Enqueue scripts and styles
37
  */
38
+ public function admin_enqueue_scripts() {
39
  wp_enqueue_style( 'wp-color-picker' );
40
 
41
  wp_enqueue_media();
46
  /**
47
  * Set settings sections
48
  *
49
+ * @param array $sections setting sections array.
50
  */
51
+ public function set_sections( $sections ) {
52
  $this->settings_sections = $sections;
53
 
54
  return $this;
57
  /**
58
  * Add a single section
59
  *
60
+ * @param array $section The section.
61
  */
62
+ public function add_section( $section ) {
63
  $this->settings_sections[] = $section;
64
 
65
  return $this;
68
  /**
69
  * Set settings fields
70
  *
71
+ * @param array $fields settings fields array.
72
  */
73
+ public function set_fields( $fields ) {
74
  $this->settings_fields = $fields;
75
 
76
  return $this;
77
  }
78
 
79
+ /**
80
+ * Add field in settings.
81
+ *
82
+ * @param array $section the section.
83
+ * @param array $field the field.
84
+ */
85
+ public function add_field( $section, $field ) {
86
  $defaults = array(
87
  'name' => '',
88
  'label' => '',
104
  * This function gets the initiated settings sections and fields. Then
105
  * registers them to WordPress and ready for use.
106
  */
107
+ public function admin_init() {
108
+ // register settings sections.
109
  foreach ( $this->settings_sections as $section ) {
110
+ if ( false === get_option( $section['id'] ) ) {
111
  add_option( $section['id'] );
112
  }
113
 
114
  if ( isset( $section['desc'] ) && ! empty( $section['desc'] ) ) {
115
  $section['desc'] = '<div class="inside">' . $section['desc'] . '</div>';
116
+ $callback = call_user_func( array( $this, 'get_description' ), $section['desc'] );
117
  } elseif ( isset( $section['callback'] ) ) {
118
  $callback = $section['callback'];
119
  } else {
123
  add_settings_section( $section['id'], $section['title'], $callback, $section['id'] );
124
  }
125
 
126
+ // register settings fields.
127
  foreach ( $this->settings_fields as $section => $field ) {
128
  foreach ( $field as $option ) {
129
 
154
  }
155
  }
156
 
157
+ // creates our settings in the options table.
158
  foreach ( $this->settings_sections as $section ) {
159
  register_setting( $section['id'], $section['id'], array( $this, 'sanitize_options' ) );
160
  }
163
  /**
164
  * Get field description for display
165
  *
166
+ * @param array $args settings field args.
167
  */
168
  public function get_field_description( $args ) {
169
  if ( ! empty( $args['desc'] ) ) {
178
  /**
179
  * Displays a text field for a settings field
180
  *
181
+ * @param array $args settings field args.
182
  */
183
+ public function callback_text( $args ) {
184
 
185
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
186
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
190
  $html = sprintf( '<input type="%1$s" class="%2$s-text" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder );
191
  $html .= $this->get_field_description( $args );
192
 
193
+ echo $html; // @codingStandardsIgnoreLine.
194
  }
195
 
196
  /**
197
  * Displays a url field for a settings field
198
  *
199
+ * @param array $args settings field args.
200
  */
201
+ public function callback_url( $args ) {
202
  $this->callback_text( $args );
203
  }
204
 
205
  /**
206
  * Displays a number field for a settings field
207
  *
208
+ * @param array $args settings field args.
209
  */
210
+ public function callback_number( $args ) {
211
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
212
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
213
  $type = isset( $args['type'] ) ? $args['type'] : 'number';
219
  $html = sprintf( '<input type="%1$s" class="%2$s-number" id="%3$s[%4$s]" name="%3$s[%4$s]" value="%5$s"%6$s%7$s%8$s%9$s/>', $type, $size, $args['section'], $args['id'], $value, $placeholder, $min, $max, $step );
220
  $html .= $this->get_field_description( $args );
221
 
222
+ echo $html; // @codingStandardsIgnoreLine.
223
  }
224
 
225
  /**
226
  * Displays a checkbox for a settings field
227
  *
228
+ * @param array $args settings field args.
229
  */
230
+ public function callback_checkbox( $args ) {
231
 
232
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
233
 
238
  $html .= sprintf( '%1$s</label>', $args['desc'] );
239
  $html .= '</fieldset>';
240
 
241
+ echo $html; // @codingStandardsIgnoreLine.
242
  }
243
 
244
  /**
245
  * Displays a multicheckbox a settings field
246
  *
247
+ * @param array $args settings field args.
248
  */
249
+ public function callback_multicheck( $args ) {
250
 
251
  $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
252
  $html = '<fieldset>';
261
  $html .= $this->get_field_description( $args );
262
  $html .= '</fieldset>';
263
 
264
+ echo $html; // @codingStandardsIgnoreLine.
265
  }
266
 
267
  /**
268
  * Displays a multicheckbox a settings field
269
  *
270
+ * @param array $args settings field args.
271
  */
272
+ public function callback_radio( $args ) {
273
 
274
  $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
275
  $html = '<fieldset>';
283
  $html .= $this->get_field_description( $args );
284
  $html .= '</fieldset>';
285
 
286
+ echo $html; // @codingStandardsIgnoreLine.
287
  }
288
 
289
  /**
290
  * Displays a selectbox for a settings field
291
  *
292
+ * @param array $args settings field args.
293
  */
294
+ public function callback_select( $args ) {
295
 
296
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
297
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
304
  $html .= sprintf( '</select>' );
305
  $html .= $this->get_field_description( $args );
306
 
307
+ echo $html; // @codingStandardsIgnoreLine.
308
  }
309
 
310
  /**
311
  * Displays a textarea for a settings field
312
  *
313
+ * @param array $args settings field args.
314
  */
315
+ public function callback_textarea( $args ) {
316
 
317
  $value = esc_textarea( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
318
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
321
  $html = sprintf( '<textarea rows="5" cols="100" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]"%4$s>%5$s</textarea>', $size, $args['section'], $args['id'], $placeholder, $value );
322
  $html .= $this->get_field_description( $args );
323
 
324
+ echo $html; // @codingStandardsIgnoreLine.
325
  }
326
 
327
  /**
328
  * Displays a textarea for a settings field
329
  *
330
+ * @param array $args settings field args.
 
331
  */
332
+ public function callback_html( $args ) {
333
+ echo $this->get_field_description( $args ); // @codingStandardsIgnoreLine.
334
  }
335
 
336
  /**
337
  * Displays a rich text textarea for a settings field
338
  *
339
+ * @param array $args settings field args.
340
  */
341
+ public function callback_wysiwyg( $args ) {
342
 
343
  $value = $this->get_option( $args['id'], $args['section'], $args['std'] );
344
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : '500px';
345
 
346
+ echo '<div style="max-width: ' . $size . ';">'; // @codingStandardsIgnoreLine.
347
 
348
  $editor_settings = array(
349
  'teeny' => true,
359
 
360
  echo '</div>';
361
 
362
+ echo $this->get_field_description( $args ); // @codingStandardsIgnoreLine.
363
  }
364
 
365
  /**
366
  * Displays a file upload field for a settings field
367
  *
368
+ * @param array $args settings field args.
369
  */
370
+ public function callback_file( $args ) {
371
 
372
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
373
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
378
  $html .= '<input type="button" class="button wpsa-browse" value="' . $label . '" />';
379
  $html .= $this->get_field_description( $args );
380
 
381
+ echo $html; // @codingStandardsIgnoreLine.
382
  }
383
 
384
  /**
385
  * Displays a password field for a settings field
386
  *
387
+ * @param array $args settings field args.
388
  */
389
+ public function callback_password( $args ) {
390
 
391
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
392
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
394
  $html = sprintf( '<input type="password" class="%1$s-text" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s"/>', $size, $args['section'], $args['id'], $value );
395
  $html .= $this->get_field_description( $args );
396
 
397
+ echo $html; // @codingStandardsIgnoreLine.
398
  }
399
 
400
  /**
401
  * Displays a color picker field for a settings field
402
  *
403
+ * @param array $args settings field args.
404
  */
405
+ public function callback_color( $args ) {
406
 
407
  $value = esc_attr( $this->get_option( $args['id'], $args['section'], $args['std'] ) );
408
  $size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
410
  $html = sprintf( '<input type="text" class="%1$s-text wp-color-picker-field" id="%2$s[%3$s]" name="%2$s[%3$s]" value="%4$s" data-default-color="%5$s" />', $size, $args['section'], $args['id'], $value, $args['std'] );
411
  $html .= $this->get_field_description( $args );
412
 
413
+ echo $html; // @codingStandardsIgnoreLine.
414
  }
415
 
416
  /**
417
  * Sanitize callback for Settings API
418
  *
419
+ * @param array $options santize option.
420
  * @return mixed
421
  */
422
+ public function sanitize_options( $options ) {
423
+
424
+ $logger_settings = array();
425
 
426
  if ( ! $options ) {
427
  return $options;
430
  foreach ( $options as $option_slug => $option_value ) {
431
  $sanitize_callback = $this->get_sanitize_callback( $option_slug );
432
 
433
+ // If callback is set, call it.
434
  if ( $sanitize_callback ) {
435
  $options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value );
436
  continue;
437
  }
438
+
439
+ $logger_settings[ 'is_using_' . $option_slug ] = !empty( trim( $option_value ) ) ? true : false;
440
+
441
  }
442
 
443
+ update_option( 'wpheaderandfooter_basics_logger', $logger_settings );
444
+
445
  return $options;
446
  }
447
 
448
  /**
449
  * Get sanitization callback for given option slug
450
  *
451
+ * @param string $slug option slug.
452
  *
453
  * @return mixed string or bool false
454
  */
455
+ public function get_sanitize_callback( $slug = '' ) {
456
  if ( empty( $slug ) ) {
457
  return false;
458
  }
459
 
460
+ // Iterate over registered fields and see if we can find proper callback.
461
  foreach ( $this->settings_fields as $section => $options ) {
462
  foreach ( $options as $option ) {
463
+ if ( $option['name'] !== $slug ) {
464
  continue;
465
  }
466
 
467
+ // Return the callback name.
468
  return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false;
469
  }
470
  }
475
  /**
476
  * Get the value of a settings field
477
  *
478
+ * @param string $option settings field name.
479
+ * @param string $section the section name this field belongs to.
480
+ * @param string $default default text if it's not found.
481
+ * @return string $default the default text if it's not found or settings field name.
482
  */
483
+ public function get_option( $option, $section, $default = '' ) {
484
 
485
  $options = get_option( $section );
486
 
496
  *
497
  * Shows all the settings section labels as tab
498
  */
499
+ public function show_navigation() {
500
  $html = '<h2 class="nav-tab-wrapper">';
501
 
502
  $count = count( $this->settings_sections );
503
 
 
 
 
 
 
504
  foreach ( $this->settings_sections as $tab ) {
505
  $html .= sprintf( '<a href="#%1$s" class="nav-tab" id="%1$s-tab">%2$s</a>', $tab['id'], $tab['title'] );
506
  }
507
 
508
  $html .= '</h2>';
509
 
510
+ echo $html; // @codingStandardsIgnoreLine.
511
  }
512
 
513
  /**
515
  *
516
  * This function displays every sections in a different form
517
  */
518
+ public function show_forms() {
519
  ?>
520
  <div class="header-and-footer-setting">
521
  <?php foreach ( $this->settings_sections as $form ) { ?>
522
+ <div id="<?php echo esc_attr( $form['id'] ); ?>" class="group" style="display: none;">
523
  <form method="post" action="options.php">
524
  <?php
525
  do_action( 'wsa_form_top_' . $form['id'], $form );
566
  <ul class="plugins_lists">
567
  <li>
568
  <a href="https://wpbrigade.com/wordpress/plugins/loginpress-pro/?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" data-count="none" target="_blank" title="<?php esc_html_e( 'Customize your login screen', 'wp-headers-and-footers' ); ?>">
569
+ <?php esc_html_e( 'LoginPress - Login Customizer', 'wp-headers-and-footers' ); ?>
570
  </a>
571
  </li>
572
 
573
  <li>
574
  <a href="https://analytify.io/ref/73/?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" target="_blank" title="<?php esc_html_e( 'Share with your facebook friends about this awesome plugin.', 'wp-headers-and-footers' ); ?>">
575
+ <?php esc_html_e( 'Google Analytics by Analytify', 'wp-headers-and-footers' ); ?>
576
  </a>
577
  </li>
578
 
579
  <li>
580
  <a href="https://simplesocialbuttons.com?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" target="_blank" title="<?php esc_html_e( 'Socialize your Website', 'wp-headers-and-footers' ); ?>">
581
+ <?php esc_html_e( 'Simple Social Buttons', 'wp-headers-and-footers' ); ?>
582
  </a>
583
  </li>
584
+ <li>
585
  <a href="http://wpbrigade.com/recommend/maintenance-mode?utm_source=wp-headers-and-footers&amp;utm_medium=sidebar&amp;utm_campaign=pro-upgrade" target="_blank" title="<?php esc_html_e( 'Socialize your Website', 'wp-headers-and-footers' ); ?>">
586
+ <?php esc_html_e( 'Under Construction & Maintenance mode', 'wp-headers-and-footers' ); ?>
587
  </a>
588
  </li>
589
  </ul>
598
  *
599
  * This code uses localstorage for displaying active tabs
600
  */
601
+ public function script() {
602
  ?>
603
  <script>
604
  jQuery(document).ready(function($) {
670
  });
671
  </script>
672
  <?php
673
+ $this->style_fix();
674
  }
675
 
676
+ /**
677
+ * The style fix if WP version is less than 5.8
678
+ */
679
+ public function style_fix() {
680
  global $wp_version;
681
 
682
  if ( version_compare( $wp_version, '3.8', '<=' ) ) :
691
  }
692
 
693
  /**
694
+ * Get Section Description
695
+ *
696
+ * @param string $desc The section description.
697
+ *
698
+ * @since 1.2.0
699
+ */
700
+ public function get_description( $desc ) {
701
  return $desc;
702
  }
703
 
704
  /**
705
+ * Prints out all settings sections added to a particular settings page
706
+ *
707
+ * @param string $page the page.
708
+ * @since 1.2.1
709
+ */
710
+ public function do_settings_sections( $page ) {
711
  global $wp_settings_sections, $wp_settings_fields;
712
 
713
+ if ( ! isset( $wp_settings_sections ) || ! isset( $wp_settings_sections[ $page ] ) ) {
714
+ return;
715
+ }
716
 
717
+ foreach ( (array) $wp_settings_sections[ $page ] as $section ) {
718
+ echo "<h3>{$section['title']}</h3>\n"; // @codingStandardsIgnoreLine.
719
+ echo $section['callback']; // @codingStandardsIgnoreLine.
720
+ if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) {
721
+ continue;
722
+ }
723
  echo '<table class="form-table">';
724
+ do_settings_fields( $page, $section['id'] );
725
  echo '</table>';
726
  }
727
  }
classes/class-setup.php CHANGED
@@ -2,13 +2,27 @@
2
 
3
  /**
4
  * WordPress Header and Footer Setup
 
 
5
  */
 
6
  if ( ! class_exists( 'WPHeaderAndFooter_Setting' ) ) :
 
 
 
7
  class WPHeaderAndFooter_Setting {
8
 
 
 
 
 
 
9
  private $settings_api;
10
 
11
- function __construct() {
 
 
 
12
 
13
  include_once WPHEADERANDFOOTER_DIR_PATH . 'classes/class-settings-api.php';
14
  $this->settings_api = new WPHeaderAndFooter_Settings_API();
@@ -17,25 +31,35 @@ if ( ! class_exists( 'WPHeaderAndFooter_Setting' ) ) :
17
  add_action( 'admin_menu', array( $this, 'register_options_page' ) );
18
  }
19
 
20
- function admin_init() {
 
 
 
21
 
22
- // set the settings
23
  $this->settings_api->set_sections( $this->get_settings_sections() );
24
  $this->settings_api->set_fields( $this->get_settings_fields() );
25
 
26
- // initialize settings
27
  $this->settings_api->admin_init();
28
  }
29
 
30
  /**
31
  * Register the plugin settings panel
 
 
32
  */
33
- function register_options_page() {
34
 
35
  add_submenu_page( 'options-general.php', __( 'WP Headers and Footers', 'wp-headers-and-footers' ), __( 'WP Headers and Footers', 'wp-headers-and-footers' ), 'manage_options', 'wp-headers-and-footers', array( $this, 'wp_header_and_footer_callback' ) );
36
  }
37
 
38
- function get_settings_sections() {
 
 
 
 
 
39
  $sections = array(
40
  array(
41
  'id' => 'wpheaderandfooter_basics',
@@ -51,27 +75,30 @@ if ( ! class_exists( 'WPHeaderAndFooter_Setting' ) ) :
51
  *
52
  * @since 1.0.0
53
  * @version 1.2.3
54
- *
55
  * @return array settings fields
56
  */
57
- function get_settings_fields() {
58
  $settings_fields = array(
59
  'wpheaderandfooter_basics' => array(
60
  array(
61
  'name' => 'wp_header_textarea',
62
  'label' => __( 'Scripts in Header', 'wp-headers-and-footers' ),
 
63
  'desc' => sprintf( __( 'These scripts will be printed in the %1$s section.', 'wp-headers-and-footers' ), '&#60head&#62' ),
64
  'type' => 'textarea',
65
  ),
66
  array(
67
  'name' => 'wp_body_textarea',
68
  'label' => __( 'Scripts in Body', 'wp-headers-and-footers' ),
 
69
  'desc' => sprintf( __( 'These scripts will be printed below the %1$s tag.', 'wp-headers-and-footers' ), '&#60body&#62' ),
70
  'type' => 'textarea',
71
  ),
72
  array(
73
  'name' => 'wp_footer_textarea',
74
  'label' => __( 'Scripts in Footer', 'wp-headers-and-footers' ),
 
75
  'desc' => sprintf( __( 'These scripts will be printed below the %1$s tag.', 'wp-headers-and-footers' ), '&#60footer&#62' ),
76
  'type' => 'textarea',
77
  ),
@@ -81,7 +108,12 @@ if ( ! class_exists( 'WPHeaderAndFooter_Setting' ) ) :
81
  return $settings_fields;
82
  }
83
 
84
- function wp_header_and_footer_callback() {
 
 
 
 
 
85
  echo '<div class="wrap wp-headers-and-footers">';
86
 
87
  $this->settings_api->show_navigation();
@@ -95,7 +127,7 @@ if ( ! class_exists( 'WPHeaderAndFooter_Setting' ) ) :
95
  *
96
  * @return array page names with key value pairs
97
  */
98
- function get_pages() {
99
  $pages = get_pages();
100
  $pages_options = array();
101
  if ( $pages ) {
2
 
3
  /**
4
  * WordPress Header and Footer Setup
5
+ *
6
+ * @package wp-headers-and-footers
7
  */
8
+
9
  if ( ! class_exists( 'WPHeaderAndFooter_Setting' ) ) :
10
+ /**
11
+ * The WPHeaderAndFooter Settings class
12
+ */
13
  class WPHeaderAndFooter_Setting {
14
 
15
+ /**
16
+ * Settings sections array
17
+ *
18
+ * @var array $settings_api The settings API array.
19
+ */
20
  private $settings_api;
21
 
22
+ /**
23
+ * The constructor of WPHeaderAndFooter Settings class
24
+ */
25
+ public function __construct() {
26
 
27
  include_once WPHEADERANDFOOTER_DIR_PATH . 'classes/class-settings-api.php';
28
  $this->settings_api = new WPHeaderAndFooter_Settings_API();
31
  add_action( 'admin_menu', array( $this, 'register_options_page' ) );
32
  }
33
 
34
+ /**
35
+ * Admin initialize function.
36
+ */
37
+ public function admin_init() {
38
 
39
+ // Set the settings.
40
  $this->settings_api->set_sections( $this->get_settings_sections() );
41
  $this->settings_api->set_fields( $this->get_settings_fields() );
42
 
43
+ // Initialize settings.
44
  $this->settings_api->admin_init();
45
  }
46
 
47
  /**
48
  * Register the plugin settings panel
49
+ *
50
+ * @since 1.1.0
51
  */
52
+ public function register_options_page() {
53
 
54
  add_submenu_page( 'options-general.php', __( 'WP Headers and Footers', 'wp-headers-and-footers' ), __( 'WP Headers and Footers', 'wp-headers-and-footers' ), 'manage_options', 'wp-headers-and-footers', array( $this, 'wp_header_and_footer_callback' ) );
55
  }
56
 
57
+ /**
58
+ * The settings section.
59
+ *
60
+ * @since 1.1.0
61
+ */
62
+ public function get_settings_sections() {
63
  $sections = array(
64
  array(
65
  'id' => 'wpheaderandfooter_basics',
75
  *
76
  * @since 1.0.0
77
  * @version 1.2.3
78
+ *
79
  * @return array settings fields
80
  */
81
+ public function get_settings_fields() {
82
  $settings_fields = array(
83
  'wpheaderandfooter_basics' => array(
84
  array(
85
  'name' => 'wp_header_textarea',
86
  'label' => __( 'Scripts in Header', 'wp-headers-and-footers' ),
87
+ /* Translators: The header textarea description */
88
  'desc' => sprintf( __( 'These scripts will be printed in the %1$s section.', 'wp-headers-and-footers' ), '&#60head&#62' ),
89
  'type' => 'textarea',
90
  ),
91
  array(
92
  'name' => 'wp_body_textarea',
93
  'label' => __( 'Scripts in Body', 'wp-headers-and-footers' ),
94
+ /* Translators: The body textarea description */
95
  'desc' => sprintf( __( 'These scripts will be printed below the %1$s tag.', 'wp-headers-and-footers' ), '&#60body&#62' ),
96
  'type' => 'textarea',
97
  ),
98
  array(
99
  'name' => 'wp_footer_textarea',
100
  'label' => __( 'Scripts in Footer', 'wp-headers-and-footers' ),
101
+ /* Translators: The footer textarea description */
102
  'desc' => sprintf( __( 'These scripts will be printed below the %1$s tag.', 'wp-headers-and-footers' ), '&#60footer&#62' ),
103
  'type' => 'textarea',
104
  ),
108
  return $settings_fields;
109
  }
110
 
111
+ /**
112
+ * The header and footer settings section and forms callback
113
+ *
114
+ * @since 1.1.0
115
+ */
116
+ public function wp_header_and_footer_callback() {
117
  echo '<div class="wrap wp-headers-and-footers">';
118
 
119
  $this->settings_api->show_navigation();
127
  *
128
  * @return array page names with key value pairs
129
  */
130
+ public function get_pages() {
131
  $pages = get_pages();
132
  $pages_options = array();
133
  if ( $pages ) {
classes/plugin-meta.php CHANGED
@@ -1,58 +1,71 @@
1
  <?php
2
  /**
3
  * WordPress Header and Footer plugins meta
 
 
4
  * @since 1.2.1
5
  */
6
 
7
  if ( ! class_exists( 'WPHeaderAndFooter_Plugin_Meta' ) ) :
8
-
 
 
 
9
  class WPHeaderAndFooter_Plugin_Meta {
10
 
11
- function __construct() {
12
-
13
- add_filter( 'plugin_row_meta', array( $this, '_row_meta'), 10, 2 );
14
- add_action( 'plugin_action_links', array( $this, '_action_links' ), 10, 2 );
 
 
 
 
 
15
  }
16
 
17
  /**
18
- * Add rating icon on plugins page.
19
- *
20
- * @since 1.2.1
21
- */
22
-
23
- public function _row_meta( $meta_fields, $file ) {
 
24
 
25
- if ( $file != 'wp-headers-and-footers/wp-headers-and-footers.php' ) {
26
 
27
- return $meta_fields;
28
- }
29
 
30
- echo "<style>.wp-headers-and-footers-rate-stars { display: inline-block; color: #ffb900; position: relative; top: 3px; }.wp-headers-and-footers-rate-stars svg{ fill:#ffb900; } .wp-headers-and-footers-rate-stars svg:hover{ fill:#ffb900 } .wp-headers-and-footers-rate-stars svg:hover ~ svg{ fill:none; } </style>";
31
 
32
- $plugin_rate = "https://wordpress.org/support/plugin/wp-headers-and-footers/reviews/?rate=5#new-post";
33
- $plugin_filter = "https://wordpress.org/support/plugin/wp-headers-and-footers/reviews/?filter=5";
34
- $svg_xmlns = "https://www.w3.org/2000/svg";
35
- $svg_icon = '';
36
 
37
- for ( $i = 0; $i < 5; $i++ ) {
38
- $svg_icon .= "<svg xmlns='" . esc_url( $svg_xmlns ) . "' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>";
39
- }
40
 
41
- // Set icon for thumbsup.
42
- $meta_fields[] = '<a href="' . esc_url( $plugin_filter ) . '" target="_blank"><span class="dashicons dashicons-thumbs-up"></span>' . __( 'Vote!', 'wp-headers-and-footers' ) . '</a>';
43
 
44
- // Set icon for 5-star reviews. v1.1.22
45
- $meta_fields[] = "<a href='" . esc_url( $plugin_rate ) . "' target='_blank' title='" . esc_html__( 'Rate', 'wp-headers-and-footers' ) . "'><i class='wp-headers-and-footers-rate-stars'>" . $svg_icon . "</i></a>";
46
 
47
- return $meta_fields;
48
  }
49
-
50
  /**
51
  * Add a link to the settings page to the plugins list
52
  *
 
 
53
  * @since 1.2.1
54
  */
55
- public function _action_links( $links, $file ) {
56
 
57
  static $this_plugin;
58
 
@@ -61,8 +74,8 @@ if ( ! class_exists( 'WPHeaderAndFooter_Plugin_Meta' ) ) :
61
  $this_plugin = 'wp-headers-and-footers/wp-headers-and-footers.php';
62
  }
63
 
64
- if ( $file == $this_plugin ) {
65
-
66
  $settings_link = sprintf( esc_html__( '%1$s Settings %2$s', 'wp-headers-and-footers' ), '<a href="' . admin_url( 'options-general.php?page=wp-headers-and-footers' ) . '">', '</a>' );
67
 
68
  array_unshift( $links, $settings_link );
@@ -74,4 +87,4 @@ if ( ! class_exists( 'WPHeaderAndFooter_Plugin_Meta' ) ) :
74
  }
75
  endif;
76
 
77
- new WPHeaderAndFooter_Plugin_Meta();
1
  <?php
2
  /**
3
  * WordPress Header and Footer plugins meta
4
+ *
5
+ * @package wp-headers-and-footers
6
  * @since 1.2.1
7
  */
8
 
9
  if ( ! class_exists( 'WPHeaderAndFooter_Plugin_Meta' ) ) :
10
+
11
+ /**
12
+ * The Meta class of Header and Footer
13
+ */
14
  class WPHeaderAndFooter_Plugin_Meta {
15
 
16
+ /**
17
+ * The class constructor
18
+ *
19
+ * @since 1.0.0.
20
+ */
21
+ public function __construct() {
22
+
23
+ add_filter( 'plugin_row_meta', array( $this, 'row_meta' ), 10, 2 );
24
+ add_action( 'plugin_action_links', array( $this, 'action_links' ), 10, 2 );
25
  }
26
 
27
  /**
28
+ * Add rating icon on plugins page.
29
+ *
30
+ * @param string $meta_fields the meta field.
31
+ * @param string $file the file name.
32
+ * @since 1.2.1
33
+ */
34
+ public function row_meta( $meta_fields, $file ) {
35
 
36
+ if ( 'wp-headers-and-footers/wp-headers-and-footers.php' !== $file ) {
37
 
38
+ return $meta_fields;
39
+ }
40
 
41
+ echo '<style>.wp-headers-and-footers-rate-stars { display: inline-block; color: #ffb900; position: relative; top: 3px; }.wp-headers-and-footers-rate-stars svg{ fill:#ffb900; } .wp-headers-and-footers-rate-stars svg:hover{ fill:#ffb900 } .wp-headers-and-footers-rate-stars svg:hover ~ svg{ fill:none; } </style>';
42
 
43
+ $plugin_rate = 'https://wordpress.org/support/plugin/wp-headers-and-footers/reviews/?rate=5#new-post';
44
+ $plugin_filter = 'https://wordpress.org/support/plugin/wp-headers-and-footers/reviews/?filter=5';
45
+ $svg_xmlns = 'https://www.w3.org/2000/svg';
46
+ $svg_icon = '';
47
 
48
+ for ( $i = 0; $i < 5; $i++ ) {
49
+ $svg_icon .= "<svg xmlns='" . esc_url( $svg_xmlns ) . "' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>";
50
+ }
51
 
52
+ // Set icon for thumbsup.
53
+ $meta_fields[] = '<a href="' . esc_url( $plugin_filter ) . '" target="_blank"><span class="dashicons dashicons-thumbs-up"></span>' . __( 'Vote!', 'wp-headers-and-footers' ) . '</a>';
54
 
55
+ // Set icon for 5-star reviews. v1.1.22.
56
+ $meta_fields[] = "<a href='" . esc_url( $plugin_rate ) . "' target='_blank' title='" . esc_html__( 'Rate', 'wp-headers-and-footers' ) . "'><i class='wp-headers-and-footers-rate-stars'>" . $svg_icon . '</i></a>';
57
 
58
+ return $meta_fields;
59
  }
60
+
61
  /**
62
  * Add a link to the settings page to the plugins list
63
  *
64
+ * @param URL $links the action link.
65
+ * @param string $file the file name.
66
  * @since 1.2.1
67
  */
68
+ public function action_links( $links, $file ) {
69
 
70
  static $this_plugin;
71
 
74
  $this_plugin = 'wp-headers-and-footers/wp-headers-and-footers.php';
75
  }
76
 
77
+ if ( $file === $this_plugin ) {
78
+ /* Translators: Settings tab */
79
  $settings_link = sprintf( esc_html__( '%1$s Settings %2$s', 'wp-headers-and-footers' ), '<a href="' . admin_url( 'options-general.php?page=wp-headers-and-footers' ) . '">', '</a>' );
80
 
81
  array_unshift( $links, $settings_link );
87
  }
88
  endif;
89
 
90
+ new WPHeaderAndFooter_Plugin_Meta();
languages/wp-header-and-footer.pot DELETED
@@ -1,101 +0,0 @@
1
- # Copyright (C) 2020 WPBrigade
2
- # This file is distributed under the same license as the WP Headers and Footers plugin.
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: 1.1.0\n"
6
- "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-header-and-footer\n"
7
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
8
- "Language-Team: LANGUAGE <LL@li.org>\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "POT-Creation-Date: 2020-02-21T10:55:12+00:00\n"
13
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
- "X-Generator: WP-CLI 2.4.0\n"
15
- "X-Domain: wp-header-and-footer\n"
16
-
17
- #. Plugin Name of the plugin
18
- #: classes/class-setup.php:35
19
- msgid "WP Headers and Footers"
20
- msgstr ""
21
-
22
- #. Plugin URI of the plugin
23
- msgid "http://www.WPBrigade.com/wordpress/plugins/wp-headers-and-footers/"
24
- msgstr ""
25
-
26
- #. Description of the plugin
27
- msgid "Allows you to insert code or text in the header or footer of your WordPress site."
28
- msgstr ""
29
-
30
- #. Author of the plugin
31
- msgid "WPBrigade"
32
- msgstr ""
33
-
34
- #. Author URI of the plugin
35
- msgid "https://www.WPBrigade.com/"
36
- msgstr ""
37
-
38
- #: classes/class-settings-api.php:525
39
- msgid "Spread the Word"
40
- msgstr ""
41
-
42
- #: classes/class-settings-api.php:528
43
- msgid "Post to Twitter Now"
44
- msgstr ""
45
-
46
- #: classes/class-settings-api.php:528
47
- msgid "Share on Twitter"
48
- msgstr ""
49
-
50
- #: classes/class-settings-api.php:531
51
- msgid "Share with your facebook friends about this awesome plugin"
52
- msgstr ""
53
-
54
- #: classes/class-settings-api.php:531
55
- msgid "Share on Facebook"
56
- msgstr ""
57
-
58
- #: classes/class-settings-api.php:535
59
- msgid "Rate on WordPress.org"
60
- msgstr ""
61
-
62
- #: classes/class-settings-api.php:541
63
- msgid "Recommended Plugins"
64
- msgstr ""
65
-
66
- #: classes/class-settings-api.php:545
67
- msgid "Customize your login screen"
68
- msgstr ""
69
-
70
- #: classes/class-settings-api.php:549
71
- msgid "Share with your facebook friends about this awesome plugin."
72
- msgstr ""
73
-
74
- #: classes/class-settings-api.php:554
75
- #: classes/class-settings-api.php:558
76
- msgid "Socialize your Website"
77
- msgstr ""
78
-
79
- #: classes/class-setup.php:42
80
- msgid "Settings"
81
- msgstr ""
82
-
83
- #: classes/class-setup.php:43
84
- msgid "WP Headers and Footers."
85
- msgstr ""
86
-
87
- #: classes/class-setup.php:59
88
- msgid "Scripts in Header"
89
- msgstr ""
90
-
91
- #: classes/class-setup.php:60
92
- msgid "These scripts will be printed in the %1$s%2$s%3$s section."
93
- msgstr ""
94
-
95
- #: classes/class-setup.php:65
96
- msgid "Scripts in Footer"
97
- msgstr ""
98
-
99
- #: classes/class-setup.php:66
100
- msgid "These scripts will be printed above the %1$s%2$s%3$s tag."
101
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/wpb-sdk/includes/wpb-sdk-logger.php ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Logger responsible for gathering user logs and send.
4
+ * In effort to provide better customer experience.
5
+ *
6
+ * @package WPB_SDK
7
+ * @since 1.4.0
8
+ */
9
+
10
+ namespace WPHeaderAndFooter_SDK;
11
+
12
+ /**
13
+ * Class responsible for logs data collection.
14
+ */
15
+ class Logger {
16
+
17
+ /**
18
+ * Contains products data for logging.
19
+ *
20
+ * @var array
21
+ */
22
+ private static $product_data;
23
+
24
+ /**
25
+ * Contains products that have a Pro version.
26
+ *
27
+ * @var array
28
+ */
29
+ private static $has_pro_version = array( 'wp-analytify', 'loginpress', 'simple-social-buttons' );
30
+
31
+ /**
32
+ * Class constructor.
33
+ *
34
+ * @param array $product_data variable.
35
+ * @return void
36
+ */
37
+ public function __construct( $product_data ) {
38
+
39
+ self::$product_data = $product_data;
40
+ $this->hooks();
41
+ }
42
+
43
+ /**
44
+ * Call wp hooks to initialize logger actions.
45
+ *
46
+ * @return void
47
+ */
48
+ public function hooks() {
49
+
50
+ add_action( 'init', array( $this, 'set_logs_schedule' ) );
51
+ add_action( 'wpb_logger_cron_' . self::$product_data['slug'], array( $this, 'log_plugin' ) );
52
+ add_action( 'admin_footer', array( $this, 'deactivation_model' ) );
53
+ add_action( 'wp_ajax_wpb_sdk_' . self::$product_data['slug'] . '_deactivation', array( $this, 'ajax_deactivation' ) );
54
+
55
+ register_activation_hook( self::$product_data['path'], array( __CLASS__, 'log_activation' ) );
56
+ register_deactivation_hook( self::$product_data['path'], array( __CLASS__, 'product_deactivation' ) );
57
+ register_uninstall_hook( self::$product_data['path'], array( __CLASS__, 'log_uninstallation' ) );
58
+ }
59
+
60
+ /**
61
+ * Set logs schedule.
62
+ */
63
+ public function set_logs_schedule() {
64
+
65
+ if ( ! wp_next_scheduled( 'wpb_logger_cron_' . self::$product_data['slug'] ) ) {
66
+ wp_schedule_event( time(), 'weekly', 'wpb_logger_cron_' . self::$product_data['slug'] );
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Add deactivation model.
72
+ *
73
+ * @return void
74
+ */
75
+ public function deactivation_model() {
76
+
77
+ if ( function_exists( 'get_current_screen' ) ) {
78
+
79
+ $screen = get_current_screen();
80
+
81
+ if ( 'plugins.php' === $screen->parent_file ) {
82
+
83
+ $product_slug = self::$product_data['slug'];
84
+ $product_name = self::$product_data['name'];
85
+
86
+ $has_pro_version = ( in_array( $product_slug, self::$has_pro_version ) ) ? true : false;
87
+
88
+ include dirname( __DIR__ ) . '/views/wpb-sdk-deactivate-form.php';
89
+ }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Ajax callback when product deactivated.
95
+ * Shows deactivation model.
96
+ *
97
+ * @return void
98
+ */
99
+ public function ajax_deactivation() {
100
+
101
+ if ( isset( $_POST['nonce'] ) && empty( $_POST['nonce'] ) ) {
102
+ return;
103
+ }
104
+
105
+ $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ) );
106
+ $verify_nonce = wp_verify_nonce( $nonce, 'deactivate-plugin_' . plugin_basename( self::$product_data['path'] ) );
107
+
108
+ if ( ! $verify_nonce ) {
109
+ return;
110
+ }
111
+
112
+ $this->log_deactivation();
113
+
114
+ wp_die();
115
+ }
116
+
117
+ /**
118
+ * Send plugin logs on cron.
119
+ *
120
+ * @return $wpb_sdk_track SDK track record.
121
+ */
122
+ public function log_plugin() {
123
+
124
+ /**
125
+ * Adding a activation check to prevent 2 hits from getting send on activation
126
+ */
127
+ if ( get_transient( 'wpb_logger_cron_' . self::$product_data['slug'] ) ) {
128
+ return;
129
+ }
130
+
131
+ $logs_data = array_merge(
132
+ self::get_logs_data(),
133
+ array(
134
+ 'explicit_logs' => array(
135
+ 'action' => 'weekly',
136
+ ),
137
+ )
138
+ );
139
+
140
+ $wpb_sdk_track = new Track( $logs_data );
141
+ $wpb_sdk_track->send();
142
+ }
143
+
144
+ /**
145
+ * Send logs when plugin is activated.
146
+ */
147
+ public static function log_activation() {
148
+
149
+ /**
150
+ * Setting a transient to add a check in the weekly track report
151
+ */
152
+ set_transient( 'wpb_logger_cron_' . self::$product_data['slug'], true, 60 );
153
+
154
+ $logs_data = array_merge(
155
+ self::get_logs_data(),
156
+ array(
157
+ 'explicit_logs' => array(
158
+ 'action' => 'activate',
159
+ ),
160
+ )
161
+ );
162
+
163
+ $wpb_sdk_track = new Track( $logs_data );
164
+ $wpb_sdk_track->send();
165
+ }
166
+
167
+ /**
168
+ * Send logs when plugin is deactivated.
169
+ */
170
+ public function log_deactivation() {
171
+ $reason = isset( $_POST['reason'] ) ? $_POST['reason'] : '';
172
+ $reason_detail = isset( $_POST['reason_detail'] ) ? $_POST['reason_detail'] : '';
173
+
174
+ $logs_data = array_merge(
175
+ self::get_logs_data(),
176
+ array(
177
+ 'explicit_logs' => array(
178
+ 'action' => 'deactivate',
179
+ 'reason' => sanitize_text_field( wp_unslash( $reason ) ),
180
+ 'reason_detail' => sanitize_text_field( wp_unslash( $reason_detail ) ),
181
+ ),
182
+ )
183
+ );
184
+
185
+ $wpb_sdk_track = new Track( $logs_data );
186
+ $wpb_sdk_track->send();
187
+ }
188
+
189
+ /**
190
+ * Remove cron schedules on deactivation.
191
+ */
192
+ public static function product_deactivation() {
193
+
194
+ wp_clear_scheduled_hook( 'wpb_logger_cron_' . self::$product_data['slug'] );
195
+ }
196
+
197
+ /**
198
+ * Send logs when plugin is uninstalled.
199
+ */
200
+ public static function log_uninstallation() {
201
+
202
+ $logs_data = array_merge(
203
+ self::get_logs_data(),
204
+ array(
205
+ 'explicit_logs' => array(
206
+ 'action' => 'uninstall',
207
+ ),
208
+ )
209
+ );
210
+
211
+ $wpb_sdk_track = new Track( $logs_data );
212
+ $wpb_sdk_track->send();
213
+ }
214
+
215
+ /**
216
+ * Collect all data for logging.
217
+ *
218
+ * @return array
219
+ */
220
+ private static function get_logs_data() {
221
+
222
+ global $wpdb;
223
+
224
+ $data = array();
225
+ $theme_data = wp_get_theme();
226
+ $curl_version = '';
227
+ $external_http_blocked = '';
228
+ $users_count = '';
229
+
230
+ $admin_users = get_users( array( 'role' => 'Administrator' ) );
231
+ $admin = isset( $admin_users[0] ) ? $admin_users[0]->data : '';
232
+ $admin_meta = ! empty( $admin ) ? get_user_meta( $admin->ID ) : '';
233
+
234
+ if ( ! function_exists( 'get_plugins' ) ) {
235
+ include ABSPATH . '/wp-admin/includes/plugin.php';
236
+ }
237
+
238
+ if ( function_exists( 'count_users' ) ) {
239
+ $users_count = count_users();
240
+ $users_count = isset( $users_count['total_users'] ) ? intval( $users_count['total_users'] ) : '';
241
+ }
242
+
243
+ // Check external http request blocked.
244
+ if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) {
245
+ $external_http_blocked = 'none';
246
+ } else {
247
+ $external_http_blocked = defined( 'WP_ACCESSIBLE_HOSTS' ) ? 'partially (accessible hosts: ' . esc_html( WP_ACCESSIBLE_HOSTS ) . ')' : 'all';
248
+ }
249
+
250
+ // Curl version.
251
+ if ( function_exists( 'curl_init' ) ) {
252
+ $curl = curl_version();
253
+ $curl_version = '(' . $curl['version'] . ' ' . $curl['ssl_version'] . ')';
254
+ }
255
+
256
+ $data['site_info'] = array(
257
+ 'site_url' => site_url(),
258
+ 'home_url' => home_url(),
259
+ );
260
+ $data['site_meta_info'] = array(
261
+ 'is_multisite' => is_multisite(),
262
+ 'multisites' => self::get_multisites(),
263
+ 'php_version' => phpversion(),
264
+ 'wp_version' => get_bloginfo( 'version' ),
265
+ 'server' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '',
266
+ 'timezoneoffset' => date('P'),
267
+ 'ext/mysqli' => ! empty( $wpdb->use_mysqli ) ? true : false,
268
+ 'mysql_version' => empty( $wpdb->use_mysqli ) ? mysql_get_server_info() : mysqli_get_server_info( $wpdb->dbh ),
269
+ 'memory_limit' => ( defined( WP_MEMORY_LIMIT ) ? WP_MEMORY_LIMIT : ini_get( 'memory_limit' ) ) ? ini_get( 'memory_limit' ) : '',
270
+ 'external_http_blocked' => $external_http_blocked,
271
+ 'wp_locale' => get_locale(),
272
+ 'db_charset' => defined( 'DB_CHARSET' ) ? DB_CHARSET : '',
273
+ 'debug_mode' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
274
+ 'wp_max_upload' => size_format( wp_max_upload_size() ),
275
+ 'php_time_limit' => function_exists( 'ini_get' ) ? ini_get( 'max_execution_time' ) : '',
276
+ 'php_error_log' => function_exists( 'ini_get' ) ? ini_get( 'error_log' ) : '',
277
+ 'fsockopen' => function_exists( 'fsockopen' ) ? true : false,
278
+ 'open_ssl' => defined( 'OPENSSL_VERSION_TEXT' ) ? OPENSSL_VERSION_TEXT : '',
279
+ 'curl' => $curl_version,
280
+ 'ip' => self::get_ip(),
281
+ 'user_count' => $users_count,
282
+ 'admin_email' => sanitize_email( get_bloginfo( 'admin_email' ) ),
283
+ 'theme_name' => sanitize_text_field( $theme_data->Name ),
284
+ 'theme_version' => sanitize_text_field( $theme_data->Version ),
285
+ );
286
+ $data['site_plugins_info'] = self::get_plugins();
287
+ $data['user_info'] = array(
288
+ 'user_email' => ! empty( $admin ) ? sanitize_email( $admin->user_email ) : '',
289
+ 'user_nickname' => ! empty( $admin ) ? sanitize_text_field( $admin->user_nicename ) : '',
290
+ 'user_firstname' => isset( $admin_meta['first_name'][0] ) ? sanitize_text_field( $admin_meta['first_name'][0] ) : '',
291
+ 'user_lastname' => isset( $admin_meta['last_name'][0] ) ? sanitize_text_field( $admin_meta['last_name'][0] ) : ''
292
+ );
293
+ $data['product_info'] = self::get_product_data();
294
+ $data['sdk_version'] = '1.0.0';
295
+
296
+ return $data;
297
+ }
298
+
299
+ /**
300
+ * Collect multisite data.
301
+ *
302
+ * @return array
303
+ */
304
+ private static function get_multisites() {
305
+
306
+ if ( ! is_multisite() ) {
307
+ return false;
308
+ }
309
+
310
+ $sites_info = array();
311
+ $sites = get_sites();
312
+
313
+ foreach ( $sites as $site ) {
314
+ $sites_info[ $site->blog_id ] = array(
315
+ 'name' => get_blog_details( $site->blog_id )->blogname,
316
+ 'domain' => $site->domain,
317
+ 'path' => $site->path,
318
+ );
319
+ }
320
+
321
+ return $sites_info;
322
+ }
323
+
324
+ /**
325
+ * Collect plugins information: Active/Inactive plugins.
326
+ *
327
+ * @return string
328
+ */
329
+ private static function get_plugins() {
330
+
331
+ $plugins = array_keys( get_plugins() );
332
+ $active_plugins = get_option( 'active_plugins', array() );
333
+
334
+ foreach ( $plugins as $key => $plugin ) {
335
+ if ( in_array( $plugin, $active_plugins ) ) {
336
+ // Remove active plugins from list.
337
+ unset( $plugins[ $key ] );
338
+ }
339
+ }
340
+
341
+ return wp_json_encode(
342
+ array(
343
+ 'active' => $active_plugins,
344
+ 'inactive' => $plugins,
345
+ )
346
+ );
347
+ }
348
+
349
+ /**
350
+ * Get user IP information.
351
+ *
352
+ * @return string|null
353
+ */
354
+ private static function get_ip() {
355
+
356
+ $fields = array(
357
+ 'HTTP_CF_CONNECTING_IP',
358
+ 'HTTP_CLIENT_IP',
359
+ 'HTTP_X_FORWARDED_FOR',
360
+ 'HTTP_X_FORWARDED',
361
+ 'HTTP_FORWARDED_FOR',
362
+ 'HTTP_FORWARDED',
363
+ 'REMOTE_ADDR',
364
+ );
365
+
366
+ foreach ( $fields as $ip_field ) {
367
+ if ( ! empty( $_SERVER[ $ip_field ] ) ) {
368
+ return $_SERVER[ $ip_field ];
369
+ }
370
+ }
371
+
372
+ return null;
373
+ }
374
+
375
+ /**
376
+ * Get product data.
377
+ *
378
+ * @return array
379
+ */
380
+ private static function get_product_data() {
381
+
382
+ $product_data = self::$product_data;
383
+ $product_settings = array();
384
+
385
+ // Pull settings data from db.
386
+ foreach ( $product_data['settings'] as $option_name => $default_value ) {
387
+ $get_option = get_option( $option_name );
388
+ $product_settings[ $option_name ] = ! empty( $get_option ) ? $get_option : $default_value;
389
+ }
390
+
391
+ $product_data['settings'] = wp_json_encode( $product_settings );
392
+
393
+ return $product_data;
394
+ }
395
+ }
lib/wpb-sdk/includes/wpb-sdk-track.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Send tracking data (logs) to WPB server.
4
+ *
5
+ * @package WPB_SDK
6
+ * @since 1.4.0
7
+ */
8
+
9
+ namespace WPHeaderAndFooter_SDK;
10
+
11
+ /**
12
+ * Class responsible for sending logs data.
13
+ */
14
+ class Track {
15
+
16
+ /**
17
+ * The logger data to be send.
18
+ *
19
+ * @var array
20
+ */
21
+ private $payload = array();
22
+
23
+ /**
24
+ * Logger tracking endpoint.
25
+ *
26
+ * @var string
27
+ */
28
+ private $tracking_endpoint = 'https://app.telemetry.wpbrigade.com/api/logger';
29
+
30
+ /**
31
+ * Class constructor.
32
+ *
33
+ * @param Obj $payload variable.
34
+ *
35
+ * @return void
36
+ */
37
+ public function __construct( $payload ) {
38
+
39
+ $this->payload = $payload;
40
+ }
41
+
42
+ /**
43
+ * Send the logs to the api endpoint.
44
+ *
45
+ * @return object
46
+ */
47
+ public function send() {
48
+
49
+ wp_remote_post(
50
+ $this->tracking_endpoint,
51
+ array(
52
+ 'method' => 'POST',
53
+ 'body' => $this->payload,
54
+ 'timeout' => 5,
55
+ 'headers' => array(),
56
+ )
57
+ );
58
+ }
59
+ }
60
+
lib/wpb-sdk/init.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WPBrigade SDK
4
+ *
5
+ * @package WPB_SDK
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) {
9
+ exit;
10
+ }
11
+
12
+ require_once dirname( __FILE__ ) . '/includes/wpb-sdk-track.php';
13
+ require_once dirname( __FILE__ ) . '/includes/wpb-sdk-logger.php';
lib/wpb-sdk/views/wpb-sdk-deactivate-form.php ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <style>
2
+ .wpb-sdk_deactivation-frm-hidden {
3
+ overflow: hidden;
4
+ }
5
+
6
+ .wpb-sdk_deactivation-frm-popup-overlay .wpb-sdk_deactivation-frm-internal-message {
7
+ margin: 3px 0 3px 22px;
8
+ display: none;
9
+ }
10
+
11
+ .wpb-sdk_deactivation-frm-reason-input {
12
+ margin: 3px 0 3px 22px;
13
+ display: none;
14
+ }
15
+
16
+ .wpb-sdk_deactivation-frm-pro-message {
17
+ margin: 3px 0 3px 22px;
18
+ display: none;
19
+ color: #ed1515;
20
+ font-size: 14px;
21
+ font-weight: 600;
22
+ }
23
+
24
+ .wpb-sdk_deactivation-frm-reason-input input[type="text"] {
25
+ width: 100%;
26
+ display: block;
27
+ }
28
+
29
+ .wpb-sdk_deactivation-frm-popup-overlay {
30
+ background: rgba(0, 0, 0, .8);
31
+ position: fixed;
32
+ top: 0;
33
+ left: 0;
34
+ height: 100%;
35
+ width: 100%;
36
+ z-index: 1000;
37
+ overflow: auto;
38
+ visibility: hidden;
39
+ opacity: 0;
40
+ transition: opacity 0.3s ease-in-out:
41
+ }
42
+
43
+ .wpb-sdk_deactivation-frm-popup-overlay.wpb-sdk_deactivation-frm-active {
44
+ opacity: 1;
45
+ visibility: visible;
46
+ }
47
+
48
+ .wpb-sdk_deactivation-frm-serveypanel {
49
+ width: 600px;
50
+ background: #fff;
51
+ margin: 65px auto 0;
52
+ }
53
+
54
+ .wpb-sdk_deactivation-frm-popup-header {
55
+ background: #f1f1f1;
56
+ padding: 20px;
57
+ border-bottom: 1px solid #ccc;
58
+ }
59
+
60
+ .wpb-sdk_deactivation-frm-popup-header h2 {
61
+ margin: 0;
62
+ }
63
+
64
+ .wpb-sdk_deactivation-frm-popup-body {
65
+ padding: 10px 20px;
66
+ }
67
+
68
+ .wpb-sdk_deactivation-frm-popup-footer {
69
+ background: #f9f3f3;
70
+ padding: 10px 20px;
71
+ border-top: 1px solid #ccc;
72
+ }
73
+
74
+ .wpb-sdk_deactivation-frm-popup-footer:after {
75
+ content: "";
76
+ display: table;
77
+ clear: both;
78
+ }
79
+
80
+ .action-btns {
81
+ float: right;
82
+ }
83
+
84
+ .wpb-sdk_deactivation-frm-anonymous {
85
+ display: none;
86
+ }
87
+
88
+ .attention,
89
+ .error-message {
90
+ color: red;
91
+ font-weight: 600;
92
+ display: none;
93
+ }
94
+
95
+ .wpb-sdk_deactivation-frm-spinner {
96
+ display: none;
97
+ }
98
+
99
+ .wpb-sdk_deactivation-frm-spinner img {
100
+ margin-top: 3px;
101
+ }
102
+ </style>
103
+ <div class="<?php echo $product_slug ?>-deactivate-wrapper">
104
+ <div class="wpb-sdk_deactivation-frm-popup-overlay">
105
+ <div class="wpb-sdk_deactivation-frm-serveypanel">
106
+ <form action="#" method="post" class="wpb-sdk_deactivation-frm-deactivate-form">
107
+
108
+ <div class="wpb-sdk_deactivation-frm-popup-header">
109
+ <h2><?php _e( 'Quick feedback about ' . $product_name, 'ucmm-wpbrigade' ); ?></h2>
110
+ </div>
111
+
112
+ <div class="wpb-sdk_deactivation-frm-popup-body">
113
+
114
+ <h3><?php _e( 'If you have a moment, please let us know why you are deactivating:', 'ucmm-wpbrigade' ); ?></h3>
115
+
116
+ <ul id="wpb-sdk_deactivation-frm-reason-list">
117
+ <?php if ( $has_pro_version ) { ?>
118
+ <li class="wpb-sdk_deactivation-frm-reason wpb-sdk_deactivation-frm-reason-pro" data-input-type="" data-input-placeholder="">
119
+ <label>
120
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="pro">
121
+ </span><span><?php _e( 'I upgraded to ' . $product_name . ' Pro', 'ucmm-wpbrigade' ); ?></span>
122
+ </label>
123
+ <div class="wpb-sdk_deactivation-frm-pro-message">
124
+ <?php _e( 'No need to deactivate this ' . $product_name . ' Core version. Pro version works as an add-on with Core version.', 'ucmm-wpbrigade' ); ?>
125
+ </div>
126
+ </li>
127
+ <?php } ?>
128
+ <li class="wpb-sdk_deactivation-frm-reason" data-input-type="" data-input-placeholder="">
129
+ <label>
130
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="1"></span>
131
+ <span><?php _e( 'I only needed the plugin for a short period', 'ucmm-wpbrigade' ); ?></span>
132
+ </label>
133
+ <div class="wpb-sdk_deactivation-frm-internal-message"></div>
134
+ </li>
135
+ <li class="wpb-sdk_deactivation-frm-reason has-input" data-input-type="textfield">
136
+ <label>
137
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="2"></span>
138
+ <span><?php _e( 'I found a better plugin', 'ucmm-wpbrigade' ); ?></span>
139
+ </label>
140
+ <div class="wpb-sdk_deactivation-frm-internal-message"></div>
141
+ <div class="wpb-sdk_deactivation-frm-reason-input">
142
+ <span class="message error-message"><?php _e( 'Kindly tell us the name of plugin', 'ucmm-wpbrigade' ); ?></span>
143
+ <input type="text" name="better_plugin" placeholder="<?php _e( "What's the plugin's name?", 'ucmm-wpbrigade' ); ?>">
144
+ </div>
145
+ </li>
146
+ <li class="wpb-sdk_deactivation-frm-reason" data-input-type="" data-input-placeholder="">
147
+ <label>
148
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="3"></span>
149
+ <span><?php _e( 'The plugin broke my site', 'ucmm-wpbrigade' ); ?></span>
150
+ </label>
151
+ <div class="wpb-sdk_deactivation-frm-internal-message"></div>
152
+ </li>
153
+ <li class="wpb-sdk_deactivation-frm-reason" data-input-type="" data-input-placeholder="">
154
+ <label>
155
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="4"></span>
156
+ <span><?php _e( 'The plugin suddenly stopped working', 'ucmm-wpbrigade' ); ?></span>
157
+ </label>
158
+ <div class="wpb-sdk_deactivation-frm-internal-message"></div>
159
+ </li>
160
+ <li class="wpb-sdk_deactivation-frm-reason" data-input-type="" data-input-placeholder="">
161
+ <label>
162
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="5"></span>
163
+ <span><?php _e( 'I no longer need the plugin', 'ucmm-wpbrigade' ); ?></span>
164
+ </label>
165
+ <div class="wpb-sdk_deactivation-frm-internal-message"></div>
166
+ </li>
167
+ <li class="wpb-sdk_deactivation-frm-reason" data-input-type="" data-input-placeholder="">
168
+ <label>
169
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="6"></span>
170
+ <span><?php _e( "It's a temporary deactivation. I'm just debugging an issue.", 'ucmm-wpbrigade' ); ?></span>
171
+ </label>
172
+ <div class="wpb-sdk_deactivation-frm-internal-message"></div>
173
+ </li>
174
+ <li class="wpb-sdk_deactivation-frm-reason has-input" data-input-type="textfield">
175
+ <label>
176
+ <span><input type="radio" name="wpb-sdk_deactivation-frm-selected-reason" value="7"></span>
177
+ <span><?php _e( 'Other', 'ucmm-wpbrigade' ); ?></span>
178
+ </label>
179
+ <div class="wpb-sdk_deactivation-frm-internal-message"></div>
180
+ <div class="wpb-sdk_deactivation-frm-reason-input"><span class="message error-message "><?php _e( 'Kindly tell us the reason so we can improve.', 'ucmm-wpbrigade' ); ?></span>
181
+ <input type="text" name="other_reason" placeholder="<?php _e( "Would you like to share what's other reason ?", 'ucmm-wpbrigade' ); ?>">
182
+ </div>
183
+ </li>
184
+ </ul>
185
+ </div>
186
+
187
+ <div class="wpb-sdk_deactivation-frm-popup-footer">
188
+ <label class="wpb-sdk_deactivation-frm-anonymous">
189
+ <input type="checkbox" />
190
+ <?php _e( 'Anonymous feedback', 'ucmm-wpbrigade' ); ?>
191
+ </label>
192
+ <input type="button" class="button button-secondary button-skip wpb-sdk_deactivation-frm-popup-skip-feedback" value="Skip &amp; Deactivate">
193
+ <div class="action-btns">
194
+ <span class="wpb-sdk_deactivation-frm-spinner"><img src="<?php echo admin_url( '/images/spinner.gif' ); ?>" alt=""></span>
195
+ <input type="submit" class="button button-secondary button-deactivate wpb-sdk_deactivation-frm-popup-allow-deactivate" value="Submit &amp; Deactivate" disabled="disabled">
196
+ <a href="#" class="button button-primary wpb-sdk_deactivation-frm-popup-button-close">
197
+ <?php _e( 'Cancel', 'ucmm-wpbrigade' ); ?>
198
+ </a>
199
+ </div>
200
+ </div>
201
+
202
+ </form>
203
+ </div>
204
+ </div>
205
+ </div>
206
+ <script>
207
+ document.addEventListener("DOMContentLoaded", function(event) {
208
+ (function($) {
209
+ $(function() {
210
+
211
+ var pluginSlug = "<?php echo $product_slug; ?>";
212
+ var pluginName = "<?php echo $product_name; ?>";
213
+
214
+ var loggerDeactiveNonce;
215
+
216
+ $(document).on('click', 'tr[data-slug="' + pluginSlug + '"] .deactivate', function(e) {
217
+ e.preventDefault();
218
+ loggerDeactiveNonce = $(this).find('a').attr('href').split("wpnonce=")[1];
219
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-overlay').addClass('wpb-sdk_deactivation-frm-active');
220
+ $('body').addClass('wpb-sdk_deactivation-frm-hidden');
221
+ });
222
+
223
+ $(document).on('click', '.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-button-close', function() {
224
+ close_popup();
225
+ });
226
+
227
+ $(document).on('click', ".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-serveypanel,tr[data-slug='" + pluginSlug + "'] .deactivate", function(e) {
228
+ e.stopPropagation();
229
+ });
230
+
231
+ $(document).on('click', function() {
232
+ close_popup();
233
+ });
234
+
235
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-reason label').on('click', function() {
236
+ if($(this).find('input[type="radio"]').is(':checked')) {
237
+ //$('.wpb-sdk_deactivation-frm-anonymous').show();
238
+ $(this).next().next('.wpb-sdk_deactivation-frm-reason-input').show().end().end().parent().siblings().find('.wpb-sdk_deactivation-frm-reason-input').hide();
239
+ }
240
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-pro-message').hide();
241
+ });
242
+
243
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-reason-pro label').on('click', function() {
244
+ if($(this).find('input[type="radio"]').is(':checked')) {
245
+ $(this).next('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-pro-message').show().end().end().parent().siblings().find('.wpb-sdk_deactivation-frm-reason-input').hide();
246
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-allow-deactivate').attr('disabled', 'disabled');
247
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-skip-feedback').attr('disabled', 'disabled');
248
+ }
249
+ });
250
+
251
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper input[type="radio"][name="wpb-sdk_deactivation-frm-selected-reason"]').on('click', function(event) {
252
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-allow-deactivate").removeAttr('disabled');
253
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-skip-feedback").removeAttr('disabled');
254
+ });
255
+
256
+ $(document).on('submit', '.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-deactivate-form', function(event) {
257
+ event.preventDefault();
258
+ var reason = $(this).find('input[type="radio"][name="wpb-sdk_deactivation-frm-selected-reason"]:checked').val();
259
+ var reasonDetails = '';
260
+ if(reason == '2') {
261
+ reasonDetails = $(this).find("input[type='text'][name='better_plugin']").val();
262
+ } else if(reason == '7') {
263
+ reasonDetails = $(this).find("input[type='text'][name='other_reason']").val();
264
+ }
265
+ if((reason == '7' || reason == '2') && reasonDetails == '') {
266
+ $('.message.error-message').show();
267
+ return;
268
+ }
269
+
270
+ let returnURL = $("tr[data-slug='" + pluginSlug + "'] .deactivate a").attr('href');
271
+
272
+ send_log(
273
+ 'wpb_sdk_' + pluginSlug + '_deactivation',
274
+ reason,
275
+ reasonDetails,
276
+ loggerDeactiveNonce,
277
+ returnURL
278
+ );
279
+
280
+ });
281
+
282
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-skip-feedback').on('click', function(e) {
283
+ send_log(
284
+ 'wpb_sdk_' + pluginSlug + '_deactivation',
285
+ 9,
286
+ '',
287
+ loggerDeactiveNonce,
288
+ $("tr[data-slug='" + pluginSlug + "'] .deactivate a").attr('href')
289
+ );
290
+ });
291
+
292
+ function close_popup() {
293
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-overlay').removeClass('wpb-sdk_deactivation-frm-active');
294
+ $('.<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-deactivate-form').trigger("reset");
295
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-allow-deactivate").attr('disabled', 'disabled');
296
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-reason-input").hide();
297
+ $('body').removeClass('wpb-sdk_deactivation-frm-hidden');
298
+ $('.message.error-message').hide();
299
+ }
300
+
301
+ function send_log( _action, _reason, _reasonDetails, _nonce, returnURL ) {
302
+ $.ajax({
303
+ url: ajaxurl,
304
+ type: 'POST',
305
+ data: {
306
+ action: _action,
307
+ reason: _reason,
308
+ reason_detail: _reasonDetails,
309
+ nonce: _nonce
310
+ },
311
+ beforeSend: function() {
312
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-spinner").show();
313
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-allow-deactivate").attr("disabled", "disabled");
314
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-skip-feedback").attr("disabled", "disabled");
315
+ }
316
+ }).done(function(res) {
317
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-spinner").hide();
318
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-allow-deactivate").removeAttr("disabled");
319
+ $(".<?php echo $product_slug; ?>-deactivate-wrapper .wpb-sdk_deactivation-frm-popup-skip-feedback").removeAttr("disabled");
320
+ window.location.href = returnURL;
321
+ });
322
+ }
323
+
324
+ });
325
+ })(jQuery);
326
+ });
327
+ </script>
readme.txt CHANGED
@@ -4,8 +4,8 @@ Author URI: https://wpbrigade.com/?utm_source=wphf-org&utm_medium=author-url-lin
4
  Donate link: Author URI: https://wpbrigade.com/?utm_source=wphf-org&utm_medium=donate-url-link
5
  Tags: header, footer, Google Analytics, custom css, Facebook Pixel
6
  Requires at least: 5.0
7
- Tested up to: 5.7
8
- Stable tag: 1.3.0
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -31,7 +31,7 @@ Google Tag Manager code/script insertion
31
  Can add Bing webmaster tool code for website verification
32
  Add Google AdSense code
33
 
34
- `If you find our plugin useful, please leave a good rating/review and check our other plugins.`
35
 
36
  * [Analytify - Google Analytics Plugin](https://analytify.io/ref/73/?utm_source=wp-headers-and-footers&amp;utm_medium=readme&amp;utm_campaign=pro-upgrade)
37
  * [LoginPress](https://loginpress.pro/) - For Custom login page and login page security
@@ -75,27 +75,34 @@ You can insert code in Header, Body and Footer areas of any WordPress site.
75
 
76
 
77
  == Changelog ==
 
 
 
 
 
 
 
78
  = 1.3.0 - 2021-06-05
79
  * New Feature: Introducing Code Editor for writing scripts.
80
  * Bugfix: Plugin language domain updated to 'wp-headers-and-footers'
81
  * Enhancement: Dashboard design updated.
82
  * Enhancement : Code Optimization.
83
- * Compatibility : WordPress 5.7
84
 
85
  = 1.2.2 - 2021-04-04
86
- * Compatibility : WordPress 5.7
87
  * Compatibility : PHP 8.0
88
  * Enhancement : Code Optimization.
89
 
90
  = 1.2.1 - 2020-12-08 =
91
- * Compatibility : WordPress 5.6
92
  * Bugfix: PHP Error.
93
 
94
  = 1.2.0 - 2020-12-08 =
95
  * Bugfix: Remove PHP 7 deprecated function.
96
 
97
  = 1.1.0 - 2020-03-21 =
98
- * Compatibility : WordPress 5.4
99
  * Enhancement: Dashboard Design updated.
100
 
101
  = 1.0.0 =
@@ -104,5 +111,5 @@ You can insert code in Header, Body and Footer areas of any WordPress site.
104
 
105
  == Upgrade Notice ==
106
 
107
- = 1.3.0 =
108
  * Upgrade Immediately.
4
  Donate link: Author URI: https://wpbrigade.com/?utm_source=wphf-org&utm_medium=donate-url-link
5
  Tags: header, footer, Google Analytics, custom css, Facebook Pixel
6
  Requires at least: 5.0
7
+ Tested up to: 5.8
8
+ Stable tag: 1.3.1
9
  License: GPLv3 or later
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
31
  Can add Bing webmaster tool code for website verification
32
  Add Google AdSense code
33
 
34
+ **If you find our plugin useful, please leave a good rating/review and check our other plugins.**
35
 
36
  * [Analytify - Google Analytics Plugin](https://analytify.io/ref/73/?utm_source=wp-headers-and-footers&amp;utm_medium=readme&amp;utm_campaign=pro-upgrade)
37
  * [LoginPress](https://loginpress.pro/) - For Custom login page and login page security
75
 
76
 
77
  == Changelog ==
78
+
79
+ = 1.3.1 - 2021-12-01
80
+ * Enhancement : Code Optimization.
81
+ * Enhancement : Add compatibility of Mozilla Firefox on dashboard settings.
82
+ * Compatibility : Compatible with WordPress 5.8.
83
+ * Compatibility : Compatible with PHP 8.0.
84
+
85
  = 1.3.0 - 2021-06-05
86
  * New Feature: Introducing Code Editor for writing scripts.
87
  * Bugfix: Plugin language domain updated to 'wp-headers-and-footers'
88
  * Enhancement: Dashboard design updated.
89
  * Enhancement : Code Optimization.
90
+ * Compatibility : Compatible with WordPress 5.7.
91
 
92
  = 1.2.2 - 2021-04-04
93
+ * Compatibility : Compatible with WordPress 5.7.
94
  * Compatibility : PHP 8.0
95
  * Enhancement : Code Optimization.
96
 
97
  = 1.2.1 - 2020-12-08 =
98
+ * Compatibility : Compatible with WordPress 5.6.
99
  * Bugfix: PHP Error.
100
 
101
  = 1.2.0 - 2020-12-08 =
102
  * Bugfix: Remove PHP 7 deprecated function.
103
 
104
  = 1.1.0 - 2020-03-21 =
105
+ * Compatibility : Compatible with WordPress 5.4.
106
  * Enhancement: Dashboard Design updated.
107
 
108
  = 1.0.0 =
111
 
112
  == Upgrade Notice ==
113
 
114
+ = 1.3.1 =
115
  * Upgrade Immediately.
wp-headers-and-footers.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WP Headers And Footers
4
  * Plugin URI: https://www.WPBrigade.com/wordpress/plugins/wp-headers-and-footers/
5
  * Description: Allows you to insert code or text in the header or footer of your WordPress site.
6
- * Version: 1.3.0
7
  * Author: WPBrigade
8
  * Author URI: https://wpbrigade.com/?utm_source=plugin-meta&utm_medium=author-uri-link
9
  * License: GPLv3
@@ -15,65 +15,97 @@
15
  * @author WPBrigade
16
  */
17
 
18
-
19
  if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
20
 
 
 
 
21
  final class WPHeaderAndFooter {
22
 
23
  /**
24
- * @var string
 
 
25
  */
26
- public $version = '1.3.0';
27
 
28
  /**
29
- * @var The single instance of the class
30
- * @since 1.0.0
 
31
  */
 
32
 
33
- protected static $_instance = null;
34
-
35
- /*
36
- * * * * * * * * *
37
- * Class constructor
38
- * * * * * * * * * */
39
  public function __construct() {
40
 
41
  $this->define_constants();
42
  $this->includes();
43
- $this->_hooks();
44
-
45
  }
46
 
47
  /**
48
  * Include required core files used in admin and on the frontend.
 
 
49
  */
50
-
51
  public function includes() {
52
 
53
  include_once WPHEADERANDFOOTER_DIR_PATH . 'classes/class-setup.php';
54
  include_once WPHEADERANDFOOTER_DIR_PATH . 'classes/plugin-meta.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
  /**
58
  * Hook into actions and filters
59
  *
60
  * @since 1.0.0
61
- *
62
- * @version 1.2.3
63
- *
64
  */
65
- private function _hooks() {
66
 
67
  add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
68
- add_action( 'admin_enqueue_scripts', array( $this, '_admin_scripts' ) );
69
- add_action( 'wp_print_scripts', array( $this, '_admin_scripts' ) );
70
- add_action( 'wp_head', array( $this, 'frontendHeader' ) );
71
-
72
- if( function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ) {
73
- add_action( 'wp_body_open', array( $this, 'frontendBody' ) );
74
  }
75
-
76
- add_action( 'wp_footer', array( $this, 'frontendFooter' ) );
77
  }
78
 
79
  /**
@@ -89,7 +121,13 @@ if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
89
  $this->define( 'WPHEADERANDFOOTER_FEEDBACK_SERVER', 'https://wpbrigade.com/' );
90
  }
91
 
92
- function _admin_scripts( $page ) {
 
 
 
 
 
 
93
 
94
  if ( 'settings_page_wp-headers-and-footers' === $page ) {
95
 
@@ -100,16 +138,16 @@ if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
100
  if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'manage_options' ) ) {
101
  $editor_args['codemirror']['readOnly'] = true;
102
  }
103
-
104
  // Enqueue code editor and settings for manipulating HTML.
105
  $settings = wp_enqueue_code_editor( $editor_args );
106
-
107
  // Bail if user disabled CodeMirror.
108
  if ( false === $settings ) {
109
  return;
110
  }
111
 
112
- wp_enqueue_script( 'wpheaderandfooter_script', plugins_url( 'asset/js/script.js', __FILE__ ), array( 'jquery' ), WPHEADERANDFOOTER_VERSION );
113
 
114
  }
115
  }
@@ -117,8 +155,8 @@ if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
117
  /**
118
  * Define constant if not already set
119
  *
120
- * @param string $name
121
- * @param string|bool $value
122
  */
123
  private function define( $name, $value ) {
124
  if ( ! defined( $name ) ) {
@@ -135,10 +173,10 @@ if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
135
  * @return Main instance
136
  */
137
  public static function instance() {
138
- if ( is_null( self::$_instance ) ) {
139
- self::$_instance = new self();
140
  }
141
- return self::$_instance;
142
  }
143
 
144
 
@@ -154,58 +192,60 @@ if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
154
  }
155
 
156
  /**
157
- * Outputs script / CSS to the header
 
158
  * @since 1.0.0
159
- *
160
- * @version 1.2.3
161
  */
162
- function frontendHeader() {
163
- $this->_output( 'wp_header_textarea' );
164
  }
165
 
166
  /**
167
- * Outputs script / CSS to the frontend below opening body
168
- * @since 1.0.0
169
- *
170
- * @version 1.2.3
171
- */
172
- function frontendBody() {
173
- $this->_output( 'wp_body_textarea' );
174
  }
175
-
176
  /**
177
- * Outputs script / CSS to the footer
 
178
  * @since 1.0.0
179
- *
180
- * @version 1.0.0
181
  */
182
- function frontendFooter() {
183
- $this->_output( 'wp_footer_textarea' );
184
  }
185
 
186
  /**
187
  * Outputs the given setting, if conditions are met
188
  *
189
- * @param string $script Setting Name
 
 
190
  * @return output
191
  */
192
- function _output( $script ) {
193
 
194
- // Ignore admin, feed, robots or trackbacks
195
  if ( is_admin() || is_feed() || is_robots() || is_trackback() ) :
196
  return;
197
  endif;
198
 
199
- // Get meta
200
- $_wphaf_setting = get_option( 'wpheaderandfooter_basics' );
201
- $meta = ! empty( $_wphaf_setting[ $script ] ) ? $_wphaf_setting[ $script ] : false;
202
 
203
- if ( trim( $meta ) == '' || ! $meta ) :
204
  return;
205
  endif;
206
 
207
- // Output
208
- echo wp_unslash( $meta ) . PHP_EOL;
209
 
210
  }
211
 
@@ -224,6 +264,6 @@ function wpheaderandfooter_loader() {
224
  return WPHeaderAndFooter::instance();
225
  }
226
 
227
- // Call the function
228
  wpheaderandfooter_loader();
229
  new WPHeaderAndFooter_Setting();
3
  * Plugin Name: WP Headers And Footers
4
  * Plugin URI: https://www.WPBrigade.com/wordpress/plugins/wp-headers-and-footers/
5
  * Description: Allows you to insert code or text in the header or footer of your WordPress site.
6
+ * Version: 1.3.1
7
  * Author: WPBrigade
8
  * Author URI: https://wpbrigade.com/?utm_source=plugin-meta&utm_medium=author-uri-link
9
  * License: GPLv3
15
  * @author WPBrigade
16
  */
17
 
 
18
  if ( ! class_exists( 'WPHeaderAndFooter' ) ) :
19
 
20
+ /**
21
+ * The class WPHeaderAndFooter
22
+ */
23
  final class WPHeaderAndFooter {
24
 
25
  /**
26
+ * The single instance of the class.
27
+ *
28
+ * @var string $version
29
  */
30
+ public $version = '1.3.1';
31
 
32
  /**
33
+ * The single instance of the class.
34
+ *
35
+ * @var object $instance
36
  */
37
+ protected static $instance = null;
38
 
39
+ /**
40
+ * WPHeaderAndFooter Class constructor
41
+ */
 
 
 
42
  public function __construct() {
43
 
44
  $this->define_constants();
45
  $this->includes();
46
+ $this->hooks();
 
47
  }
48
 
49
  /**
50
  * Include required core files used in admin and on the frontend.
51
+ *
52
+ * @version 1.4.0
53
  */
 
54
  public function includes() {
55
 
56
  include_once WPHEADERANDFOOTER_DIR_PATH . 'classes/class-setup.php';
57
  include_once WPHEADERANDFOOTER_DIR_PATH . 'classes/plugin-meta.php';
58
+
59
+ // set the logger settings option if was not set before.
60
+ if ( ! get_option( 'wpheaderandfooter_basics_logger' ) ) {
61
+
62
+ $setting = get_option( 'wpheaderandfooter_basics' );
63
+
64
+ $logger_value = array();
65
+
66
+ $logger_value['is_using_wp_header_textarea'] = isset( $setting['wp_header_textarea'] ) && ! empty( trim( $setting['wp_header_textarea'] ) ) ? true : false;
67
+ $logger_value['is_using_wp_body_textarea'] = isset( $setting['wp_body_textarea'] ) && ! empty( trim( $setting['wp_body_textarea'] ) ) ? true : false;
68
+ $logger_value['is_using_wp_footer_textarea'] = isset( $setting['wp_footer_textarea'] ) && ! empty( trim( $setting['wp_footer_textarea'] ) ) ? true : false;
69
+
70
+ update_option( 'wpheaderandfooter_basics_logger', $logger_value );
71
+ }
72
+
73
+ // init logger.
74
+ include_once WPHEADERANDFOOTER_DIR_PATH . 'lib/wpb-sdk/init.php';
75
+
76
+ new WPHeaderAndFooter_SDK\Logger(
77
+ array(
78
+ 'name' => 'WP Headers And Footers',
79
+ 'slug' => 'wp-headers-and-footers',
80
+ 'path' => __FILE__,
81
+ 'version' => $this->version,
82
+ 'license' => '',
83
+ 'settings' => array(
84
+ 'wpheaderandfooter_basics_logger' => false,
85
+ ),
86
+ )
87
+ );
88
+
89
  }
90
 
91
  /**
92
  * Hook into actions and filters
93
  *
94
  * @since 1.0.0
95
+ * @version 1.4.0
 
 
96
  */
97
+ private function hooks() {
98
 
99
  add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
100
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
101
+ add_action( 'wp_print_scripts', array( $this, 'admin_scripts' ) );
102
+ add_action( 'wp_head', array( $this, 'frontend_header' ) );
103
+
104
+ if ( function_exists( 'wp_body_open' ) && version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ) {
105
+ add_action( 'wp_body_open', array( $this, 'frontend_body' ) );
106
  }
107
+
108
+ add_action( 'wp_footer', array( $this, 'frontend_footer' ) );
109
  }
110
 
111
  /**
121
  $this->define( 'WPHEADERANDFOOTER_FEEDBACK_SERVER', 'https://wpbrigade.com/' );
122
  }
123
 
124
+ /**
125
+ * Admin Scripts
126
+ *
127
+ * @param string $page The page slug.
128
+ * @version 1.4.0
129
+ */
130
+ public function admin_scripts( $page ) {
131
 
132
  if ( 'settings_page_wp-headers-and-footers' === $page ) {
133
 
138
  if ( ! current_user_can( 'unfiltered_html' ) || ! current_user_can( 'manage_options' ) ) {
139
  $editor_args['codemirror']['readOnly'] = true;
140
  }
141
+
142
  // Enqueue code editor and settings for manipulating HTML.
143
  $settings = wp_enqueue_code_editor( $editor_args );
144
+
145
  // Bail if user disabled CodeMirror.
146
  if ( false === $settings ) {
147
  return;
148
  }
149
 
150
+ wp_enqueue_script( 'wpheaderandfooter_script', plugins_url( 'asset/js/script.js', __FILE__ ), array( 'jquery' ), WPHEADERANDFOOTER_VERSION, false );
151
 
152
  }
153
  }
155
  /**
156
  * Define constant if not already set
157
  *
158
+ * @param string $name The name of the variable.
159
+ * @param string|bool $value The value of the variable.
160
  */
161
  private function define( $name, $value ) {
162
  if ( ! defined( $name ) ) {
173
  * @return Main instance
174
  */
175
  public static function instance() {
176
+ if ( is_null( self::$instance ) ) {
177
+ self::$instance = new self();
178
  }
179
+ return self::$instance;
180
  }
181
 
182
 
192
  }
193
 
194
  /**
195
+ * Outputs script / style to the header
196
+ *
197
  * @since 1.0.0
198
+ * @version 1.4.0
 
199
  */
200
+ public function frontend_header() {
201
+ $this->wp_hnf_output( 'wp_header_textarea' );
202
  }
203
 
204
  /**
205
+ * Outputs script / style to the frontend below opening body
206
+ *
207
+ * @since 1.0.0
208
+ * @version 1.4.0
209
+ */
210
+ public function frontend_body() {
211
+ $this->wp_hnf_output( 'wp_body_textarea' );
212
  }
213
+
214
  /**
215
+ * Outputs script / style to the footer
216
+ *
217
  * @since 1.0.0
218
+ * @version 1.4.0
 
219
  */
220
+ public function frontend_footer() {
221
+ $this->wp_hnf_output( 'wp_footer_textarea' );
222
  }
223
 
224
  /**
225
  * Outputs the given setting, if conditions are met
226
  *
227
+ * @param string $script Setting Name.
228
+ *
229
+ * @version 1.4.0
230
  * @return output
231
  */
232
+ public function wp_hnf_output( $script ) {
233
 
234
+ // Ignore admin, feed, robots or track backs.
235
  if ( is_admin() || is_feed() || is_robots() || is_trackback() ) :
236
  return;
237
  endif;
238
 
239
+ // Get meta.
240
+ $wp_hnf_setting = get_option( 'wpheaderandfooter_basics' );
241
+ $meta = ! empty( $wp_hnf_setting[ $script ] ) ? $wp_hnf_setting[ $script ] : false;
242
 
243
+ if ( '' === trim( $meta ) || ! $meta ) :
244
  return;
245
  endif;
246
 
247
+ // Output.
248
+ echo wp_unslash( $meta ) . PHP_EOL; // @codingStandardsIgnoreLine.
249
 
250
  }
251
 
264
  return WPHeaderAndFooter::instance();
265
  }
266
 
267
+ // Call the function.
268
  wpheaderandfooter_loader();
269
  new WPHeaderAndFooter_Setting();