Header Footer Code Manager - Version 1.1.9

Version Description

2021-02-18 * UPDATED: Compatibility with WordPress 5.6.1

Download this release

Release Info

Developer 99robots
Plugin Icon 128x128 Header Footer Code Manager
Version 1.1.9
Comparing to
See all releases

Code changes from version 1.1.8 to 1.1.9

Files changed (2) hide show
  1. 99robots-header-footer-code-manager.php +385 -372
  2. readme.txt +5 -2
99robots-header-footer-code-manager.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Header Footer Code Manager
4
  * Plugin URI: https://draftpress.com/products
5
  * Description: Header Footer Code Manager by 99 Robots is a quick and simple way for you to add tracking code snippets, conversion pixels, or other scripts required by third party services for analytics, tracking, marketing, or chat functions. For detailed documentation, please visit the plugin's <a href="https://draftpress.com/"> official page</a>.
6
- * Version: 1.1.8
7
  * Author: 99robots
8
  * Author URI: https://draftpress.com/
9
  * Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
@@ -12,8 +12,8 @@
12
  */
13
 
14
  // If this file is called directly, abort.
15
- if ( ! defined( 'WPINC' ) ) {
16
- die;
17
  }
18
 
19
  global $hfcm_db_version;
@@ -21,19 +21,19 @@ $hfcm_db_version = '1.1';
21
 
22
 
23
  // function to create the DB / Options / Defaults
24
- function hfcm_options_install() {
 
 
 
 
25
 
26
- $hfcm_now = strtotime( "now" );
27
- add_option( 'hfcm_activation_date', $hfcm_now );
28
- update_option( 'hfcm_activation_date', $hfcm_now );
29
-
30
- global $wpdb;
31
- global $hfcm_db_version;
32
 
33
- $table_name = $wpdb->prefix . 'hfcm_scripts';
34
- $charset_collate = $wpdb->get_charset_collate();
35
- $sql =
36
- "CREATE TABLE IF NOT EXISTS $table_name(
37
  `script_id` int(10) NOT NULL AUTO_INCREMENT,
38
  `name` varchar(100) DEFAULT NULL,
39
  `snippet` text,
@@ -56,438 +56,451 @@ function hfcm_options_install() {
56
  PRIMARY KEY (`script_id`)
57
  ) $charset_collate; ";
58
 
59
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
60
- dbDelta( $sql );
61
- add_option( 'hfcm_db_version', $hfcm_db_version );
62
-
63
  }
64
- register_activation_hook( __FILE__, 'hfcm_options_install' );
65
 
66
- function hfcm_db_update_check() {
 
67
  global $hfcm_db_version;
68
- global $wpdb;
69
- $table_name = $wpdb->prefix . 'hfcm_scripts';
70
- if ( get_site_option( 'hfcm_db_version' ) != $hfcm_db_version ) {
71
- $wpdb->show_errors();
72
- //Check for Exclude Pages
73
- $column_name = 'ex_pages';
74
- $checkcolumn = $wpdb->get_results($wpdb->prepare(
75
- "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
76
- DB_NAME, $table_name, $column_name
77
- )) ;
78
- if ( empty( $checkcolumn ) ) {
79
- $altersql = "ALTER TABLE `$table_name` ADD `ex_pages` varchar(300) DEFAULT 0 AFTER `s_pages`";
80
- $wpdb->query($altersql);
81
- }
82
-
83
- //Check for Exclude Posts
84
- $column_name1 = 'ex_posts';
85
- $checkcolumn2 = $wpdb->get_results($wpdb->prepare(
86
- "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
87
- DB_NAME, $table_name, $column_name1
88
- ));
89
- if ( empty( $checkcolumn2 ) ) {
90
- $altersql = "ALTER TABLE `$table_name` ADD `ex_posts` varchar(300) DEFAULT 0 AFTER `s_posts`";
91
- $wpdb->query($altersql);
92
- }
 
 
 
 
93
  hfcm_options_install();
94
  }
95
- update_option( 'hfcm_db_version', $hfcm_db_version );
96
  }
97
- add_action( 'plugins_loaded', 'hfcm_db_update_check' );
98
 
99
  /*
100
  * Enqueue style-file, if it exists.
101
  */
102
- function hfcm_enqueue_assets( $hook ) {
103
-
104
- $allowed_pages = array(
105
- 'toplevel_page_hfcm-list',
106
- 'hfcm_page_hfcm-create',
107
- 'admin_page_hfcm-update',
108
- );
109
-
110
- wp_register_style( 'hfcm_general_admin_assets', plugins_url( 'css/style-general-admin.css', __FILE__ ) );
111
- wp_enqueue_style( 'hfcm_general_admin_assets' );
112
-
113
- if ( in_array( $hook, $allowed_pages ) ) {
114
- // Plugin's CSS
115
- wp_register_style( 'hfcm_assets', plugins_url( 'css/style-admin.css', __FILE__ ) );
116
- wp_enqueue_style( 'hfcm_assets' );
117
- }
118
-
119
- // Remove hfcm-list from $allowed_pages
120
- array_shift( $allowed_pages );
121
-
122
- if ( in_array( $hook, $allowed_pages ) ) {
123
- // selectize.js plugin CSS and JS files
124
- wp_register_style( 'selectize-css', plugins_url( 'css/selectize.bootstrap3.css', __FILE__ ) );
125
- wp_enqueue_style( 'selectize-css' );
126
-
127
- wp_register_script( 'selectize-js', plugins_url( 'js/selectize.min.js', __FILE__ ), array( 'jquery' ) );
128
- wp_enqueue_script( 'selectize-js' );
129
- }
130
  }
