Version Description
2021-02-18 * UPDATED: Compatibility with WordPress 5.6.1
Download this release
Release Info
Developer | 99robots |
Plugin | Header Footer Code Manager |
Version | 1.1.9 |
Comparing to | |
See all releases |
Code changes from version 1.1.8 to 1.1.9
- 99robots-header-footer-code-manager.php +385 -372
- 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.
|
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 (
|
16 |
-
|
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 |
-
|
27 |
-
|
28 |
-
update_option( 'hfcm_activation_date', $hfcm_now );
|
29 |
-
|
30 |
-
global $wpdb;
|
31 |
-
global $hfcm_db_version;
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
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 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
}
|
64 |
-
register_activation_hook(
|
65 |
|
66 |
-
function hfcm_db_update_check()
|
|
|
67 |
global $hfcm_db_version;
|
68 |
-
|
69 |
-
|
70 |
-
if (
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
93 |
hfcm_options_install();
|
94 |
}
|
95 |
-
|
96 |
}
|
97 |
-
add_action(
|
98 |
|
99 |
/*
|
100 |
* Enqueue style-file, if it exists.
|
101 |
*/
|
102 |
-
function hfcm_enqueue_assets(
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
}
|
131 |
-
add_action(
|
132 |
|
133 |
/*
|
134 |
* This function loads plugins translation files
|
135 |
*/
|
136 |
-
function hfcm_load_translation_files()
|
137 |
-
|
|
|
138 |
}
|
139 |
-
add_action(
|
140 |
|
141 |
// function to create menu page, and submenu pages.
|
142 |
-
function hfcm_modifymenu()
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
193 |
}
|
194 |
-
add_action(
|
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(
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
203 |
}
|
204 |
|
205 |
//Check Installation Date
|
206 |
-
function hfcm_check_installation_date()
|
207 |
-
|
208 |
-
$install_date = get_option(
|
209 |
-
$past_date = strtotime(
|
210 |
-
|
211 |
-
if ( $past_date >= $install_date ) {
|
212 |
-
|
213 |
-
add_action( 'admin_notices', 'hfcm_review_push_notice' );
|
214 |
|
|
|
|
|
215 |
}
|
216 |
-
|
217 |
}
|
218 |
-
add_action(
|
219 |
|
220 |
// Create the Admin Notice
|
221 |
-
function hfcm_review_push_notice()
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
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 |
-
|
247 |
-
if (
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
}
|
255 |
-
add_action(
|
256 |
|
257 |
/*****/
|
258 |
|
259 |
// Files containing submenu functions
|
260 |
-
require_once(
|
261 |
-
require_once(
|
262 |
-
require_once(
|
263 |
-
require_once(
|
264 |
|
265 |
// Function to render the snippet
|
266 |
-
function hfcm_render_snippet(
|
267 |
-
|
|
|
268 |
|
269 |
-
|
270 |
}
|
271 |
|
272 |
// Function to implement shortcode
|
273 |
-
function hfcm_shortcode(
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
|
|
284 |
}
|
285 |
-
add_shortcode(
|
286 |
|
287 |
// Function to json_decode array and check if empty
|
288 |
-
function hfcm_not_empty(
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
|
|
294 |
}
|
295 |
|
296 |
// Function to decide which snippets to show - triggered by hooks
|
297 |
-
function hfcm_add_snippets(
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
}
|
420 |
|
421 |
// Function to add snippets in the header
|
422 |
-
function hfcm_header_scripts()
|
423 |
-
|
|
|
424 |
}
|
425 |
-
add_action(
|
426 |
|
427 |
// Function to add snippets in the footer
|
428 |
-
function hfcm_footer_scripts()
|
429 |
-
|
|
|
430 |
}
|
431 |
-
add_action(
|
432 |
|
433 |
|
434 |
// Function to add snippets before/after the content
|
435 |
-
function hfcm_content_scripts(
|
436 |
-
|
|
|
437 |
}
|
438 |
-
add_action(
|
439 |
|
440 |
// Load redirection Javascript code
|
441 |
-
function hfcm_redirect(
|
442 |
-
|
443 |
-
|
|
|
444 |
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
|
449 |
-
|
450 |
-
|
451 |
}
|
452 |
|
453 |
// Handle AJAX requests
|
454 |
-
add_action(
|
455 |
|
456 |
// Function to sanitize POST data
|
457 |
-
function hfcm_sanitize_text(
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
|
467 |
-
|
468 |
}
|
469 |
|
470 |
// Function to sanitize strings within POST data arrays
|
471 |
-
function hfcm_sanitize_array(
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
|
492 |
-
|
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.
|
6 |
-
Stable tag: 1.1.
|
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
|