Version Description
2022-06-29 * UPDATED: Code improvements as per WordPress standards
Download this release
Release Info
Developer | 99robots |
Plugin | Header Footer Code Manager |
Version | 1.1.25 |
Comparing to | |
See all releases |
Code changes from version 1.1.24 to 1.1.25
- 99robots-header-footer-code-manager.php +527 -424
- css/style-admin.css +69 -69
- includes/class-hfcm-snippets-list.php +236 -212
- includes/hfcm-add-edit.php +139 -129
- includes/hfcm-tools.php +27 -23
- js/location.js +2 -2
- js/nnr-hfcm-showboxes.js +67 -55
- js/toggle.js +33 -22
- readme.txt +4 -1
- uninstall.php +4 -4
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 |
* Requires at least: 4.9
|
8 |
* Requires PHP: 5.6.20
|
9 |
* Author: 99robots
|
@@ -16,28 +16,32 @@
|
|
16 |
/*
|
17 |
* If this file is called directly, abort.
|
18 |
*/
|
19 |
-
if (
|
20 |
die;
|
21 |
}
|
22 |
|
23 |
-
register_activation_hook(
|
24 |
-
add_action(
|
25 |
-
add_action(
|
26 |
-
add_action(
|
27 |
-
add_action(
|
28 |
-
add_filter(
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
add_action(
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
|
37 |
// Files containing submenu functions
|
38 |
-
require_once
|
39 |
|
40 |
-
if (
|
41 |
|
42 |
class NNR_HFCM
|
43 |
{
|
@@ -60,16 +64,15 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
60 |
*/
|
61 |
public static function hfcm_options_install()
|
62 |
{
|
63 |
-
$hfcm_now = strtotime(
|
64 |
-
add_option(
|
65 |
-
update_option(
|
66 |
|
67 |
global $wpdb;
|
68 |
|
69 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
70 |
$charset_collate = $wpdb->get_charset_collate();
|
71 |
-
$sql =
|
72 |
-
"CREATE TABLE $table_name (
|
73 |
`script_id` int(10) NOT NULL AUTO_INCREMENT,
|
74 |
`name` varchar(100) DEFAULT NULL,
|
75 |
`snippet` LONGTEXT,
|
@@ -91,11 +94,11 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
91 |
`created` datetime DEFAULT NULL,
|
92 |
`last_revision_date` datetime DEFAULT NULL,
|
93 |
PRIMARY KEY (`script_id`)
|
94 |
-
) $charset_collate
|
95 |
|
96 |
-
|
97 |
-
dbDelta(
|
98 |
-
add_option(
|
99 |
}
|
100 |
|
101 |
/*
|
@@ -106,61 +109,67 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
106 |
global $wpdb;
|
107 |
|
108 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
109 |
-
if (
|
110 |
$wpdb->show_errors();
|
111 |
|
112 |
-
if (
|
113 |
// Check for Exclude Pages
|
114 |
$nnr_column_ex_pages = 'ex_pages';
|
115 |
-
$nnr_check_column_ex_pages = $wpdb->get_results(
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
124 |
}
|
125 |
|
126 |
// Check for Exclude Posts
|
127 |
$nnr_column_ex_posts = 'ex_posts';
|
128 |
-
$nnr_check_column_ex_posts = $wpdb->get_results(
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
137 |
}
|
138 |
|
139 |
// Check for Snippet Type
|
140 |
$nnr_column_snippet_type = 'snippet_type';
|
141 |
-
$nnr_check_column_snippet_type = $wpdb->get_results(
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
150 |
}
|
151 |
|
152 |
-
$nnr_alter_sql = "ALTER TABLE
|
153 |
-
$wpdb->query(
|
154 |
|
155 |
-
$nnr_alter_sql = "ALTER TABLE
|
156 |
-
$wpdb->query(
|
157 |
|
158 |
-
$nnr_alter_sql = "ALTER TABLE
|
159 |
-
$wpdb->query(
|
160 |
}
|
161 |
self::hfcm_options_install();
|
162 |
}
|
163 |
-
update_option(
|
164 |
}
|
165 |
|
166 |
/*
|
@@ -174,27 +183,27 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
174 |
'admin_page_hfcm-update',
|
175 |
);
|
176 |
|
177 |
-
wp_register_style(
|
178 |
-
wp_enqueue_style(
|
179 |
|
180 |
-
if (
|
181 |
// Plugin's CSS
|
182 |
-
wp_register_style(
|
183 |
-
wp_enqueue_style(
|
184 |
}
|
185 |
|
186 |
// Remove hfcm-list from $allowed_pages
|
187 |
-
array_shift(
|
188 |
|
189 |
-
if (
|
190 |
// selectize.js plugin CSS and JS files
|
191 |
-
wp_register_style(
|
192 |
-
wp_enqueue_style(
|
193 |
|
194 |
-
wp_register_script(
|
195 |
-
wp_enqueue_script(
|
196 |
|
197 |
-
wp_enqueue_code_editor(
|
198 |
}
|
199 |
}
|
200 |
|
@@ -204,7 +213,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
204 |
|
205 |
public static function hfcm_load_translation_files()
|
206 |
{
|
207 |
-
load_plugin_textdomain(
|
208 |
}
|
209 |
|
210 |
/*
|
@@ -215,8 +224,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
215 |
|
216 |
// This is the main item for the menu
|
217 |
add_menu_page(
|
218 |
-
__(
|
219 |
-
__(
|
220 |
'manage_options',
|
221 |
'hfcm-list',
|
222 |
array( 'NNR_HFCM', 'hfcm_list' ),
|
@@ -226,8 +235,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
226 |
// This is a submenu
|
227 |
add_submenu_page(
|
228 |
'hfcm-list',
|
229 |
-
__(
|
230 |
-
__(
|
231 |
'manage_options',
|
232 |
'hfcm-list',
|
233 |
array( 'NNR_HFCM', 'hfcm_list' )
|
@@ -236,8 +245,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
236 |
// This is a submenu
|
237 |
add_submenu_page(
|
238 |
'hfcm-list',
|
239 |
-
__(
|
240 |
-
__(
|
241 |
'manage_options',
|
242 |
'hfcm-create',
|
243 |
array( 'NNR_HFCM', 'hfcm_create' )
|
@@ -246,8 +255,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
246 |
// This is a submenu
|
247 |
add_submenu_page(
|
248 |
'hfcm-list',
|
249 |
-
__(
|
250 |
-
__(
|
251 |
'manage_options',
|
252 |
'hfcm-tools',
|
253 |
array( 'NNR_HFCM', 'hfcm_tools' )
|
@@ -256,8 +265,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
256 |
// This submenu is HIDDEN, however, we need to add it anyways
|
257 |
add_submenu_page(
|
258 |
null,
|
259 |
-
__(
|
260 |
-
__(
|
261 |
'manage_options',
|
262 |
'hfcm-update',
|
263 |
array( 'NNR_HFCM', 'hfcm_update' )
|
@@ -266,8 +275,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
266 |
// This submenu is HIDDEN, however, we need to add it anyways
|
267 |
add_submenu_page(
|
268 |
null,
|
269 |
-
__(
|
270 |
-
__(
|
271 |
'manage_options',
|
272 |
'hfcm-request-handler',
|
273 |
array( 'NNR_HFCM', 'hfcm_request_handler' )
|
@@ -280,7 +289,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
280 |
public static function hfcm_add_plugin_page_settings_link( $links )
|
281 |
{
|
282 |
$links = array_merge(
|
283 |
-
array( '<a href="' . admin_url(
|
284 |
$links
|
285 |
);
|
286 |
return $links;
|
@@ -291,13 +300,13 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
291 |
*/
|
292 |
public static function hfcm_check_installation_date()
|
293 |
{
|
294 |
-
$install_date = get_option(
|
295 |
-
$past_date = strtotime(
|
296 |
|
297 |
-
if (
|
298 |
-
add_action(
|
299 |
}
|
300 |
-
add_action(
|
301 |
}
|
302 |
|
303 |
/*
|
@@ -314,13 +323,13 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
314 |
|
315 |
$user_id = get_current_user_id();
|
316 |
// Check if current user has already dismissed it
|
317 |
-
$install_date = get_option(
|
318 |
|
319 |
-
if (
|
320 |
?>
|
321 |
<div id="hfcm-message" class="notice notice-success">
|
322 |
<a class="hfcm-dismiss-alert notice-dismiss" href="?hfcm-admin-notice-dismissed">Dismiss</a>
|
323 |
-
<p><?php _e(
|
324 |
</p>
|
325 |
</div>
|
326 |
<?php
|
@@ -339,7 +348,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
339 |
);
|
340 |
$screen = get_current_screen()->id;
|
341 |
|
342 |
-
if (
|
343 |
?>
|
344 |
<div id="hfcm-message" class="notice notice-success">
|
345 |
<p>
|
@@ -361,11 +370,11 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
361 |
{
|
362 |
$user_id = get_current_user_id();
|
363 |
// Checking if user clicked on the Dismiss button
|
364 |
-
if (
|
365 |
-
add_user_meta(
|
366 |
// Redirect to original page the user was on
|
367 |
$current_url = wp_get_referer();
|
368 |
-
wp_redirect(
|
369 |
exit;
|
370 |
}
|
371 |
}
|
@@ -375,7 +384,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
375 |
*/
|
376 |
public static function hfcm_render_snippet( $scriptdata )
|
377 |
{
|
378 |
-
$
|
|
|
379 |
|
380 |
return $output;
|
381 |
}
|
@@ -387,12 +397,18 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
387 |
{
|
388 |
global $wpdb;
|
389 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
390 |
-
if (
|
391 |
-
$id = (
|
392 |
$hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
|
393 |
-
$script = $wpdb->get_results(
|
394 |
-
|
395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
}
|
397 |
}
|
398 |
}
|
@@ -402,8 +418,8 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
402 |
*/
|
403 |
public static function hfcm_not_empty( $scriptdata, $prop_name )
|
404 |
{
|
405 |
-
$data = json_decode(
|
406 |
-
if (
|
407 |
return false;
|
408 |
}
|
409 |
return true;
|
@@ -418,128 +434,137 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
418 |
|
419 |
$beforecontent = '';
|
420 |
$aftercontent = '';
|
|
|
|
|
|
|
|
|
|
|
421 |
|
422 |
-
if (
|
423 |
-
$
|
|
|
424 |
} else {
|
425 |
-
$
|
426 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
427 |
|
428 |
-
|
429 |
-
$hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
|
430 |
-
$script = $wpdb->get_results( "SELECT * FROM $table_name WHERE $display_location AND status='active' AND device_type!='$hide_device'" );
|
431 |
-
|
432 |
-
if ( !empty( $script ) ) {
|
433 |
foreach ( $script as $key => $scriptdata ) {
|
434 |
$out = '';
|
435 |
switch ( $scriptdata->display_on ) {
|
436 |
-
|
437 |
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
} else {
|
443 |
-
$
|
|
|
|
|
|
|
|
|
444 |
}
|
445 |
-
break;
|
446 |
-
case 'latest_posts':
|
447 |
-
if ( is_single() ) {
|
448 |
-
if ( !empty( $scriptdata->lp_count ) ) {
|
449 |
-
$nnr_hfcm_latest_posts = wp_get_recent_posts(
|
450 |
-
array(
|
451 |
-
'numberposts' => $scriptdata->lp_count,
|
452 |
-
)
|
453 |
-
);
|
454 |
-
} else {
|
455 |
-
$nnr_hfcm_latest_posts = wp_get_recent_posts(
|
456 |
-
array(
|
457 |
-
'numberposts' => 5
|
458 |
-
)
|
459 |
-
);
|
460 |
-
}
|
461 |
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
}
|
466 |
}
|
467 |
}
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
if ( !is_archive() && !is_home() ) {
|
476 |
-
$out = self::hfcm_render_snippet( $scriptdata );
|
477 |
-
}
|
478 |
-
}
|
479 |
-
break;
|
480 |
-
case 's_custom_posts':
|
481 |
-
$is_not_empty_s_custom_posts = self::hfcm_not_empty( $scriptdata, 's_custom_posts' );
|
482 |
-
if ( $is_not_empty_s_custom_posts && is_singular( json_decode( $scriptdata->s_custom_posts ) ) ) {
|
483 |
-
$out = self::hfcm_render_snippet( $scriptdata );
|
484 |
-
}
|
485 |
-
break;
|
486 |
-
case 's_posts':
|
487 |
-
$is_not_empty_s_posts = self::hfcm_not_empty( $scriptdata, 's_posts' );
|
488 |
-
if ( $is_not_empty_s_posts && is_single( json_decode( $scriptdata->s_posts ) ) ) {
|
489 |
-
$out = self::hfcm_render_snippet( $scriptdata );
|
490 |
-
}
|
491 |
-
break;
|
492 |
-
case 's_is_home':
|
493 |
-
if ( is_home() ) {
|
494 |
-
$out = self::hfcm_render_snippet( $scriptdata );
|
495 |
-
}
|
496 |
-
break;
|
497 |
-
case 's_is_archive':
|
498 |
-
if ( is_archive() ) {
|
499 |
-
$out = self::hfcm_render_snippet( $scriptdata );
|
500 |
}
|
501 |
-
|
502 |
-
|
503 |
-
if ( is_search() ) {
|
504 |
-
$out = self::hfcm_render_snippet( $scriptdata );
|
505 |
}
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
}
|
|
|
|
|
520 |
}
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
if ( !is_archive() && !is_home() ) {
|
529 |
-
$out = self::hfcm_render_snippet( $scriptdata );
|
530 |
-
}
|
531 |
}
|
|
|
|
|
|
|
|
|
532 |
}
|
533 |
|
534 |
switch ( $scriptdata->location ) {
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
|
|
543 |
}
|
544 |
}
|
545 |
}
|
@@ -547,12 +572,66 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
547 |
return $beforecontent . $content . $aftercontent;
|
548 |
}
|
549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
550 |
/*
|
551 |
* function to add snippets in the header
|
552 |
*/
|
553 |
public static function hfcm_header_scripts()
|
554 |
{
|
555 |
-
self::hfcm_add_snippets(
|
556 |
}
|
557 |
|
558 |
/*
|
@@ -560,7 +639,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
560 |
*/
|
561 |
public static function hfcm_footer_scripts()
|
562 |
{
|
563 |
-
self::hfcm_add_snippets(
|
564 |
}
|
565 |
|
566 |
/*
|
@@ -568,7 +647,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
568 |
*/
|
569 |
public static function hfcm_content_scripts( $content )
|
570 |
{
|
571 |
-
return self::hfcm_add_snippets(
|
572 |
}
|
573 |
|
574 |
/*
|
@@ -577,14 +656,14 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
577 |
public static function hfcm_redirect( $url = '' )
|
578 |
{
|
579 |
// Register the script
|
580 |
-
wp_register_script(
|
581 |
|
582 |
// Localize the script with new data
|
583 |
$translation_array = array( 'url' => $url );
|
584 |
-
wp_localize_script(
|
585 |
|
586 |
// Enqueued script with localized data.
|
587 |
-
wp_enqueue_script(
|
588 |
}
|
589 |
|
590 |
/*
|
@@ -592,12 +671,13 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
592 |
*/
|
593 |
public static function hfcm_sanitize_text( $key, $is_not_snippet = true )
|
594 |
{
|
595 |
-
if (
|
596 |
-
$post_data = stripslashes_deep(
|
597 |
-
if (
|
598 |
-
$post_data = sanitize_text_field(
|
599 |
} else {
|
600 |
-
$
|
|
|
601 |
}
|
602 |
return $post_data;
|
603 |
}
|
@@ -610,19 +690,19 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
610 |
*/
|
611 |
public static function hfcm_sanitize_array( $key, $type = 'integer' )
|
612 |
{
|
613 |
-
if (
|
614 |
$arr = $_POST['data'][ $key ];
|
615 |
|
616 |
-
if (
|
617 |
return array();
|
618 |
}
|
619 |
|
620 |
-
if (
|
621 |
-
return array_map(
|
622 |
} else { // strings
|
623 |
$new_array = array();
|
624 |
foreach ( $arr as $val ) {
|
625 |
-
$new_array[] = sanitize_text_field(
|
626 |
}
|
627 |
}
|
628 |
|
@@ -639,7 +719,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
639 |
{
|
640 |
|
641 |
// check user capabilities
|
642 |
-
current_user_can(
|
643 |
|
644 |
// prepare variables for includes/hfcm-add-edit.php
|
645 |
$name = '';
|
@@ -661,7 +741,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
661 |
// Notify hfcm-add-edit.php NOT to make changes for update
|
662 |
$update = false;
|
663 |
|
664 |
-
|
665 |
}
|
666 |
|
667 |
/*
|
@@ -671,29 +751,29 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
671 |
{
|
672 |
|
673 |
// Check user capabilities
|
674 |
-
current_user_can(
|
675 |
|
676 |
-
if (
|
677 |
// Check nonce
|
678 |
-
check_admin_referer(
|
679 |
} else {
|
680 |
-
if (
|
681 |
-
die(
|
682 |
}
|
683 |
-
$id = absint(
|
684 |
}
|
685 |
-
if (
|
686 |
// Check nonce
|
687 |
-
check_admin_referer(
|
688 |
}
|
689 |
|
690 |
// Handle AJAX on/off toggle for snippets
|
691 |
-
if (
|
692 |
|
693 |
// Check nonce
|
694 |
-
check_ajax_referer(
|
695 |
|
696 |
-
if (
|
697 |
$status = 'active';
|
698 |
} else {
|
699 |
$status = 'inactive';
|
@@ -711,31 +791,31 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
711 |
array( '%s' ) //where format
|
712 |
);
|
713 |
|
714 |
-
} elseif (
|
715 |
|
716 |
// Create / update snippet
|
717 |
|
718 |
// Sanitize fields
|
719 |
-
$name = self::hfcm_sanitize_text(
|
720 |
-
$snippet = self::hfcm_sanitize_text(
|
721 |
-
$nnr_snippet_type = self::hfcm_sanitize_text(
|
722 |
-
$device_type = self::hfcm_sanitize_text(
|
723 |
-
$display_on = self::hfcm_sanitize_text(
|
724 |
-
$location = self::hfcm_sanitize_text(
|
725 |
-
$lp_count = self::hfcm_sanitize_text(
|
726 |
-
$status = self::hfcm_sanitize_text(
|
727 |
-
$s_pages = self::hfcm_sanitize_array(
|
728 |
-
$ex_pages = self::hfcm_sanitize_array(
|
729 |
-
$s_posts = self::hfcm_sanitize_array(
|
730 |
-
$ex_posts = self::hfcm_sanitize_array(
|
731 |
-
$s_custom_posts = self::hfcm_sanitize_array(
|
732 |
-
$s_categories = self::hfcm_sanitize_array(
|
733 |
-
$s_tags = self::hfcm_sanitize_array(
|
734 |
-
|
735 |
-
if (
|
736 |
$location = '';
|
737 |
}
|
738 |
-
$lp_count = max(
|
739 |
|
740 |
// Global vars
|
741 |
global $wpdb;
|
@@ -743,9 +823,10 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
743 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
744 |
|
745 |
// Update snippet
|
746 |
-
if (
|
747 |
|
748 |
-
$wpdb->update(
|
|
|
749 |
// Data
|
750 |
array(
|
751 |
'name' => $name,
|
@@ -756,15 +837,15 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
756 |
'display_on' => $display_on,
|
757 |
'status' => $status,
|
758 |
'lp_count' => $lp_count,
|
759 |
-
's_pages' => wp_json_encode(
|
760 |
-
'ex_pages' => wp_json_encode(
|
761 |
-
's_posts' => wp_json_encode(
|
762 |
-
'ex_posts' => wp_json_encode(
|
763 |
-
's_custom_posts' => wp_json_encode(
|
764 |
-
's_categories' => wp_json_encode(
|
765 |
-
's_tags' => wp_json_encode(
|
766 |
-
'last_revision_date' => current_time(
|
767 |
-
'last_modified_by' => sanitize_text_field(
|
768 |
),
|
769 |
// Where
|
770 |
array( 'script_id' => $id ),
|
@@ -783,11 +864,12 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
783 |
// Where format
|
784 |
array( '%s' )
|
785 |
);
|
786 |
-
self::hfcm_redirect(
|
787 |
} else {
|
788 |
|
789 |
// Create new snippet
|
790 |
-
$wpdb->insert(
|
|
|
791 |
array(
|
792 |
'name' => $name,
|
793 |
'snippet' => $snippet,
|
@@ -797,15 +879,15 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
797 |
'display_on' => $display_on,
|
798 |
'status' => $status,
|
799 |
'lp_count' => $lp_count,
|
800 |
-
's_pages' => wp_json_encode(
|
801 |
-
'ex_pages' => wp_json_encode(
|
802 |
-
's_posts' => wp_json_encode(
|
803 |
-
'ex_posts' => wp_json_encode(
|
804 |
-
's_custom_posts' => wp_json_encode(
|
805 |
-
's_categories' => wp_json_encode(
|
806 |
-
's_tags' => wp_json_encode(
|
807 |
-
'created' => current_time(
|
808 |
-
'created_by' => sanitize_text_field(
|
809 |
), array(
|
810 |
'%s',
|
811 |
'%s',
|
@@ -827,41 +909,45 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
827 |
)
|
828 |
);
|
829 |
$lastid = $wpdb->insert_id;
|
830 |
-
self::hfcm_redirect(
|
831 |
}
|
832 |
-
} elseif (
|
833 |
|
834 |
// JSON return posts for AJAX
|
835 |
|
836 |
// Check nonce
|
837 |
-
check_ajax_referer(
|
838 |
|
839 |
// Global vars
|
840 |
global $wpdb;
|
841 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
842 |
// Get all selected posts
|
843 |
-
if (
|
844 |
$s_posts = array();
|
845 |
$ex_posts = array();
|
846 |
} else {
|
847 |
// Select value to update
|
848 |
-
$script = $wpdb->get_results(
|
|
|
|
|
849 |
$s_posts = array();
|
850 |
-
if (
|
851 |
foreach ( $script as $s ) {
|
852 |
-
$s_posts = json_decode(
|
853 |
-
if (
|
854 |
$s_posts = array();
|
855 |
}
|
856 |
}
|
857 |
}
|
858 |
|
859 |
$ex_posts = array();
|
860 |
-
$script_ex = $wpdb->get_results(
|
861 |
-
|
|
|
|
|
862 |
foreach ( $script_ex as $s ) {
|
863 |
-
$ex_posts = json_decode(
|
864 |
-
if (
|
865 |
$ex_posts = array();
|
866 |
}
|
867 |
}
|
@@ -877,7 +963,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
877 |
$output = 'names'; // names or objects, note names is the default
|
878 |
$operator = 'and'; // 'and' or 'or'
|
879 |
|
880 |
-
$c_posttypes = get_post_types(
|
881 |
$posttypes = array( 'post' );
|
882 |
foreach ( $c_posttypes as $cpdata ) {
|
883 |
$posttypes[] = $cpdata;
|
@@ -898,29 +984,29 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
898 |
'excluded' => array(),
|
899 |
);
|
900 |
|
901 |
-
if (
|
902 |
foreach ( $posts as $pdata ) {
|
903 |
-
$nnr_hfcm_post_title = trim(
|
904 |
|
905 |
-
if (
|
906 |
$nnr_hfcm_post_title = "(no title)";
|
907 |
}
|
908 |
-
if (
|
909 |
$json_output['excluded'][] = $pdata->ID;
|
910 |
}
|
911 |
|
912 |
-
if (
|
913 |
$json_output['selected'][] = $pdata->ID;
|
914 |
}
|
915 |
|
916 |
$json_output['posts'][] = array(
|
917 |
-
'text' => sanitize_text_field(
|
918 |
'value' => $pdata->ID,
|
919 |
);
|
920 |
}
|
921 |
}
|
922 |
|
923 |
-
echo wp_json_encode(
|
924 |
wp_die();
|
925 |
}
|
926 |
}
|
@@ -931,21 +1017,23 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
931 |
public static function hfcm_update()
|
932 |
{
|
933 |
|
934 |
-
add_action(
|
935 |
|
936 |
// check user capabilities
|
937 |
-
current_user_can(
|
938 |
|
939 |
-
if (
|
940 |
-
die(
|
941 |
}
|
942 |
-
$id = absint(
|
943 |
|
944 |
global $wpdb;
|
945 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
946 |
|
947 |
//selecting value to update
|
948 |
-
$nnr_hfcm_snippets = $wpdb->get_results(
|
|
|
|
|
949 |
foreach ( $nnr_hfcm_snippets as $s ) {
|
950 |
$name = $s->name;
|
951 |
$snippet = $s->snippet;
|
@@ -955,66 +1043,66 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
955 |
$display_on = $s->display_on;
|
956 |
$status = $s->status;
|
957 |
$lp_count = $s->lp_count;
|
958 |
-
if (
|
959 |
$lp_count = 5;
|
960 |
}
|
961 |
-
$s_pages = json_decode(
|
962 |
-
$ex_pages = json_decode(
|
963 |
-
$ex_posts = json_decode(
|
964 |
|
965 |
-
if (
|
966 |
$s_pages = array();
|
967 |
}
|
968 |
|
969 |
-
if (
|
970 |
$ex_pages = array();
|
971 |
}
|
972 |
|
973 |
-
$s_posts = json_decode(
|
974 |
-
if (
|
975 |
$s_posts = array();
|
976 |
}
|
977 |
|
978 |
-
$ex_posts = json_decode(
|
979 |
-
if (
|
980 |
$ex_posts = array();
|
981 |
}
|
982 |
|
983 |
-
$s_custom_posts = json_decode(
|
984 |
-
if (
|
985 |
$s_custom_posts = array();
|
986 |
}
|
987 |
|
988 |
-
$s_categories = json_decode(
|
989 |
-
if (
|
990 |
$s_categories = array();
|
991 |
}
|
992 |
|
993 |
-
$s_tags = json_decode(
|
994 |
-
if (
|
995 |
$s_tags = array();
|
996 |
}
|
997 |
|
998 |
-
$createdby = esc_html(
|
999 |
-
$lastmodifiedby = esc_html(
|
1000 |
-
$createdon = esc_html(
|
1001 |
-
$lastrevisiondate = esc_html(
|
1002 |
}
|
1003 |
|
1004 |
// escape for html output
|
1005 |
-
$name = esc_textarea(
|
1006 |
-
$snippet = esc_textarea(
|
1007 |
-
$nnr_snippet_type = esc_textarea(
|
1008 |
-
$device_type = esc_html(
|
1009 |
-
$location = esc_html(
|
1010 |
-
$display_on = esc_html(
|
1011 |
-
$status = esc_html(
|
1012 |
-
$lp_count = esc_html(
|
1013 |
-
$i = esc_html(
|
1014 |
// Notify hfcm-add-edit.php to make necesary changes for update
|
1015 |
$update = true;
|
1016 |
|
1017 |
-
|
1018 |
}
|
1019 |
|
1020 |
/*
|
@@ -1032,17 +1120,19 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1032 |
|
1033 |
$is_pro_version_active = self::is_hfcm_pro_active();
|
1034 |
|
1035 |
-
if (
|
1036 |
?>
|
1037 |
<div class="notice hfcm-warning-notice notice-warning">
|
1038 |
-
<?php _e(
|
1039 |
-
|
|
|
|
|
1040 |
</div>
|
1041 |
<?php
|
1042 |
}
|
1043 |
|
1044 |
-
if (
|
1045 |
-
if (
|
1046 |
$message = "Header Footer Code Manager has successfully imported all snippets and set them as INACTIVE. Please review each snippet individually and ACTIVATE those that are needed for this site. Snippet types that are only available in the PRO version are skipped";
|
1047 |
} else {
|
1048 |
$message = "Header Footer Code Manager has successfully imported all snippets and set them as INACTIVE. Please review each snippet individually and ACTIVATE those that are needed for this site.";
|
@@ -1050,32 +1140,35 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1050 |
?>
|
1051 |
<div id="hfcm-message" class="notice notice-success is-dismissible">
|
1052 |
<p>
|
1053 |
-
<?php _e(
|
1054 |
</p>
|
1055 |
</div>
|
1056 |
<?php
|
1057 |
}
|
1058 |
-
if (
|
1059 |
-
|
|
|
|
|
1060 |
$allclass = '';
|
1061 |
-
if (
|
1062 |
$activeclass = 'current';
|
1063 |
}
|
1064 |
-
if (
|
1065 |
$inactiveclass = 'current';
|
1066 |
}
|
1067 |
}
|
1068 |
?>
|
1069 |
<div class="wrap">
|
1070 |
-
<h1><?php esc_html_e(
|
1071 |
-
<a href="<?php echo admin_url(
|
1072 |
-
|
|
|
1073 |
</h1>
|
1074 |
|
1075 |
<form method="post">
|
1076 |
<?php
|
1077 |
$snippet_obj->prepare_items();
|
1078 |
-
$snippet_obj->search_box(
|
1079 |
$snippet_obj->display();
|
1080 |
?>
|
1081 |
</form>
|
@@ -1084,17 +1177,17 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1084 |
<?php
|
1085 |
|
1086 |
// Register the script
|
1087 |
-
wp_register_script(
|
1088 |
|
1089 |
// Localize the script with new data
|
1090 |
$translation_array = array(
|
1091 |
-
'url' => admin_url(
|
1092 |
-
'security' => wp_create_nonce(
|
1093 |
);
|
1094 |
-
wp_localize_script(
|
1095 |
|
1096 |
// Enqueued script with localized data.
|
1097 |
-
wp_enqueue_script(
|
1098 |
}
|
1099 |
|
1100 |
/*
|
@@ -1105,9 +1198,9 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1105 |
global $wpdb;
|
1106 |
$nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
1107 |
|
1108 |
-
$nnr_hfcm_snippets = $wpdb->get_results(
|
1109 |
|
1110 |
-
|
1111 |
}
|
1112 |
|
1113 |
/*
|
@@ -1118,34 +1211,36 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1118 |
global $wpdb;
|
1119 |
$nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
1120 |
|
1121 |
-
if (
|
1122 |
$nnr_hfcm_snippets_comma_separated = "";
|
1123 |
foreach ( $_POST['nnr_hfcm_snippets'] as $nnr_hfcm_key => $nnr_hfcm_snippet ) {
|
1124 |
-
$nnr_hfcm_snippet = str_replace(
|
1125 |
-
$nnr_hfcm_snippet = absint(
|
1126 |
-
if (
|
1127 |
-
if (
|
1128 |
$nnr_hfcm_snippets_comma_separated .= $nnr_hfcm_snippet;
|
1129 |
} else {
|
1130 |
$nnr_hfcm_snippets_comma_separated .= "," . $nnr_hfcm_snippet;
|
1131 |
}
|
1132 |
}
|
1133 |
}
|
1134 |
-
if (
|
1135 |
-
$nnr_hfcm_snippets = $wpdb->get_results(
|
|
|
|
|
1136 |
|
1137 |
-
if (
|
1138 |
$nnr_hfcm_export_snippets = array( "title" => "Header Footer Code Manager" );
|
1139 |
|
1140 |
foreach ( $nnr_hfcm_snippets as $nnr_hfcm_snippet_key => $nnr_hfcm_snippet_item ) {
|
1141 |
-
unset(
|
1142 |
$nnr_hfcm_export_snippets['snippets'][ $nnr_hfcm_snippet_key ] = $nnr_hfcm_snippet_item;
|
1143 |
}
|
1144 |
-
$file_name = 'hfcm-export-' . date(
|
1145 |
-
header(
|
1146 |
-
header(
|
1147 |
-
header(
|
1148 |
-
echo json_encode(
|
1149 |
}
|
1150 |
}
|
1151 |
die;
|
@@ -1157,11 +1252,11 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1157 |
*/
|
1158 |
public static function hfcm_import_snippets()
|
1159 |
{
|
1160 |
-
if (
|
1161 |
-
if (
|
1162 |
?>
|
1163 |
<div class="notice hfcm-warning-notice notice-warning">
|
1164 |
-
<?php _e(
|
1165 |
</div>
|
1166 |
<?php
|
1167 |
return;
|
@@ -1170,13 +1265,13 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1170 |
global $wpdb;
|
1171 |
$nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
1172 |
|
1173 |
-
$nnr_hfcm_snippets_json = file_get_contents(
|
1174 |
-
$nnr_hfcm_snippets = json_decode(
|
1175 |
|
1176 |
-
if (
|
1177 |
?>
|
1178 |
<div class="notice hfcm-warning-notice notice-warning">
|
1179 |
-
<?php _e(
|
1180 |
</div>
|
1181 |
<?php
|
1182 |
return;
|
@@ -1185,16 +1280,18 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1185 |
$nnr_non_script_snippets = 1;
|
1186 |
foreach ( $nnr_hfcm_snippets->snippets as $nnr_hfcm_key => $nnr_hfcm_snippet ) {
|
1187 |
$nnr_hfcm_snippet = (array) $nnr_hfcm_snippet;
|
1188 |
-
if (
|
1189 |
-
|
1190 |
-
|
|
|
1191 |
$nnr_non_script_snippets = 2;
|
1192 |
continue;
|
1193 |
}
|
1194 |
-
if (
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
|
|
1198 |
$nnr_non_script_snippets = 2;
|
1199 |
continue;
|
1200 |
}
|
@@ -1206,42 +1303,44 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1206 |
"created_by", "last_modified_by", "created", "last_revision_date"
|
1207 |
);
|
1208 |
foreach ( $nnr_hfcm_snippet as $nnr_key => $nnr_item ) {
|
1209 |
-
$nnr_key = sanitize_text_field(
|
1210 |
-
if (
|
1211 |
-
if (
|
1212 |
-
$nnr_item = absint(
|
1213 |
-
} elseif (
|
1214 |
-
$nnr_item = sanitize_text_field(
|
1215 |
}
|
1216 |
$nnr_hfcm_sanitizes_snippet[ $nnr_key ] = $nnr_item;
|
1217 |
}
|
1218 |
}
|
1219 |
$nnr_hfcm_sanitizes_snippet['status'] = 'inactive';
|
1220 |
|
1221 |
-
$wpdb->insert(
|
1222 |
-
|
1223 |
-
|
1224 |
-
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
|
|
|
|
1242 |
}
|
1243 |
|
1244 |
-
self::hfcm_redirect(
|
1245 |
}
|
1246 |
}
|
1247 |
|
@@ -1252,7 +1351,7 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1252 |
*/
|
1253 |
public static function is_hfcm_pro_active()
|
1254 |
{
|
1255 |
-
if (
|
1256 |
return true;
|
1257 |
}
|
1258 |
|
@@ -1267,15 +1366,17 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1267 |
);
|
1268 |
$output = 'objects'; // or objects
|
1269 |
$operator = 'and'; // 'and' or 'or'
|
1270 |
-
$taxonomies = get_taxonomies(
|
1271 |
|
1272 |
$nnr_hfcm_categories = [];
|
1273 |
|
1274 |
foreach ( $taxonomies as $taxonomy ) {
|
1275 |
-
$nnr_hfcm_taxonomy_categories = get_categories(
|
1276 |
-
|
1277 |
-
|
1278 |
-
|
|
|
|
|
1279 |
$nnr_hfcm_taxonomy_categories = [
|
1280 |
'name' => $taxonomy->label,
|
1281 |
'terms' => $nnr_hfcm_taxonomy_categories
|
@@ -1295,15 +1396,17 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1295 |
);
|
1296 |
$output = 'objects'; // or objects
|
1297 |
$operator = 'and'; // 'and' or 'or'
|
1298 |
-
$taxonomies = get_taxonomies(
|
1299 |
|
1300 |
$nnr_hfcm_tags = [];
|
1301 |
|
1302 |
foreach ( $taxonomies as $taxonomy ) {
|
1303 |
-
$nnr_hfcm_taxonomy_tags = get_tags(
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
|
|
|
|
1307 |
$nnr_hfcm_taxonomy_tags = [
|
1308 |
'name' => $taxonomy->label,
|
1309 |
'terms' => $nnr_hfcm_taxonomy_tags
|
@@ -1315,4 +1418,4 @@ if ( !class_exists( 'NNR_HFCM' ) ) :
|
|
1315 |
}
|
1316 |
}
|
1317 |
|
1318 |
-
endif;
|
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.25
|
7 |
* Requires at least: 4.9
|
8 |
* Requires PHP: 5.6.20
|
9 |
* Author: 99robots
|
16 |
/*
|
17 |
* If this file is called directly, abort.
|
18 |
*/
|
19 |
+
if (!defined('WPINC') ) {
|
20 |
die;
|
21 |
}
|
22 |
|
23 |
+
register_activation_hook(__FILE__, array( 'NNR_HFCM', 'hfcm_options_install' ));
|
24 |
+
add_action('plugins_loaded', array( 'NNR_HFCM', 'hfcm_db_update_check' ));
|
25 |
+
add_action('admin_enqueue_scripts', array( 'NNR_HFCM', 'hfcm_enqueue_assets' ));
|
26 |
+
add_action('plugins_loaded', array( 'NNR_HFCM', 'hfcm_load_translation_files' ));
|
27 |
+
add_action('admin_menu', array( 'NNR_HFCM', 'hfcm_modifymenu' ));
|
28 |
+
add_filter(
|
29 |
+
'plugin_action_links_' . plugin_basename(__FILE__), array(
|
30 |
+
'NNR_HFCM',
|
31 |
+
'hfcm_add_plugin_page_settings_link'
|
32 |
+
)
|
33 |
+
);
|
34 |
+
add_action('admin_init', array( 'NNR_HFCM', 'hfcm_init' ));
|
35 |
+
add_shortcode('hfcm', array( 'NNR_HFCM', 'hfcm_shortcode' ));
|
36 |
+
add_action('wp_head', array( 'NNR_HFCM', 'hfcm_header_scripts' ));
|
37 |
+
add_action('wp_footer', array( 'NNR_HFCM', 'hfcm_footer_scripts' ));
|
38 |
+
add_action('the_content', array( 'NNR_HFCM', 'hfcm_content_scripts' ));
|
39 |
+
add_action('wp_ajax_hfcm-request', array( 'NNR_HFCM', 'hfcm_request_handler' ));
|
40 |
|
41 |
// Files containing submenu functions
|
42 |
+
require_once plugin_dir_path(__FILE__) . 'includes/class-hfcm-snippets-list.php';
|
43 |
|
44 |
+
if (!class_exists('NNR_HFCM') ) :
|
45 |
|
46 |
class NNR_HFCM
|
47 |
{
|
64 |
*/
|
65 |
public static function hfcm_options_install()
|
66 |
{
|
67 |
+
$hfcm_now = strtotime("now");
|
68 |
+
add_option('hfcm_activation_date', $hfcm_now);
|
69 |
+
update_option('hfcm_activation_date', $hfcm_now);
|
70 |
|
71 |
global $wpdb;
|
72 |
|
73 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
74 |
$charset_collate = $wpdb->get_charset_collate();
|
75 |
+
$sql = "CREATE TABLE `{$table_name}` (
|
|
|
76 |
`script_id` int(10) NOT NULL AUTO_INCREMENT,
|
77 |
`name` varchar(100) DEFAULT NULL,
|
78 |
`snippet` LONGTEXT,
|
94 |
`created` datetime DEFAULT NULL,
|
95 |
`last_revision_date` datetime DEFAULT NULL,
|
96 |
PRIMARY KEY (`script_id`)
|
97 |
+
) $charset_collate";
|
98 |
|
99 |
+
include_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
100 |
+
dbDelta($sql);
|
101 |
+
add_option('hfcm_db_version', self::$nnr_hfcm_db_version);
|
102 |
}
|
103 |
|
104 |
/*
|
109 |
global $wpdb;
|
110 |
|
111 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
112 |
+
if (get_option('hfcm_db_version') != self::$nnr_hfcm_db_version ) {
|
113 |
$wpdb->show_errors();
|
114 |
|
115 |
+
if (!empty($wpdb->dbname) ) {
|
116 |
// Check for Exclude Pages
|
117 |
$nnr_column_ex_pages = 'ex_pages';
|
118 |
+
$nnr_check_column_ex_pages = $wpdb->get_results(
|
119 |
+
$wpdb->prepare(
|
120 |
+
"SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
|
121 |
+
$wpdb->dbname,
|
122 |
+
$table_name,
|
123 |
+
$nnr_column_ex_pages
|
124 |
+
)
|
125 |
+
);
|
126 |
+
if (empty($nnr_check_column_ex_pages) ) {
|
127 |
+
$nnr_alter_sql = "ALTER TABLE `{$table_name}` ADD `ex_pages` varchar(300) DEFAULT 0 AFTER `s_pages`";
|
128 |
+
$wpdb->query($nnr_alter_sql);
|
129 |
}
|
130 |
|
131 |
// Check for Exclude Posts
|
132 |
$nnr_column_ex_posts = 'ex_posts';
|
133 |
+
$nnr_check_column_ex_posts = $wpdb->get_results(
|
134 |
+
$wpdb->prepare(
|
135 |
+
"SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
|
136 |
+
$wpdb->dbname,
|
137 |
+
$table_name,
|
138 |
+
$nnr_column_ex_posts
|
139 |
+
)
|
140 |
+
);
|
141 |
+
if (empty($nnr_check_column_ex_posts) ) {
|
142 |
+
$nnr_alter_sql = "ALTER TABLE `{$table_name}` ADD `ex_posts` varchar(300) DEFAULT 0 AFTER `s_posts`";
|
143 |
+
$wpdb->query($nnr_alter_sql);
|
144 |
}
|
145 |
|
146 |
// Check for Snippet Type
|
147 |
$nnr_column_snippet_type = 'snippet_type';
|
148 |
+
$nnr_check_column_snippet_type = $wpdb->get_results(
|
149 |
+
$wpdb->prepare(
|
150 |
+
"SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = %s ",
|
151 |
+
$wpdb->dbname,
|
152 |
+
$table_name,
|
153 |
+
$nnr_column_snippet_type
|
154 |
+
)
|
155 |
+
);
|
156 |
+
if (empty($nnr_check_column_snippet_type) ) {
|
157 |
+
$nnr_alter_sql = "ALTER TABLE `{$table_name}` ADD `snippet_type` enum('html', 'js', 'css') DEFAULT 'html' AFTER `snippet`";
|
158 |
+
$wpdb->query($nnr_alter_sql);
|
159 |
}
|
160 |
|
161 |
+
$nnr_alter_sql = "ALTER TABLE `{$table_name}` CHANGE `snippet` `snippet` LONGTEXT NULL";
|
162 |
+
$wpdb->query($nnr_alter_sql);
|
163 |
|
164 |
+
$nnr_alter_sql = "ALTER TABLE `{$table_name}` CHANGE `display_on` `display_on` ENUM('All','s_pages','s_posts','s_categories','s_custom_posts','s_tags','s_is_home','s_is_archive','s_is_search','latest_posts','manual') DEFAULT 'All' NOT NULL";
|
165 |
+
$wpdb->query($nnr_alter_sql);
|
166 |
|
167 |
+
$nnr_alter_sql = "ALTER TABLE `{$table_name}` CHANGE `s_pages` `s_pages` MEDIUMTEXT NULL, CHANGE `ex_pages` `ex_pages` MEDIUMTEXT NULL, CHANGE `s_posts` `s_posts` MEDIUMTEXT NULL, CHANGE `ex_posts` `ex_posts` MEDIUMTEXT NULL";
|
168 |
+
$wpdb->query($nnr_alter_sql);
|
169 |
}
|
170 |
self::hfcm_options_install();
|
171 |
}
|
172 |
+
update_option('hfcm_db_version', self::$nnr_hfcm_db_version);
|
173 |
}
|
174 |
|
175 |
/*
|
183 |
'admin_page_hfcm-update',
|
184 |
);
|
185 |
|
186 |
+
wp_register_style('hfcm_general_admin_assets', plugins_url('css/style-general-admin.css', __FILE__));
|
187 |
+
wp_enqueue_style('hfcm_general_admin_assets');
|
188 |
|
189 |
+
if (in_array($hook, $allowed_pages) ) {
|
190 |
// Plugin's CSS
|
191 |
+
wp_register_style('hfcm_assets', plugins_url('css/style-admin.css', __FILE__));
|
192 |
+
wp_enqueue_style('hfcm_assets');
|
193 |
}
|
194 |
|
195 |
// Remove hfcm-list from $allowed_pages
|
196 |
+
array_shift($allowed_pages);
|
197 |
|
198 |
+
if (in_array($hook, $allowed_pages) ) {
|
199 |
// selectize.js plugin CSS and JS files
|
200 |
+
wp_register_style('selectize-css', plugins_url('css/selectize.bootstrap3.css', __FILE__));
|
201 |
+
wp_enqueue_style('selectize-css');
|
202 |
|
203 |
+
wp_register_script('selectize-js', plugins_url('js/selectize.min.js', __FILE__), array( 'jquery' ));
|
204 |
+
wp_enqueue_script('selectize-js');
|
205 |
|
206 |
+
wp_enqueue_code_editor(array( 'type' => 'text/html' ));
|
207 |
}
|
208 |
}
|
209 |
|
213 |
|
214 |
public static function hfcm_load_translation_files()
|
215 |
{
|
216 |
+
load_plugin_textdomain('99robots-header-footer-code-manager', false, dirname(plugin_basename(__FILE__)) . '/languages');
|
217 |
}
|
218 |
|
219 |
/*
|
224 |
|
225 |
// This is the main item for the menu
|
226 |
add_menu_page(
|
227 |
+
__('Header Footer Code Manager', '99robots-header-footer-code-manager'),
|
228 |
+
__('HFCM', '99robots-header-footer-code-manager'),
|
229 |
'manage_options',
|
230 |
'hfcm-list',
|
231 |
array( 'NNR_HFCM', 'hfcm_list' ),
|
235 |
// This is a submenu
|
236 |
add_submenu_page(
|
237 |
'hfcm-list',
|
238 |
+
__('All Snippets', '99robots-header-footer-code-manager'),
|
239 |
+
__('All Snippets', '99robots-header-footer-code-manager'),
|
240 |
'manage_options',
|
241 |
'hfcm-list',
|
242 |
array( 'NNR_HFCM', 'hfcm_list' )
|
245 |
// This is a submenu
|
246 |
add_submenu_page(
|
247 |
'hfcm-list',
|
248 |
+
__('Add New Snippet', '99robots-header-footer-code-manager'),
|
249 |
+
__('Add New', '99robots-header-footer-code-manager'),
|
250 |
'manage_options',
|
251 |
'hfcm-create',
|
252 |
array( 'NNR_HFCM', 'hfcm_create' )
|
255 |
// This is a submenu
|
256 |
add_submenu_page(
|
257 |
'hfcm-list',
|
258 |
+
__('Tools', '99robots-header-footer-code-manager'),
|
259 |
+
__('Tools', '99robots-header-footer-code-manager'),
|
260 |
'manage_options',
|
261 |
'hfcm-tools',
|
262 |
array( 'NNR_HFCM', 'hfcm_tools' )
|
265 |
// This submenu is HIDDEN, however, we need to add it anyways
|
266 |
add_submenu_page(
|
267 |
null,
|
268 |
+
__('Update Script', '99robots-header-footer-code-manager'),
|
269 |
+
__('Update', '99robots-header-footer-code-manager'),
|
270 |
'manage_options',
|
271 |
'hfcm-update',
|
272 |
array( 'NNR_HFCM', 'hfcm_update' )
|
275 |
// This submenu is HIDDEN, however, we need to add it anyways
|
276 |
add_submenu_page(
|
277 |
null,
|
278 |
+
__('Request Handler Script', '99robots-header-footer-code-manager'),
|
279 |
+
__('Request Handler', '99robots-header-footer-code-manager'),
|
280 |
'manage_options',
|
281 |
'hfcm-request-handler',
|
282 |
array( 'NNR_HFCM', 'hfcm_request_handler' )
|
289 |
public static function hfcm_add_plugin_page_settings_link( $links )
|
290 |
{
|
291 |
$links = array_merge(
|
292 |
+
array( '<a href="' . admin_url('admin.php?page=hfcm-list') . '">' . __('Settings') . '</a>' ),
|
293 |
$links
|
294 |
);
|
295 |
return $links;
|
300 |
*/
|
301 |
public static function hfcm_check_installation_date()
|
302 |
{
|
303 |
+
$install_date = get_option('hfcm_activation_date');
|
304 |
+
$past_date = strtotime('-7 days');
|
305 |
|
306 |
+
if ($past_date >= $install_date ) {
|
307 |
+
add_action('admin_notices', array( 'NNR_HFCM', 'hfcm_review_push_notice' ));
|
308 |
}
|
309 |
+
add_action('admin_notices', array( 'NNR_HFCM', 'hfcm_static_notices' ));
|
310 |
}
|
311 |
|
312 |
/*
|
323 |
|
324 |
$user_id = get_current_user_id();
|
325 |
// Check if current user has already dismissed it
|
326 |
+
$install_date = get_option('hfcm_activation_date');
|
327 |
|
328 |
+
if (!get_user_meta($user_id, 'hfcm_plugin_notice_dismissed') && in_array($screen, $allowed_pages_notices) ) {
|
329 |
?>
|
330 |
<div id="hfcm-message" class="notice notice-success">
|
331 |
<a class="hfcm-dismiss-alert notice-dismiss" href="?hfcm-admin-notice-dismissed">Dismiss</a>
|
332 |
+
<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'); ?>
|
333 |
</p>
|
334 |
</div>
|
335 |
<?php
|
348 |
);
|
349 |
$screen = get_current_screen()->id;
|
350 |
|
351 |
+
if (in_array($screen, $allowed_pages_notices) ) {
|
352 |
?>
|
353 |
<div id="hfcm-message" class="notice notice-success">
|
354 |
<p>
|
370 |
{
|
371 |
$user_id = get_current_user_id();
|
372 |
// Checking if user clicked on the Dismiss button
|
373 |
+
if (isset($_GET['hfcm-admin-notice-dismissed']) ) {
|
374 |
+
add_user_meta($user_id, 'hfcm_plugin_notice_dismissed', 'true', true);
|
375 |
// Redirect to original page the user was on
|
376 |
$current_url = wp_get_referer();
|
377 |
+
wp_redirect($current_url);
|
378 |
exit;
|
379 |
}
|
380 |
}
|
384 |
*/
|
385 |
public static function hfcm_render_snippet( $scriptdata )
|
386 |
{
|
387 |
+
$nnr_hfcm_allowed_tags = self::hfcm_allowed_tags();
|
388 |
+
$output = "<!-- HFCM by 99 Robots - Snippet # " . absint($scriptdata->script_id) . ": " . esc_html($scriptdata->name) . " -->\n" . wp_kses(html_entity_decode($scriptdata->snippet), $nnr_hfcm_allowed_tags) . "\n<!-- /end HFCM by 99 Robots -->\n";
|
389 |
|
390 |
return $output;
|
391 |
}
|
397 |
{
|
398 |
global $wpdb;
|
399 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
400 |
+
if (!empty($atts['id']) ) {
|
401 |
+
$id = absint($atts['id']);
|
402 |
$hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
|
403 |
+
$script = $wpdb->get_results(
|
404 |
+
$wpdb->prepare(
|
405 |
+
"SELECT * FROM `{$table_name}` WHERE status='active' AND device_type!=%s AND script_id=%d",
|
406 |
+
$hide_device,
|
407 |
+
$id
|
408 |
+
)
|
409 |
+
);
|
410 |
+
if (!empty($script) ) {
|
411 |
+
return self::hfcm_render_snippet($script[0]);
|
412 |
}
|
413 |
}
|
414 |
}
|
418 |
*/
|
419 |
public static function hfcm_not_empty( $scriptdata, $prop_name )
|
420 |
{
|
421 |
+
$data = json_decode($scriptdata->{$prop_name});
|
422 |
+
if (empty($data) ) {
|
423 |
return false;
|
424 |
}
|
425 |
return true;
|
434 |
|
435 |
$beforecontent = '';
|
436 |
$aftercontent = '';
|
437 |
+
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
438 |
+
$hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
|
439 |
+
|
440 |
+
$nnr_hfcm_snippets_sql = "SELECT * FROM `{$table_name}` WHERE status='active' AND device_type!=%s";
|
441 |
+
$nnr_hfcm_snippet_placeholder_args = [ $hide_device ];
|
442 |
|
443 |
+
if ($location && in_array($location, array( 'header', 'footer' )) ) {
|
444 |
+
$nnr_hfcm_snippets_sql .= " AND location=%s";
|
445 |
+
$nnr_hfcm_snippet_placeholder_args[] = $location;
|
446 |
} else {
|
447 |
+
$nnr_hfcm_snippets_sql .= " AND location NOT IN ( 'header', 'footer' )";
|
448 |
}
|
449 |
+
$script = $wpdb->get_results(
|
450 |
+
$wpdb->prepare(
|
451 |
+
$nnr_hfcm_snippets_sql,
|
452 |
+
$nnr_hfcm_snippet_placeholder_args
|
453 |
+
)
|
454 |
+
);
|
455 |
|
456 |
+
if (!empty($script) ) {
|
|
|
|
|
|
|
|
|
457 |
foreach ( $script as $key => $scriptdata ) {
|
458 |
$out = '';
|
459 |
switch ( $scriptdata->display_on ) {
|
460 |
+
case 'All':
|
461 |
|
462 |
+
$is_not_empty_ex_pages = self::hfcm_not_empty($scriptdata, 'ex_pages');
|
463 |
+
$is_not_empty_ex_posts = self::hfcm_not_empty($scriptdata, 'ex_posts');
|
464 |
+
if (($is_not_empty_ex_pages && is_page(json_decode($scriptdata->ex_pages))) || ($is_not_empty_ex_posts && is_single(json_decode($scriptdata->ex_posts))) ) {
|
465 |
+
$out = '';
|
466 |
+
} else {
|
467 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
468 |
+
}
|
469 |
+
break;
|
470 |
+
case 'latest_posts':
|
471 |
+
if (is_single() ) {
|
472 |
+
if (!empty($scriptdata->lp_count) ) {
|
473 |
+
$nnr_hfcm_latest_posts = wp_get_recent_posts(
|
474 |
+
array(
|
475 |
+
'numberposts' => absint($scriptdata->lp_count),
|
476 |
+
)
|
477 |
+
);
|
478 |
} else {
|
479 |
+
$nnr_hfcm_latest_posts = wp_get_recent_posts(
|
480 |
+
array(
|
481 |
+
'numberposts' => 5
|
482 |
+
)
|
483 |
+
);
|
484 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
485 |
|
486 |
+
foreach ( $nnr_hfcm_latest_posts as $key => $lpostdata ) {
|
487 |
+
if (get_the_ID() == $lpostdata['ID'] ) {
|
488 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
|
|
489 |
}
|
490 |
}
|
491 |
+
}
|
492 |
+
break;
|
493 |
+
case 's_categories':
|
494 |
+
$is_not_empty_s_categories = self::hfcm_not_empty($scriptdata, 's_categories');
|
495 |
+
if ($is_not_empty_s_categories && in_category(json_decode($scriptdata->s_categories)) ) {
|
496 |
+
if (is_category(json_decode($scriptdata->s_categories)) ) {
|
497 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
}
|
499 |
+
if (!is_archive() && !is_home() ) {
|
500 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
|
|
|
|
501 |
}
|
502 |
+
}
|
503 |
+
break;
|
504 |
+
case 's_custom_posts':
|
505 |
+
$is_not_empty_s_custom_posts = self::hfcm_not_empty($scriptdata, 's_custom_posts');
|
506 |
+
if ($is_not_empty_s_custom_posts && is_singular(json_decode($scriptdata->s_custom_posts)) ) {
|
507 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
508 |
+
}
|
509 |
+
break;
|
510 |
+
case 's_posts':
|
511 |
+
$is_not_empty_s_posts = self::hfcm_not_empty($scriptdata, 's_posts');
|
512 |
+
if ($is_not_empty_s_posts && is_single(json_decode($scriptdata->s_posts)) ) {
|
513 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
514 |
+
}
|
515 |
+
break;
|
516 |
+
case 's_is_home':
|
517 |
+
if (is_home() || is_front_page() ) {
|
518 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
519 |
+
}
|
520 |
+
break;
|
521 |
+
case 's_is_archive':
|
522 |
+
if (is_archive() ) {
|
523 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
524 |
+
}
|
525 |
+
break;
|
526 |
+
case 's_is_search':
|
527 |
+
if (is_search() ) {
|
528 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
529 |
+
}
|
530 |
+
break;
|
531 |
+
case 's_pages':
|
532 |
+
$is_not_empty_s_pages = self::hfcm_not_empty($scriptdata, 's_pages');
|
533 |
+
if ($is_not_empty_s_pages ) {
|
534 |
+
// Gets the page ID of the blog page
|
535 |
+
$blog_page = get_option('page_for_posts');
|
536 |
+
// Checks if the blog page is present in the array of selected pages
|
537 |
+
if (in_array($blog_page, json_decode($scriptdata->s_pages)) ) {
|
538 |
+
if (is_page(json_decode($scriptdata->s_pages)) || (!is_front_page() && is_home()) ) {
|
539 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
540 |
}
|
541 |
+
} elseif (is_page(json_decode($scriptdata->s_pages)) ) {
|
542 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
543 |
}
|
544 |
+
}
|
545 |
+
break;
|
546 |
+
case 's_tags':
|
547 |
+
$is_not_empty_s_tags = self::hfcm_not_empty($scriptdata, 's_tags');
|
548 |
+
if ($is_not_empty_s_tags && has_tag(json_decode($scriptdata->s_tags)) ) {
|
549 |
+
if (is_tag(json_decode($scriptdata->s_tags)) ) {
|
550 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
|
|
|
|
|
|
551 |
}
|
552 |
+
if (!is_archive() && !is_home() ) {
|
553 |
+
$out = self::hfcm_render_snippet($scriptdata);
|
554 |
+
}
|
555 |
+
}
|
556 |
}
|
557 |
|
558 |
switch ( $scriptdata->location ) {
|
559 |
+
case 'before_content':
|
560 |
+
$beforecontent .= $out;
|
561 |
+
break;
|
562 |
+
case 'after_content':
|
563 |
+
$aftercontent .= $out;
|
564 |
+
break;
|
565 |
+
default:
|
566 |
+
$nnr_hfcm_allowed_tags = self::hfcm_allowed_tags();
|
567 |
+
echo wp_kses($out, $nnr_hfcm_allowed_tags);
|
568 |
}
|
569 |
}
|
570 |
}
|
572 |
return $beforecontent . $content . $aftercontent;
|
573 |
}
|
574 |
|
575 |
+
/*
|
576 |
+
* function to return allowed html tags
|
577 |
+
*/
|
578 |
+
|
579 |
+
public static function hfcm_allowed_tags()
|
580 |
+
{
|
581 |
+
$nnr_hfcm_allowed_tags = [];
|
582 |
+
|
583 |
+
// allows all most inline elements
|
584 |
+
$nnr_hfcm_allowed_tags = array_merge($nnr_hfcm_allowed_tags, wp_kses_allowed_html('data'));
|
585 |
+
|
586 |
+
// very permissive: allows pretty much all HTML to pass - same as what's normally applied to the_content by default
|
587 |
+
$nnr_hfcm_allowed_tags = array_merge($nnr_hfcm_allowed_tags, wp_kses_allowed_html('post'));
|
588 |
+
|
589 |
+
if (empty($nnr_hfcm_allowed_tags['script']) ) {
|
590 |
+
$nnr_hfcm_allowed_tags['script'] = [
|
591 |
+
"src" => true,
|
592 |
+
"async" => true,
|
593 |
+
"height" => true,
|
594 |
+
"width" => true,
|
595 |
+
"type" => true,
|
596 |
+
"crossorigin" => true,
|
597 |
+
"defer" => true,
|
598 |
+
"integrity" => true,
|
599 |
+
"nomodule" => true,
|
600 |
+
"referrerpolicy" => true
|
601 |
+
];
|
602 |
+
}
|
603 |
+
if (empty($nnr_hfcm_allowed_tags['style']) ) {
|
604 |
+
$nnr_hfcm_allowed_tags['style'] = [ "type" => true, "media" => true ];
|
605 |
+
}
|
606 |
+
if (empty($nnr_hfcm_allowed_tags['iframe']) ) {
|
607 |
+
$nnr_hfcm_allowed_tags['iframe'] = [
|
608 |
+
"src" => true,
|
609 |
+
"allow" => true,
|
610 |
+
"height" => true,
|
611 |
+
"width" => true,
|
612 |
+
"type" => true,
|
613 |
+
"style" => true,
|
614 |
+
"allowfullscreen" => true,
|
615 |
+
"loading" => true,
|
616 |
+
"autoplay" => true,
|
617 |
+
"loop" => true,
|
618 |
+
"controls" => true
|
619 |
+
];
|
620 |
+
}
|
621 |
+
$nnr_hfcm_allowed_tags['span']['itemprop'] = true;
|
622 |
+
$nnr_hfcm_allowed_tags['div']['itemprop'] = true;
|
623 |
+
$nnr_hfcm_allowed_tags['div']['itemscope'] = true;
|
624 |
+
$nnr_hfcm_allowed_tags['div']['itemtype'] = true;
|
625 |
+
|
626 |
+
return $nnr_hfcm_allowed_tags;
|
627 |
+
}
|
628 |
+
|
629 |
/*
|
630 |
* function to add snippets in the header
|
631 |
*/
|
632 |
public static function hfcm_header_scripts()
|
633 |
{
|
634 |
+
self::hfcm_add_snippets('header');
|
635 |
}
|
636 |
|
637 |
/*
|
639 |
*/
|
640 |
public static function hfcm_footer_scripts()
|
641 |
{
|
642 |
+
self::hfcm_add_snippets('footer');
|
643 |
}
|
644 |
|
645 |
/*
|
647 |
*/
|
648 |
public static function hfcm_content_scripts( $content )
|
649 |
{
|
650 |
+
return self::hfcm_add_snippets(false, $content);
|
651 |
}
|
652 |
|
653 |
/*
|
656 |
public static function hfcm_redirect( $url = '' )
|
657 |
{
|
658 |
// Register the script
|
659 |
+
wp_register_script('hfcm_redirection', plugins_url('js/location.js', __FILE__));
|
660 |
|
661 |
// Localize the script with new data
|
662 |
$translation_array = array( 'url' => $url );
|
663 |
+
wp_localize_script('hfcm_redirection', 'hfcm_location', $translation_array);
|
664 |
|
665 |
// Enqueued script with localized data.
|
666 |
+
wp_enqueue_script('hfcm_redirection');
|
667 |
}
|
668 |
|
669 |
/*
|
671 |
*/
|
672 |
public static function hfcm_sanitize_text( $key, $is_not_snippet = true )
|
673 |
{
|
674 |
+
if (!empty($_POST['data'][ $key ]) ) {
|
675 |
+
$post_data = stripslashes_deep($_POST['data'][ $key ]);
|
676 |
+
if ($is_not_snippet ) {
|
677 |
+
$post_data = sanitize_text_field($post_data);
|
678 |
} else {
|
679 |
+
$nnr_hfcm_allowed_tags = self::hfcm_allowed_tags();
|
680 |
+
$post_data = wp_kses(htmlentities($post_data), $nnr_hfcm_allowed_tags);
|
681 |
}
|
682 |
return $post_data;
|
683 |
}
|
690 |
*/
|
691 |
public static function hfcm_sanitize_array( $key, $type = 'integer' )
|
692 |
{
|
693 |
+
if (!empty($_POST['data'][ $key ]) ) {
|
694 |
$arr = $_POST['data'][ $key ];
|
695 |
|
696 |
+
if (!is_array($arr) ) {
|
697 |
return array();
|
698 |
}
|
699 |
|
700 |
+
if ('integer' === $type ) {
|
701 |
+
return array_map('absint', $arr);
|
702 |
} else { // strings
|
703 |
$new_array = array();
|
704 |
foreach ( $arr as $val ) {
|
705 |
+
$new_array[] = sanitize_text_field($val);
|
706 |
}
|
707 |
}
|
708 |
|
719 |
{
|
720 |
|
721 |
// check user capabilities
|
722 |
+
current_user_can('administrator');
|
723 |
|
724 |
// prepare variables for includes/hfcm-add-edit.php
|
725 |
$name = '';
|
741 |
// Notify hfcm-add-edit.php NOT to make changes for update
|
742 |
$update = false;
|
743 |
|
744 |
+
include_once plugin_dir_path(__FILE__) . 'includes/hfcm-add-edit.php';
|
745 |
}
|
746 |
|
747 |
/*
|
751 |
{
|
752 |
|
753 |
// Check user capabilities
|
754 |
+
current_user_can('administrator');
|
755 |
|
756 |
+
if (isset($_POST['insert']) ) {
|
757 |
// Check nonce
|
758 |
+
check_admin_referer('create-snippet');
|
759 |
} else {
|
760 |
+
if (empty($_REQUEST['id']) ) {
|
761 |
+
die('Missing ID parameter.');
|
762 |
}
|
763 |
+
$id = absint($_REQUEST['id']);
|
764 |
}
|
765 |
+
if (isset($_POST['update']) ) {
|
766 |
// Check nonce
|
767 |
+
check_admin_referer('update-snippet_' . $id);
|
768 |
}
|
769 |
|
770 |
// Handle AJAX on/off toggle for snippets
|
771 |
+
if (isset($_REQUEST['toggle']) && !empty($_REQUEST['togvalue']) ) {
|
772 |
|
773 |
// Check nonce
|
774 |
+
check_ajax_referer('hfcm-toggle-snippet', 'security');
|
775 |
|
776 |
+
if ('on' === $_REQUEST['togvalue'] ) {
|
777 |
$status = 'active';
|
778 |
} else {
|
779 |
$status = 'inactive';
|
791 |
array( '%s' ) //where format
|
792 |
);
|
793 |
|
794 |
+
} elseif (isset($_POST['insert']) || isset($_POST['update']) ) {
|
795 |
|
796 |
// Create / update snippet
|
797 |
|
798 |
// Sanitize fields
|
799 |
+
$name = self::hfcm_sanitize_text('name');
|
800 |
+
$snippet = self::hfcm_sanitize_text('snippet', false);
|
801 |
+
$nnr_snippet_type = self::hfcm_sanitize_text('snippet_type');
|
802 |
+
$device_type = self::hfcm_sanitize_text('device_type');
|
803 |
+
$display_on = self::hfcm_sanitize_text('display_on');
|
804 |
+
$location = self::hfcm_sanitize_text('location');
|
805 |
+
$lp_count = self::hfcm_sanitize_text('lp_count');
|
806 |
+
$status = self::hfcm_sanitize_text('status');
|
807 |
+
$s_pages = self::hfcm_sanitize_array('s_pages');
|
808 |
+
$ex_pages = self::hfcm_sanitize_array('ex_pages');
|
809 |
+
$s_posts = self::hfcm_sanitize_array('s_posts');
|
810 |
+
$ex_posts = self::hfcm_sanitize_array('ex_posts');
|
811 |
+
$s_custom_posts = self::hfcm_sanitize_array('s_custom_posts', 'string');
|
812 |
+
$s_categories = self::hfcm_sanitize_array('s_categories');
|
813 |
+
$s_tags = self::hfcm_sanitize_array('s_tags');
|
814 |
+
|
815 |
+
if ('manual' === $display_on ) {
|
816 |
$location = '';
|
817 |
}
|
818 |
+
$lp_count = max(1, (int) $lp_count);
|
819 |
|
820 |
// Global vars
|
821 |
global $wpdb;
|
823 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
824 |
|
825 |
// Update snippet
|
826 |
+
if (isset($id) ) {
|
827 |
|
828 |
+
$wpdb->update(
|
829 |
+
$table_name, //table
|
830 |
// Data
|
831 |
array(
|
832 |
'name' => $name,
|
837 |
'display_on' => $display_on,
|
838 |
'status' => $status,
|
839 |
'lp_count' => $lp_count,
|
840 |
+
's_pages' => wp_json_encode($s_pages),
|
841 |
+
'ex_pages' => wp_json_encode($ex_pages),
|
842 |
+
's_posts' => wp_json_encode($s_posts),
|
843 |
+
'ex_posts' => wp_json_encode($ex_posts),
|
844 |
+
's_custom_posts' => wp_json_encode($s_custom_posts),
|
845 |
+
's_categories' => wp_json_encode($s_categories),
|
846 |
+
's_tags' => wp_json_encode($s_tags),
|
847 |
+
'last_revision_date' => current_time('Y-m-d H:i:s'),
|
848 |
+
'last_modified_by' => sanitize_text_field($current_user->display_name),
|
849 |
),
|
850 |
// Where
|
851 |
array( 'script_id' => $id ),
|
864 |
// Where format
|
865 |
array( '%s' )
|
866 |
);
|
867 |
+
self::hfcm_redirect(admin_url('admin.php?page=hfcm-update&message=1&id=' . $id));
|
868 |
} else {
|
869 |
|
870 |
// Create new snippet
|
871 |
+
$wpdb->insert(
|
872 |
+
$table_name, //table
|
873 |
array(
|
874 |
'name' => $name,
|
875 |
'snippet' => $snippet,
|
879 |
'display_on' => $display_on,
|
880 |
'status' => $status,
|
881 |
'lp_count' => $lp_count,
|
882 |
+
's_pages' => wp_json_encode($s_pages),
|
883 |
+
'ex_pages' => wp_json_encode($ex_pages),
|
884 |
+
's_posts' => wp_json_encode($s_posts),
|
885 |
+
'ex_posts' => wp_json_encode($ex_posts),
|
886 |
+
's_custom_posts' => wp_json_encode($s_custom_posts),
|
887 |
+
's_categories' => wp_json_encode($s_categories),
|
888 |
+
's_tags' => wp_json_encode($s_tags),
|
889 |
+
'created' => current_time('Y-m-d H:i:s'),
|
890 |
+
'created_by' => sanitize_text_field($current_user->display_name),
|
891 |
), array(
|
892 |
'%s',
|
893 |
'%s',
|
909 |
)
|
910 |
);
|
911 |
$lastid = $wpdb->insert_id;
|
912 |
+
self::hfcm_redirect(admin_url('admin.php?page=hfcm-update&message=6&id=' . $lastid));
|
913 |
}
|
914 |
+
} elseif (isset($_POST['get_posts']) ) {
|
915 |
|
916 |
// JSON return posts for AJAX
|
917 |
|
918 |
// Check nonce
|
919 |
+
check_ajax_referer('hfcm-get-posts', 'security');
|
920 |
|
921 |
// Global vars
|
922 |
global $wpdb;
|
923 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
924 |
// Get all selected posts
|
925 |
+
if (-1 === $id ) {
|
926 |
$s_posts = array();
|
927 |
$ex_posts = array();
|
928 |
} else {
|
929 |
// Select value to update
|
930 |
+
$script = $wpdb->get_results(
|
931 |
+
$wpdb->prepare("SELECT s_posts FROM `{$table_name}` WHERE script_id=%s", $id)
|
932 |
+
);
|
933 |
$s_posts = array();
|
934 |
+
if (!empty($script) ) {
|
935 |
foreach ( $script as $s ) {
|
936 |
+
$s_posts = json_decode($s->s_posts);
|
937 |
+
if (!is_array($s_posts) ) {
|
938 |
$s_posts = array();
|
939 |
}
|
940 |
}
|
941 |
}
|
942 |
|
943 |
$ex_posts = array();
|
944 |
+
$script_ex = $wpdb->get_results(
|
945 |
+
$wpdb->prepare("SELECT ex_posts FROM `{$table_name}` WHERE script_id=%s", $id)
|
946 |
+
);
|
947 |
+
if (!empty($script_ex) ) {
|
948 |
foreach ( $script_ex as $s ) {
|
949 |
+
$ex_posts = json_decode($s->ex_posts);
|
950 |
+
if (!is_array($ex_posts) ) {
|
951 |
$ex_posts = array();
|
952 |
}
|
953 |
}
|
963 |
$output = 'names'; // names or objects, note names is the default
|
964 |
$operator = 'and'; // 'and' or 'or'
|
965 |
|
966 |
+
$c_posttypes = get_post_types($args, $output, $operator);
|
967 |
$posttypes = array( 'post' );
|
968 |
foreach ( $c_posttypes as $cpdata ) {
|
969 |
$posttypes[] = $cpdata;
|
984 |
'excluded' => array(),
|
985 |
);
|
986 |
|
987 |
+
if (!empty($posts) ) {
|
988 |
foreach ( $posts as $pdata ) {
|
989 |
+
$nnr_hfcm_post_title = trim($pdata->post_title);
|
990 |
|
991 |
+
if (empty($nnr_hfcm_post_title) ) {
|
992 |
$nnr_hfcm_post_title = "(no title)";
|
993 |
}
|
994 |
+
if (!empty($ex_posts) && in_array($pdata->ID, $ex_posts) ) {
|
995 |
$json_output['excluded'][] = $pdata->ID;
|
996 |
}
|
997 |
|
998 |
+
if (!empty($s_posts) && in_array($pdata->ID, $s_posts) ) {
|
999 |
$json_output['selected'][] = $pdata->ID;
|
1000 |
}
|
1001 |
|
1002 |
$json_output['posts'][] = array(
|
1003 |
+
'text' => sanitize_text_field($nnr_hfcm_post_title),
|
1004 |
'value' => $pdata->ID,
|
1005 |
);
|
1006 |
}
|
1007 |
}
|
1008 |
|
1009 |
+
echo wp_json_encode($json_output);
|
1010 |
wp_die();
|
1011 |
}
|
1012 |
}
|
1017 |
public static function hfcm_update()
|
1018 |
{
|
1019 |
|
1020 |
+
add_action('wp_enqueue_scripts', 'hfcm_selectize_enqueue');
|
1021 |
|
1022 |
// check user capabilities
|
1023 |
+
current_user_can('administrator');
|
1024 |
|
1025 |
+
if (empty($_GET['id']) ) {
|
1026 |
+
die('Missing ID parameter.');
|
1027 |
}
|
1028 |
+
$id = absint($_GET['id']);
|
1029 |
|
1030 |
global $wpdb;
|
1031 |
$table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
1032 |
|
1033 |
//selecting value to update
|
1034 |
+
$nnr_hfcm_snippets = $wpdb->get_results(
|
1035 |
+
$wpdb->prepare("SELECT * FROM `{$table_name}` WHERE script_id=%s", $id)
|
1036 |
+
);
|
1037 |
foreach ( $nnr_hfcm_snippets as $s ) {
|
1038 |
$name = $s->name;
|
1039 |
$snippet = $s->snippet;
|
1043 |
$display_on = $s->display_on;
|
1044 |
$status = $s->status;
|
1045 |
$lp_count = $s->lp_count;
|
1046 |
+
if (empty($lp_count) ) {
|
1047 |
$lp_count = 5;
|
1048 |
}
|
1049 |
+
$s_pages = json_decode($s->s_pages);
|
1050 |
+
$ex_pages = json_decode($s->ex_pages);
|
1051 |
+
$ex_posts = json_decode($s->ex_posts);
|
1052 |
|
1053 |
+
if (!is_array($s_pages) ) {
|
1054 |
$s_pages = array();
|
1055 |
}
|
1056 |
|
1057 |
+
if (!is_array($ex_pages) ) {
|
1058 |
$ex_pages = array();
|
1059 |
}
|
1060 |
|
1061 |
+
$s_posts = json_decode($s->s_posts);
|
1062 |
+
if (!is_array($s_posts) ) {
|
1063 |
$s_posts = array();
|
1064 |
}
|
1065 |
|
1066 |
+
$ex_posts = json_decode($s->ex_posts);
|
1067 |
+
if (!is_array($ex_posts) ) {
|
1068 |
$ex_posts = array();
|
1069 |
}
|
1070 |
|
1071 |
+
$s_custom_posts = json_decode($s->s_custom_posts);
|
1072 |
+
if (!is_array($s_custom_posts) ) {
|
1073 |
$s_custom_posts = array();
|
1074 |
}
|
1075 |
|
1076 |
+
$s_categories = json_decode($s->s_categories);
|
1077 |
+
if (!is_array($s_categories) ) {
|
1078 |
$s_categories = array();
|
1079 |
}
|
1080 |
|
1081 |
+
$s_tags = json_decode($s->s_tags);
|
1082 |
+
if (!is_array($s_tags) ) {
|
1083 |
$s_tags = array();
|
1084 |
}
|
1085 |
|
1086 |
+
$createdby = esc_html($s->created_by);
|
1087 |
+
$lastmodifiedby = esc_html($s->last_modified_by);
|
1088 |
+
$createdon = esc_html($s->created);
|
1089 |
+
$lastrevisiondate = esc_html($s->last_revision_date);
|
1090 |
}
|
1091 |
|
1092 |
// escape for html output
|
1093 |
+
$name = esc_textarea($name);
|
1094 |
+
$snippet = esc_textarea($snippet);
|
1095 |
+
$nnr_snippet_type = esc_textarea($nnr_snippet_type);
|
1096 |
+
$device_type = esc_html($device_type);
|
1097 |
+
$location = esc_html($location);
|
1098 |
+
$display_on = esc_html($display_on);
|
1099 |
+
$status = esc_html($status);
|
1100 |
+
$lp_count = esc_html($lp_count);
|
1101 |
+
$i = esc_html($lp_count);
|
1102 |
// Notify hfcm-add-edit.php to make necesary changes for update
|
1103 |
$update = true;
|
1104 |
|
1105 |
+
include_once plugin_dir_path(__FILE__) . 'includes/hfcm-add-edit.php';
|
1106 |
}
|
1107 |
|
1108 |
/*
|
1120 |
|
1121 |
$is_pro_version_active = self::is_hfcm_pro_active();
|
1122 |
|
1123 |
+
if ($is_pro_version_active ) {
|
1124 |
?>
|
1125 |
<div class="notice hfcm-warning-notice notice-warning">
|
1126 |
+
<?php _e(
|
1127 |
+
'Please deactivate the free version of this plugin in order to avoid duplication of the snippets.
|
1128 |
+
You can use our tools to import all the snippets from the free version of this plugin.', '99robots-header-footer-code-manager'
|
1129 |
+
); ?>
|
1130 |
</div>
|
1131 |
<?php
|
1132 |
}
|
1133 |
|
1134 |
+
if (!empty($_GET['import']) ) {
|
1135 |
+
if ($_GET['import'] == 2 ) {
|
1136 |
$message = "Header Footer Code Manager has successfully imported all snippets and set them as INACTIVE. Please review each snippet individually and ACTIVATE those that are needed for this site. Snippet types that are only available in the PRO version are skipped";
|
1137 |
} else {
|
1138 |
$message = "Header Footer Code Manager has successfully imported all snippets and set them as INACTIVE. Please review each snippet individually and ACTIVATE those that are needed for this site.";
|
1140 |
?>
|
1141 |
<div id="hfcm-message" class="notice notice-success is-dismissible">
|
1142 |
<p>
|
1143 |
+
<?php _e($message, '99robots-header-footer-code-manager'); ?>
|
1144 |
</p>
|
1145 |
</div>
|
1146 |
<?php
|
1147 |
}
|
1148 |
+
if (!empty($_GET['script_status']) && in_array(
|
1149 |
+
$_GET['script_status'], array( 'active', 'inactive' )
|
1150 |
+
)
|
1151 |
+
) {
|
1152 |
$allclass = '';
|
1153 |
+
if ('active' === $_GET['script_status'] ) {
|
1154 |
$activeclass = 'current';
|
1155 |
}
|
1156 |
+
if ('inactive' === $_GET['script_status'] ) {
|
1157 |
$inactiveclass = 'current';
|
1158 |
}
|
1159 |
}
|
1160 |
?>
|
1161 |
<div class="wrap">
|
1162 |
+
<h1><?php esc_html_e('Snippets', '99robots-header-footer-code-manager') ?>
|
1163 |
+
<a href="<?php echo admin_url('admin.php?page=hfcm-create') ?>" class="page-title-action">
|
1164 |
+
<?php esc_html_e('Add New Snippet', '99robots-header-footer-code-manager') ?>
|
1165 |
+
</a>
|
1166 |
</h1>
|
1167 |
|
1168 |
<form method="post">
|
1169 |
<?php
|
1170 |
$snippet_obj->prepare_items();
|
1171 |
+
$snippet_obj->search_box('Search Snippets', 'search_id');
|
1172 |
$snippet_obj->display();
|
1173 |
?>
|
1174 |
</form>
|
1177 |
<?php
|
1178 |
|
1179 |
// Register the script
|
1180 |
+
wp_register_script('hfcm_toggle', plugins_url('js/toggle.js', __FILE__));
|
1181 |
|
1182 |
// Localize the script with new data
|
1183 |
$translation_array = array(
|
1184 |
+
'url' => admin_url('admin.php'),
|
1185 |
+
'security' => wp_create_nonce('hfcm-toggle-snippet'),
|
1186 |
);
|
1187 |
+
wp_localize_script('hfcm_toggle', 'hfcm_ajax', $translation_array);
|
1188 |
|
1189 |
// Enqueued script with localized data.
|
1190 |
+
wp_enqueue_script('hfcm_toggle');
|
1191 |
}
|
1192 |
|
1193 |
/*
|
1198 |
global $wpdb;
|
1199 |
$nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
1200 |
|
1201 |
+
$nnr_hfcm_snippets = $wpdb->get_results("SELECT * from `{$nnr_hfcm_table_name}`");
|
1202 |
|
1203 |
+
include_once plugin_dir_path(__FILE__) . 'includes/hfcm-tools.php';
|
1204 |
}
|
1205 |
|
1206 |
/*
|
1211 |
global $wpdb;
|
1212 |
$nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
1213 |
|
1214 |
+
if (!empty($_POST['nnr_hfcm_snippets']) && !empty($_POST['action']) && ($_POST['action'] == "download") && check_admin_referer('hfcm-nonce') ) {
|
1215 |
$nnr_hfcm_snippets_comma_separated = "";
|
1216 |
foreach ( $_POST['nnr_hfcm_snippets'] as $nnr_hfcm_key => $nnr_hfcm_snippet ) {
|
1217 |
+
$nnr_hfcm_snippet = str_replace("snippet_", "", sanitize_text_field($nnr_hfcm_snippet));
|
1218 |
+
$nnr_hfcm_snippet = absint($nnr_hfcm_snippet);
|
1219 |
+
if (!empty($nnr_hfcm_snippet) ) {
|
1220 |
+
if (empty($nnr_hfcm_snippets_comma_separated) ) {
|
1221 |
$nnr_hfcm_snippets_comma_separated .= $nnr_hfcm_snippet;
|
1222 |
} else {
|
1223 |
$nnr_hfcm_snippets_comma_separated .= "," . $nnr_hfcm_snippet;
|
1224 |
}
|
1225 |
}
|
1226 |
}
|
1227 |
+
if (!empty($nnr_hfcm_snippets_comma_separated) ) {
|
1228 |
+
$nnr_hfcm_snippets = $wpdb->get_results(
|
1229 |
+
"SELECT * FROM `{$nnr_hfcm_table_name}` WHERE script_id IN (".$nnr_hfcm_snippets_comma_separated.")"
|
1230 |
+
);
|
1231 |
|
1232 |
+
if (!empty($nnr_hfcm_snippets) ) {
|
1233 |
$nnr_hfcm_export_snippets = array( "title" => "Header Footer Code Manager" );
|
1234 |
|
1235 |
foreach ( $nnr_hfcm_snippets as $nnr_hfcm_snippet_key => $nnr_hfcm_snippet_item ) {
|
1236 |
+
unset($nnr_hfcm_snippet_item->script_id);
|
1237 |
$nnr_hfcm_export_snippets['snippets'][ $nnr_hfcm_snippet_key ] = $nnr_hfcm_snippet_item;
|
1238 |
}
|
1239 |
+
$file_name = 'hfcm-export-' . date('Y-m-d') . '.json';
|
1240 |
+
header("Content-Description: File Transfer");
|
1241 |
+
header("Content-Disposition: attachment; filename={$file_name}");
|
1242 |
+
header("Content-Type: application/json; charset=utf-8");
|
1243 |
+
echo json_encode($nnr_hfcm_export_snippets, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
1244 |
}
|
1245 |
}
|
1246 |
die;
|
1252 |
*/
|
1253 |
public static function hfcm_import_snippets()
|
1254 |
{
|
1255 |
+
if (!empty($_FILES['nnr_hfcm_import_file']['tmp_name']) && check_admin_referer('hfcm-nonce') ) {
|
1256 |
+
if (!empty($_FILES['nnr_hfcm_pro_import_file']['type']) && $_FILES['nnr_hfcm_pro_import_file']['type'] != "application/json" ) {
|
1257 |
?>
|
1258 |
<div class="notice hfcm-warning-notice notice-warning">
|
1259 |
+
<?php _e('Please upload a valid import file', '99robots-header-footer-code-manager'); ?>
|
1260 |
</div>
|
1261 |
<?php
|
1262 |
return;
|
1265 |
global $wpdb;
|
1266 |
$nnr_hfcm_table_name = $wpdb->prefix . self::$nnr_hfcm_table;
|
1267 |
|
1268 |
+
$nnr_hfcm_snippets_json = file_get_contents($_FILES['nnr_hfcm_import_file']['tmp_name']);
|
1269 |
+
$nnr_hfcm_snippets = json_decode($nnr_hfcm_snippets_json);
|
1270 |
|
1271 |
+
if (empty($nnr_hfcm_snippets->title) || (!empty($nnr_hfcm_snippets->title) && $nnr_hfcm_snippets->title != "Header Footer Code Manager") ) {
|
1272 |
?>
|
1273 |
<div class="notice hfcm-warning-notice notice-warning">
|
1274 |
+
<?php _e('Please upload a valid import file', '99robots-header-footer-code-manager'); ?>
|
1275 |
</div>
|
1276 |
<?php
|
1277 |
return;
|
1280 |
$nnr_non_script_snippets = 1;
|
1281 |
foreach ( $nnr_hfcm_snippets->snippets as $nnr_hfcm_key => $nnr_hfcm_snippet ) {
|
1282 |
$nnr_hfcm_snippet = (array) $nnr_hfcm_snippet;
|
1283 |
+
if (!empty($nnr_hfcm_snippet['snippet_type']) && !in_array(
|
1284 |
+
$nnr_hfcm_snippet['snippet_type'], array( "html", "css", "js" )
|
1285 |
+
)
|
1286 |
+
) {
|
1287 |
$nnr_non_script_snippets = 2;
|
1288 |
continue;
|
1289 |
}
|
1290 |
+
if (!empty($nnr_hfcm_snippet['location']) && !in_array(
|
1291 |
+
$nnr_hfcm_snippet['location'], array( 'header', 'before_content', 'after_content',
|
1292 |
+
'footer' )
|
1293 |
+
)
|
1294 |
+
) {
|
1295 |
$nnr_non_script_snippets = 2;
|
1296 |
continue;
|
1297 |
}
|
1303 |
"created_by", "last_modified_by", "created", "last_revision_date"
|
1304 |
);
|
1305 |
foreach ( $nnr_hfcm_snippet as $nnr_key => $nnr_item ) {
|
1306 |
+
$nnr_key = sanitize_text_field($nnr_key);
|
1307 |
+
if (in_array($nnr_key, $nnr_hfcm_keys) ) {
|
1308 |
+
if ($nnr_key == "lp_count" ) {
|
1309 |
+
$nnr_item = absint($nnr_item);
|
1310 |
+
} elseif ($nnr_key != "snippet" ) {
|
1311 |
+
$nnr_item = sanitize_text_field($nnr_item);
|
1312 |
}
|
1313 |
$nnr_hfcm_sanitizes_snippet[ $nnr_key ] = $nnr_item;
|
1314 |
}
|
1315 |
}
|
1316 |
$nnr_hfcm_sanitizes_snippet['status'] = 'inactive';
|
1317 |
|
1318 |
+
$wpdb->insert(
|
1319 |
+
$nnr_hfcm_table_name, $nnr_hfcm_sanitizes_snippet, array(
|
1320 |
+
'%s',
|
1321 |
+
'%s',
|
1322 |
+
'%s',
|
1323 |
+
'%s',
|
1324 |
+
'%s',
|
1325 |
+
'%s',
|
1326 |
+
'%d',
|
1327 |
+
'%s',
|
1328 |
+
'%s',
|
1329 |
+
'%s',
|
1330 |
+
'%s',
|
1331 |
+
'%s',
|
1332 |
+
'%s',
|
1333 |
+
'%s',
|
1334 |
+
'%s',
|
1335 |
+
'%s',
|
1336 |
+
'%s',
|
1337 |
+
'%s',
|
1338 |
+
'%s'
|
1339 |
+
)
|
1340 |
+
);
|
1341 |
}
|
1342 |
|
1343 |
+
self::hfcm_redirect(admin_url('admin.php?page=hfcm-list&import=' . $nnr_non_script_snippets));
|
1344 |
}
|
1345 |
}
|
1346 |
|
1351 |
*/
|
1352 |
public static function is_hfcm_pro_active()
|
1353 |
{
|
1354 |
+
if (is_plugin_active('99robots-header-footer-code-manager-pro/99robots-header-footer-code-manager-pro.php') ) {
|
1355 |
return true;
|
1356 |
}
|
1357 |
|
1366 |
);
|
1367 |
$output = 'objects'; // or objects
|
1368 |
$operator = 'and'; // 'and' or 'or'
|
1369 |
+
$taxonomies = get_taxonomies($args, $output, $operator);
|
1370 |
|
1371 |
$nnr_hfcm_categories = [];
|
1372 |
|
1373 |
foreach ( $taxonomies as $taxonomy ) {
|
1374 |
+
$nnr_hfcm_taxonomy_categories = get_categories(
|
1375 |
+
[
|
1376 |
+
'taxonomy' => $taxonomy->name,
|
1377 |
+
'hide_empty' => 0
|
1378 |
+
]
|
1379 |
+
);
|
1380 |
$nnr_hfcm_taxonomy_categories = [
|
1381 |
'name' => $taxonomy->label,
|
1382 |
'terms' => $nnr_hfcm_taxonomy_categories
|
1396 |
);
|
1397 |
$output = 'objects'; // or objects
|
1398 |
$operator = 'and'; // 'and' or 'or'
|
1399 |
+
$taxonomies = get_taxonomies($args, $output, $operator);
|
1400 |
|
1401 |
$nnr_hfcm_tags = [];
|
1402 |
|
1403 |
foreach ( $taxonomies as $taxonomy ) {
|
1404 |
+
$nnr_hfcm_taxonomy_tags = get_tags(
|
1405 |
+
[
|
1406 |
+
'taxonomy' => $taxonomy->name,
|
1407 |
+
'hide_empty' => 0
|
1408 |
+
]
|
1409 |
+
);
|
1410 |
$nnr_hfcm_taxonomy_tags = [
|
1411 |
'name' => $taxonomy->label,
|
1412 |
'terms' => $nnr_hfcm_taxonomy_tags
|
1418 |
}
|
1419 |
}
|
1420 |
|
1421 |
+
endif;
|
css/style-admin.css
CHANGED
@@ -1,127 +1,127 @@
|
|
1 |
.hfcm-form-width,
|
2 |
.widefat {
|
3 |
-
|
4 |
}
|
5 |
.hfcm-list-width {
|
6 |
-
|
7 |
}
|
8 |
.hfcm-th-width {
|
9 |
-
|
10 |
-
|
11 |
}
|
12 |
.hfcm-field-width,
|
13 |
.hfcm-form-width select,
|
14 |
.selectize-control {
|
15 |
-
|
16 |
}
|
17 |
#nnr_newcontent {
|
18 |
-
|
19 |
}
|
20 |
.nnr-btndelete {
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
}
|
25 |
.nnr-btnsave, .nnr-btndelete, .nnr-btn-click-to-copy {
|
26 |
-
|
27 |
}
|
28 |
.nnr-btn-copy-inline {
|
29 |
-
|
30 |
-
|
31 |
}
|
32 |
.padding20 {
|
33 |
-
|
34 |
}
|
35 |
/* toggle switch */
|
36 |
|
37 |
.round-toggle {
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
}
|
42 |
.round-toggle + label {
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
}
|
50 |
input.round-toggle-round-flat + label {
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
}
|
59 |
input.round-toggle-round-flat + label:before,
|
60 |
input.round-toggle-round-flat + label:after {
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
}
|
65 |
input.round-toggle-round-flat + label:after {
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
}
|
75 |
input.round-toggle-round-flat:checked + label:after {
|
76 |
-
|
77 |
}
|
78 |
.nnr-switch {
|
79 |
-
|
80 |
-
|
81 |
}
|
82 |
.nnr-switch label {
|
83 |
-
|
84 |
}
|
85 |
.nnr-switch label:hover {
|
86 |
-
|
87 |
}
|
88 |
.nnr-switch label:first-child:hover {
|
89 |
-
|
90 |
}
|
91 |
input.round-toggle-round-flat:checked + label {
|
92 |
-
|
93 |
-
|
94 |
}
|
95 |
input.round-toggle-round-flat:checked + label:hover {
|
96 |
-
|
97 |
}
|
98 |
.hfcm-red {
|
99 |
-
|
100 |
}
|
101 |
.nnr-wraptext {
|
102 |
-
|
103 |
}
|
104 |
.nnr-hfcm-codeeditor-box .CodeMirror.CodeMirror-wrap {
|
105 |
-
|
106 |
}
|
107 |
.nnr-mt-20 {
|
108 |
-
|
109 |
}
|
110 |
@media (max-width: 782px) {
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
}
|
1 |
.hfcm-form-width,
|
2 |
.widefat {
|
3 |
+
width: 100%;
|
4 |
}
|
5 |
.hfcm-list-width {
|
6 |
+
min-width: 10%
|
7 |
}
|
8 |
.hfcm-th-width {
|
9 |
+
width: 25%;
|
10 |
+
padding: 20px 20px 0 !important;
|
11 |
}
|
12 |
.hfcm-field-width,
|
13 |
.hfcm-form-width select,
|
14 |
.selectize-control {
|
15 |
+
width: 400px;
|
16 |
}
|
17 |
#nnr_newcontent {
|
18 |
+
width: 75%;
|
19 |
}
|
20 |
.nnr-btndelete {
|
21 |
+
color: #cc1818 !important;
|
22 |
+
box-shadow: inset 0 0 0 1px #cc1818 !important;
|
23 |
+
border: #cc1818 !important;
|
24 |
}
|
25 |
.nnr-btnsave, .nnr-btndelete, .nnr-btn-click-to-copy {
|
26 |
+
margin-top: 10px !important;
|
27 |
}
|
28 |
.nnr-btn-copy-inline {
|
29 |
+
text-decoration: underline !important;
|
30 |
+
margin-left: 10px;
|
31 |
}
|
32 |
.padding20 {
|
33 |
+
padding: 20px !important;
|
34 |
}
|
35 |
/* toggle switch */
|
36 |
|
37 |
.round-toggle {
|
38 |
+
position: absolute;
|
39 |
+
margin-left: -9999px;
|
40 |
+
visibility: hidden;
|
41 |
}
|
42 |
.round-toggle + label {
|
43 |
+
display: inline-block;
|
44 |
+
position: relative;
|
45 |
+
cursor: pointer;
|
46 |
+
outline: none;
|
47 |
+
user-select: none;
|
48 |
+
vertical-align: middle;
|
49 |
}
|
50 |
input.round-toggle-round-flat + label {
|
51 |
+
padding: 2px;
|
52 |
+
width: 14px;
|
53 |
+
height: 5px;
|
54 |
+
color: #ddd;
|
55 |
+
border: 2px solid;
|
56 |
+
border-radius: 6px;
|
57 |
+
transition: color .3s;
|
58 |
}
|
59 |
input.round-toggle-round-flat + label:before,
|
60 |
input.round-toggle-round-flat + label:after {
|
61 |
+
display: block;
|
62 |
+
position: absolute;
|
63 |
+
content: '';
|
64 |
}
|
65 |
input.round-toggle-round-flat + label:after {
|
66 |
+
top: -2px;
|
67 |
+
left: -2px;
|
68 |
+
bottom: -2px;
|
69 |
+
width: 8px;
|
70 |
+
border: 2px solid;
|
71 |
+
border-radius: 6px;
|
72 |
+
background: #fff;
|
73 |
+
transition: margin .3s;
|
74 |
}
|
75 |
input.round-toggle-round-flat:checked + label:after {
|
76 |
+
margin-left: 10px;
|
77 |
}
|
78 |
.nnr-switch {
|
79 |
+
text-align: left;
|
80 |
+
white-space: nowrap;
|
81 |
}
|
82 |
.nnr-switch label {
|
83 |
+
cursor: pointer;
|
84 |
}
|
85 |
.nnr-switch label:hover {
|
86 |
+
color: #40B000;
|
87 |
}
|
88 |
.nnr-switch label:first-child:hover {
|
89 |
+
color: #ff2525;
|
90 |
}
|
91 |
input.round-toggle-round-flat:checked + label {
|
92 |
+
color: #4aaeee;
|
93 |
+
background: #4aaeee;
|
94 |
}
|
95 |
input.round-toggle-round-flat:checked + label:hover {
|
96 |
+
color: #ff2525;
|
97 |
}
|
98 |
.hfcm-red {
|
99 |
+
color: red
|
100 |
}
|
101 |
.nnr-wraptext {
|
102 |
+
width: -moz-available;
|
103 |
}
|
104 |
.nnr-hfcm-codeeditor-box .CodeMirror.CodeMirror-wrap {
|
105 |
+
height: 500px !important;
|
106 |
}
|
107 |
.nnr-mt-20 {
|
108 |
+
margin-top: 20px;
|
109 |
}
|
110 |
@media (max-width: 782px) {
|
111 |
+
.hfcm-form-width select {
|
112 |
+
min-width: auto;
|
113 |
+
}
|
114 |
+
#nnr_newcontent {
|
115 |
+
width: 103%;
|
116 |
+
width: calc(100% + 24px);
|
117 |
+
}
|
118 |
+
table.hfcm-form-width td {
|
119 |
+
padding: 10px 21px 0 17px;
|
120 |
+
}
|
121 |
+
table.hfcm-form-width tr:last-child td {
|
122 |
+
padding-bottom: 20px;
|
123 |
+
}
|
124 |
+
#wpbody .hfcm-form-width select[multiple] {
|
125 |
+
height: auto;
|
126 |
+
}
|
127 |
}
|
includes/class-hfcm-snippets-list.php
CHANGED
@@ -1,19 +1,21 @@
|
|
1 |
<?php
|
2 |
-
if (
|
3 |
-
|
4 |
}
|
5 |
|
6 |
class Hfcm_Snippets_List extends WP_List_Table
|
7 |
{
|
8 |
|
9 |
-
/**
|
|
|
|
|
10 |
public function __construct()
|
11 |
{
|
12 |
|
13 |
parent::__construct(
|
14 |
array(
|
15 |
-
'singular' => esc_html__(
|
16 |
-
'plural' => esc_html__(
|
17 |
'ajax' => false,
|
18 |
)
|
19 |
);
|
@@ -32,44 +34,57 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
32 |
|
33 |
global $wpdb;
|
34 |
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
35 |
-
$page_number = absint(
|
36 |
-
$per_page = absint(
|
37 |
-
$customvar = sanitize_text_field(
|
38 |
$orderby = 'script_id';
|
39 |
$order = 'ASC';
|
40 |
|
41 |
-
if (
|
42 |
-
$orderby = sanitize_sql_orderby(
|
43 |
-
if (
|
44 |
$orderby = 'script_id';
|
45 |
}
|
46 |
}
|
47 |
-
if (
|
48 |
-
$order = strtolower(
|
49 |
-
if (
|
50 |
$order = 'ASC';
|
51 |
}
|
52 |
}
|
53 |
|
54 |
-
$sql
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
58 |
}
|
59 |
-
if (
|
60 |
-
$snippet_type = addslashes(
|
61 |
-
if (
|
62 |
-
$sql
|
|
|
63 |
}
|
64 |
}
|
65 |
-
if (
|
66 |
-
$search_query
|
67 |
-
$sql
|
|
|
68 |
}
|
69 |
|
70 |
-
$sql
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
$result = $wpdb->get_results( $sql, 'ARRAY_A' );
|
73 |
return $result;
|
74 |
}
|
75 |
|
@@ -81,7 +96,7 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
81 |
public static function delete_snippet( $id )
|
82 |
{
|
83 |
$id = (int) $id;
|
84 |
-
if (
|
85 |
return;
|
86 |
}
|
87 |
|
@@ -102,7 +117,7 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
102 |
{
|
103 |
|
104 |
$id = (int) $id;
|
105 |
-
if (
|
106 |
return;
|
107 |
}
|
108 |
|
@@ -112,7 +127,7 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
112 |
$wpdb->update(
|
113 |
$table_name, array(
|
114 |
'status' => 'active',
|
115 |
-
|
116 |
);
|
117 |
}
|
118 |
|
@@ -125,7 +140,7 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
125 |
{
|
126 |
|
127 |
$id = (int) $id;
|
128 |
-
if (
|
129 |
return;
|
130 |
}
|
131 |
|
@@ -135,7 +150,7 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
135 |
$wpdb->update(
|
136 |
$table_name, array(
|
137 |
'status' => 'inactive',
|
138 |
-
|
139 |
);
|
140 |
}
|
141 |
|
@@ -148,28 +163,35 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
148 |
{
|
149 |
|
150 |
global $wpdb;
|
151 |
-
$table_name
|
152 |
-
$sql
|
|
|
153 |
|
154 |
-
$customvar = sanitize_text_field(
|
155 |
|
156 |
-
if (
|
157 |
-
$sql
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
|
160 |
-
return $wpdb->get_var(
|
161 |
}
|
162 |
|
163 |
-
/**
|
|
|
|
|
164 |
public function no_items()
|
165 |
{
|
166 |
-
esc_html_e(
|
167 |
}
|
168 |
|
169 |
/**
|
170 |
* Render a column when no column specific method exist.
|
171 |
*
|
172 |
-
* @param array
|
173 |
* @param string $column_name
|
174 |
*
|
175 |
* @return mixed
|
@@ -178,105 +200,106 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
178 |
{
|
179 |
|
180 |
switch ( $column_name ) {
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
}
|
210 |
-
if ( $empty ) {
|
211 |
-
return '<span class="hfcm-red">' . esc_html__( 'No post selected', '99robots-header-footer-code-manager' ) . '</span>';
|
212 |
}
|
213 |
}
|
|
|
|
|
|
|
|
|
214 |
|
215 |
-
|
216 |
|
217 |
-
|
218 |
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
<label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
|
255 |
-
<input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" />
|
256 |
-
<label for="nnr-round-toggle' . $item['script_id'] . '"></label>
|
257 |
-
<label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
|
258 |
</div>
|
259 |
';
|
260 |
-
|
261 |
-
|
262 |
-
<label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
|
263 |
-
<input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" checked="checked" />
|
264 |
-
<label for="nnr-round-toggle' . $item['script_id'] . '"></label>
|
265 |
-
<label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
|
266 |
</div>
|
267 |
';
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
|
272 |
-
|
273 |
-
|
274 |
|
275 |
-
|
276 |
-
|
277 |
|
278 |
-
|
279 |
-
|
280 |
}
|
281 |
}
|
282 |
|
@@ -304,25 +327,25 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
304 |
function column_name( $item )
|
305 |
{
|
306 |
|
307 |
-
$delete_nonce = wp_create_nonce(
|
308 |
-
$edit_nonce = wp_create_nonce(
|
309 |
|
310 |
-
$title = '<strong>' . $item['name'] . '</strong>';
|
311 |
|
312 |
$nnr_current_screen = get_current_screen();
|
313 |
|
314 |
-
if (
|
315 |
$page = $nnr_current_screen->parent_base;
|
316 |
} else {
|
317 |
-
$page = sanitize_text_field(
|
318 |
}
|
319 |
$actions = array(
|
320 |
-
'edit' => sprintf(
|
321 |
-
'copy' => sprintf(
|
322 |
-
'delete' => sprintf(
|
323 |
);
|
324 |
|
325 |
-
return $title . $this->row_actions(
|
326 |
}
|
327 |
|
328 |
/**
|
@@ -334,14 +357,14 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
334 |
{
|
335 |
$columns = array(
|
336 |
'cb' => '<input type="checkbox" />',
|
337 |
-
'script_id' => esc_html__(
|
338 |
-
'status' => esc_html__(
|
339 |
-
'name' => esc_html__(
|
340 |
-
'display_on' => esc_html__(
|
341 |
-
'location' => esc_html__(
|
342 |
-
'snippet_type' => esc_html__(
|
343 |
-
'device_type' => esc_html__(
|
344 |
-
'shortcode' => esc_html__(
|
345 |
);
|
346 |
|
347 |
return $columns;
|
@@ -371,9 +394,9 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
371 |
{
|
372 |
|
373 |
return array(
|
374 |
-
'bulk-activate' => esc_html__(
|
375 |
-
'bulk-deactivate' => esc_html__(
|
376 |
-
'bulk-delete' => esc_html__(
|
377 |
);
|
378 |
}
|
379 |
|
@@ -384,28 +407,28 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
384 |
*/
|
385 |
public function extra_tablenav( $which )
|
386 |
{
|
387 |
-
if (
|
388 |
-
$query = isset(
|
389 |
$snippet_type = array(
|
390 |
-
'html' => esc_html__(
|
391 |
-
'css' => esc_html__(
|
392 |
-
'js' => esc_html__(
|
393 |
);
|
394 |
|
395 |
echo '<div class="alignleft actions">';
|
396 |
echo '<select name="snippet_type">';
|
397 |
-
echo '<option value="">' . esc_html__(
|
398 |
|
399 |
foreach ( $snippet_type as $key_type => $type ) {
|
400 |
-
if (
|
401 |
-
echo '<option value="' . $key_type . '" selected>' . $type . '</option>';
|
402 |
} else {
|
403 |
-
echo '<option value="' . $key_type . '">' . $type . '</option>';
|
404 |
}
|
405 |
}
|
406 |
|
407 |
echo '</select>';
|
408 |
-
submit_button(
|
409 |
echo '</div>';
|
410 |
}
|
411 |
|
@@ -427,51 +450,55 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
427 |
|
428 |
// Retrieve $customvar for use in query to get items.
|
429 |
$customvar = 'all';
|
430 |
-
if (
|
431 |
-
$customvar = sanitize_text_field(
|
432 |
-
if (
|
433 |
$customvar = 'all';
|
434 |
}
|
435 |
}
|
436 |
$this->_column_headers = array( $columns, $hidden, $sortable );
|
437 |
|
438 |
-
/**
|
|
|
|
|
439 |
$this->process_bulk_action();
|
440 |
$this->views();
|
441 |
-
$per_page = $this->get_items_per_page(
|
442 |
$current_page = $this->get_pagenum();
|
443 |
$total_items = self::record_count();
|
444 |
|
445 |
-
$this->set_pagination_args(
|
446 |
-
|
447 |
-
|
448 |
-
|
|
|
|
|
449 |
|
450 |
-
$this->items = self::get_snippets(
|
451 |
}
|
452 |
|
453 |
public function get_views()
|
454 |
{
|
455 |
$views = array();
|
456 |
$current = 'all';
|
457 |
-
if (
|
458 |
-
$current = sanitize_text_field(
|
459 |
}
|
460 |
|
461 |
//All link
|
462 |
$class = 'all' === $current ? 'current' : '';
|
463 |
-
$all_url = remove_query_arg(
|
464 |
-
$views['all'] = '<a href="'. esc_html($all_url).'" class="'. esc_html($class).'">' . esc_html__(
|
465 |
|
466 |
//Foo link
|
467 |
-
$foo_url = add_query_arg(
|
468 |
$class = ('active' === $current ? 'current' : '');
|
469 |
-
$views['active'] = '<a href="'. esc_html($foo_url).'" class="'. esc_html($class).'">' . esc_html__(
|
470 |
|
471 |
//Bar link
|
472 |
-
$bar_url = add_query_arg(
|
473 |
$class = ('inactive' === $current ? 'current' : '');
|
474 |
-
$views['inactive'] = '<a href="'. esc_html($bar_url).'" class="'. esc_html($class).'">' . esc_html__(
|
475 |
|
476 |
return $views;
|
477 |
}
|
@@ -479,76 +506,73 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
479 |
public function process_bulk_action()
|
480 |
{
|
481 |
//Detect when a bulk action is being triggered...
|
482 |
-
if (
|
483 |
|
484 |
// In our file that handles the request, verify the nonce.
|
485 |
-
$nonce = sanitize_text_field(
|
486 |
|
487 |
-
if (
|
488 |
-
die(
|
489 |
} else {
|
490 |
-
if (
|
491 |
-
$snippet_id = absint(
|
492 |
-
if (
|
493 |
-
self::delete_snippet(
|
494 |
}
|
495 |
}
|
496 |
|
497 |
-
NNR_HFCM::hfcm_redirect(
|
498 |
return;
|
499 |
}
|
500 |
}
|
501 |
|
502 |
// If the delete bulk action is triggered
|
503 |
-
if (
|
504 |
-
(isset(
|
505 |
-
(isset( $_POST['action2'] ) && 'bulk-delete' === $_POST['action2'])
|
506 |
) {
|
507 |
$delete_ids = $_POST['snippets'];
|
508 |
|
509 |
// loop over the array of record IDs and delete them
|
510 |
foreach ( $delete_ids as $id ) {
|
511 |
-
$id = absint(
|
512 |
-
if (
|
513 |
-
self::delete_snippet(
|
514 |
}
|
515 |
}
|
516 |
|
517 |
-
NNR_HFCM::hfcm_redirect(
|
518 |
return;
|
519 |
-
} elseif (
|
520 |
-
(isset(
|
521 |
-
(isset( $_POST['action2'] ) && 'bulk-activate' === $_POST['action2'])
|
522 |
) {
|
523 |
|
524 |
$activate_ids = $_POST['snippets'];
|
525 |
|
526 |
// loop over the array of record IDs and activate them
|
527 |
foreach ( $activate_ids as $id ) {
|
528 |
-
$id = absint(
|
529 |
-
if (
|
530 |
-
self::activate_snippet(
|
531 |
}
|
532 |
}
|
533 |
|
534 |
-
NNR_HFCM::hfcm_redirect(
|
535 |
return;
|
536 |
-
} elseif (
|
537 |
-
(isset(
|
538 |
-
(isset( $_POST['action2'] ) && 'bulk-deactivate' === $_POST['action2'])
|
539 |
) {
|
540 |
|
541 |
$delete_ids = $_POST['snippets'];
|
542 |
|
543 |
// loop over the array of record IDs and deactivate them
|
544 |
foreach ( $delete_ids as $id ) {
|
545 |
-
$id = absint(
|
546 |
-
if (
|
547 |
-
self::deactivate_snippet(
|
548 |
}
|
549 |
}
|
550 |
|
551 |
-
NNR_HFCM::hfcm_redirect(
|
552 |
|
553 |
return;
|
554 |
}
|
@@ -557,23 +581,23 @@ class Hfcm_Snippets_List extends WP_List_Table
|
|
557 |
/**
|
558 |
* Displays the search box.
|
559 |
*
|
560 |
-
* @param string $text
|
561 |
* @param string $input_id ID attribute value for the search input field.
|
562 |
* @since 3.1.0
|
563 |
-
*
|
564 |
*/
|
565 |
public function search_box( $text, $input_id )
|
566 |
{
|
567 |
-
if (
|
568 |
return;
|
569 |
}
|
570 |
$input_id = $input_id . '-search-input';
|
571 |
?>
|
572 |
<p class="search-box">
|
573 |
-
<label class="screen-reader-text"
|
574 |
-
|
575 |
-
|
576 |
-
|
|
|
577 |
</p>
|
578 |
<?php
|
579 |
}
|
1 |
<?php
|
2 |
+
if (!class_exists('WP_List_Table') ) {
|
3 |
+
include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
4 |
}
|
5 |
|
6 |
class Hfcm_Snippets_List extends WP_List_Table
|
7 |
{
|
8 |
|
9 |
+
/**
|
10 |
+
* Class constructor
|
11 |
+
*/
|
12 |
public function __construct()
|
13 |
{
|
14 |
|
15 |
parent::__construct(
|
16 |
array(
|
17 |
+
'singular' => esc_html__('Snippet', '99robots-header-footer-code-manager'),
|
18 |
+
'plural' => esc_html__('Snippets', '99robots-header-footer-code-manager'),
|
19 |
'ajax' => false,
|
20 |
)
|
21 |
);
|
34 |
|
35 |
global $wpdb;
|
36 |
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
37 |
+
$page_number = absint($page_number);
|
38 |
+
$per_page = absint($per_page);
|
39 |
+
$customvar = sanitize_text_field($customvar);
|
40 |
$orderby = 'script_id';
|
41 |
$order = 'ASC';
|
42 |
|
43 |
+
if (!empty($_GET['orderby']) ) {
|
44 |
+
$orderby = sanitize_sql_orderby($_GET['orderby']);
|
45 |
+
if (empty($orderby) || !in_array($orderby, array( 'script_id', 'name', 'location' )) ) {
|
46 |
$orderby = 'script_id';
|
47 |
}
|
48 |
}
|
49 |
+
if (!empty($_GET['order']) ) {
|
50 |
+
$order = strtolower(sanitize_sql_orderby($_GET['order']));
|
51 |
+
if (empty($order) || !in_array($order, array( 'desc', 'asc' )) ) {
|
52 |
$order = 'ASC';
|
53 |
}
|
54 |
}
|
55 |
|
56 |
+
$sql = "SELECT * FROM `{$table_name}` WHERE 1";
|
57 |
+
$placeholder_args = array();
|
58 |
+
if (in_array($customvar, array( 'inactive', 'active' )) ) {
|
59 |
+
$sql .= " AND status = '%s'";
|
60 |
+
$placeholder_args[] = $customvar;
|
61 |
}
|
62 |
+
if (!empty($_POST['snippet_type']) ) {
|
63 |
+
$snippet_type = addslashes(sanitize_text_field($_POST['snippet_type']));
|
64 |
+
if (in_array($snippet_type, array( 'html', 'css', 'js' )) ) {
|
65 |
+
$sql .= " AND snippet_type = %s";
|
66 |
+
$placeholder_args[] = $snippet_type;
|
67 |
}
|
68 |
}
|
69 |
+
if (!empty($_POST['s']) ) {
|
70 |
+
$search_query = addslashes(sanitize_text_field($_POST['s']));
|
71 |
+
$sql .= " AND name LIKE %s";
|
72 |
+
$placeholder_args[] = '%'.$search_query.'%';
|
73 |
}
|
74 |
|
75 |
+
$sql .= ' ORDER BY %s %s LIMIT %d OFFSET %d';
|
76 |
+
$placeholder_args[] = $orderby;
|
77 |
+
$placeholder_args[] = $order;
|
78 |
+
$placeholder_args[] = $per_page;
|
79 |
+
$placeholder_args[] = ($page_number - 1) * $per_page;
|
80 |
+
|
81 |
+
if (!empty($placeholder_args) ) {
|
82 |
+
$sql = $wpdb->prepare($sql, $placeholder_args);
|
83 |
+
}
|
84 |
+
$result = $wpdb->get_results(
|
85 |
+
$sql, 'ARRAY_A'
|
86 |
+
);
|
87 |
|
|
|
88 |
return $result;
|
89 |
}
|
90 |
|
96 |
public static function delete_snippet( $id )
|
97 |
{
|
98 |
$id = (int) $id;
|
99 |
+
if (empty($id) ) {
|
100 |
return;
|
101 |
}
|
102 |
|
117 |
{
|
118 |
|
119 |
$id = (int) $id;
|
120 |
+
if (empty($id) ) {
|
121 |
return;
|
122 |
}
|
123 |
|
127 |
$wpdb->update(
|
128 |
$table_name, array(
|
129 |
'status' => 'active',
|
130 |
+
), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
|
131 |
);
|
132 |
}
|
133 |
|
140 |
{
|
141 |
|
142 |
$id = (int) $id;
|
143 |
+
if (empty($id) ) {
|
144 |
return;
|
145 |
}
|
146 |
|
150 |
$wpdb->update(
|
151 |
$table_name, array(
|
152 |
'status' => 'inactive',
|
153 |
+
), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
|
154 |
);
|
155 |
}
|
156 |
|
163 |
{
|
164 |
|
165 |
global $wpdb;
|
166 |
+
$table_name = "{$wpdb->prefix}hfcm_scripts";
|
167 |
+
$sql = "SELECT COUNT(*) FROM `{$table_name}`";
|
168 |
+
$placeholder_args = [];
|
169 |
|
170 |
+
$customvar = sanitize_text_field($customvar);
|
171 |
|
172 |
+
if (in_array($customvar, array( 'inactive', 'active' )) ) {
|
173 |
+
$sql .= " WHERE status = %s";
|
174 |
+
$placeholder_args[] = $customvar;
|
175 |
+
}
|
176 |
+
if(!empty($placeholder_args)) {
|
177 |
+
$sql = $wpdb->prepare($sql, $placeholder_args);
|
178 |
}
|
179 |
|
180 |
+
return $wpdb->get_var($sql);
|
181 |
}
|
182 |
|
183 |
+
/**
|
184 |
+
* Text displayed when no snippet data is available
|
185 |
+
*/
|
186 |
public function no_items()
|
187 |
{
|
188 |
+
esc_html_e('No Snippets available.', '99robots-header-footer-code-manager');
|
189 |
}
|
190 |
|
191 |
/**
|
192 |
* Render a column when no column specific method exist.
|
193 |
*
|
194 |
+
* @param array $item
|
195 |
* @param string $column_name
|
196 |
*
|
197 |
* @return mixed
|
200 |
{
|
201 |
|
202 |
switch ( $column_name ) {
|
203 |
+
case 'name':
|
204 |
+
return esc_html($item[ $column_name ]);
|
205 |
+
|
206 |
+
case 'display_on':
|
207 |
+
$nnr_hfcm_display_array = array(
|
208 |
+
'All' => esc_html__('Site Wide', '99robots-header-footer-code-manager'),
|
209 |
+
's_posts' => esc_html__('Specific Posts', '99robots-header-footer-code-manager'),
|
210 |
+
's_pages' => esc_html__('Specific Pages', '99robots-header-footer-code-manager'),
|
211 |
+
's_categories' => esc_html__('Specific Categories', '99robots-header-footer-code-manager'),
|
212 |
+
's_custom_posts' => esc_html__('Specific Custom Post Types', '99robots-header-footer-code-manager'),
|
213 |
+
's_tags' => esc_html__('Specific Tags', '99robots-header-footer-code-manager'),
|
214 |
+
's_is_home' => esc_html__('Home Page', '99robots-header-footer-code-manager'),
|
215 |
+
's_is_search' => esc_html__('Search Page', '99robots-header-footer-code-manager'),
|
216 |
+
's_is_archive' => esc_html__('Archive Page', '99robots-header-footer-code-manager'),
|
217 |
+
'latest_posts' => esc_html__('Latest Posts', '99robots-header-footer-code-manager'),
|
218 |
+
'manual' => esc_html__('Shortcode Only', '99robots-header-footer-code-manager'),
|
219 |
+
);
|
220 |
+
|
221 |
+
if ('s_posts' === $item[ $column_name ] ) {
|
222 |
+
|
223 |
+
$empty = 1;
|
224 |
+
$s_posts = json_decode($item['s_posts']);
|
225 |
+
|
226 |
+
foreach ( $s_posts as $id ) {
|
227 |
+
$id = absint($id);
|
228 |
+
if ('publish' === get_post_status($id) ) {
|
229 |
+
$empty = 0;
|
230 |
+
break;
|
|
|
|
|
|
|
231 |
}
|
232 |
}
|
233 |
+
if ($empty ) {
|
234 |
+
return '<span class="hfcm-red">' . esc_html__('No post selected', '99robots-header-footer-code-manager') . '</span>';
|
235 |
+
}
|
236 |
+
}
|
237 |
|
238 |
+
return esc_html($nnr_hfcm_display_array[ $item[ $column_name ] ]);
|
239 |
|
240 |
+
case 'location':
|
241 |
|
242 |
+
if (!$item[ $column_name ] ) {
|
243 |
+
return esc_html__('N/A', '99robots-header-footer-code-manager');
|
244 |
+
}
|
245 |
|
246 |
+
$nnr_hfcm_locations = array(
|
247 |
+
'header' => esc_html__('Header', '99robots-header-footer-code-manager'),
|
248 |
+
'before_content' => esc_html__('Before Content', '99robots-header-footer-code-manager'),
|
249 |
+
'after_content' => esc_html__('After Content', '99robots-header-footer-code-manager'),
|
250 |
+
'footer' => esc_html__('Footer', '99robots-header-footer-code-manager'),
|
251 |
+
);
|
252 |
+
return esc_html($nnr_hfcm_locations[ $item[ $column_name ] ]);
|
253 |
+
|
254 |
+
case 'device_type':
|
255 |
+
|
256 |
+
if ('both' === $item[ $column_name ] ) {
|
257 |
+
return esc_html__('Show on All Devices', '99robots-header-footer-code-manager');
|
258 |
+
} elseif ('mobile' === $item[ $column_name ] ) {
|
259 |
+
return esc_html__('Only Mobile Devices', '99robots-header-footer-code-manager');
|
260 |
+
} elseif ('desktop' === $item[ $column_name ] ) {
|
261 |
+
return esc_html__('Only Desktop', '99robots-header-footer-code-manager');
|
262 |
+
} else {
|
263 |
+
return esc_html($item[ $column_name ]);
|
264 |
+
}
|
265 |
+
case 'snippet_type':
|
266 |
+
$snippet_types = array(
|
267 |
+
'html' => esc_html__('HTML', '99robots-header-footer-code-manager'),
|
268 |
+
'css' => esc_html__('CSS', '99robots-header-footer-code-manager'),
|
269 |
+
'js' => esc_html__('Javascript', '99robots-header-footer-code-manager')
|
270 |
+
);
|
271 |
+
return esc_html($snippet_types[ $item[ $column_name ] ]);
|
272 |
+
|
273 |
+
case 'status':
|
274 |
+
|
275 |
+
if ('inactive' === $item[ $column_name ] ) {
|
276 |
+
return '<div class="nnr-switch">
|
277 |
+
<label for="nnr-round-toggle' . esc_attr($item['script_id']) . '">OFF</label>
|
278 |
+
<input id="nnr-round-toggle' . esc_attr($item['script_id']) . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . esc_attr($item['script_id']) . '" />
|
279 |
+
<label for="nnr-round-toggle' . esc_attr($item['script_id']) . '"></label>
|
280 |
+
<label for="nnr-round-toggle' . esc_attr($item['script_id']) . '">ON</label>
|
281 |
</div>
|
282 |
';
|
283 |
+
} elseif ('active' === $item[ $column_name ] ) {
|
284 |
+
return '<div class="nnr-switch">
|
285 |
+
<label for="nnr-round-toggle' . esc_attr($item['script_id']) . '">OFF</label>
|
286 |
+
<input id="nnr-round-toggle' . esc_attr($item['script_id']) . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . esc_attr($item['script_id']) . '" checked="checked" />
|
287 |
+
<label for="nnr-round-toggle' . esc_attr($item['script_id']) . '"></label>
|
288 |
+
<label for="nnr-round-toggle' . esc_attr($item['script_id']) . '">ON</label>
|
289 |
</div>
|
290 |
';
|
291 |
+
} else {
|
292 |
+
return esc_html($item[ $column_name ]);
|
293 |
+
}
|
294 |
|
295 |
+
case 'script_id':
|
296 |
+
return esc_html($item[ $column_name ]);
|
297 |
|
298 |
+
case 'shortcode':
|
299 |
+
return '[hfcm id="' . absint($item['script_id']) . '"]';
|
300 |
|
301 |
+
default:
|
302 |
+
return esc_html(print_r($item, true)); // Show the whole array for troubleshooting purposes
|
303 |
}
|
304 |
}
|
305 |
|
327 |
function column_name( $item )
|
328 |
{
|
329 |
|
330 |
+
$delete_nonce = wp_create_nonce('hfcm_delete_snippet');
|
331 |
+
$edit_nonce = wp_create_nonce('hfcm_edit_snippet');
|
332 |
|
333 |
+
$title = '<strong>' . esc_html($item['name']) . '</strong>';
|
334 |
|
335 |
$nnr_current_screen = get_current_screen();
|
336 |
|
337 |
+
if (!empty($nnr_current_screen->parent_base) ) {
|
338 |
$page = $nnr_current_screen->parent_base;
|
339 |
} else {
|
340 |
+
$page = sanitize_text_field($_GET['page']);
|
341 |
}
|
342 |
$actions = array(
|
343 |
+
'edit' => sprintf('<a href="?page=%s&action=%s&id=%s&_wpnonce=%s">' . esc_html__('Edit', '99robots-header-footer-code-manager') . '</a>', esc_attr('hfcm-update'), 'edit', absint($item['script_id']), $edit_nonce),
|
344 |
+
'copy' => sprintf('<a href="javascript:void(0);" data-shortcode=\'[hfcm id="%s"]\' class="hfcm_copy_shortcode" id="hfcm_copy_shortcode_%s">' . esc_html__('Copy Shortcode', '99robots-header-footer-code-manager') . '</a>', absint($item['script_id']), absint($item['script_id'])),
|
345 |
+
'delete' => sprintf('<a href="?page=%s&action=%s&snippet=%s&_wpnonce=%s">' . esc_html__('Delete', '99robots-header-footer-code-manager') . '</a>', $page, 'delete', absint($item['script_id']), $delete_nonce),
|
346 |
);
|
347 |
|
348 |
+
return $title . $this->row_actions($actions);
|
349 |
}
|
350 |
|
351 |
/**
|
357 |
{
|
358 |
$columns = array(
|
359 |
'cb' => '<input type="checkbox" />',
|
360 |
+
'script_id' => esc_html__('ID', '99robots-header-footer-code-manager'),
|
361 |
+
'status' => esc_html__('Status', '99robots-header-footer-code-manager'),
|
362 |
+
'name' => esc_html__('Snippet Name', '99robots-header-footer-code-manager'),
|
363 |
+
'display_on' => esc_html__('Display On', '99robots-header-footer-code-manager'),
|
364 |
+
'location' => esc_html__('Location', '99robots-header-footer-code-manager'),
|
365 |
+
'snippet_type' => esc_html__('Snippet Type', '99robots-header-footer-code-manager'),
|
366 |
+
'device_type' => esc_html__('Devices', '99robots-header-footer-code-manager'),
|
367 |
+
'shortcode' => esc_html__('Shortcode', '99robots-header-footer-code-manager'),
|
368 |
);
|
369 |
|
370 |
return $columns;
|
394 |
{
|
395 |
|
396 |
return array(
|
397 |
+
'bulk-activate' => esc_html__('Activate', '99robots-header-footer-code-manager'),
|
398 |
+
'bulk-deactivate' => esc_html__('Deactivate', '99robots-header-footer-code-manager'),
|
399 |
+
'bulk-delete' => esc_html__('Remove', '99robots-header-footer-code-manager'),
|
400 |
);
|
401 |
}
|
402 |
|
407 |
*/
|
408 |
public function extra_tablenav( $which )
|
409 |
{
|
410 |
+
if ('top' === $which ) {
|
411 |
+
$query = isset($_POST['snippet_type']) ? sanitize_text_field($_POST['snippet_type']) : '';
|
412 |
$snippet_type = array(
|
413 |
+
'html' => esc_html__('HTML', '99robots-header-footer-code-manager'),
|
414 |
+
'css' => esc_html__('CSS', '99robots-header-footer-code-manager'),
|
415 |
+
'js' => esc_html__('Javascript', '99robots-header-footer-code-manager')
|
416 |
);
|
417 |
|
418 |
echo '<div class="alignleft actions">';
|
419 |
echo '<select name="snippet_type">';
|
420 |
+
echo '<option value="">' . esc_html__('All Snippet Types', '99robots-header-footer-code-manager') . '</option>';
|
421 |
|
422 |
foreach ( $snippet_type as $key_type => $type ) {
|
423 |
+
if ($key_type == $query ) {
|
424 |
+
echo '<option value="' . esc_attr($key_type) . '" selected>' . esc_html($type) . '</option>';
|
425 |
} else {
|
426 |
+
echo '<option value="' . esc_attr($key_type) . '">' . esc_html($type) . '</option>';
|
427 |
}
|
428 |
}
|
429 |
|
430 |
echo '</select>';
|
431 |
+
submit_button(__('Filter', '99robots-header-footer-code-manager'), 'button', 'filter_action', false);
|
432 |
echo '</div>';
|
433 |
}
|
434 |
|
450 |
|
451 |
// Retrieve $customvar for use in query to get items.
|
452 |
$customvar = 'all';
|
453 |
+
if (!empty($_GET['customvar']) ) {
|
454 |
+
$customvar = sanitize_text_field($_GET['customvar']);
|
455 |
+
if (empty($customvar) || !in_array($customvar, [ 'inactive', 'active', 'all' ]) ) {
|
456 |
$customvar = 'all';
|
457 |
}
|
458 |
}
|
459 |
$this->_column_headers = array( $columns, $hidden, $sortable );
|
460 |
|
461 |
+
/**
|
462 |
+
* Process bulk action
|
463 |
+
*/
|
464 |
$this->process_bulk_action();
|
465 |
$this->views();
|
466 |
+
$per_page = $this->get_items_per_page('snippets_per_page', 20);
|
467 |
$current_page = $this->get_pagenum();
|
468 |
$total_items = self::record_count();
|
469 |
|
470 |
+
$this->set_pagination_args(
|
471 |
+
array(
|
472 |
+
'total_items' => $total_items,
|
473 |
+
'per_page' => $per_page,
|
474 |
+
)
|
475 |
+
);
|
476 |
|
477 |
+
$this->items = self::get_snippets($per_page, $current_page, $customvar);
|
478 |
}
|
479 |
|
480 |
public function get_views()
|
481 |
{
|
482 |
$views = array();
|
483 |
$current = 'all';
|
484 |
+
if (!empty($_GET['customvar']) ) {
|
485 |
+
$current = sanitize_text_field($_GET['customvar']);
|
486 |
}
|
487 |
|
488 |
//All link
|
489 |
$class = 'all' === $current ? 'current' : '';
|
490 |
+
$all_url = remove_query_arg('customvar');
|
491 |
+
$views['all'] = '<a href="' . esc_html($all_url) . '" class="' . esc_html($class) . '">' . esc_html__('All', '99robots-header-footer-code-manager') . ' (' . esc_html__($this->record_count()) . ')</a>';
|
492 |
|
493 |
//Foo link
|
494 |
+
$foo_url = add_query_arg('customvar', 'active');
|
495 |
$class = ('active' === $current ? 'current' : '');
|
496 |
+
$views['active'] = '<a href="' . esc_html($foo_url) . '" class="' . esc_html($class) . '">' . esc_html__('Active', '99robots-header-footer-code-manager') . ' (' . esc_html__($this->record_count('active')) . ')</a>';
|
497 |
|
498 |
//Bar link
|
499 |
+
$bar_url = add_query_arg('customvar', 'inactive');
|
500 |
$class = ('inactive' === $current ? 'current' : '');
|
501 |
+
$views['inactive'] = '<a href="' . esc_html($bar_url) . '" class="' . esc_html($class) . '">' . esc_html__('Inactive', '99robots-header-footer-code-manager') . ' (' . esc_html__($this->record_count('inactive')) . ')</a>';
|
502 |
|
503 |
return $views;
|
504 |
}
|
506 |
public function process_bulk_action()
|
507 |
{
|
508 |
//Detect when a bulk action is being triggered...
|
509 |
+
if ('delete' === $this->current_action() ) {
|
510 |
|
511 |
// In our file that handles the request, verify the nonce.
|
512 |
+
$nonce = sanitize_text_field($_REQUEST['_wpnonce']);
|
513 |
|
514 |
+
if (!wp_verify_nonce($nonce, 'hfcm_delete_snippet') ) {
|
515 |
+
die('Go get a life script kiddies');
|
516 |
} else {
|
517 |
+
if (!empty($_GET['snippet']) ) {
|
518 |
+
$snippet_id = absint($_GET['snippet']);
|
519 |
+
if (!empty($snippet_id) ) {
|
520 |
+
self::delete_snippet($snippet_id);
|
521 |
}
|
522 |
}
|
523 |
|
524 |
+
NNR_HFCM::hfcm_redirect(admin_url('admin.php?page=hfcm-list'));
|
525 |
return;
|
526 |
}
|
527 |
}
|
528 |
|
529 |
// If the delete bulk action is triggered
|
530 |
+
if ((isset($_POST['action']) && 'bulk-delete' === $_POST['action'])
|
531 |
+
|| (isset($_POST['action2']) && 'bulk-delete' === $_POST['action2'])
|
|
|
532 |
) {
|
533 |
$delete_ids = $_POST['snippets'];
|
534 |
|
535 |
// loop over the array of record IDs and delete them
|
536 |
foreach ( $delete_ids as $id ) {
|
537 |
+
$id = absint($id);
|
538 |
+
if (!empty($id) && is_int($id) ) {
|
539 |
+
self::delete_snippet($id);
|
540 |
}
|
541 |
}
|
542 |
|
543 |
+
NNR_HFCM::hfcm_redirect(admin_url('admin.php?page=hfcm-list'));
|
544 |
return;
|
545 |
+
} elseif ((isset($_POST['action']) && 'bulk-activate' === $_POST['action'])
|
546 |
+
|| (isset($_POST['action2']) && 'bulk-activate' === $_POST['action2'])
|
|
|
547 |
) {
|
548 |
|
549 |
$activate_ids = $_POST['snippets'];
|
550 |
|
551 |
// loop over the array of record IDs and activate them
|
552 |
foreach ( $activate_ids as $id ) {
|
553 |
+
$id = absint($id);
|
554 |
+
if (!empty($id) && is_int($id) ) {
|
555 |
+
self::activate_snippet($id);
|
556 |
}
|
557 |
}
|
558 |
|
559 |
+
NNR_HFCM::hfcm_redirect(admin_url('admin.php?page=hfcm-list'));
|
560 |
return;
|
561 |
+
} elseif ((isset($_POST['action']) && 'bulk-deactivate' === $_POST['action'])
|
562 |
+
|| (isset($_POST['action2']) && 'bulk-deactivate' === $_POST['action2'])
|
|
|
563 |
) {
|
564 |
|
565 |
$delete_ids = $_POST['snippets'];
|
566 |
|
567 |
// loop over the array of record IDs and deactivate them
|
568 |
foreach ( $delete_ids as $id ) {
|
569 |
+
$id = absint($id);
|
570 |
+
if (!empty($id) && is_int($id) ) {
|
571 |
+
self::deactivate_snippet($id);
|
572 |
}
|
573 |
}
|
574 |
|
575 |
+
NNR_HFCM::hfcm_redirect(admin_url('admin.php?page=hfcm-list'));
|
576 |
|
577 |
return;
|
578 |
}
|
581 |
/**
|
582 |
* Displays the search box.
|
583 |
*
|
584 |
+
* @param string $text The 'submit' button label.
|
585 |
* @param string $input_id ID attribute value for the search input field.
|
586 |
* @since 3.1.0
|
|
|
587 |
*/
|
588 |
public function search_box( $text, $input_id )
|
589 |
{
|
590 |
+
if (empty($_REQUEST['s']) && !$this->has_items() ) {
|
591 |
return;
|
592 |
}
|
593 |
$input_id = $input_id . '-search-input';
|
594 |
?>
|
595 |
<p class="search-box">
|
596 |
+
<label class="screen-reader-text"
|
597 |
+
for="<?php echo esc_attr($input_id); ?>"><?php echo esc_html($text); ?>:</label>
|
598 |
+
<input type="search" id="<?php echo esc_attr($input_id); ?>" name="s"
|
599 |
+
value="<?php esc_attr(_admin_search_query()); ?>"/>
|
600 |
+
<?php submit_button($text, '', '', false, array( 'id' => 'search-submit' )); ?>
|
601 |
</p>
|
602 |
<?php
|
603 |
}
|
includes/hfcm-add-edit.php
CHANGED
@@ -1,91 +1,93 @@
|
|
1 |
<?php
|
2 |
|
3 |
// Register the script
|
4 |
-
wp_register_script(
|
5 |
|
6 |
// prepare ID (for AJAX)
|
7 |
-
if (
|
8 |
$id = -1;
|
9 |
}
|
10 |
|
11 |
// Localize the script with new data
|
12 |
$translation_array = array(
|
13 |
-
'header' => __(
|
14 |
-
'before_content' => __(
|
15 |
-
'after_content' => __(
|
16 |
-
'footer' => __(
|
17 |
-
'id' => $id,
|
18 |
-
'security' => wp_create_nonce(
|
19 |
);
|
20 |
-
wp_localize_script(
|
21 |
|
22 |
// Enqueued script with localized data.
|
23 |
-
wp_enqueue_script(
|
24 |
?>
|
25 |
|
26 |
<div class="wrap">
|
27 |
<h1>
|
28 |
-
<?php echo $update ? esc_html__(
|
29 |
-
<?php if (
|
30 |
-
<a href="<?php echo admin_url(
|
31 |
-
<?php esc_html_e(
|
32 |
</a>
|
33 |
<?php endif; ?>
|
34 |
</h1>
|
35 |
<?php
|
36 |
-
if (
|
37 |
-
if (
|
38 |
?>
|
39 |
<div class="updated">
|
40 |
-
<p><?php esc_html_e(
|
41 |
</div>
|
42 |
-
<a href="<?php echo admin_url(
|
43 |
-
<?php elseif (
|
44 |
<div class="updated">
|
45 |
-
<p><?php esc_html_e(
|
46 |
</div>
|
47 |
-
<a href="<?php echo admin_url(
|
48 |
-
|
49 |
endif;
|
50 |
endif;
|
51 |
|
52 |
-
if (
|
53 |
-
$hfcm_form_action = admin_url(
|
54 |
else :
|
55 |
-
$hfcm_form_action = admin_url(
|
56 |
endif;
|
57 |
?>
|
58 |
<form method="post" action="<?php echo $hfcm_form_action ?>">
|
59 |
<?php
|
60 |
-
if (
|
61 |
-
wp_nonce_field(
|
62 |
else :
|
63 |
-
wp_nonce_field(
|
64 |
endif;
|
65 |
?>
|
66 |
<table class="wp-list-table widefat fixed hfcm-form-width form-table">
|
67 |
<tr>
|
68 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
69 |
-
<td
|
70 |
-
|
71 |
</td>
|
72 |
</tr>
|
73 |
<?php
|
74 |
$nnr_hfcm_snippet_type_array = array(
|
75 |
-
'html' => esc_html__(
|
76 |
-
'css' => esc_html__(
|
77 |
-
'js' => esc_html__(
|
78 |
); ?>
|
79 |
<tr id="snippet_type">
|
80 |
-
<th class="hfcm-th-width"
|
|
|
|
|
81 |
<td>
|
82 |
<select name="data[snippet_type]">
|
83 |
<?php
|
84 |
foreach ( $nnr_hfcm_snippet_type_array as $nnr_key => $nnr_item ) {
|
85 |
-
if (
|
86 |
-
echo "<option value='" . esc_attr(
|
87 |
} else {
|
88 |
-
echo "<option value='" . esc_attr(
|
89 |
}
|
90 |
}
|
91 |
?>
|
@@ -94,28 +96,28 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
94 |
</tr>
|
95 |
<?php
|
96 |
$nnr_hfcm_display_array = array(
|
97 |
-
'All' => esc_html__(
|
98 |
-
's_posts' => esc_html__(
|
99 |
-
's_pages' => esc_html__(
|
100 |
-
's_categories' => esc_html__(
|
101 |
-
's_custom_posts' => esc_html__(
|
102 |
-
's_tags' => esc_html__(
|
103 |
-
's_is_home' => esc_html__(
|
104 |
-
's_is_search' => esc_html__(
|
105 |
-
's_is_archive' => esc_html__(
|
106 |
-
'latest_posts' => esc_html__(
|
107 |
-
'manual' => esc_html__(
|
108 |
); ?>
|
109 |
<tr>
|
110 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
111 |
<td>
|
112 |
<select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
|
113 |
<?php
|
114 |
foreach ( $nnr_hfcm_display_array as $dkey => $statusv ) {
|
115 |
-
if (
|
116 |
-
printf(
|
117 |
} else {
|
118 |
-
printf(
|
119 |
}
|
120 |
}
|
121 |
?>
|
@@ -133,16 +135,16 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
133 |
$nnr_hfcm_exclude_manual_style = 'manual' === $display_on ? 'display:none;' : '';
|
134 |
?>
|
135 |
<tr id="ex_pages"
|
136 |
-
style="<?php echo $nnr_hfcm_exclude_pages_style . $nnr_hfcm_exclude_posts_style . $nnr_hfcm_exclude_tags_style . $nnr_hfcm_exclude_custom_posts_style . $nnr_hfcm_exclude_categories_style . $nnr_hfcm_exclude_lp_count_style . $nnr_hfcm_exclude_manual_style; ?>">
|
137 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
138 |
<td>
|
139 |
<select name="data[ex_pages][]" multiple>
|
140 |
<?php
|
141 |
foreach ( $nnr_hfcm_pages as $pdata ) {
|
142 |
-
if (
|
143 |
-
printf(
|
144 |
} else {
|
145 |
-
printf(
|
146 |
}
|
147 |
}
|
148 |
?>
|
@@ -150,29 +152,31 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
150 |
</td>
|
151 |
</tr>
|
152 |
<tr id="ex_posts"
|
153 |
-
style="<?php echo $nnr_hfcm_exclude_pages_style . $nnr_hfcm_exclude_posts_style . $nnr_hfcm_exclude_tags_style . $nnr_hfcm_exclude_custom_posts_style . $nnr_hfcm_exclude_categories_style . $nnr_hfcm_exclude_lp_count_style . $nnr_hfcm_exclude_manual_style; ?>">
|
154 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
155 |
<td>
|
156 |
<select class="nnr-wraptext" name="data[ex_posts][]" multiple>
|
157 |
<option disabled></option>
|
158 |
</select> <img id="loader"
|
159 |
-
src="<?php echo plugins_url(
|
160 |
</td>
|
161 |
</tr>
|
162 |
<?php
|
163 |
$nnr_hfcm_pages = get_pages();
|
164 |
$nnr_hfcm_pages_style = ('s_pages' === $display_on) ? '' : 'display:none;';
|
165 |
?>
|
166 |
-
<tr id="s_pages" style="<?php echo esc_attr(
|
167 |
-
<th class="hfcm-th-width"
|
|
|
|
|
168 |
<td>
|
169 |
<select name="data[s_pages][]" multiple>
|
170 |
<?php
|
171 |
foreach ( $nnr_hfcm_pages as $pdata ) {
|
172 |
-
if (
|
173 |
-
printf(
|
174 |
} else {
|
175 |
-
printf(
|
176 |
}
|
177 |
}
|
178 |
?>
|
@@ -180,8 +184,10 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
180 |
</td>
|
181 |
</tr>
|
182 |
<?php $nnr_hfcm_posts_style = 's_posts' === $display_on ? '' : 'display:none;'; ?>
|
183 |
-
<tr id="s_posts" style="<?php echo esc_attr(
|
184 |
-
<th class="hfcm-th-width"
|
|
|
|
|
185 |
<td>
|
186 |
<select class="nnr-wraptext" name="data[s_posts][]" multiple>
|
187 |
<option disabled>...</option>
|
@@ -206,23 +212,23 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
206 |
$output = 'names';
|
207 |
$operator = 'and';
|
208 |
|
209 |
-
$nnr_hfcm_custom_post_types = get_post_types(
|
210 |
$nnr_hfcm_post_types = array( 'post' );
|
211 |
foreach ( $nnr_hfcm_custom_post_types as $cpdata ) {
|
212 |
$nnr_hfcm_post_types[] = $cpdata;
|
213 |
}
|
214 |
?>
|
215 |
-
<tr id="s_categories" style="<?php echo esc_attr(
|
216 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
217 |
<td>
|
218 |
<select name="data[s_categories][]" multiple>
|
219 |
<?php
|
220 |
foreach ( $nnr_hfcm_categories as $nnr_key_cat => $nnr_item_cat ) {
|
221 |
foreach($nnr_item_cat['terms'] as $nnr_item_cat_key => $nnr_item_cat_term) {
|
222 |
-
if (
|
223 |
-
echo "<option value='" . esc_attr(
|
224 |
} else {
|
225 |
-
echo "<option value='" . esc_attr(
|
226 |
}
|
227 |
}
|
228 |
}
|
@@ -230,17 +236,17 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
230 |
</select>
|
231 |
</td>
|
232 |
</tr>
|
233 |
-
<tr id="s_tags" style="<?php echo esc_attr(
|
234 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
235 |
<td>
|
236 |
<select name="data[s_tags][]" multiple>
|
237 |
<?php
|
238 |
foreach ($nnr_hfcm_tags as $nnr_key_cat => $nnr_item_tag) {
|
239 |
foreach ( $nnr_item_tag['terms'] as $nnr_item_tag_key => $nnr_item_tag_term ) {
|
240 |
-
if (
|
241 |
-
echo "<option value='" . esc_attr(
|
242 |
} else {
|
243 |
-
echo "<option value='" . esc_attr(
|
244 |
}
|
245 |
}
|
246 |
}
|
@@ -248,32 +254,32 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
248 |
</select>
|
249 |
</td>
|
250 |
</tr>
|
251 |
-
<tr id="c_posttype" style="<?php echo esc_attr(
|
252 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
253 |
<td>
|
254 |
<select name="data[s_custom_posts][]" multiple>
|
255 |
<?php
|
256 |
foreach ( $nnr_hfcm_custom_post_types as $cpkey => $cpdata ) {
|
257 |
-
if (
|
258 |
-
echo "<option value='" . esc_attr(
|
259 |
} else {
|
260 |
-
echo "<option value='" . esc_attr(
|
261 |
}
|
262 |
}
|
263 |
?>
|
264 |
</select>
|
265 |
</td>
|
266 |
</tr>
|
267 |
-
<tr id="lp_count" style="<?php echo $nnr_hfcm_lpcount_style; ?>">
|
268 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
269 |
<td>
|
270 |
<select name="data[lp_count]">
|
271 |
<?php
|
272 |
for ( $i = 1; $i <= 20; $i++ ) {
|
273 |
-
if (
|
274 |
-
echo "<option value='
|
275 |
} else {
|
276 |
-
echo "<option value='
|
277 |
}
|
278 |
}
|
279 |
?>
|
@@ -281,51 +287,53 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
281 |
</td>
|
282 |
</tr>
|
283 |
<?php
|
284 |
-
if (
|
285 |
$nnr_hfcm_locations = array( 'header' => 'Header', 'before_content' => 'Before Content',
|
286 |
'after_content' => 'After Content', 'footer' => 'Footer' );
|
287 |
} else {
|
288 |
$nnr_hfcm_locations = array( 'header' => 'Header', 'footer' => 'Footer' );
|
289 |
}
|
290 |
?>
|
291 |
-
<tr id="locationtr" style="<?php echo esc_attr(
|
292 |
-
<th class="hfcm-th-width"
|
|
|
|
|
293 |
<td>
|
294 |
<select name="data[location]" id="data_location">
|
295 |
<?php
|
296 |
foreach ( $nnr_hfcm_locations as $lkey => $statusv ) {
|
297 |
-
if (
|
298 |
-
echo "<option value='" . esc_attr(
|
299 |
} else {
|
300 |
-
echo "<option value='" . esc_attr(
|
301 |
}
|
302 |
}
|
303 |
?>
|
304 |
</select>
|
305 |
<p>
|
306 |
-
<b><?php _e(
|
307 |
.</p>
|
308 |
</td>
|
309 |
</tr>
|
310 |
<?php $nnr_hfcm_device_type_array = array(
|
311 |
-
'both' => __(
|
312 |
-
'desktop' => __(
|
313 |
-
'mobile' => __(
|
314 |
) ?>
|
315 |
<?php $nnr_hfcm_status_array = array(
|
316 |
-
'active' => __(
|
317 |
-
'inactive' => __(
|
318 |
) ?>
|
319 |
<tr>
|
320 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
321 |
<td>
|
322 |
<select name="data[device_type]">
|
323 |
<?php
|
324 |
foreach ( $nnr_hfcm_device_type_array as $smkey => $typev ) {
|
325 |
-
if (
|
326 |
-
echo "<option value='" . esc_attr(
|
327 |
} else {
|
328 |
-
echo "<option value='" . esc_attr(
|
329 |
}
|
330 |
}
|
331 |
?>
|
@@ -333,31 +341,31 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
333 |
</td>
|
334 |
</tr>
|
335 |
<tr>
|
336 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
337 |
<td>
|
338 |
<select name="data[status]">
|
339 |
<?php
|
340 |
foreach ( $nnr_hfcm_status_array as $skey => $statusv ) {
|
341 |
-
if (
|
342 |
-
echo "<option value='" . esc_attr(
|
343 |
} else {
|
344 |
-
echo "<option value='" . esc_attr(
|
345 |
}
|
346 |
}
|
347 |
?>
|
348 |
</select>
|
349 |
</td>
|
350 |
</tr>
|
351 |
-
<?php if (
|
352 |
<tr>
|
353 |
-
<th class="hfcm-th-width"><?php esc_html_e(
|
354 |
<td>
|
355 |
<p>
|
356 |
-
[hfcm id="<?php echo esc_html(
|
357 |
-
<?php if (
|
358 |
?>
|
359 |
-
<a data-shortcode='[hfcm id="<?php echo
|
360 |
-
<?php esc_html_e(
|
361 |
</a>
|
362 |
<?php endif; ?>
|
363 |
</p>
|
@@ -365,15 +373,17 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
365 |
</td>
|
366 |
</tr>
|
367 |
<tr>
|
368 |
-
<th class="hfcm-th-width"
|
|
|
|
|
369 |
<td>
|
370 |
<p>
|
371 |
-
<?php esc_html_e(
|
372 |
-
<b><?php echo esc_html(
|
373 |
<br/>
|
374 |
-
<?php if (
|
375 |
-
<?php esc_html_e(
|
376 |
-
<b><?php echo esc_html(
|
377 |
<?php endif; ?>
|
378 |
</p>
|
379 |
</td>
|
@@ -381,21 +391,21 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
381 |
<?php endif; ?>
|
382 |
</table>
|
383 |
<div class="nnr-mt-20">
|
384 |
-
<h1><?php esc_html_e(
|
385 |
-
/ <?php esc_html_e(
|
386 |
<div class="nnr-mt-20 nnr-hfcm-codeeditor-box">
|
387 |
<textarea name="data[snippet]" aria-describedby="nnr-newcontent-description" id="nnr_newcontent"
|
388 |
-
rows="20"><?php echo html_entity_decode(
|
389 |
<div class="wp-core-ui">
|
390 |
<input type="submit"
|
391 |
name="<?php echo $update ? 'update' : 'insert'; ?>"
|
392 |
-
value="<?php echo $update ? esc_html__(
|
393 |
class="button button-primary button-large nnr-btnsave">
|
394 |
-
<?php if (
|
395 |
-
$delete_nonce = wp_create_nonce(
|
396 |
?>
|
397 |
-
<a onclick="return nnr_confirm_delete_snippet();" href="<?php echo esc_url(
|
398 |
-
class="button button-secondary button-large nnr-btndelete"><?php esc_html_e(
|
399 |
<?php endif; ?>
|
400 |
</div>
|
401 |
</div>
|
1 |
<?php
|
2 |
|
3 |
// Register the script
|
4 |
+
wp_register_script('hfcm_showboxes', plugins_url('js/nnr-hfcm-showboxes.js', dirname(__FILE__)), array( 'jquery' ));
|
5 |
|
6 |
// prepare ID (for AJAX)
|
7 |
+
if (!isset($id) ) {
|
8 |
$id = -1;
|
9 |
}
|
10 |
|
11 |
// Localize the script with new data
|
12 |
$translation_array = array(
|
13 |
+
'header' => __('Header', '99robots-header-footer-code-manager'),
|
14 |
+
'before_content' => __('Before Content', '99robots-header-footer-code-manager'),
|
15 |
+
'after_content' => __('After Content', '99robots-header-footer-code-manager'),
|
16 |
+
'footer' => __('Footer', '99robots-header-footer-code-manager'),
|
17 |
+
'id' => absint($id),
|
18 |
+
'security' => wp_create_nonce('hfcm-get-posts'),
|
19 |
);
|
20 |
+
wp_localize_script('hfcm_showboxes', 'hfcm_localize', $translation_array);
|
21 |
|
22 |
// Enqueued script with localized data.
|
23 |
+
wp_enqueue_script('hfcm_showboxes');
|
24 |
?>
|
25 |
|
26 |
<div class="wrap">
|
27 |
<h1>
|
28 |
+
<?php echo $update ? esc_html__('Edit Snippet', '99robots-header-footer-code-manager') : esc_html__('Add New Snippet', '99robots-header-footer-code-manager') ?>
|
29 |
+
<?php if ($update ) : ?>
|
30 |
+
<a href="<?php echo admin_url('admin.php?page=hfcm-create') ?>" class="page-title-action">
|
31 |
+
<?php esc_html_e('Add New Snippet', '99robots-header-footer-code-manager') ?>
|
32 |
</a>
|
33 |
<?php endif; ?>
|
34 |
</h1>
|
35 |
<?php
|
36 |
+
if (!empty($_GET['message']) ) :
|
37 |
+
if (1 === $_GET['message'] ) :
|
38 |
?>
|
39 |
<div class="updated">
|
40 |
+
<p><?php esc_html_e('Script updated', '99robots-header-footer-code-manager'); ?></p>
|
41 |
</div>
|
42 |
+
<a href="<?php echo admin_url('admin.php?page=hfcm-list') ?>">« <?php esc_html_e('Back to list', '99robots-header-footer-code-manager'); ?></a>
|
43 |
+
<?php elseif (6 === $_GET['message'] ) : ?>
|
44 |
<div class="updated">
|
45 |
+
<p><?php esc_html_e('Script Added Successfully', '99robots-header-footer-code-manager'); ?></p>
|
46 |
</div>
|
47 |
+
<a href="<?php echo admin_url('admin.php?page=hfcm-list') ?>">« <?php esc_html_e('Back to list', '99robots-header-footer-code-manager'); ?></a>
|
48 |
+
<?php
|
49 |
endif;
|
50 |
endif;
|
51 |
|
52 |
+
if ($update ) :
|
53 |
+
$hfcm_form_action = admin_url('admin.php?page=hfcm-request-handler&id=' . absint($id));
|
54 |
else :
|
55 |
+
$hfcm_form_action = admin_url('admin.php?page=hfcm-request-handler');
|
56 |
endif;
|
57 |
?>
|
58 |
<form method="post" action="<?php echo $hfcm_form_action ?>">
|
59 |
<?php
|
60 |
+
if ($update ) :
|
61 |
+
wp_nonce_field('update-snippet_' . absint($id));
|
62 |
else :
|
63 |
+
wp_nonce_field('create-snippet');
|
64 |
endif;
|
65 |
?>
|
66 |
<table class="wp-list-table widefat fixed hfcm-form-width form-table">
|
67 |
<tr>
|
68 |
+
<th class="hfcm-th-width"><?php esc_html_e('Snippet Name', '99robots-header-footer-code-manager'); ?></th>
|
69 |
+
<td>
|
70 |
+
<input type="text" name="data[name]" value="<?php echo esc_attr($name); ?>" class="hfcm-field-width"/>
|
71 |
</td>
|
72 |
</tr>
|
73 |
<?php
|
74 |
$nnr_hfcm_snippet_type_array = array(
|
75 |
+
'html' => esc_html__('HTML', '99robots-header-footer-code-manager'),
|
76 |
+
'css' => esc_html__('CSS', '99robots-header-footer-code-manager'),
|
77 |
+
'js' => esc_html__('Javascript', '99robots-header-footer-code-manager')
|
78 |
); ?>
|
79 |
<tr id="snippet_type">
|
80 |
+
<th class="hfcm-th-width">
|
81 |
+
<?php esc_html_e('Snippet Type', '99robots-header-footer-code-manager'); ?>
|
82 |
+
</th>
|
83 |
<td>
|
84 |
<select name="data[snippet_type]">
|
85 |
<?php
|
86 |
foreach ( $nnr_hfcm_snippet_type_array as $nnr_key => $nnr_item ) {
|
87 |
+
if ($nnr_key === $nnr_snippet_type ) {
|
88 |
+
echo "<option value='" . esc_attr($nnr_key) . "' selected>" . esc_html($nnr_item) . "</option>";
|
89 |
} else {
|
90 |
+
echo "<option value='" . esc_attr($nnr_key) . "'>" . esc_html($nnr_item) . "</option>";
|
91 |
}
|
92 |
}
|
93 |
?>
|
96 |
</tr>
|
97 |
<?php
|
98 |
$nnr_hfcm_display_array = array(
|
99 |
+
'All' => esc_html__('Site Wide', '99robots-header-footer-code-manager'),
|
100 |
+
's_posts' => esc_html__('Specific Posts', '99robots-header-footer-code-manager'),
|
101 |
+
's_pages' => esc_html__('Specific Pages', '99robots-header-footer-code-manager'),
|
102 |
+
's_categories' => esc_html__('Specific Categories (Archive & Posts)', '99robots-header-footer-code-manager'),
|
103 |
+
's_custom_posts' => esc_html__('Specific Post Types (Archive & Posts)', '99robots-header-footer-code-manager'),
|
104 |
+
's_tags' => esc_html__('Specific Tags (Archive & Posts)', '99robots-header-footer-code-manager'),
|
105 |
+
's_is_home' => esc_html__('Home Page', '99robots-header-footer-code-manager'),
|
106 |
+
's_is_search' => esc_html__('Search Page', '99robots-header-footer-code-manager'),
|
107 |
+
's_is_archive' => esc_html__('Archive Page', '99robots-header-footer-code-manager'),
|
108 |
+
'latest_posts' => esc_html__('Latest Posts', '99robots-header-footer-code-manager'),
|
109 |
+
'manual' => esc_html__('Shortcode Only', '99robots-header-footer-code-manager'),
|
110 |
); ?>
|
111 |
<tr>
|
112 |
+
<th class="hfcm-th-width"><?php esc_html_e('Site Display', '99robots-header-footer-code-manager'); ?></th>
|
113 |
<td>
|
114 |
<select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
|
115 |
<?php
|
116 |
foreach ( $nnr_hfcm_display_array as $dkey => $statusv ) {
|
117 |
+
if ($display_on === $dkey ) {
|
118 |
+
printf('<option value="%1$s" selected="selected">%2$s</option>', $dkey, $statusv);
|
119 |
} else {
|
120 |
+
printf('<option value="%1$s">%2$s</option>', $dkey, $statusv);
|
121 |
}
|
122 |
}
|
123 |
?>
|
135 |
$nnr_hfcm_exclude_manual_style = 'manual' === $display_on ? 'display:none;' : '';
|
136 |
?>
|
137 |
<tr id="ex_pages"
|
138 |
+
style="<?php echo esc_attr($nnr_hfcm_exclude_pages_style . $nnr_hfcm_exclude_posts_style . $nnr_hfcm_exclude_tags_style . $nnr_hfcm_exclude_custom_posts_style . $nnr_hfcm_exclude_categories_style . $nnr_hfcm_exclude_lp_count_style . $nnr_hfcm_exclude_manual_style); ?>">
|
139 |
+
<th class="hfcm-th-width"><?php esc_html_e('Exclude Pages', '99robots-header-footer-code-manager'); ?></th>
|
140 |
<td>
|
141 |
<select name="data[ex_pages][]" multiple>
|
142 |
<?php
|
143 |
foreach ( $nnr_hfcm_pages as $pdata ) {
|
144 |
+
if (in_array($pdata->ID, $ex_pages) ) {
|
145 |
+
printf('<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title);
|
146 |
} else {
|
147 |
+
printf('<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title);
|
148 |
}
|
149 |
}
|
150 |
?>
|
152 |
</td>
|
153 |
</tr>
|
154 |
<tr id="ex_posts"
|
155 |
+
style="<?php echo esc_attr($nnr_hfcm_exclude_pages_style . $nnr_hfcm_exclude_posts_style . $nnr_hfcm_exclude_tags_style . $nnr_hfcm_exclude_custom_posts_style . $nnr_hfcm_exclude_categories_style . $nnr_hfcm_exclude_lp_count_style . $nnr_hfcm_exclude_manual_style); ?>">
|
156 |
+
<th class="hfcm-th-width"><?php esc_html_e('Exclude Posts', '99robots-header-footer-code-manager'); ?></th>
|
157 |
<td>
|
158 |
<select class="nnr-wraptext" name="data[ex_posts][]" multiple>
|
159 |
<option disabled></option>
|
160 |
</select> <img id="loader"
|
161 |
+
src="<?php echo plugins_url('images/ajax-loader.gif', dirname(__FILE__)); ?>">
|
162 |
</td>
|
163 |
</tr>
|
164 |
<?php
|
165 |
$nnr_hfcm_pages = get_pages();
|
166 |
$nnr_hfcm_pages_style = ('s_pages' === $display_on) ? '' : 'display:none;';
|
167 |
?>
|
168 |
+
<tr id="s_pages" style="<?php echo esc_attr($nnr_hfcm_pages_style); ?>">
|
169 |
+
<th class="hfcm-th-width">
|
170 |
+
<?php esc_html_e('Page List', '99robots-header-footer-code-manager'); ?>
|
171 |
+
</th>
|
172 |
<td>
|
173 |
<select name="data[s_pages][]" multiple>
|
174 |
<?php
|
175 |
foreach ( $nnr_hfcm_pages as $pdata ) {
|
176 |
+
if (in_array($pdata->ID, $s_pages) ) {
|
177 |
+
printf('<option value="%1$s" selected="selected">%2$s</option>', esc_attr($pdata->ID), esc_attr($pdata->post_title));
|
178 |
} else {
|
179 |
+
printf('<option value="%1$s">%2$s</option>', esc_attr($pdata->ID), esc_attr($pdata->post_title));
|
180 |
}
|
181 |
}
|
182 |
?>
|
184 |
</td>
|
185 |
</tr>
|
186 |
<?php $nnr_hfcm_posts_style = 's_posts' === $display_on ? '' : 'display:none;'; ?>
|
187 |
+
<tr id="s_posts" style="<?php echo esc_attr($nnr_hfcm_posts_style); ?>">
|
188 |
+
<th class="hfcm-th-width">
|
189 |
+
<?php esc_html_e('Post List', '99robots-header-footer-code-manager'); ?>
|
190 |
+
</th>
|
191 |
<td>
|
192 |
<select class="nnr-wraptext" name="data[s_posts][]" multiple>
|
193 |
<option disabled>...</option>
|
212 |
$output = 'names';
|
213 |
$operator = 'and';
|
214 |
|
215 |
+
$nnr_hfcm_custom_post_types = get_post_types($args, $output, $operator);
|
216 |
$nnr_hfcm_post_types = array( 'post' );
|
217 |
foreach ( $nnr_hfcm_custom_post_types as $cpdata ) {
|
218 |
$nnr_hfcm_post_types[] = $cpdata;
|
219 |
}
|
220 |
?>
|
221 |
+
<tr id="s_categories" style="<?php echo esc_attr($nnr_hfcm_categories_style); ?>">
|
222 |
+
<th class="hfcm-th-width"><?php esc_html_e('Category List', '99robots-header-footer-code-manager'); ?></th>
|
223 |
<td>
|
224 |
<select name="data[s_categories][]" multiple>
|
225 |
<?php
|
226 |
foreach ( $nnr_hfcm_categories as $nnr_key_cat => $nnr_item_cat ) {
|
227 |
foreach($nnr_item_cat['terms'] as $nnr_item_cat_key => $nnr_item_cat_term) {
|
228 |
+
if (in_array($nnr_item_cat_term->term_id, $s_categories) ) {
|
229 |
+
echo "<option value='" . esc_attr($nnr_item_cat_term->term_id) . "' selected>" . esc_html($nnr_item_cat['name']) . " - " . esc_html($nnr_item_cat_term->name) . "</option>";
|
230 |
} else {
|
231 |
+
echo "<option value='" . esc_attr($nnr_item_cat_term->term_id) . "'>" . esc_html($nnr_item_cat['name']) . " - " . esc_html($nnr_item_cat_term->name) . "</option>";
|
232 |
}
|
233 |
}
|
234 |
}
|
236 |
</select>
|
237 |
</td>
|
238 |
</tr>
|
239 |
+
<tr id="s_tags" style="<?php echo esc_attr($nnr_hfcm_tags_style); ?>">
|
240 |
+
<th class="hfcm-th-width"><?php esc_html_e('Tags List', '99robots-header-footer-code-manager'); ?></th>
|
241 |
<td>
|
242 |
<select name="data[s_tags][]" multiple>
|
243 |
<?php
|
244 |
foreach ($nnr_hfcm_tags as $nnr_key_cat => $nnr_item_tag) {
|
245 |
foreach ( $nnr_item_tag['terms'] as $nnr_item_tag_key => $nnr_item_tag_term ) {
|
246 |
+
if (in_array($nnr_item_tag_term->term_id, $s_tags) ) {
|
247 |
+
echo "<option value='" . esc_attr($nnr_item_tag_term->term_id) . "' selected>" . esc_html($nnr_item_tag['name']) . " - " . esc_html($nnr_item_tag_term->name) . "</option>";
|
248 |
} else {
|
249 |
+
echo "<option value='" . esc_attr($nnr_item_tag_term->term_id) . "'>" . esc_html($nnr_item_tag['name']) . " - " . esc_html($nnr_item_tag_term->name) . "</option>";
|
250 |
}
|
251 |
}
|
252 |
}
|
254 |
</select>
|
255 |
</td>
|
256 |
</tr>
|
257 |
+
<tr id="c_posttype" style="<?php echo esc_attr($nnr_hfcm_custom_posts_style); ?>">
|
258 |
+
<th class="hfcm-th-width"><?php esc_html_e('Post Types', '99robots-header-footer-code-manager'); ?></th>
|
259 |
<td>
|
260 |
<select name="data[s_custom_posts][]" multiple>
|
261 |
<?php
|
262 |
foreach ( $nnr_hfcm_custom_post_types as $cpkey => $cpdata ) {
|
263 |
+
if (in_array($cpkey, $s_custom_posts) ) {
|
264 |
+
echo "<option value='" . esc_attr($cpkey) . "' selected>" . esc_html($cpdata) . "</option>";
|
265 |
} else {
|
266 |
+
echo "<option value='" . esc_attr($cpkey) . "'>" . esc_html($cpdata) . "</option>";
|
267 |
}
|
268 |
}
|
269 |
?>
|
270 |
</select>
|
271 |
</td>
|
272 |
</tr>
|
273 |
+
<tr id="lp_count" style="<?php echo esc_attr($nnr_hfcm_lpcount_style); ?>">
|
274 |
+
<th class="hfcm-th-width"><?php esc_html_e('Post Count', '99robots-header-footer-code-manager'); ?></th>
|
275 |
<td>
|
276 |
<select name="data[lp_count]">
|
277 |
<?php
|
278 |
for ( $i = 1; $i <= 20; $i++ ) {
|
279 |
+
if ($i == $lp_count ) {
|
280 |
+
echo "<option value='".esc_attr($i)."' selected>".esc_html($i)."</option>";
|
281 |
} else {
|
282 |
+
echo "<option value='".esc_attr($i)."'>".esc_html($i)."</option>";
|
283 |
}
|
284 |
}
|
285 |
?>
|
287 |
</td>
|
288 |
</tr>
|
289 |
<?php
|
290 |
+
if (in_array($display_on, array( 's_posts', 's_pages', 's_custom_posts', 's_tags', 'latest_posts' )) ) {
|
291 |
$nnr_hfcm_locations = array( 'header' => 'Header', 'before_content' => 'Before Content',
|
292 |
'after_content' => 'After Content', 'footer' => 'Footer' );
|
293 |
} else {
|
294 |
$nnr_hfcm_locations = array( 'header' => 'Header', 'footer' => 'Footer' );
|
295 |
}
|
296 |
?>
|
297 |
+
<tr id="locationtr" style="<?php echo esc_attr($nnr_hfcm_location_style); ?>">
|
298 |
+
<th class="hfcm-th-width">
|
299 |
+
<?php esc_html_e('Location', '99robots-header-footer-code-manager'); ?>
|
300 |
+
</th>
|
301 |
<td>
|
302 |
<select name="data[location]" id="data_location">
|
303 |
<?php
|
304 |
foreach ( $nnr_hfcm_locations as $lkey => $statusv ) {
|
305 |
+
if ($location === $lkey ) {
|
306 |
+
echo "<option value='" . esc_attr($lkey) . "' selected='selected'>" . esc_html($statusv) . '</option>';
|
307 |
} else {
|
308 |
+
echo "<option value='" . esc_attr($lkey) . "'>" . esc_html($statusv) . '</option>';
|
309 |
}
|
310 |
}
|
311 |
?>
|
312 |
</select>
|
313 |
<p>
|
314 |
+
<b><?php _e("Note", '99robots-header-footer-code-manager'); ?></b>: <?php _e("Snippet will only execute if the placement hook exists on the page", '99robots-header-footer-code-manager'); ?>
|
315 |
.</p>
|
316 |
</td>
|
317 |
</tr>
|
318 |
<?php $nnr_hfcm_device_type_array = array(
|
319 |
+
'both' => __('Show on All Devices', '99robots-header-footer-code-manager'),
|
320 |
+
'desktop' => __('Only Desktop', '99robots-header-footer-code-manager'),
|
321 |
+
'mobile' => __('Only Mobile Devices', '99robots-header-footer-code-manager')
|
322 |
) ?>
|
323 |
<?php $nnr_hfcm_status_array = array(
|
324 |
+
'active' => __('Active', '99robots-header-footer-code-manager'),
|
325 |
+
'inactive' => __('Inactive', '99robots-header-footer-code-manager')
|
326 |
) ?>
|
327 |
<tr>
|
328 |
+
<th class="hfcm-th-width"><?php esc_html_e('Device Display', '99robots-header-footer-code-manager'); ?></th>
|
329 |
<td>
|
330 |
<select name="data[device_type]">
|
331 |
<?php
|
332 |
foreach ( $nnr_hfcm_device_type_array as $smkey => $typev ) {
|
333 |
+
if ($device_type === $smkey ) {
|
334 |
+
echo "<option value='" . esc_attr($smkey) . "' selected='selected'>" . esc_html($typev) . '</option>';
|
335 |
} else {
|
336 |
+
echo "<option value='" . esc_attr($smkey) . "'>" . esc_html($typev) . '</option>';
|
337 |
}
|
338 |
}
|
339 |
?>
|
341 |
</td>
|
342 |
</tr>
|
343 |
<tr>
|
344 |
+
<th class="hfcm-th-width"><?php esc_html_e('Status', '99robots-header-footer-code-manager'); ?></th>
|
345 |
<td>
|
346 |
<select name="data[status]">
|
347 |
<?php
|
348 |
foreach ( $nnr_hfcm_status_array as $skey => $statusv ) {
|
349 |
+
if ($status === $skey ) {
|
350 |
+
echo "<option value='" . esc_attr($skey) . "' selected='selected'>" . esc_html($statusv) . '</option>';
|
351 |
} else {
|
352 |
+
echo "<option value='" . esc_attr($skey) . "'>" . esc_html($statusv) . '</option>';
|
353 |
}
|
354 |
}
|
355 |
?>
|
356 |
</select>
|
357 |
</td>
|
358 |
</tr>
|
359 |
+
<?php if ($update ) : ?>
|
360 |
<tr>
|
361 |
+
<th class="hfcm-th-width"><?php esc_html_e('Shortcode', '99robots-header-footer-code-manager'); ?></th>
|
362 |
<td>
|
363 |
<p>
|
364 |
+
[hfcm id="<?php echo esc_html($id); ?>"]
|
365 |
+
<?php if ($update ) :
|
366 |
?>
|
367 |
+
<a data-shortcode='[hfcm id="<?php echo absint($id); ?>"]' href="javascript:void(0);" class="nnr-btn-click-to-copy nnr-btn-copy-inline" id="hfcm_copy_shortcode">
|
368 |
+
<?php esc_html_e('Copy', '99robots-header-footer-code-manager'); ?>
|
369 |
</a>
|
370 |
<?php endif; ?>
|
371 |
</p>
|
373 |
</td>
|
374 |
</tr>
|
375 |
<tr>
|
376 |
+
<th class="hfcm-th-width">
|
377 |
+
<?php esc_html_e('Changelog', '99robots-header-footer-code-manager'); ?>
|
378 |
+
</th>
|
379 |
<td>
|
380 |
<p>
|
381 |
+
<?php esc_html_e('Snippet created by', '99robots-header-footer-code-manager'); ?>
|
382 |
+
<b><?php echo esc_html($createdby); ?></b> <?php echo _e('on', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('date_format'), strtotime($createdon)) . ' ' . __('at', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('time_format'), strtotime($createdon)) ?>
|
383 |
<br/>
|
384 |
+
<?php if (!empty($lastmodifiedby) ) : ?>
|
385 |
+
<?php esc_html_e('Last edited by', '99robots-header-footer-code-manager'); ?>
|
386 |
+
<b><?php echo esc_html($lastmodifiedby); ?></b> <?php echo _e('on', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('date_format'), strtotime($lastrevisiondate)) . ' ' . __('at', '99robots-header-footer-code-manager') . ' ' . date_i18n(get_option('time_format'), strtotime($lastrevisiondate)) ?>
|
387 |
<?php endif; ?>
|
388 |
</p>
|
389 |
</td>
|
391 |
<?php endif; ?>
|
392 |
</table>
|
393 |
<div class="nnr-mt-20">
|
394 |
+
<h1><?php esc_html_e('Snippet', '99robots-header-footer-code-manager'); ?>
|
395 |
+
/ <?php esc_html_e('Code', '99robots-header-footer-code-manager') ?></h1>
|
396 |
<div class="nnr-mt-20 nnr-hfcm-codeeditor-box">
|
397 |
<textarea name="data[snippet]" aria-describedby="nnr-newcontent-description" id="nnr_newcontent"
|
398 |
+
rows="20"><?php echo html_entity_decode($snippet); ?></textarea>
|
399 |
<div class="wp-core-ui">
|
400 |
<input type="submit"
|
401 |
name="<?php echo $update ? 'update' : 'insert'; ?>"
|
402 |
+
value="<?php echo $update ? esc_html__('Update', '99robots-header-footer-code-manager') : esc_html__('Save', '99robots-header-footer-code-manager') ?>"
|
403 |
class="button button-primary button-large nnr-btnsave">
|
404 |
+
<?php if ($update ) :
|
405 |
+
$delete_nonce = wp_create_nonce('hfcm_delete_snippet');
|
406 |
?>
|
407 |
+
<a onclick="return nnr_confirm_delete_snippet();" href="<?php echo esc_url(admin_url('admin.php?page=hfcm-list&action=delete&_wpnonce=' . $delete_nonce . '&snippet=' . absint($id))); ?>"
|
408 |
+
class="button button-secondary button-large nnr-btndelete"><?php esc_html_e('Delete', '99robots-header-footer-code-manager'); ?></a>
|
409 |
<?php endif; ?>
|
410 |
</div>
|
411 |
</div>
|
includes/hfcm-tools.php
CHANGED
@@ -1,56 +1,58 @@
|
|
1 |
<?php
|
2 |
|
3 |
// Register the script
|
4 |
-
wp_register_script(
|
5 |
|
6 |
|
7 |
// Localize the script with new data
|
8 |
$translation_array = array(
|
9 |
-
'header' => __(
|
10 |
-
'before_content' => __(
|
11 |
-
'after_content' => __(
|
12 |
-
'footer' => __(
|
13 |
-
'security' => wp_create_nonce(
|
14 |
);
|
15 |
-
wp_localize_script(
|
16 |
|
17 |
// Enqueued script with localized data.
|
18 |
-
wp_enqueue_script(
|
19 |
?>
|
20 |
|
21 |
<div class="wrap">
|
22 |
<h1>
|
23 |
-
<?php _e(
|
24 |
</h1>
|
25 |
<div class="hfcm-meta-box-wrap hfcm-grid">
|
26 |
<div id="normal-sortables" class="meta-box-sortables">
|
27 |
<div id="hfcm-admin-tool-export" class="postbox ">
|
28 |
<div class="postbox-header">
|
29 |
<h2 class="hndle">
|
30 |
-
<?php _e(
|
31 |
</h2>
|
32 |
</div>
|
33 |
<div class="inside">
|
34 |
<form method="post">
|
35 |
<p>
|
36 |
-
<?php _e(
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
</p>
|
40 |
<div class="hfcm-notice notice-warning">
|
41 |
-
<p><?php _e(
|
42 |
</div>
|
43 |
<div class="hfcm-fields">
|
44 |
<div class="hfcm-field hfcm-field-checkbox" data-name="keys" data-type="checkbox">
|
45 |
<div class="hfcm-label">
|
46 |
<label for="keys">
|
47 |
-
<?php _e(
|
48 |
</label>
|
49 |
</div>
|
50 |
<div class="hfcm-input">
|
51 |
<input type="hidden" name="keys">
|
52 |
<ul class="hfcm-checkbox-list hfcm-bl">
|
53 |
-
<?php if (
|
54 |
foreach ( $nnr_hfcm_snippets as $nnr_key => $nnr_hfcm_snippet ) {
|
55 |
?>
|
56 |
<li>
|
@@ -70,30 +72,32 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
70 |
</div>
|
71 |
<p class="hfcm-submit">
|
72 |
<button type="submit" name="action" class="button button-primary" value="download">
|
73 |
-
<?php _e(
|
74 |
</button>
|
75 |
</p>
|
76 |
-
<?php wp_nonce_field(
|
77 |
</form>
|
78 |
</div>
|
79 |
</div>
|
80 |
<div id="hfcm-admin-tool-import" class="postbox ">
|
81 |
<div class="postbox-header">
|
82 |
<h2 class="hndle">
|
83 |
-
<?php _e(
|
84 |
</h2>
|
85 |
</div>
|
86 |
<div class="inside">
|
87 |
<form method="post" enctype="multipart/form-data">
|
88 |
<p>
|
89 |
-
<?php _e(
|
90 |
-
|
|
|
|
|
91 |
</p>
|
92 |
<div class="hfcm-fields">
|
93 |
<div class="hfcm-field hfcm-field-file" data-name="hfcm_import_file" data-type="file">
|
94 |
<div class="hfcm-label">
|
95 |
<label for="hfcm_import_file">
|
96 |
-
<?php _e(
|
97 |
</label>
|
98 |
</div>
|
99 |
<div class="hfcm-input">
|
@@ -112,7 +116,7 @@ wp_enqueue_script( 'hfcm_showboxes' );
|
|
112 |
<p class="hfcm-submit">
|
113 |
<input type="submit" class="button button-primary" value="Import">
|
114 |
</p>
|
115 |
-
<?php wp_nonce_field(
|
116 |
</form>
|
117 |
</div>
|
118 |
</div>
|
1 |
<?php
|
2 |
|
3 |
// Register the script
|
4 |
+
wp_register_script('hfcm_showboxes', plugins_url('js/nnr-hfcm-showboxes.js', dirname(__FILE__)), array( 'jquery' ));
|
5 |
|
6 |
|
7 |
// Localize the script with new data
|
8 |
$translation_array = array(
|
9 |
+
'header' => __('Header', '99robots-header-footer-code-manager'),
|
10 |
+
'before_content' => __('Before Content', '99robots-header-footer-code-manager'),
|
11 |
+
'after_content' => __('After Content', '99robots-header-footer-code-manager'),
|
12 |
+
'footer' => __('Footer', '99robots-header-footer-code-manager'),
|
13 |
+
'security' => wp_create_nonce('hfcm-get-posts'),
|
14 |
);
|
15 |
+
wp_localize_script('hfcm_showboxes', 'hfcm_localize', $translation_array);
|
16 |
|
17 |
// Enqueued script with localized data.
|
18 |
+
wp_enqueue_script('hfcm_showboxes');
|
19 |
?>
|
20 |
|
21 |
<div class="wrap">
|
22 |
<h1>
|
23 |
+
<?php _e('Tools', '99robots-header-footer-code-manager'); ?>
|
24 |
</h1>
|
25 |
<div class="hfcm-meta-box-wrap hfcm-grid">
|
26 |
<div id="normal-sortables" class="meta-box-sortables">
|
27 |
<div id="hfcm-admin-tool-export" class="postbox ">
|
28 |
<div class="postbox-header">
|
29 |
<h2 class="hndle">
|
30 |
+
<?php _e('Export Snippets', '99robots-header-footer-code-manager'); ?>
|
31 |
</h2>
|
32 |
</div>
|
33 |
<div class="inside">
|
34 |
<form method="post">
|
35 |
<p>
|
36 |
+
<?php _e(
|
37 |
+
'Select the snippets you would like to export and then select your export method. Use the
|
38 |
+
download button to export to a .json file which you can then import to another HFCM
|
39 |
+
installation', '99robots-header-footer-code-manager'
|
40 |
+
); ?>.
|
41 |
</p>
|
42 |
<div class="hfcm-notice notice-warning">
|
43 |
+
<p><?php _e('NOTE: Import/Export Functionality is only intended to operate within the same website. Using the export/import to move snippets from one website to a different site, may result in inconsistent behavior, particularly if you have specific elements as criteria such as pages, posts, categories, or tags.', '99robots-header-footer-code-manager'); ?></p>
|
44 |
</div>
|
45 |
<div class="hfcm-fields">
|
46 |
<div class="hfcm-field hfcm-field-checkbox" data-name="keys" data-type="checkbox">
|
47 |
<div class="hfcm-label">
|
48 |
<label for="keys">
|
49 |
+
<?php _e('Select Snippets', '99robots-header-footer-code-manager'); ?>
|
50 |
</label>
|
51 |
</div>
|
52 |
<div class="hfcm-input">
|
53 |
<input type="hidden" name="keys">
|
54 |
<ul class="hfcm-checkbox-list hfcm-bl">
|
55 |
+
<?php if (!empty($nnr_hfcm_snippets) ) {
|
56 |
foreach ( $nnr_hfcm_snippets as $nnr_key => $nnr_hfcm_snippet ) {
|
57 |
?>
|
58 |
<li>
|
72 |
</div>
|
73 |
<p class="hfcm-submit">
|
74 |
<button type="submit" name="action" class="button button-primary" value="download">
|
75 |
+
<?php _e('Export File', '99robots-header-footer-code-manager'); ?>
|
76 |
</button>
|
77 |
</p>
|
78 |
+
<?php wp_nonce_field('hfcm-nonce'); ?>
|
79 |
</form>
|
80 |
</div>
|
81 |
</div>
|
82 |
<div id="hfcm-admin-tool-import" class="postbox ">
|
83 |
<div class="postbox-header">
|
84 |
<h2 class="hndle">
|
85 |
+
<?php _e('Import Snippets', '99robots-header-footer-code-manager'); ?>
|
86 |
</h2>
|
87 |
</div>
|
88 |
<div class="inside">
|
89 |
<form method="post" enctype="multipart/form-data">
|
90 |
<p>
|
91 |
+
<?php _e(
|
92 |
+
'Select the HFCM JSON file you would like to import. When you click the import button below,
|
93 |
+
HFCM will import the field groups.', '99robots-header-footer-code-manager'
|
94 |
+
); ?>
|
95 |
</p>
|
96 |
<div class="hfcm-fields">
|
97 |
<div class="hfcm-field hfcm-field-file" data-name="hfcm_import_file" data-type="file">
|
98 |
<div class="hfcm-label">
|
99 |
<label for="hfcm_import_file">
|
100 |
+
<?php _e('Select File', '99robots-header-footer-code-manager'); ?>
|
101 |
</label>
|
102 |
</div>
|
103 |
<div class="hfcm-input">
|
116 |
<p class="hfcm-submit">
|
117 |
<input type="submit" class="button button-primary" value="Import">
|
118 |
</p>
|
119 |
+
<?php wp_nonce_field('hfcm-nonce'); ?>
|
120 |
</form>
|
121 |
</div>
|
122 |
</div>
|
js/location.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
// simple redirect
|
2 |
-
if (
|
3 |
-
|
4 |
}
|
5 |
window.location.replace(hfcm_location.url);
|
1 |
// simple redirect
|
2 |
+
if ('undefined' == typeof hfcm_location ) {
|
3 |
+
var hfcm_location = {url:''};
|
4 |
}
|
5 |
window.location.replace(hfcm_location.url);
|
js/nnr-hfcm-showboxes.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
// function to show dependent dropdowns for "Site Display" field.
|
2 |
|
3 |
-
function hfcm_showotherboxes(type)
|
|
|
4 |
var header = '<option value="header">' + hfcm_localize.header + '</option>',
|
5 |
before_content = '<option value="before_content">' + hfcm_localize.before_content + '</option>',
|
6 |
after_content = '<option value="after_content">' + hfcm_localize.after_content + '</option>',
|
@@ -44,13 +45,15 @@ function hfcm_showotherboxes(type) {
|
|
44 |
}
|
45 |
}
|
46 |
|
47 |
-
function hfcm_remember_loc(new_html)
|
|
|
48 |
var tmp = jQuery('#data_location option:selected').val();
|
49 |
jQuery('#data_location').html(new_html);
|
50 |
jQuery('#data_location option[value="' + tmp + '"]').prop('selected', true);
|
51 |
}
|
52 |
|
53 |
-
function hfcmCopyToClipboard(elem)
|
|
|
54 |
// create hidden text element, if it doesn't already exist
|
55 |
var targetId = "_hiddenCopyText_";
|
56 |
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
|
@@ -69,9 +72,11 @@ function hfcmCopyToClipboard(elem) {
|
|
69 |
target.textContent = elem.getAttribute('data-shortcode');
|
70 |
elem.textContent = "Copied!";
|
71 |
|
72 |
-
setTimeout(
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
// select the content
|
76 |
var currentFocus = document.activeElement;
|
77 |
target.focus();
|
@@ -100,63 +105,70 @@ function hfcmCopyToClipboard(elem) {
|
|
100 |
return succeed;
|
101 |
}
|
102 |
|
103 |
-
function nnr_confirm_delete_snippet()
|
|
|
104 |
return confirm("Are you sure you want to delete this snippet?");
|
105 |
}
|
106 |
|
107 |
// init selectize.js
|
108 |
jQuery('#loader').show();
|
109 |
-
jQuery(
|
110 |
-
|
111 |
-
var nnr_hfcm_data = {
|
112 |
-
action: 'hfcm-request',
|
113 |
-
id: hfcm_localize.id,
|
114 |
-
get_posts: true,
|
115 |
-
security: hfcm_localize.security
|
116 |
-
};
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
plugins: ['remove_button'],
|
125 |
-
options: all_posts,
|
126 |
-
items: new_data.selected
|
127 |
-
};
|
128 |
-
$('#loader').hide();
|
129 |
-
$('#s_posts select').selectize(options);
|
130 |
-
var options = {
|
131 |
-
plugins: ['remove_button'],
|
132 |
-
options: new_data.posts,
|
133 |
-
items: new_data.excluded
|
134 |
-
};
|
135 |
-
$('#loader').hide();
|
136 |
-
$('#ex_posts select').selectize(options);
|
137 |
-
},
|
138 |
-
'json', // ajax result format
|
139 |
-
);
|
140 |
-
// selectize all <select multiple> elements
|
141 |
-
$('#s_pages select, #s_categories select, #c_posttype select, #s_tags select, #ex_pages select').selectize({
|
142 |
-
plugins: ['remove_button']
|
143 |
-
});
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
{
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
{
|
151 |
-
|
152 |
-
tabSize: 2,
|
153 |
-
//mode: 'javascript',
|
154 |
}
|
155 |
);
|
156 |
-
var editor = wp.codeEditor.initialize($('#nnr_newcontent'), editorSettings);
|
157 |
-
}
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
// function to show dependent dropdowns for "Site Display" field.
|
2 |
|
3 |
+
function hfcm_showotherboxes(type)
|
4 |
+
{
|
5 |
var header = '<option value="header">' + hfcm_localize.header + '</option>',
|
6 |
before_content = '<option value="before_content">' + hfcm_localize.before_content + '</option>',
|
7 |
after_content = '<option value="after_content">' + hfcm_localize.after_content + '</option>',
|
45 |
}
|
46 |
}
|
47 |
|
48 |
+
function hfcm_remember_loc(new_html)
|
49 |
+
{
|
50 |
var tmp = jQuery('#data_location option:selected').val();
|
51 |
jQuery('#data_location').html(new_html);
|
52 |
jQuery('#data_location option[value="' + tmp + '"]').prop('selected', true);
|
53 |
}
|
54 |
|
55 |
+
function hfcmCopyToClipboard(elem)
|
56 |
+
{
|
57 |
// create hidden text element, if it doesn't already exist
|
58 |
var targetId = "_hiddenCopyText_";
|
59 |
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
|
72 |
target.textContent = elem.getAttribute('data-shortcode');
|
73 |
elem.textContent = "Copied!";
|
74 |
|
75 |
+
setTimeout(
|
76 |
+
function () {
|
77 |
+
elem.textContent = "Copy";
|
78 |
+
}, 2000
|
79 |
+
);
|
80 |
// select the content
|
81 |
var currentFocus = document.activeElement;
|
82 |
target.focus();
|
105 |
return succeed;
|
106 |
}
|
107 |
|
108 |
+
function nnr_confirm_delete_snippet()
|
109 |
+
{
|
110 |
return confirm("Are you sure you want to delete this snippet?");
|
111 |
}
|
112 |
|
113 |
// init selectize.js
|
114 |
jQuery('#loader').show();
|
115 |
+
jQuery(
|
116 |
+
function ($) {
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
+
var nnr_hfcm_data = {
|
119 |
+
action: 'hfcm-request',
|
120 |
+
id: hfcm_localize.id,
|
121 |
+
get_posts: true,
|
122 |
+
security: hfcm_localize.security
|
123 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
+
$.post(
|
126 |
+
ajaxurl,
|
127 |
+
nnr_hfcm_data,
|
128 |
+
function (new_data) {
|
129 |
+
var all_posts = $.merge([{text: "", value:""}], new_data.posts);
|
130 |
+
var options = {
|
131 |
+
plugins: ['remove_button'],
|
132 |
+
options: all_posts,
|
133 |
+
items: new_data.selected
|
134 |
+
};
|
135 |
+
$('#loader').hide();
|
136 |
+
$('#s_posts select').selectize(options);
|
137 |
+
var options = {
|
138 |
+
plugins: ['remove_button'],
|
139 |
+
options: new_data.posts,
|
140 |
+
items: new_data.excluded
|
141 |
+
};
|
142 |
+
$('#loader').hide();
|
143 |
+
$('#ex_posts select').selectize(options);
|
144 |
+
},
|
145 |
+
'json', // ajax result format
|
146 |
+
);
|
147 |
+
// selectize all <select multiple> elements
|
148 |
+
$('#s_pages select, #s_categories select, #c_posttype select, #s_tags select, #ex_pages select').selectize(
|
149 |
{
|
150 |
+
plugins: ['remove_button']
|
|
|
|
|
151 |
}
|
152 |
);
|
|
|
|
|
153 |
|
154 |
+
if ($('#nnr_newcontent').length) {
|
155 |
+
var editorSettings = wp.codeEditor.defaultSettings ? _.clone(wp.codeEditor.defaultSettings) : {};
|
156 |
+
editorSettings.codemirror = _.extend(
|
157 |
+
{},
|
158 |
+
editorSettings.codemirror,
|
159 |
+
{
|
160 |
+
indentUnit: 2,
|
161 |
+
tabSize: 2,
|
162 |
+
//mode: 'javascript',
|
163 |
+
}
|
164 |
+
);
|
165 |
+
var editor = wp.codeEditor.initialize($('#nnr_newcontent'), editorSettings);
|
166 |
+
}
|
167 |
+
|
168 |
+
document.getElementById("hfcm_copy_shortcode").addEventListener(
|
169 |
+
"click", function () {
|
170 |
+
hfcmCopyToClipboard(document.getElementById("hfcm_copy_shortcode"));
|
171 |
+
}
|
172 |
+
);
|
173 |
+
}
|
174 |
+
);
|
js/toggle.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
// Toggle switch
|
2 |
-
jQuery('.nnr-switch input').on(
|
3 |
-
|
|
|
4 |
togvalue = t.is(':checked') ? 'on' : 'off',
|
5 |
scriptid = t.data('id'),
|
6 |
data = {
|
@@ -11,19 +12,23 @@ jQuery('.nnr-switch input').on('click', function () {
|
|
11 |
security: hfcm_ajax.security
|
12 |
};
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
}
|
|
|
19 |
|
20 |
// Delete confirmation
|
21 |
-
jQuery('.snippets .delete > a').on(
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
function hfcmCopyToClipboard(elem)
|
|
|
27 |
// create hidden text element, if it doesn't already exist
|
28 |
var targetId = "_hiddenCopyText_";
|
29 |
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
|
@@ -42,9 +47,11 @@ function hfcmCopyToClipboard(elem) {
|
|
42 |
target.textContent = elem.getAttribute('data-shortcode');
|
43 |
elem.textContent = "Copied!";
|
44 |
|
45 |
-
setTimeout(
|
46 |
-
|
47 |
-
|
|
|
|
|
48 |
// select the content
|
49 |
var currentFocus = document.activeElement;
|
50 |
target.focus();
|
@@ -73,12 +80,16 @@ function hfcmCopyToClipboard(elem) {
|
|
73 |
return succeed;
|
74 |
}
|
75 |
|
76 |
-
jQuery(
|
77 |
-
|
|
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
83 |
}
|
84 |
-
|
1 |
// Toggle switch
|
2 |
+
jQuery('.nnr-switch input').on(
|
3 |
+
'click', function () {
|
4 |
+
var t = jQuery(this),
|
5 |
togvalue = t.is(':checked') ? 'on' : 'off',
|
6 |
scriptid = t.data('id'),
|
7 |
data = {
|
12 |
security: hfcm_ajax.security
|
13 |
};
|
14 |
|
15 |
+
jQuery.post(
|
16 |
+
ajaxurl,
|
17 |
+
data
|
18 |
+
);
|
19 |
+
}
|
20 |
+
);
|
21 |
|
22 |
// Delete confirmation
|
23 |
+
jQuery('.snippets .delete > a').on(
|
24 |
+
'click', function () {
|
25 |
+
var name = jQuery(this).parents('.name').find('> strong').text();
|
26 |
+
return confirm('Snippet name: ' + name + '\n\nAre you sure you want to delete this snippet?');
|
27 |
+
}
|
28 |
+
);
|
29 |
|
30 |
+
function hfcmCopyToClipboard(elem)
|
31 |
+
{
|
32 |
// create hidden text element, if it doesn't already exist
|
33 |
var targetId = "_hiddenCopyText_";
|
34 |
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
|
47 |
target.textContent = elem.getAttribute('data-shortcode');
|
48 |
elem.textContent = "Copied!";
|
49 |
|
50 |
+
setTimeout(
|
51 |
+
function () {
|
52 |
+
elem.textContent = "Copy Shortcode";
|
53 |
+
}, 2000
|
54 |
+
);
|
55 |
// select the content
|
56 |
var currentFocus = document.activeElement;
|
57 |
target.focus();
|
80 |
return succeed;
|
81 |
}
|
82 |
|
83 |
+
jQuery(
|
84 |
+
function ($) {
|
85 |
+
var elemsCopyBtn = document.getElementsByClassName('hfcm_copy_shortcode');
|
86 |
|
87 |
+
for (var i = 0; i < elemsCopyBtn.length; i++) {
|
88 |
+
elemsCopyBtn[i].addEventListener(
|
89 |
+
"click", function () {
|
90 |
+
hfcmCopyToClipboard(document.getElementById(this.id));
|
91 |
+
}
|
92 |
+
);
|
93 |
+
}
|
94 |
}
|
95 |
+
);
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: header, footer, code manager, snippet, functions.php, tracking, google ana
|
|
4 |
Requires at least: 4.9
|
5 |
Requires PHP: 5.6.20
|
6 |
Tested up to: 6.0
|
7 |
-
Stable tag: 1.1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
Donate link: https://draftpress.com
|
@@ -114,6 +114,9 @@ A. Free plugins rely on user feedback. Therefore, the best thing you can do for
|
|
114 |
A. If your script is not supported, just let us know and we'll look into it immediately. We will do our best to ensure all reputable services are supported. When requesting support for a particular script, it would be nice to get a sample of the script so that we can see its structure.
|
115 |
|
116 |
== Changelog ==
|
|
|
|
|
|
|
117 |
= 1.1.24 = 2022-06-25
|
118 |
* FIXED: XSS Security Vulnerability fix
|
119 |
|
4 |
Requires at least: 4.9
|
5 |
Requires PHP: 5.6.20
|
6 |
Tested up to: 6.0
|
7 |
+
Stable tag: 1.1.25
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
Donate link: https://draftpress.com
|
114 |
A. If your script is not supported, just let us know and we'll look into it immediately. We will do our best to ensure all reputable services are supported. When requesting support for a particular script, it would be nice to get a sample of the script so that we can see its structure.
|
115 |
|
116 |
== Changelog ==
|
117 |
+
= 1.1.25 = 2022-06-29
|
118 |
+
* UPDATED: Code improvements as per WordPress standards
|
119 |
+
|
120 |
= 1.1.24 = 2022-06-25
|
121 |
* FIXED: XSS Security Vulnerability fix
|
122 |
|
uninstall.php
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
<?php
|
2 |
// If uninstall is not called from WordPress, exit
|
3 |
-
if (
|
4 |
-
|
5 |
}
|
6 |
|
7 |
$option_name = 'hfcm_db_version';
|
8 |
-
delete_option(
|
9 |
|
10 |
// Drop a custom db table
|
11 |
global $wpdb;
|
12 |
$table_name = $wpdb->prefix . 'hfcm_scripts';
|
13 |
|
14 |
-
$wpdb->query(
|
1 |
<?php
|
2 |
// If uninstall is not called from WordPress, exit
|
3 |
+
if (! defined('WP_UNINSTALL_PLUGIN') ) {
|
4 |
+
exit;
|
5 |
}
|
6 |
|
7 |
$option_name = 'hfcm_db_version';
|
8 |
+
delete_option($option_name);
|
9 |
|
10 |
// Drop a custom db table
|
11 |
global $wpdb;
|
12 |
$table_name = $wpdb->prefix . 'hfcm_scripts';
|
13 |
|
14 |
+
$wpdb->query("DROP TABLE IF EXISTS $table_name");
|