131
- add_action( 'admin_enqueue_scripts', 'hfcm_enqueue_assets' );
132
 
133
  /*
134
  * This function loads plugins translation files
135
  */
136
- function hfcm_load_translation_files() {
137
- load_plugin_textdomain( '99robots-header-footer-code-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
 
138
  }
139
- add_action( 'plugins_loaded', 'hfcm_load_translation_files' );
140
 
141
  // function to create menu page, and submenu pages.
142
- function hfcm_modifymenu() {
143
-
144
- // This is the main item for the menu
145
- add_menu_page(
146
- __( 'Header Footer Code Manager', '99robots-header-footer-code-manager'),
147
- __( 'HFCM', '99robots-header-footer-code-manager'),
148
- 'manage_options',
149
- 'hfcm-list',
150
- 'hfcm_list',
151
- plugins_url( 'images/', __FILE__ ) . '99robots.png'
152
- );
153
-
154
- // This is a submenu
155
- add_submenu_page(
156
- 'hfcm-list',
157
- __( 'All Snippets', '99robots-header-footer-code-manager' ),
158
- __( 'All Snippets', '99robots-header-footer-code-manager' ),
159
- 'manage_options',
160
- 'hfcm-list',
161
- 'hfcm_list'
162
- );
163
-
164
- // This is a submenu
165
- add_submenu_page(
166
- 'hfcm-list',
167
- __( 'Add New Snippet', '99robots-header-footer-code-manager' ),
168
- __( 'Add New', '99robots-header-footer-code-manager' ),
169
- 'manage_options',
170
- 'hfcm-create',
171
- 'hfcm_create'
172
- );
173
-
174
- // This submenu is HIDDEN, however, we need to add it anyways
175
- add_submenu_page(
176
- null,
177
- __( 'Update Script', '99robots-header-footer-code-manager' ),
178
- __( 'Update', '99robots-header-footer-code-manager' ),
179
- 'manage_options',
180
- 'hfcm-update',
181
- 'hfcm_update'
182
- );
183
-
184
- // This submenu is HIDDEN, however, we need to add it anyways
185
- add_submenu_page(
186
- null,
187
- __( 'Request Handler Script', '99robots-header-footer-code-manager' ),
188
- __( 'Request Handler', '99robots-header-footer-code-manager' ),
189
- 'manage_options',
190
- 'hfcm-request-handler',
191
- 'hfcm_request_handler'
192
- );
 
193
  }
194
- add_action( 'admin_menu', 'hfcm_modifymenu' );
195
 
196
  // Adding A settings link for the plugin on the Settings Page
197
  add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'hfcm_add_plugin_page_settings_link');
198
- function hfcm_add_plugin_page_settings_link( $links ) {
199
- $links = array_merge(array('<a href="' .
200
- admin_url( 'admin.php?page=hfcm-list' ) .
201
- '">' . __('Settings') . '</a>'), $links);
202
- return $links;
 
203
  }
204
 
205
  //Check Installation Date
206
- function hfcm_check_installation_date() {
207
-
208
- $install_date = get_option( 'hfcm_activation_date' );
209
- $past_date = strtotime( '-7 days' );
210
-
211
- if ( $past_date >= $install_date ) {
212
-
213
- add_action( 'admin_notices', 'hfcm_review_push_notice' );
214
 
 
 
215
  }
216
-
217
  }
218
- add_action( 'admin_init', 'hfcm_check_installation_date' );
219
 
220
  // Create the Admin Notice
221
- function hfcm_review_push_notice() {
222
-
223
- $allowed_pages_notices = array(
224
- 'toplevel_page_hfcm-list',
225
- 'hfcm_page_hfcm-create',
226
- 'admin_page_hfcm-update',
227
- );
228
- $screen = get_current_screen()->id;
229
-
230
- $user_id = get_current_user_id();
231
- // Check if current user has already dismissed it
232
- $install_date = get_option( 'hfcm_activation_date' );
233
- if ( !get_user_meta( $user_id, 'hfcm_plugin_notice_dismissed') && in_array($screen, $allowed_pages_notices)) {
234
- ?>
235
- <div id="hfcm-message" class="notice notice-success">
236
- <a class="hfcm-dismiss-alert notice-dismiss" href="?hfcm-admin-notice-dismissed">Dismiss</a>
237
- <p><?php _e( 'Hey there! You’ve been using the <strong>Header Footer Code Manager</strong> plugin for a while now. If you like the plugin, please support our awesome development and support team by leaving a <a class="hfcm-review-stars" href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/"><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span></a> rating. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Rate it!</a> It’ll mean the world to us and keep this plugin free and constantly updated. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Leave A Review</a>', '99robots-header-footer-code-manager' ); ?></p>
238
- </div>
239
- <?php
240
- }
 
241
  }
242
 
243
  // Check if current user has already dismissed it
244
- function hfcm_plugin_notice_dismissed() {
 
245
  $user_id = get_current_user_id();
246
- // Checking if user clicked on the Dismiss button
247
- if ( isset( $_GET['hfcm-admin-notice-dismissed'] ) ){
248
- add_user_meta( $user_id, 'hfcm_plugin_notice_dismissed', 'true', true );
249
- // Redirect to original page the user was on
250
- $current_url = wp_get_referer();
251
- wp_redirect($current_url);
252
- exit;
253
- }
254
  }
255
- add_action( 'admin_init', 'hfcm_plugin_notice_dismissed' );
256
 
257
  /*****/
258
 
259
  // Files containing submenu functions
260
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-list.php' );
261
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-create.php' );
262
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-update.php' );
263
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-request-handler.php' );
264
 
265
  // Function to render the snippet
266
- function hfcm_render_snippet( $scriptdata ) {
267
- $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
 
268
 
269
- return $output;
270
  }
271
 
272
  // Function to implement shortcode
273
- function hfcm_shortcode( $atts ) {
274
- global $wpdb;
275
- $table_name = $wpdb->prefix . 'hfcm_scripts';
276
- if ( ! empty( $atts['id'] ) ) {
277
- $id = (int) $atts['id'];
278
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
279
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id ) );
280
- if ( ! empty( $script ) ) {
281
- return hfcm_render_snippet( $script[0] );
282
- }
283
- }
 
284
  }
285
- add_shortcode( 'hfcm', 'hfcm_shortcode' );
286
 
287
  // Function to json_decode array and check if empty
288
- function hfcm_not_empty( $scriptdata, $prop_name ) {
289
- $data = json_decode( $scriptdata->{$prop_name} );
290
- if ( empty( $data ) ) {
291
- return false;
292
- }
293
- return true;
 
294
  }
295
 
296
  // Function to decide which snippets to show - triggered by hooks
297
- function hfcm_add_snippets( $location = '', $content = '' ) {
298
- global $wpdb;
299
-
300
- $beforecontent = '';
301
- $aftercontent = '';
302
-
303
- if ( $location && in_array( $location, array( 'header', 'footer' ) ) ) {
304
- $display_location = "location='$location'";
305
- } else {
306
- $display_location = "location NOT IN ( 'header', 'footer' )";
307
- }
308
-
309
- $table_name = $wpdb->prefix . 'hfcm_scripts';
310
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
311
- $script = $wpdb->get_results( "SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'" );
312
-
313
- if ( ! empty( $script ) ) {
314
- foreach ( $script as $key => $scriptdata ) {
315
- $out = '';
316
- switch ( $scriptdata->display_on ) {
317
- case 'All':
318
-
319
- if ( (hfcm_not_empty( $scriptdata, 'ex_pages' ) && is_page( json_decode( $scriptdata->ex_pages ) )) || (hfcm_not_empty( $scriptdata, 'ex_posts' ) && is_single( json_decode( $scriptdata->ex_posts ) )) ){
320
- $out = '';
321
- }else{
322
- $out = hfcm_render_snippet( $scriptdata );
323
- }
324
- break;
325
- case 'latest_posts':
326
- if ( is_single() ) {
327
- $args = array(
328
- 'public' => true,
329
- '_builtin' => false,
330
- );
331
- $output = 'names'; // names or objects, note names is the default
332
- $operator = 'and'; // 'and' or 'or'
333
- $c_posttypes = get_post_types( $args, $output, $operator );
334
- $posttypes = array( 'post' );
335
- foreach ( $c_posttypes as $cpkey => $cpdata ) {
336
- $posttypes[] = $cpdata;
337
- }
338
- if ( ! empty( $scriptdata->lp_count ) ) {
339
- $latestposts = wp_get_recent_posts( array(
340
- 'numberposts' => $scriptdata->lp_count,
341
- 'post_type' => $posttypes,
342
- ) );
343
- } else {
344
- $latestposts = wp_get_recent_posts( array( 'post_type' => $posttypes ) );
345
- }
346
-
347
- $islatest = false;
348
- foreach ( $latestposts as $key => $lpostdata ) {
349
- if ( get_the_ID() == $lpostdata['ID'] ) {
350
- $islatest = true;
351
- }
352
- }
353
-
354
- if ( $islatest ) {
355
- $out = hfcm_render_snippet( $scriptdata );
356
- }
357
- }
358
- break;
359
- case 's_categories':
360
- if ( hfcm_not_empty( $scriptdata, 's_categories' ) && in_category( json_decode( $scriptdata->s_categories ) ) ) {
361
-
362
- if(is_category(json_decode( $scriptdata->s_categories ))){
363
- $out = hfcm_render_snippet( $scriptdata );
364
- }
365
- if(!is_archive() && !is_home()){
366
- $out = hfcm_render_snippet( $scriptdata );
367
- }
368
- }
369
- break;
370
- case 's_custom_posts':
371
- if ( hfcm_not_empty( $scriptdata, 's_custom_posts' ) && is_singular( json_decode( $scriptdata->s_custom_posts ) ) ) {
372
- $out = hfcm_render_snippet( $scriptdata );
373
- }
374
- break;
375
- case 's_posts':
376
- if ( hfcm_not_empty( $scriptdata, 's_posts' ) && is_single( json_decode( $scriptdata->s_posts ) ) ) {
377
- $out = hfcm_render_snippet( $scriptdata );
378
- }
379
- break;
380
- case 's_pages':
381
- if ( hfcm_not_empty( $scriptdata, 's_pages' ) ) {
382
- // Gets the page ID of the blog page
383
- $blog_page = get_option('page_for_posts');
384
- // Checks if the blog page is present in the array of selected pages
385
- if (in_array($blog_page, json_decode($scriptdata->s_pages))){
386
- if( is_page(json_decode($scriptdata->s_pages)) || (!is_front_page() && is_home()) ){
387
- $out = hfcm_render_snippet( $scriptdata );
388
- }
389
- }elseif(is_page(json_decode($scriptdata->s_pages))) {
390
- $out = hfcm_render_snippet( $scriptdata );
391
- }
392
- }
393
- break;
394
- case 's_tags':
395
- if ( hfcm_not_empty( $scriptdata, 's_tags' ) && has_tag( json_decode( $scriptdata->s_tags ) )) {
396
- if(is_tag(json_decode( $scriptdata->s_tags ))){
397
- $out = hfcm_render_snippet( $scriptdata );
398
- }
399
- if(!is_archive() && !is_home()){
400
- $out = hfcm_render_snippet( $scriptdata );
401
- }
402
- }
403
- }
404
-
405
- switch ( $scriptdata->location ) {
406
- case 'before_content':
407
- $beforecontent .= $out;
408
- break;
409
- case 'after_content':
410
- $aftercontent .= $out;
411
- break;
412
- default:
413
- echo $out;
414
- }
415
- }
416
- }
417
- // Return results after the loop finishes
418
- return $beforecontent . $content . $aftercontent;
419
  }
420
 
421
  // Function to add snippets in the header
422
- function hfcm_header_scripts() {
423
- hfcm_add_snippets( 'header' );
 
424
  }
425
- add_action( 'wp_head', 'hfcm_header_scripts' );
426
 
427
  // Function to add snippets in the footer
428
- function hfcm_footer_scripts() {
429
- hfcm_add_snippets( 'footer' );
 
430
  }
431
- add_action( 'wp_footer', 'hfcm_footer_scripts' );
432
 
433
 
434
  // Function to add snippets before/after the content
435
- function hfcm_content_scripts( $content ) {
436
- return hfcm_add_snippets( false, $content );
 
437
  }
438
- add_action( 'the_content', 'hfcm_content_scripts' );
439
 
440
  // Load redirection Javascript code
441
- function hfcm_redirect( $url = '' ) {
442
- // Register the script
443
- wp_register_script( 'hfcm_redirection', plugins_url( 'js/location.js', __FILE__ ) );
 
444
 
445
- // Localize the script with new data
446
- $translation_array = array( 'url' => $url );
447
- wp_localize_script( 'hfcm_redirection', 'hfcm_location', $translation_array );
448
 
449
- // Enqueued script with localized data.
450
- wp_enqueue_script( 'hfcm_redirection' );
451
  }
452
 
453
  // Handle AJAX requests
454
- add_action( 'wp_ajax_hfcm-request', 'hfcm_request_handler' );
455
 
456
  // Function to sanitize POST data
457
- function hfcm_sanitize_text( $key, $sanitize = true ) {
458
-
459
- if ( ! empty( $_POST['data'][ $key ] ) ) {
460
- $out = stripslashes_deep( $_POST['data'][ $key ] );
461
- if ( $sanitize ) {
462
- $out = sanitize_text_field( $out );
463
- }
464
- return $out;
465
- }
466
 
467
- return '';
468
  }
469
 
470
  // Function to sanitize strings within POST data arrays
471
- function hfcm_sanitize_array( $key, $type = 'integer' ) {
472
- if ( ! empty( $_POST['data'][ $key ] ) ) {
473
-
474
- $arr = $_POST['data'][ $key ];
475
-
476
- if ( ! is_array( $arr ) ) {
477
- return array();
478
- }
479
-
480
- if ( 'integer' === $type ) {
481
- return array_map( 'absint', $arr );
482
- } else { // strings
483
- $new_array = array();
484
- foreach ( $arr as $val ) {
485
- $new_array[] = sanitize_text_field( $val );
486
- }
487
- }
488
-
489
- return $new_array;
490
- }
491
 
492
- return array();
493
  }
3
  * Plugin Name: Header Footer Code Manager
4
  * Plugin URI: https://draftpress.com/products
5
  * Description: Header Footer Code Manager by 99 Robots is a quick and simple way for you to add tracking code snippets, conversion pixels, or other scripts required by third party services for analytics, tracking, marketing, or chat functions. For detailed documentation, please visit the plugin's <a href="https://draftpress.com/"> official page</a>.
6
+ * Version: 1.1.9
7
  * Author: 99robots
8
  * Author URI: https://draftpress.com/
9
  * Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
12
  */
13
 
14
  // If this file is called directly, abort.
15
+ if (! defined('WPINC')) {
16
+ die;
17
  }
18
 
19
  global $hfcm_db_version;
21
 
22
 
23
  // function to create the DB / Options / Defaults
24
+ function hfcm_options_install()
25
+ {
26
+ $hfcm_now = strtotime("now");
27
+ add_option('hfcm_activation_date', $hfcm_now);
28
+ update_option('hfcm_activation_date', $hfcm_now);
29
 
30
+ global $wpdb;
31
+ global $hfcm_db_version;
 
 
 
 
32
 
33
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
34
+ $charset_collate = $wpdb->get_charset_collate();
35
+ $sql =
36
+ "CREATE TABLE IF NOT EXISTS $table_name(
37
  `script_id` int(10) NOT NULL AUTO_INCREMENT,
38
  `name` varchar(100) DEFAULT NULL,
39
  `snippet` text,
56
  PRIMARY KEY (`script_id`)
57
  ) $charset_collate; ";
58
 
59
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
60
+ dbDelta($sql);
61
+ add_option('hfcm_db_version', $hfcm_db_version);
 
62
  }
63
+ register_activation_hook(__FILE__, 'hfcm_options_install');
64
 
65
+ function hfcm_db_update_check()
66
+ {
67
  global $hfcm_db_version;
68
+ global $wpdb;
69
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
70
+ if (get_site_option('hfcm_db_version') != $hfcm_db_version) {
71
+ $wpdb->show_errors();
72
+ //Check for Exclude Pages
73
+ $column_name = 'ex_pages';
74
+ $checkcolumn = $wpdb->get_results($wpdb->prepare(
75
+ "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
76
+ DB_NAME,
77
+ $table_name,
78
+ $column_name
79
+ )) ;
80
+ if (empty($checkcolumn)) {
81
+ $altersql = "ALTER TABLE `$table_name` ADD `ex_pages` varchar(300) DEFAULT 0 AFTER `s_pages`";
82
+ $wpdb->query($altersql);
83
+ }
84
+
85
+ //Check for Exclude Posts
86
+ $column_name1 = 'ex_posts';
87
+ $checkcolumn2 = $wpdb->get_results($wpdb->prepare(
88
+ "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
89
+ DB_NAME,
90
+ $table_name,
91
+ $column_name1
92
+ ));
93
+ if (empty($checkcolumn2)) {
94
+ $altersql = "ALTER TABLE `$table_name` ADD `ex_posts` varchar(300) DEFAULT 0 AFTER `s_posts`";
95
+ $wpdb->query($altersql);
96
+ }
97
  hfcm_options_install();
98
  }
99
+ update_option('hfcm_db_version', $hfcm_db_version);
100
  }
101
+ add_action('plugins_loaded', 'hfcm_db_update_check');
102
 
103
  /*
104
  * Enqueue style-file, if it exists.
105
  */
106
+ function hfcm_enqueue_assets($hook)
107
+ {
108
+ $allowed_pages = array(
109
+ 'toplevel_page_hfcm-list',
110
+ 'hfcm_page_hfcm-create',
111
+ 'admin_page_hfcm-update',
112
+ );
113
+
114
+ wp_register_style('hfcm_general_admin_assets', plugins_url('css/style-general-admin.css', __FILE__));
115
+ wp_enqueue_style('hfcm_general_admin_assets');
116
+
117
+ if (in_array($hook, $allowed_pages)) {
118
+ // Plugin's CSS
119
+ wp_register_style('hfcm_assets', plugins_url('css/style-admin.css', __FILE__));
120
+ wp_enqueue_style('hfcm_assets');
121
+ }
122
+
123
+ // Remove hfcm-list from $allowed_pages
124
+ array_shift($allowed_pages);
125
+
126
+ if (in_array($hook, $allowed_pages)) {
127
+ // selectize.js plugin CSS and JS files
128
+ wp_register_style('selectize-css', plugins_url('css/selectize.bootstrap3.css', __FILE__));
129
+ wp_enqueue_style('selectize-css');
130
+
131
+ wp_register_script('selectize-js', plugins_url('js/selectize.min.js', __FILE__), array( 'jquery' ));
132
+ wp_enqueue_script('selectize-js');
133
+ }
134
  }
135
+ add_action('admin_enqueue_scripts', 'hfcm_enqueue_assets');
136
 
137
  /*
138
  * This function loads plugins translation files
139
  */
140
+ function hfcm_load_translation_files()
141
+ {
142
+ load_plugin_textdomain('99robots-header-footer-code-manager', false, dirname(plugin_basename(__FILE__)) . '/languages');
143
  }
144
+ add_action('plugins_loaded', 'hfcm_load_translation_files');
145
 
146
  // function to create menu page, and submenu pages.
147
+ function hfcm_modifymenu()
148
+ {
149
+
150
+ // This is the main item for the menu
151
+ add_menu_page(
152
+ __('Header Footer Code Manager', '99robots-header-footer-code-manager'),
153
+ __('HFCM', '99robots-header-footer-code-manager'),
154
+ 'manage_options',
155
+ 'hfcm-list',
156
+ 'hfcm_list',
157
+ plugins_url('images/', __FILE__) . '99robots.png'
158
+ );
159
+
160
+ // This is a submenu
161
+ add_submenu_page(
162
+ 'hfcm-list',
163
+ __('All Snippets', '99robots-header-footer-code-manager'),
164
+ __('All Snippets', '99robots-header-footer-code-manager'),
165
+ 'manage_options',
166
+ 'hfcm-list',
167
+ 'hfcm_list'
168
+ );
169
+
170
+ // This is a submenu
171
+ add_submenu_page(
172
+ 'hfcm-list',
173
+ __('Add New Snippet', '99robots-header-footer-code-manager'),
174
+ __('Add New', '99robots-header-footer-code-manager'),
175
+ 'manage_options',
176
+ 'hfcm-create',
177
+ 'hfcm_create'
178
+ );
179
+
180
+ // This submenu is HIDDEN, however, we need to add it anyways
181
+ add_submenu_page(
182
+ null,
183
+ __('Update Script', '99robots-header-footer-code-manager'),
184
+ __('Update', '99robots-header-footer-code-manager'),
185
+ 'manage_options',
186
+ 'hfcm-update',
187
+ 'hfcm_update'
188
+ );
189
+
190
+ // This submenu is HIDDEN, however, we need to add it anyways
191
+ add_submenu_page(
192
+ null,
193
+ __('Request Handler Script', '99robots-header-footer-code-manager'),
194
+ __('Request Handler', '99robots-header-footer-code-manager'),
195
+ 'manage_options',
196
+ 'hfcm-request-handler',
197
+ 'hfcm_request_handler'
198
+ );
199
  }
200
+ add_action('admin_menu', 'hfcm_modifymenu');
201
 
202
  // Adding A settings link for the plugin on the Settings Page
203
  add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'hfcm_add_plugin_page_settings_link');
204
+ function hfcm_add_plugin_page_settings_link($links)
205
+ {
206
+ $links = array_merge(array('<a href="' .
207
+ admin_url('admin.php?page=hfcm-list') .
208
+ '">' . __('Settings') . '</a>'), $links);
209
+ return $links;
210
  }
211
 
212
  //Check Installation Date
213
+ function hfcm_check_installation_date()
214
+ {
215
+ $install_date = get_option('hfcm_activation_date');
216
+ $past_date = strtotime('-7 days');
 
 
 
 
217
 
218
+ if ($past_date >= $install_date) {
219
+ add_action('admin_notices', 'hfcm_review_push_notice');
220
  }
 
221
  }
222
+ add_action('admin_init', 'hfcm_check_installation_date');
223
 
224
  // Create the Admin Notice
225
+ function hfcm_review_push_notice()
226
+ {
227
+ $allowed_pages_notices = array(
228
+ 'toplevel_page_hfcm-list',
229
+ 'hfcm_page_hfcm-create',
230
+ 'admin_page_hfcm-update',
231
+ );
232
+ $screen = get_current_screen()->id;
233
+
234
+ $user_id = get_current_user_id();
235
+ // Check if current user has already dismissed it
236
+ $install_date = get_option('hfcm_activation_date');
237
+ if (!get_user_meta($user_id, 'hfcm_plugin_notice_dismissed') && in_array($screen, $allowed_pages_notices)) {
238
+ ?>
239
+ <div id="hfcm-message" class="notice notice-success">
240
+ <a class="hfcm-dismiss-alert notice-dismiss" href="?hfcm-admin-notice-dismissed">Dismiss</a>
241
+ <p><?php _e('Hey there! You’ve been using the <strong>Header Footer Code Manager</strong> plugin for a while now. If you like the plugin, please support our awesome development and support team by leaving a <a class="hfcm-review-stars" href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/"><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span><span class="dashicons dashicons-star-filled"></span></a> rating. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Rate it!</a> It’ll mean the world to us and keep this plugin free and constantly updated. <a href="https://wordpress.org/support/plugin/header-footer-code-manager/reviews/">Leave A Review</a>', '99robots-header-footer-code-manager'); ?>
242
+ </p>
243
+ </div>
244
+ <?php
245
+ }
246
  }
247
 
248
  // Check if current user has already dismissed it
249
+ function hfcm_plugin_notice_dismissed()
250
+ {
251
  $user_id = get_current_user_id();
252
+ // Checking if user clicked on the Dismiss button
253
+ if (isset($_GET['hfcm-admin-notice-dismissed'])) {
254
+ add_user_meta($user_id, 'hfcm_plugin_notice_dismissed', 'true', true);
255
+ // Redirect to original page the user was on
256
+ $current_url = wp_get_referer();
257
+ wp_redirect($current_url);
258
+ exit;
259
+ }
260
  }
261
+ add_action('admin_init', 'hfcm_plugin_notice_dismissed');
262
 
263
  /*****/
264
 
265
  // Files containing submenu functions
266
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-list.php');
267
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-create.php');
268
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-update.php');
269
+ require_once(plugin_dir_path(__FILE__) . 'includes/hfcm-request-handler.php');
270
 
271
  // Function to render the snippet
272
+ function hfcm_render_snippet($scriptdata)
273
+ {
274
+ $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
275
 
276
+ return $output;
277
  }
278
 
279
  // Function to implement shortcode
280
+ function hfcm_shortcode($atts)
281
+ {
282
+ global $wpdb;
283
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
284
+ if (! empty($atts['id'])) {
285
+ $id = (int) $atts['id'];
286
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
287
+ $script = $wpdb->get_results($wpdb->prepare("SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id));
288
+ if (! empty($script)) {
289
+ return hfcm_render_snippet($script[0]);
290
+ }
291
+ }
292
  }
293
+ add_shortcode('hfcm', 'hfcm_shortcode');
294
 
295
  // Function to json_decode array and check if empty
296
+ function hfcm_not_empty($scriptdata, $prop_name)
297
+ {
298
+ $data = json_decode($scriptdata->{$prop_name});
299
+ if (empty($data)) {
300
+ return false;
301
+ }
302
+ return true;
303
  }
304
 
305
  // Function to decide which snippets to show - triggered by hooks
306
+ function hfcm_add_snippets($location = '', $content = '')
307
+ {
308
+ global $wpdb;
309
+
310
+ $beforecontent = '';
311
+ $aftercontent = '';
312
+
313
+ if ($location && in_array($location, array( 'header', 'footer' ))) {
314
+ $display_location = "location='$location'";
315
+ } else {
316
+ $display_location = "location NOT IN ( 'header', 'footer' )";
317
+ }
318
+
319
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
320
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
321
+ $script = $wpdb->get_results("SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'");
322
+
323
+ if (! empty($script)) {
324
+ foreach ($script as $key => $scriptdata) {
325
+ $out = '';
326
+ switch ($scriptdata->display_on) {
327
+ case 'All':
328
+
329
+ if ((hfcm_not_empty($scriptdata, 'ex_pages') && is_page(json_decode($scriptdata->ex_pages))) || (hfcm_not_empty($scriptdata, 'ex_posts') && is_single(json_decode($scriptdata->ex_posts)))) {
330
+ $out = '';
331
+ } else {
332
+ $out = hfcm_render_snippet($scriptdata);
333
+ }
334
+ break;
335
+ case 'latest_posts':
336
+ if (is_single()) {
337
+ $args = array(
338
+ 'public' => true,
339
+ '_builtin' => false,
340
+ );
341
+ $output = 'names'; // names or objects, note names is the default
342
+ $operator = 'and'; // 'and' or 'or'
343
+ $c_posttypes = get_post_types($args, $output, $operator);
344
+ $posttypes = array( 'post' );
345
+ foreach ($c_posttypes as $cpkey => $cpdata) {
346
+ $posttypes[] = $cpdata;
347
+ }
348
+ if (! empty($scriptdata->lp_count)) {
349
+ $latestposts = wp_get_recent_posts(array(
350
+ 'numberposts' => $scriptdata->lp_count,
351
+ 'post_type' => $posttypes,
352
+ ));
353
+ } else {
354
+ $latestposts = wp_get_recent_posts(array( 'post_type' => $posttypes ));
355
+ }
356
+
357
+ $islatest = false;
358
+ foreach ($latestposts as $key => $lpostdata) {
359
+ if (get_the_ID() == $lpostdata['ID']) {
360
+ $islatest = true;
361
+ }
362
+ }
363
+
364
+ if ($islatest) {
365
+ $out = hfcm_render_snippet($scriptdata);
366
+ }
367
+ }
368
+ break;
369
+ case 's_categories':
370
+ if (hfcm_not_empty($scriptdata, 's_categories') && in_category(json_decode($scriptdata->s_categories))) {
371
+ if (is_category(json_decode($scriptdata->s_categories))) {
372
+ $out = hfcm_render_snippet($scriptdata);
373
+ }
374
+ if (!is_archive() && !is_home()) {
375
+ $out = hfcm_render_snippet($scriptdata);
376
+ }
377
+ }
378
+ break;
379
+ case 's_custom_posts':
380
+ if (hfcm_not_empty($scriptdata, 's_custom_posts') && is_singular(json_decode($scriptdata->s_custom_posts))) {
381
+ $out = hfcm_render_snippet($scriptdata);
382
+ }
383
+ break;
384
+ case 's_posts':
385
+ if (hfcm_not_empty($scriptdata, 's_posts') && is_single(json_decode($scriptdata->s_posts))) {
386
+ $out = hfcm_render_snippet($scriptdata);
387
+ }
388
+ break;
389
+ case 's_pages':
390
+ if (hfcm_not_empty($scriptdata, 's_pages')) {
391
+ // Gets the page ID of the blog page
392
+ $blog_page = get_option('page_for_posts');
393
+ // Checks if the blog page is present in the array of selected pages
394
+ if (in_array($blog_page, json_decode($scriptdata->s_pages))) {
395
+ if (is_page(json_decode($scriptdata->s_pages)) || (!is_front_page() && is_home())) {
396
+ $out = hfcm_render_snippet($scriptdata);
397
+ }
398
+ } elseif (is_page(json_decode($scriptdata->s_pages))) {
399
+ $out = hfcm_render_snippet($scriptdata);
400
+ }
401
+ }
402
+ break;
403
+ case 's_tags':
404
+ if (hfcm_not_empty($scriptdata, 's_tags') && has_tag(json_decode($scriptdata->s_tags))) {
405
+ if (is_tag(json_decode($scriptdata->s_tags))) {
406
+ $out = hfcm_render_snippet($scriptdata);
407
+ }
408
+ if (!is_archive() && !is_home()) {
409
+ $out = hfcm_render_snippet($scriptdata);
410
+ }
411
+ }
412
+ }
413
+
414
+ switch ($scriptdata->location) {
415
+ case 'before_content':
416
+ $beforecontent .= $out;
417
+ break;
418
+ case 'after_content':
419
+ $aftercontent .= $out;
420
+ break;
421
+ default:
422
+ echo $out;
423
+ }
424
+ }
425
+ }
426
+ // Return results after the loop finishes
427
+ return $beforecontent . $content . $aftercontent;
428
  }
429
 
430
  // Function to add snippets in the header
431
+ function hfcm_header_scripts()
432
+ {
433
+ hfcm_add_snippets('header');
434
  }
435
+ add_action('wp_head', 'hfcm_header_scripts');
436
 
437
  // Function to add snippets in the footer
438
+ function hfcm_footer_scripts()
439
+ {
440
+ hfcm_add_snippets('footer');
441
  }
442
+ add_action('wp_footer', 'hfcm_footer_scripts');
443
 
444
 
445
  // Function to add snippets before/after the content
446
+ function hfcm_content_scripts($content)
447
+ {
448
+ return hfcm_add_snippets(false, $content);
449
  }
450
+ add_action('the_content', 'hfcm_content_scripts');
451
 
452
  // Load redirection Javascript code
453
+ function hfcm_redirect($url = '')
454
+ {
455
+ // Register the script
456
+ wp_register_script('hfcm_redirection', plugins_url('js/location.js', __FILE__));
457
 
458
+ // Localize the script with new data
459
+ $translation_array = array( 'url' => $url );
460
+ wp_localize_script('hfcm_redirection', 'hfcm_location', $translation_array);
461
 
462
+ // Enqueued script with localized data.
463
+ wp_enqueue_script('hfcm_redirection');
464
  }
465
 
466
  // Handle AJAX requests
467
+ add_action('wp_ajax_hfcm-request', 'hfcm_request_handler');
468
 
469
  // Function to sanitize POST data
470
+ function hfcm_sanitize_text($key, $sanitize = true)
471
+ {
472
+ if (! empty($_POST['data'][ $key ])) {
473
+ $out = stripslashes_deep($_POST['data'][ $key ]);
474
+ if ($sanitize) {
475
+ $out = sanitize_text_field($out);
476
+ }
477
+ return $out;
478
+ }
479
 
480
+ return '';
481
  }
482
 
483
  // Function to sanitize strings within POST data arrays
484
+ function hfcm_sanitize_array($key, $type = 'integer')
485
+ {
486
+ if (! empty($_POST['data'][ $key ])) {
487
+ $arr = $_POST['data'][ $key ];
488
+
489
+ if (! is_array($arr)) {
490
+ return array();
491
+ }
492
+
493
+ if ('integer' === $type) {
494
+ return array_map('absint', $arr);
495
+ } else { // strings
496
+ $new_array = array();
497
+ foreach ($arr as $val) {
498
+ $new_array[] = sanitize_text_field($val);
499
+ }
500
+ }
501
+
502
+ return $new_array;
503
+ }
504
 
505
+ return array();
506
  }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: 99robots, charliepatel, DraftPress
3
  Tags: header, footer, code manager, snippet, functions.php, tracking, google analytics, adsense, verification, pixel
4
  Requires at least: 4.0
5
- Tested up to: 5.5.0
6
- Stable tag: 1.1.8
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://draftpress.com
@@ -113,6 +113,9 @@ A. If your script is not supported, just let us know and we'll look into it imme
113
 
114
  == Changelog ==
115
 
 
 
 
116
  = 1.1.8 = 2020-09-01
117
  * FIXED: Specific Taxonomy Snippets showing on archives with at least one instance.
118
  * UPDATED: Compatibility with WordPress 5.5.0
2
  Contributors: 99robots, charliepatel, DraftPress
3
  Tags: header, footer, code manager, snippet, functions.php, tracking, google analytics, adsense, verification, pixel
4
  Requires at least: 4.0
5
+ Tested up to: 5.6.1
6
+ Stable tag: 1.1.9
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://draftpress.com
113
 
114
  == Changelog ==
115
 
116
+ = 1.1.9 = 2021-02-18
117
+ * UPDATED: Compatibility with WordPress 5.6.1
118
+
119
  = 1.1.8 = 2020-09-01
120
  * FIXED: Specific Taxonomy Snippets showing on archives with at least one instance.
121
  * UPDATED: Compatibility with WordPress 5.5.0