Header Footer Code Manager - Version 1.0.6

Version Description

2018-07-10 * FIXED: Latest Posts dropdown selection always resets to 1 on save / update.

Download this release

Release Info

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

Code changes from version 1.0.3 to 1.0.6

99robots-header-footer-code-manager.php CHANGED
@@ -1,362 +1,362 @@
1
- <?php
2
- /**
3
- * Plugin Name: Header Footer Code Manager
4
- * Plugin URI: https://99robots.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://99robots.com/"> official page</a>.
6
- * Version: 1.0.3
7
- * Author: 99robots
8
- * Author URI: https://99robots.com/
9
- * Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
10
- * Text Domain: 99robots-header-footer-code-manager
11
- * Domain Path: /languages
12
- */
13
-
14
- // If this file is called directly, abort.
15
- if ( ! defined( 'WPINC' ) ) {
16
- die;
17
- }
18
-
19
- global $hfcm_db_version;
20
- $hfcm_db_version = '1.0';
21
-
22
- // function to create the DB / Options / Defaults
23
- function hfcm_options_install() {
24
-
25
- global $wpdb;
26
- global $hfcm_db_version;
27
-
28
- $table_name = $wpdb->prefix . 'hfcm_scripts';
29
- $charset_collate = $wpdb->get_charset_collate();
30
- $sql =
31
- "CREATE TABLE IF NOT EXISTS $table_name(
32
- `script_id` int(10) NOT NULL AUTO_INCREMENT,
33
- `name` varchar(100) DEFAULT NULL,
34
- `snippet` text,
35
- `device_type` enum('mobile','desktop', 'both') DEFAULT 'both',
36
- `location` varchar(100) NOT NULL,
37
- `display_on` enum('All','s_pages', 's_posts','s_categories','s_custom_posts','s_tags','latest_posts','manual') NOT NULL DEFAULT 'All',
38
- `lp_count` int(10) DEFAULT NULL,
39
- `s_pages` varchar(300) DEFAULT NULL,
40
- `s_posts` varchar(1000) DEFAULT NULL,
41
- `s_custom_posts` varchar(300) DEFAULT NULL,
42
- `s_categories` varchar(300) DEFAULT NULL,
43
- `s_tags` varchar(300) DEFAULT NULL,
44
- `status` enum('active','inactive') NOT NULL DEFAULT 'active',
45
- `created_by` varchar(300) DEFAULT NULL,
46
- `last_modified_by` varchar(300) DEFAULT NULL,
47
- `created` datetime DEFAULT NULL,
48
- `last_revision_date` datetime DEFAULT NULL,
49
- PRIMARY KEY (`script_id`)
50
- ) $charset_collate; ";
51
-
52
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
53
- dbDelta( $sql );
54
-
55
- add_option( 'hfcm_db_version', $hfcm_db_version );
56
- }
57
- register_activation_hook( __FILE__, 'hfcm_options_install' );
58
-
59
- /*
60
- * Enqueue style-file, if it exists.
61
- */
62
- function hfcm_enqueue_assets( $hook ) {
63
-
64
- $allowed_pages = array(
65
- 'toplevel_page_hfcm-list',
66
- 'header-footer-code-manager_page_hfcm-create',
67
- 'admin_page_hfcm-update',
68
- );
69
-
70
- if ( in_array( $hook, $allowed_pages ) ) {
71
- // Plugin's CSS
72
- wp_register_style( 'hfcm_assets', plugins_url( 'css/style-admin.css', __FILE__ ) );
73
- wp_enqueue_style( 'hfcm_assets' );
74
- }
75
-
76
- // Remove hfcm-list from $allowed_pages
77
- array_shift( $allowed_pages );
78
-
79
- if ( in_array( $hook, $allowed_pages ) ) {
80
- // selectize.js plugin CSS and JS files
81
- wp_register_style( 'selectize-css', plugins_url( 'css/selectize.bootstrap3.css', __FILE__ ) );
82
- wp_enqueue_style( 'selectize-css' );
83
-
84
- wp_register_script( 'selectize-js', plugins_url( 'js/selectize.min.js', __FILE__ ), array( 'jquery' ) );
85
- wp_enqueue_script( 'selectize-js' );
86
- }
87
- }
88
- add_action( 'admin_enqueue_scripts', 'hfcm_enqueue_assets' );
89
-
90
- /*
91
- * This function loads plugins translation files
92
- */
93
- function hfcm_load_translation_files() {
94
- load_plugin_textdomain( '99robots-header-footer-code-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
95
- }
96
- add_action( 'plugins_loaded', 'hfcm_load_translation_files' );
97
-
98
- // function to create menu page, and submenu pages.
99
- function hfcm_modifymenu() {
100
-
101
- // This is the main item for the menu
102
- add_menu_page(
103
- __( 'Header Footer Code Manager', '99robots-header-footer-code-manager' ),
104
- __( 'HFCM', '99robots-header-footer-code-manager' ),
105
- 'manage_options',
106
- 'hfcm-list',
107
- 'hfcm_list',
108
- plugins_url( 'images/', __FILE__ ) . '99robots.png'
109
- );
110
-
111
- // This is a submenu
112
- add_submenu_page(
113
- 'hfcm-list',
114
- __( 'All Snippets', '99robots-header-footer-code-manager' ),
115
- __( 'All Snippets', '99robots-header-footer-code-manager' ),
116
- 'manage_options',
117
- 'hfcm-list',
118
- 'hfcm_list'
119
- );
120
-
121
- // This is a submenu
122
- add_submenu_page(
123
- 'hfcm-list',
124
- __( 'Add New Snippet', '99robots-header-footer-code-manager' ),
125
- __( 'Add New', '99robots-header-footer-code-manager' ),
126
- 'manage_options',
127
- 'hfcm-create',
128
- 'hfcm_create'
129
- );
130
-
131
- // This submenu is HIDDEN, however, we need to add it anyways
132
- add_submenu_page(
133
- null,
134
- __( 'Update Script', '99robots-header-footer-code-manager' ),
135
- __( 'Update', '99robots-header-footer-code-manager' ),
136
- 'manage_options',
137
- 'hfcm-update',
138
- 'hfcm_update'
139
- );
140
-
141
- // This submenu is HIDDEN, however, we need to add it anyways
142
- add_submenu_page(
143
- null,
144
- __( 'Request Handler Script', '99robots-header-footer-code-manager' ),
145
- __( 'Request Handler', '99robots-header-footer-code-manager' ),
146
- 'manage_options',
147
- 'hfcm-request-handler',
148
- 'hfcm_request_handler'
149
- );
150
- }
151
- add_action( 'admin_menu', 'hfcm_modifymenu' );
152
-
153
- // Files containing submenu functions
154
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-list.php' );
155
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-create.php' );
156
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-update.php' );
157
- require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-request-handler.php' );
158
-
159
- // Function to render the snippet
160
- function hfcm_render_snippet( $scriptdata ) {
161
- $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
162
-
163
- return $output;
164
- }
165
-
166
- // Function to implement shortcode
167
- function hfcm_shortcode( $atts ) {
168
- global $wpdb;
169
- $table_name = $wpdb->prefix . 'hfcm_scripts';
170
- if ( ! empty( $atts['id'] ) ) {
171
- $id = (int) $atts['id'];
172
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
173
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id ) );
174
- if ( ! empty( $script ) ) {
175
- return hfcm_render_snippet( $script[0] );
176
- }
177
- }
178
- }
179
- add_shortcode( 'hfcm', 'hfcm_shortcode' );
180
-
181
- // Function to json_decode array and check if empty
182
- function hfcm_not_empty( $scriptdata, $prop_name ) {
183
- $data = json_decode( $scriptdata->{$prop_name} );
184
- if ( empty( $data ) ) {
185
- return false;
186
- }
187
- return true;
188
- }
189
-
190
- // Function to decide which snippets to show - triggered by hooks
191
- function hfcm_add_snippets( $location = '', $content = '' ) {
192
- global $wpdb;
193
-
194
- $beforecontent = '';
195
- $aftercontent = '';
196
-
197
- if ( $location && in_array( $location, array( 'header', 'footer' ) ) ) {
198
- $display_location = "location='$location'";
199
- } else {
200
- $display_location = "location NOT IN ( 'header', 'footer' )";
201
- }
202
-
203
- $table_name = $wpdb->prefix . 'hfcm_scripts';
204
- $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
205
- $script = $wpdb->get_results( "SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'" );
206
-
207
- if ( ! empty( $script ) ) {
208
- foreach ( $script as $key => $scriptdata ) {
209
- $out = '';
210
- switch ( $scriptdata->display_on ) {
211
- case 'All':
212
- $out = hfcm_render_snippet( $scriptdata );
213
- break;
214
- case 'latest_posts':
215
- if ( is_single() ) {
216
- $args = array(
217
- 'public' => true,
218
- '_builtin' => false,
219
- );
220
- $output = 'names'; // names or objects, note names is the default
221
- $operator = 'and'; // 'and' or 'or'
222
- $c_posttypes = get_post_types( $args, $output, $operator );
223
- $posttypes = array( 'post' );
224
- foreach ( $c_posttypes as $cpkey => $cpdata ) {
225
- $posttypes[] = $cpdata;
226
- }
227
- if ( ! empty( $scriptdata->lp_count ) ) {
228
- $latestposts = wp_get_recent_posts( array(
229
- 'numberposts' => $scriptdata->lp_count,
230
- 'post_type' => $posttypes,
231
- ) );
232
- } else {
233
- $latestposts = wp_get_recent_posts( array( 'post_type' => $posttypes ) );
234
- }
235
-
236
- $islatest = false;
237
- foreach ( $latestposts as $key => $lpostdata ) {
238
- if ( get_the_ID() == $lpostdata['ID'] ) {
239
- $islatest = true;
240
- }
241
- }
242
-
243
- if ( $islatest ) {
244
- $out = hfcm_render_snippet( $scriptdata );
245
- }
246
- }
247
- break;
248
- case 's_categories':
249
- if ( hfcm_not_empty( $scriptdata, 's_categories' ) && in_category( json_decode( $scriptdata->s_categories ) ) ) {
250
- $out = hfcm_render_snippet( $scriptdata );
251
- }
252
- break;
253
- case 's_custom_posts':
254
- if ( hfcm_not_empty( $scriptdata, 's_custom_posts' ) && is_singular( json_decode( $scriptdata->s_custom_posts ) ) ) {
255
- $out = hfcm_render_snippet( $scriptdata );
256
- }
257
- break;
258
- case 's_posts':
259
- if ( hfcm_not_empty( $scriptdata, 's_posts' ) && is_single( json_decode( $scriptdata->s_posts ) ) ) {
260
- $out = hfcm_render_snippet( $scriptdata );
261
- }
262
- break;
263
- case 's_pages':
264
- if ( hfcm_not_empty( $scriptdata, 's_pages' ) && is_page( json_decode( $scriptdata->s_pages ) ) ) {
265
- $out = hfcm_render_snippet( $scriptdata );
266
- }
267
- break;
268
- case 's_tags':
269
- if ( hfcm_not_empty( $scriptdata, 's_tags' ) && has_tag( json_decode( $scriptdata->s_tags ) ) ) {
270
- $out = hfcm_render_snippet( $scriptdata );
271
- }
272
- }
273
-
274
- switch ( $scriptdata->location ) {
275
- case 'before_content':
276
- $beforecontent .= $out;
277
- break;
278
- case 'after_content':
279
- $aftercontent .= $out;
280
- break;
281
- default:
282
- echo $out;
283
- }
284
- }
285
- }
286
- // Return results after the loop finishes
287
- return $beforecontent . $content . $aftercontent;
288
- }
289
-
290
- // Function to add snippets in the header
291
- function hfcm_header_scripts() {
292
- hfcm_add_snippets( 'header' );
293
- }
294
- add_action( 'wp_head', 'hfcm_header_scripts' );
295
-
296
- // Function to add snippets in the footer
297
- function hfcm_footer_scripts() {
298
- hfcm_add_snippets( 'footer' );
299
- }
300
- add_action( 'wp_footer', 'hfcm_footer_scripts' );
301
-
302
-
303
- // Function to add snippets before/after the content
304
- function hfcm_content_scripts( $content ) {
305
- return hfcm_add_snippets( false, $content );
306
- }
307
- add_action( 'the_content', 'hfcm_content_scripts' );
308
-
309
- // Load redirection Javascript code
310
- function hfcm_redirect( $url = '' ) {
311
- // Register the script
312
- wp_register_script( 'hfcm_redirection', plugins_url( 'js/location.js', __FILE__ ) );
313
-
314
- // Localize the script with new data
315
- $translation_array = array( 'url' => $url );
316
- wp_localize_script( 'hfcm_redirection', 'hfcm_location', $translation_array );
317
-
318
- // Enqueued script with localized data.
319
- wp_enqueue_script( 'hfcm_redirection' );
320
- }
321
-
322
- // Handle AJAX requests
323
- add_action( 'wp_ajax_hfcm-request', 'hfcm_request_handler' );
324
-
325
- // Function to sanitize POST data
326
- function hfcm_sanitize_text( $key, $sanitize = true ) {
327
-
328
- if ( ! empty( $_POST['data'][ $key ] ) ) {
329
- $out = stripslashes_deep( $_POST['data'][ $key ] );
330
- if ( $sanitize ) {
331
- $out = sanitize_text_field( $out );
332
- }
333
- return $out;
334
- }
335
-
336
- return '';
337
- }
338
-
339
- // Function to sanitize strings within POST data arrays
340
- function hfcm_sanitize_array( $key, $type = 'integer' ) {
341
- if ( ! empty( $_POST['data'][ $key ] ) ) {
342
-
343
- $arr = $_POST['data'][ $key ];
344
-
345
- if ( ! is_array( $arr ) ) {
346
- return array();
347
- }
348
-
349
- if ( 'integer' === $type ) {
350
- return array_map( 'absint', $arr );
351
- } else { // strings
352
- $new_array = array();
353
- foreach ( $arr as $val ) {
354
- $new_array[] = sanitize_text_field( $val );
355
- }
356
- }
357
-
358
- return $new_array;
359
- }
360
-
361
- return array();
362
- }
1
+ <?php
2
+ /**
3
+ * Plugin Name: Header Footer Code Manager
4
+ * Plugin URI: https://99robots.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://99robots.com/"> official page</a>.
6
+ * Version: 1.0.6
7
+ * Author: 99robots
8
+ * Author URI: https://99robots.com/
9
+ * Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
10
+ * Text Domain: 99robots-header-footer-code-manager
11
+ * Domain Path: /languages
12
+ */
13
+
14
+ // If this file is called directly, abort.
15
+ if ( ! defined( 'WPINC' ) ) {
16
+ die;
17
+ }
18
+
19
+ global $hfcm_db_version;
20
+ $hfcm_db_version = '1.0';
21
+
22
+ // function to create the DB / Options / Defaults
23
+ function hfcm_options_install() {
24
+
25
+ global $wpdb;
26
+ global $hfcm_db_version;
27
+
28
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
29
+ $charset_collate = $wpdb->get_charset_collate();
30
+ $sql =
31
+ "CREATE TABLE IF NOT EXISTS $table_name(
32
+ `script_id` int(10) NOT NULL AUTO_INCREMENT,
33
+ `name` varchar(100) DEFAULT NULL,
34
+ `snippet` text,
35
+ `device_type` enum('mobile','desktop', 'both') DEFAULT 'both',
36
+ `location` varchar(100) NOT NULL,
37
+ `display_on` enum('All','s_pages', 's_posts','s_categories','s_custom_posts','s_tags','latest_posts','manual') NOT NULL DEFAULT 'All',
38
+ `lp_count` int(10) DEFAULT NULL,
39
+ `s_pages` varchar(300) DEFAULT NULL,
40
+ `s_posts` varchar(1000) DEFAULT NULL,
41
+ `s_custom_posts` varchar(300) DEFAULT NULL,
42
+ `s_categories` varchar(300) DEFAULT NULL,
43
+ `s_tags` varchar(300) DEFAULT NULL,
44
+ `status` enum('active','inactive') NOT NULL DEFAULT 'active',
45
+ `created_by` varchar(300) DEFAULT NULL,
46
+ `last_modified_by` varchar(300) DEFAULT NULL,
47
+ `created` datetime DEFAULT NULL,
48
+ `last_revision_date` datetime DEFAULT NULL,
49
+ PRIMARY KEY (`script_id`)
50
+ ) $charset_collate; ";
51
+
52
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
53
+ dbDelta( $sql );
54
+
55
+ add_option( 'hfcm_db_version', $hfcm_db_version );
56
+ }
57
+ register_activation_hook( __FILE__, 'hfcm_options_install' );
58
+
59
+ /*
60
+ * Enqueue style-file, if it exists.
61
+ */
62
+ function hfcm_enqueue_assets( $hook ) {
63
+
64
+ $allowed_pages = array(
65
+ 'toplevel_page_hfcm-list',
66
+ 'hfcm_page_hfcm-create',
67
+ 'admin_page_hfcm-update',
68
+ );
69
+
70
+ if ( in_array( $hook, $allowed_pages ) ) {
71
+ // Plugin's CSS
72
+ wp_register_style( 'hfcm_assets', plugins_url( 'css/style-admin.css', __FILE__ ) );
73
+ wp_enqueue_style( 'hfcm_assets' );
74
+ }
75
+
76
+ // Remove hfcm-list from $allowed_pages
77
+ array_shift( $allowed_pages );
78
+
79
+ if ( in_array( $hook, $allowed_pages ) ) {
80
+ // selectize.js plugin CSS and JS files
81
+ wp_register_style( 'selectize-css', plugins_url( 'css/selectize.bootstrap3.css', __FILE__ ) );
82
+ wp_enqueue_style( 'selectize-css' );
83
+
84
+ wp_register_script( 'selectize-js', plugins_url( 'js/selectize.min.js', __FILE__ ), array( 'jquery' ) );
85
+ wp_enqueue_script( 'selectize-js' );
86
+ }
87
+ }
88
+ add_action( 'admin_enqueue_scripts', 'hfcm_enqueue_assets' );
89
+
90
+ /*
91
+ * This function loads plugins translation files
92
+ */
93
+ function hfcm_load_translation_files() {
94
+ load_plugin_textdomain( '99robots-header-footer-code-manager', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
95
+ }
96
+ add_action( 'plugins_loaded', 'hfcm_load_translation_files' );
97
+
98
+ // function to create menu page, and submenu pages.
99
+ function hfcm_modifymenu() {
100
+
101
+ // This is the main item for the menu
102
+ add_menu_page(
103
+ __( 'Header Footer Code Manager', '99robots-header-footer-code-manager'),
104
+ __( 'HFCM', '99robots-header-footer-code-manager'),
105
+ 'manage_options',
106
+ 'hfcm-list',
107
+ 'hfcm_list',
108
+ plugins_url( 'images/', __FILE__ ) . '99robots.png'
109
+ );
110
+
111
+ // This is a submenu
112
+ add_submenu_page(
113
+ 'hfcm-list',
114
+ __( 'All Snippets', '99robots-header-footer-code-manager' ),
115
+ __( 'All Snippets', '99robots-header-footer-code-manager' ),
116
+ 'manage_options',
117
+ 'hfcm-list',
118
+ 'hfcm_list'
119
+ );
120
+
121
+ // This is a submenu
122
+ add_submenu_page(
123
+ 'hfcm-list',
124
+ __( 'Add New Snippet', '99robots-header-footer-code-manager' ),
125
+ __( 'Add New', '99robots-header-footer-code-manager' ),
126
+ 'manage_options',
127
+ 'hfcm-create',
128
+ 'hfcm_create'
129
+ );
130
+
131
+ // This submenu is HIDDEN, however, we need to add it anyways
132
+ add_submenu_page(
133
+ null,
134
+ __( 'Update Script', '99robots-header-footer-code-manager' ),
135
+ __( 'Update', '99robots-header-footer-code-manager' ),
136
+ 'manage_options',
137
+ 'hfcm-update',
138
+ 'hfcm_update'
139
+ );
140
+
141
+ // This submenu is HIDDEN, however, we need to add it anyways
142
+ add_submenu_page(
143
+ null,
144
+ __( 'Request Handler Script', '99robots-header-footer-code-manager' ),
145
+ __( 'Request Handler', '99robots-header-footer-code-manager' ),
146
+ 'manage_options',
147
+ 'hfcm-request-handler',
148
+ 'hfcm_request_handler'
149
+ );
150
+ }
151
+ add_action( 'admin_menu', 'hfcm_modifymenu' );
152
+
153
+ // Files containing submenu functions
154
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-list.php' );
155
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-create.php' );
156
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-update.php' );
157
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/hfcm-request-handler.php' );
158
+
159
+ // Function to render the snippet
160
+ function hfcm_render_snippet( $scriptdata ) {
161
+ $output = "<!-- HFCM by 99 Robots - Snippet # {$scriptdata->script_id}: {$scriptdata->name} -->\n{$scriptdata->snippet}\n<!-- /end HFCM by 99 Robots -->\n";
162
+
163
+ return $output;
164
+ }
165
+
166
+ // Function to implement shortcode
167
+ function hfcm_shortcode( $atts ) {
168
+ global $wpdb;
169
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
170
+ if ( ! empty( $atts['id'] ) ) {
171
+ $id = (int) $atts['id'];
172
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
173
+ $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where status='active' AND device_type!='$hide_device' AND script_id=%s", $id ) );
174
+ if ( ! empty( $script ) ) {
175
+ return hfcm_render_snippet( $script[0] );
176
+ }
177
+ }
178
+ }
179
+ add_shortcode( 'hfcm', 'hfcm_shortcode' );
180
+
181
+ // Function to json_decode array and check if empty
182
+ function hfcm_not_empty( $scriptdata, $prop_name ) {
183
+ $data = json_decode( $scriptdata->{$prop_name} );
184
+ if ( empty( $data ) ) {
185
+ return false;
186
+ }
187
+ return true;
188
+ }
189
+
190
+ // Function to decide which snippets to show - triggered by hooks
191
+ function hfcm_add_snippets( $location = '', $content = '' ) {
192
+ global $wpdb;
193
+
194
+ $beforecontent = '';
195
+ $aftercontent = '';
196
+
197
+ if ( $location && in_array( $location, array( 'header', 'footer' ) ) ) {
198
+ $display_location = "location='$location'";
199
+ } else {
200
+ $display_location = "location NOT IN ( 'header', 'footer' )";
201
+ }
202
+
203
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
204
+ $hide_device = wp_is_mobile() ? 'desktop' : 'mobile';
205
+ $script = $wpdb->get_results( "SELECT * from $table_name where $display_location AND status='active' AND device_type!='$hide_device'" );
206
+
207
+ if ( ! empty( $script ) ) {
208
+ foreach ( $script as $key => $scriptdata ) {
209
+ $out = '';
210
+ switch ( $scriptdata->display_on ) {
211
+ case 'All':
212
+ $out = hfcm_render_snippet( $scriptdata );
213
+ break;
214
+ case 'latest_posts':
215
+ if ( is_single() ) {
216
+ $args = array(
217
+ 'public' => true,
218
+ '_builtin' => false,
219
+ );
220
+ $output = 'names'; // names or objects, note names is the default
221
+ $operator = 'and'; // 'and' or 'or'
222
+ $c_posttypes = get_post_types( $args, $output, $operator );
223
+ $posttypes = array( 'post' );
224
+ foreach ( $c_posttypes as $cpkey => $cpdata ) {
225
+ $posttypes[] = $cpdata;
226
+ }
227
+ if ( ! empty( $scriptdata->lp_count ) ) {
228
+ $latestposts = wp_get_recent_posts( array(
229
+ 'numberposts' => $scriptdata->lp_count,
230
+ 'post_type' => $posttypes,
231
+ ) );
232
+ } else {
233
+ $latestposts = wp_get_recent_posts( array( 'post_type' => $posttypes ) );
234
+ }
235
+
236
+ $islatest = false;
237
+ foreach ( $latestposts as $key => $lpostdata ) {
238
+ if ( get_the_ID() == $lpostdata['ID'] ) {
239
+ $islatest = true;
240
+ }
241
+ }
242
+
243
+ if ( $islatest ) {
244
+ $out = hfcm_render_snippet( $scriptdata );
245
+ }
246
+ }
247
+ break;
248
+ case 's_categories':
249
+ if ( hfcm_not_empty( $scriptdata, 's_categories' ) && in_category( json_decode( $scriptdata->s_categories ) ) ) {
250
+ $out = hfcm_render_snippet( $scriptdata );
251
+ }
252
+ break;
253
+ case 's_custom_posts':
254
+ if ( hfcm_not_empty( $scriptdata, 's_custom_posts' ) && is_singular( json_decode( $scriptdata->s_custom_posts ) ) ) {
255
+ $out = hfcm_render_snippet( $scriptdata );
256
+ }
257
+ break;
258
+ case 's_posts':
259
+ if ( hfcm_not_empty( $scriptdata, 's_posts' ) && is_single( json_decode( $scriptdata->s_posts ) ) ) {
260
+ $out = hfcm_render_snippet( $scriptdata );
261
+ }
262
+ break;
263
+ case 's_pages':
264
+ if ( hfcm_not_empty( $scriptdata, 's_pages' ) && is_page( json_decode( $scriptdata->s_pages ) ) ) {
265
+ $out = hfcm_render_snippet( $scriptdata );
266
+ }
267
+ break;
268
+ case 's_tags':
269
+ if ( hfcm_not_empty( $scriptdata, 's_tags' ) && has_tag( json_decode( $scriptdata->s_tags ) ) ) {
270
+ $out = hfcm_render_snippet( $scriptdata );
271
+ }
272
+ }
273
+
274
+ switch ( $scriptdata->location ) {
275
+ case 'before_content':
276
+ $beforecontent .= $out;
277
+ break;
278
+ case 'after_content':
279
+ $aftercontent .= $out;
280
+ break;
281
+ default:
282
+ echo $out;
283
+ }
284
+ }
285
+ }
286
+ // Return results after the loop finishes
287
+ return $beforecontent . $content . $aftercontent;
288
+ }
289
+
290
+ // Function to add snippets in the header
291
+ function hfcm_header_scripts() {
292
+ hfcm_add_snippets( 'header' );
293
+ }
294
+ add_action( 'wp_head', 'hfcm_header_scripts' );
295
+
296
+ // Function to add snippets in the footer
297
+ function hfcm_footer_scripts() {
298
+ hfcm_add_snippets( 'footer' );
299
+ }
300
+ add_action( 'wp_footer', 'hfcm_footer_scripts' );
301
+
302
+
303
+ // Function to add snippets before/after the content
304
+ function hfcm_content_scripts( $content ) {
305
+ return hfcm_add_snippets( false, $content );
306
+ }
307
+ add_action( 'the_content', 'hfcm_content_scripts' );
308
+
309
+ // Load redirection Javascript code
310
+ function hfcm_redirect( $url = '' ) {
311
+ // Register the script
312
+ wp_register_script( 'hfcm_redirection', plugins_url( 'js/location.js', __FILE__ ) );
313
+
314
+ // Localize the script with new data
315
+ $translation_array = array( 'url' => $url );
316
+ wp_localize_script( 'hfcm_redirection', 'hfcm_location', $translation_array );
317
+
318
+ // Enqueued script with localized data.
319
+ wp_enqueue_script( 'hfcm_redirection' );
320
+ }
321
+
322
+ // Handle AJAX requests
323
+ add_action( 'wp_ajax_hfcm-request', 'hfcm_request_handler' );
324
+
325
+ // Function to sanitize POST data
326
+ function hfcm_sanitize_text( $key, $sanitize = true ) {
327
+
328
+ if ( ! empty( $_POST['data'][ $key ] ) ) {
329
+ $out = stripslashes_deep( $_POST['data'][ $key ] );
330
+ if ( $sanitize ) {
331
+ $out = sanitize_text_field( $out );
332
+ }
333
+ return $out;
334
+ }
335
+
336
+ return '';
337
+ }
338
+
339
+ // Function to sanitize strings within POST data arrays
340
+ function hfcm_sanitize_array( $key, $type = 'integer' ) {
341
+ if ( ! empty( $_POST['data'][ $key ] ) ) {
342
+
343
+ $arr = $_POST['data'][ $key ];
344
+
345
+ if ( ! is_array( $arr ) ) {
346
+ return array();
347
+ }
348
+
349
+ if ( 'integer' === $type ) {
350
+ return array_map( 'absint', $arr );
351
+ } else { // strings
352
+ $new_array = array();
353
+ foreach ( $arr as $val ) {
354
+ $new_array[] = sanitize_text_field( $val );
355
+ }
356
+ }
357
+
358
+ return $new_array;
359
+ }
360
+
361
+ return array();
362
+ }
includes/hfcm-add-edit.php CHANGED
@@ -1,305 +1,306 @@
1
- <?php
2
-
3
- // Register the script
4
- wp_register_script( 'hfcm_showboxes', plugins_url( 'js/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' => $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' ) ?>">&laquo; <?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' ) ?>">&laquo; <?php esc_html_e( 'Back to list', '99robots-header-footer-code-manager' ); ?></a>
48
- <?php
49
- endif;
50
- endif;
51
-
52
- if ( $update ) : ?>
53
- <form method="post" action="<?php echo admin_url( 'admin.php?page=hfcm-request-handler&id=' . $id ) ?>">
54
- <?php
55
- wp_nonce_field( 'update-snippet_' . $id );
56
- else :
57
- ?>
58
- <form method="post" action="<?php echo admin_url( 'admin.php?page=hfcm-request-handler' ) ?>">
59
- <?php
60
- wp_nonce_field( 'create-snippet' );
61
- endif;
62
- ?>
63
- <table class="wp-list-table widefat fixed hfcm-form-width form-table">
64
- <tr>
65
- <th class="hfcm-th-width"><?php esc_html_e( 'Snippet Name', '99robots-header-footer-code-manager' ); ?></th>
66
- <td><input type="text" name="data[name]" value="<?php echo $name; ?>" class="hfcm-field-width" /></td>
67
- </tr>
68
- <?php
69
- $darray = array(
70
- 'All' => esc_html__( 'Site Wide', '99robots-header-footer-code-manager' ),
71
- 's_posts' => esc_html__( 'Specific Posts', '99robots-header-footer-code-manager' ),
72
- 's_pages' => esc_html__( 'Specific Pages', '99robots-header-footer-code-manager' ),
73
- 's_categories' => esc_html__( 'Specific Categories', '99robots-header-footer-code-manager' ),
74
- 's_custom_posts' => esc_html__( 'Specific Custom Post Types', '99robots-header-footer-code-manager' ),
75
- 's_tags' => esc_html__( 'Specific Tags', '99robots-header-footer-code-manager' ),
76
- 'latest_posts' => esc_html__( 'Latest Posts', '99robots-header-footer-code-manager' ),
77
- 'manual' => esc_html__( 'Shortcode Only', '99robots-header-footer-code-manager' ),
78
- ); ?>
79
- <tr>
80
- <th class="hfcm-th-width"><?php esc_html_e( 'Site Display', '99robots-header-footer-code-manager' ); ?></th>
81
- <td>
82
- <select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
83
- <?php
84
- foreach ( $darray as $dkey => $statusv ) {
85
- if ( $display_on === $dkey ) {
86
- printf( '<option value="%1$s" selected="selected">%2$s</option>', $dkey, $statusv );
87
- } else {
88
- printf( '<option value="%1$s">%2$s</option>', $dkey, $statusv );
89
- }
90
- }
91
- ?>
92
- </select>
93
- </td>
94
- </tr>
95
- <?php
96
- $pages = get_pages();
97
- $spagesstyle = ( 's_pages' === $display_on ) ? '' : 'display:none;';
98
- ?>
99
- <tr id="s_pages" style="<?php echo $spagesstyle; ?>">
100
- <th class="hfcm-th-width"><?php esc_html_e( 'Page List', '99robots-header-footer-code-manager' ); ?></th>
101
- <td>
102
- <select name="data[s_pages][]" multiple>
103
- <?php
104
- foreach ( $pages as $pdata ) {
105
- if ( in_array( $pdata->ID, $s_pages ) ) {
106
- printf( '<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title );
107
- } else {
108
- printf( '<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title );
109
- }
110
- }
111
- ?>
112
- </select>
113
- </td>
114
- </tr>
115
- <?php $spostsstyle = 's_posts' === $display_on ? '' : 'display:none;'; ?>
116
- <tr id="s_posts" style="<?php echo $spostsstyle; ?>">
117
- <th class="hfcm-th-width"><?php esc_html_e( 'Post List', '99robots-header-footer-code-manager' ); ?></th>
118
- <td>
119
- <select class="nnr-wraptext" name="data[s_posts][]" multiple>
120
- <option disabled>...</option>
121
- </select>
122
- </td>
123
- </tr>
124
- <?php
125
- $args = array( 'hide_empty' => 0 );
126
- $categories = get_categories( $args );
127
- $tags = get_tags( $args );
128
-
129
- $scategoriesstyle = 's_categories' === $display_on ? '' : 'display:none;';
130
- $stagsstyle = 's_tags' === $display_on ? '' : 'display:none;';
131
- $cpostssstyle = 's_custom_posts' === $display_on ? '' : 'display:none;';
132
- $lpcountstyle = 'latest_posts' === $display_on ? '' : 'display:none;';
133
- $locationstyle = 'manual' === $display_on ? 'display:none;' : '';
134
-
135
- // Get all names of Custom Post Types
136
- $args = array(
137
- 'public' => true,
138
- '_builtin' => false,
139
- );
140
-
141
- $output = 'names';
142
- $operator = 'and';
143
-
144
- $c_posttypes = get_post_types( $args, $output, $operator );
145
- $posttypes = array( 'post' );
146
- foreach ( $c_posttypes as $cpdata ) {
147
- $posttypes[] = $cpdata;
148
- }
149
- ?>
150
- <tr id="s_categories" style="<?php echo $scategoriesstyle; ?>">
151
- <th class="hfcm-th-width"><?php esc_html_e( 'Category List', '99robots-header-footer-code-manager' ); ?></th>
152
- <td>
153
- <select name="data[s_categories][]" multiple>
154
- <?php
155
- foreach ( $categories as $cdata ) {
156
- if ( in_array( $cdata->term_id, $s_categories ) ) {
157
- echo "<option value='{$cdata->term_id}' selected>{$cdata->name}</option>";
158
- } else {
159
- echo "<option value='{$cdata->term_id}'>{$cdata->name}</option>";
160
- }
161
- }
162
- ?>
163
- </select>
164
- </td>
165
- </tr>
166
- <tr id="s_tags" style="<?php echo $stagsstyle; ?>">
167
- <th class="hfcm-th-width"><?php esc_html_e( 'Tags List', '99robots-header-footer-code-manager' ); ?></th>
168
- <td>
169
- <select name="data[s_tags][]" multiple>
170
- <?php
171
- foreach ( $tags as $tdata ) {
172
- if ( in_array( $tdata->term_id, $s_tags ) ) {
173
- echo "<option value='{$tdata->term_id}' selected>{$tdata->name}</option>";
174
- } else {
175
- echo "<option value='{$tdata->term_id}'>{$tdata->name}</option>";
176
- }
177
- }
178
- ?>
179
- </select>
180
- </td>
181
- </tr>
182
- <tr id="c_posttype" style="<?php echo $cpostssstyle; ?>">
183
- <th class="hfcm-th-width"><?php esc_html_e( 'Custom Post Types', '99robots-header-footer-code-manager' ); ?></th>
184
- <td>
185
- <select name="data[s_custom_posts][]" multiple>
186
- <?php
187
- foreach ( $c_posttypes as $cpkey => $cpdata ) {
188
- if ( in_array( $cpkey, $s_custom_posts ) ) {
189
- echo "<option value='$cpkey' selected>$cpdata</option>";
190
- } else {
191
- echo "<option value='$cpkey'>$cpdata</option>";
192
- }
193
- }
194
- ?>
195
- </select>
196
- </td>
197
- </tr>
198
- <tr id="lp_count" style="<?php echo $lpcountstyle; ?>">
199
- <th class="hfcm-th-width"><?php esc_html_e( 'Post Count', '99robots-header-footer-code-manager' ); ?></th>
200
- <td>
201
- <select name="data[lp_count]">
202
- <?php
203
- for ( $i = 1; $i <= 20; $i++ ) {
204
- if ( $i === $lp_count ) {
205
- echo "<option value='{$i}' selected>{$i}</option>";
206
- } else {
207
- echo "<option value='{$i}'>{$i}</option>";
208
- }
209
- }
210
- ?>
211
- </select>
212
- </td>
213
- </tr>
214
- <?php
215
- if ( in_array( $display_on, array( 's_posts', 's_pages', 's_categories', 's_custom_posts', 's_tags', 'latest_posts' ) ) ) {
216
- $larray = array( 'header' => 'Header', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer' );
217
- } else {
218
- $larray = array( 'header' => 'Header', 'footer' => 'Footer' );
219
- }
220
- ?>
221
- <tr id="locationtr" style="<?php echo $locationstyle; ?>">
222
- <th class="hfcm-th-width"><?php esc_html_e( 'Location', '99robots-header-footer-code-manager' ); ?></th>
223
- <td>
224
- <select name="data[location]" id="data_location">
225
- <?php
226
- foreach ( $larray as $lkey => $statusv ) {
227
- if ( $location === $lkey ) {
228
- echo "<option value='" . $lkey . "' selected='selected'>" . $statusv . '</option>';
229
- } else {
230
- echo "<option value='" . $lkey . "'>" . $statusv . '</option>';
231
- }
232
- }
233
- ?>
234
- </select>
235
- </td>
236
- </tr>
237
- <?php $devicetypearray = array( 'both' => 'Show on All Devices', 'desktop' => 'Only Desktop', 'mobile' => 'Only Mobile Devices' ) ?>
238
- <?php $statusarray = array( 'active' => 'Active', 'inactive' => 'Inactive' ) ?>
239
- <tr>
240
- <th class="hfcm-th-width"><?php esc_html_e( 'Device Display', '99robots-header-footer-code-manager' ); ?></th>
241
- <td>
242
- <select name="data[device_type]">
243
- <?php
244
- foreach ( $devicetypearray as $smkey => $typev ) {
245
- if ( $device_type === $smkey ) {
246
- echo "<option value='" . $smkey . "' selected='selected'>" . $typev . '</option>';
247
- } else {
248
- echo "<option value='" . $smkey . "'>" . $typev . '</option>';
249
- }
250
- }
251
- ?>
252
- </select>
253
- </td>
254
- </tr>
255
- <tr>
256
- <th class="hfcm-th-width"><?php esc_html_e( 'Status', '99robots-header-footer-code-manager' ); ?></th>
257
- <td>
258
- <select name="data[status]">
259
- <?php
260
- foreach ( $statusarray as $skey => $statusv ) {
261
- if ( $status === $skey ) {
262
- echo "<option value='" . $skey . "' selected='selected'>" . $statusv . '</option>';
263
- } else {
264
- echo "<option value='" . $skey . "'>" . $statusv . '</option>';
265
- }
266
- }
267
- ?>
268
- </select>
269
- </td>
270
- </tr>
271
- <?php if ( $update ) : ?>
272
- <tr>
273
- <th class="hfcm-th-width"><?php esc_html_e( 'Shortcode', '99robots-header-footer-code-manager' ); ?></th>
274
- <td>
275
- <p>[hfcm id="<?php echo $id; ?>"]</p>
276
- </td>
277
- </tr>
278
- <tr>
279
- <th class="hfcm-th-width"><?php esc_html_e( 'Changelog', '99robots-header-footer-code-manager' ); ?></th>
280
- <td>
281
- <p>
282
- <?php esc_html_e( 'Snippet created by', '99robots-header-footer-code-manager' ); ?> <b><?php echo $createdby; ?></b> <?php echo __( '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 ) ) ?>
283
- <br/>
284
- <?php if ( ! empty( $lastmodifiedby ) ) : ?>
285
- <?php esc_html_e( 'Last edited by', '99robots-header-footer-code-manager' ); ?> <b><?php echo $lastmodifiedby; ?></b> <?php echo __( '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 ) ) ?>
286
- <?php endif; ?>
287
- </p>
288
- </td>
289
- </tr>
290
- <?php endif; ?>
291
- </table>
292
- <div class="wrap">
293
- <h1><?php esc_html_e( 'Snippet', '99robots-header-footer-code-manager' ); ?> / <?php esc_html_e( 'Code', '99robots-header-footer-code-manager' ) ?></h1>
294
- <div class="wrap">
295
- <textarea name="data[snippet]" aria-describedby="newcontent-description" id="newcontent" name="newcontent" rows="10"><?php echo $snippet; ?></textarea>
296
- <div class="wp-core-ui">
297
- <input type="submit"
298
- name="<?php echo $update ? 'update' : 'insert'; ?>"
299
- value="<?php echo $update ? esc_html__( 'Update', '99robots-header-footer-code-manager' ) : esc_html__( 'Save', '99robots-header-footer-code-manager' ) ?>"
300
- class="button button-primary button-large nnr-btnsave" >
301
- </div>
302
- </div>
303
- </div>
304
- </form>
305
- </div>
 
1
+ <?php
2
+
3
+ // Register the script
4
+ wp_register_script( 'hfcm_showboxes', plugins_url( 'js/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' => $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' ) ?>">&laquo; <?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' ) ?>">&laquo; <?php esc_html_e( 'Back to list', '99robots-header-footer-code-manager' ); ?></a>
48
+ <?php
49
+ endif;
50
+ endif;
51
+
52
+ if ( $update ) : ?>
53
+ <form method="post" action="<?php echo admin_url( 'admin.php?page=hfcm-request-handler&id=' . $id ) ?>">
54
+ <?php
55
+ wp_nonce_field( 'update-snippet_' . $id );
56
+ else :
57
+ ?>
58
+ <form method="post" action="<?php echo admin_url( 'admin.php?page=hfcm-request-handler' ) ?>">
59
+ <?php
60
+ wp_nonce_field( 'create-snippet' );
61
+ endif;
62
+ ?>
63
+ <table class="wp-list-table widefat fixed hfcm-form-width form-table">
64
+ <tr>
65
+ <th class="hfcm-th-width"><?php esc_html_e( 'Snippet Name', '99robots-header-footer-code-manager' ); ?></th>
66
+ <td><input type="text" name="data[name]" value="<?php echo $name; ?>" class="hfcm-field-width" /></td>
67
+ </tr>
68
+ <?php
69
+ $darray = array(
70
+ 'All' => esc_html__( 'Site Wide', '99robots-header-footer-code-manager' ),
71
+ 's_posts' => esc_html__( 'Specific Posts', '99robots-header-footer-code-manager' ),
72
+ 's_pages' => esc_html__( 'Specific Pages', '99robots-header-footer-code-manager' ),
73
+ 's_categories' => esc_html__( 'Specific Categories', '99robots-header-footer-code-manager' ),
74
+ 's_custom_posts' => esc_html__( 'Specific Custom Post Types', '99robots-header-footer-code-manager' ),
75
+ 's_tags' => esc_html__( 'Specific Tags', '99robots-header-footer-code-manager' ),
76
+ 'latest_posts' => esc_html__( 'Latest Posts', '99robots-header-footer-code-manager' ),
77
+ 'manual' => esc_html__( 'Shortcode Only', '99robots-header-footer-code-manager' ),
78
+ ); ?>
79
+ <tr>
80
+ <th class="hfcm-th-width"><?php esc_html_e( 'Site Display', '99robots-header-footer-code-manager' ); ?></th>
81
+ <td>
82
+ <select name="data[display_on]" onchange="hfcm_showotherboxes(this.value);">
83
+ <?php
84
+ foreach ( $darray as $dkey => $statusv ) {
85
+ if ( $display_on === $dkey ) {
86
+ printf( '<option value="%1$s" selected="selected">%2$s</option>', $dkey, $statusv );
87
+ } else {
88
+ printf( '<option value="%1$s">%2$s</option>', $dkey, $statusv );
89
+ }
90
+ }
91
+ ?>
92
+ </select>
93
+ </td>
94
+ </tr>
95
+ <?php
96
+ $pages = get_pages();
97
+ $spagesstyle = ( 's_pages' === $display_on ) ? '' : 'display:none;';
98
+ ?>
99
+ <tr id="s_pages" style="<?php echo $spagesstyle; ?>">
100
+ <th class="hfcm-th-width"><?php esc_html_e( 'Page List', '99robots-header-footer-code-manager' ); ?></th>
101
+ <td>
102
+ <select name="data[s_pages][]" multiple>
103
+ <?php
104
+ foreach ( $pages as $pdata ) {
105
+ if ( in_array( $pdata->ID, $s_pages ) ) {
106
+ printf( '<option value="%1$s" selected="selected">%2$s</option>', $pdata->ID, $pdata->post_title );
107
+ } else {
108
+ printf( '<option value="%1$s">%2$s</option>', $pdata->ID, $pdata->post_title );
109
+ }
110
+ }
111
+ ?>
112
+ </select>
113
+ </td>
114
+ </tr>
115
+ <?php $spostsstyle = 's_posts' === $display_on ? '' : 'display:none;'; ?>
116
+ <tr id="s_posts" style="<?php echo $spostsstyle; ?>">
117
+ <th class="hfcm-th-width"><?php esc_html_e( 'Post List', '99robots-header-footer-code-manager' ); ?></th>
118
+ <td>
119
+ <select class="nnr-wraptext" name="data[s_posts][]" multiple>
120
+ <option disabled>...</option>
121
+ </select>
122
+ </td>
123
+ </tr>
124
+ <?php
125
+ $args = array( 'hide_empty' => 0 );
126
+ $categories = get_categories( $args );
127
+ $tags = get_tags( $args );
128
+
129
+ $scategoriesstyle = 's_categories' === $display_on ? '' : 'display:none;';
130
+ $stagsstyle = 's_tags' === $display_on ? '' : 'display:none;';
131
+ $cpostssstyle = 's_custom_posts' === $display_on ? '' : 'display:none;';
132
+ $lpcountstyle = 'latest_posts' === $display_on ? '' : 'display:none;';
133
+ $locationstyle = 'manual' === $display_on ? 'display:none;' : '';
134
+
135
+ // Get all names of Custom Post Types
136
+ $args = array(
137
+ 'public' => true,
138
+ '_builtin' => false,
139
+ );
140
+
141
+ $output = 'names';
142
+ $operator = 'and';
143
+
144
+ $c_posttypes = get_post_types( $args, $output, $operator );
145
+ $posttypes = array( 'post' );
146
+ foreach ( $c_posttypes as $cpdata ) {
147
+ $posttypes[] = $cpdata;
148
+ }
149
+ ?>
150
+ <tr id="s_categories" style="<?php echo $scategoriesstyle; ?>">
151
+ <th class="hfcm-th-width"><?php esc_html_e( 'Category List', '99robots-header-footer-code-manager' ); ?></th>
152
+ <td>
153
+ <select name="data[s_categories][]" multiple>
154
+ <?php
155
+ foreach ( $categories as $cdata ) {
156
+ if ( in_array( $cdata->term_id, $s_categories ) ) {
157
+ echo "<option value='{$cdata->term_id}' selected>{$cdata->name}</option>";
158
+ } else {
159
+ echo "<option value='{$cdata->term_id}'>{$cdata->name}</option>";
160
+ }
161
+ }
162
+ ?>
163
+ </select>
164
+ </td>
165
+ </tr>
166
+ <tr id="s_tags" style="<?php echo $stagsstyle; ?>">
167
+ <th class="hfcm-th-width"><?php esc_html_e( 'Tags List', '99robots-header-footer-code-manager' ); ?></th>
168
+ <td>
169
+ <select name="data[s_tags][]" multiple>
170
+ <?php
171
+ foreach ( $tags as $tdata ) {
172
+ if ( in_array( $tdata->term_id, $s_tags ) ) {
173
+ echo "<option value='{$tdata->term_id}' selected>{$tdata->name}</option>";
174
+ } else {
175
+ echo "<option value='{$tdata->term_id}'>{$tdata->name}</option>";
176
+ }
177
+ }
178
+ ?>
179
+ </select>
180
+ </td>
181
+ </tr>
182
+ <tr id="c_posttype" style="<?php echo $cpostssstyle; ?>">
183
+ <th class="hfcm-th-width"><?php esc_html_e( 'Custom Post Types', '99robots-header-footer-code-manager' ); ?></th>
184
+ <td>
185
+ <select name="data[s_custom_posts][]" multiple>
186
+ <?php
187
+ foreach ( $c_posttypes as $cpkey => $cpdata ) {
188
+ if ( in_array( $cpkey, $s_custom_posts ) ) {
189
+ echo "<option value='$cpkey' selected>$cpdata</option>";
190
+ } else {
191
+ echo "<option value='$cpkey'>$cpdata</option>";
192
+ }
193
+ }
194
+ ?>
195
+ </select>
196
+ </td>
197
+ </tr>
198
+ <tr id="lp_count" style="<?php echo $lpcountstyle; ?>">
199
+ <th class="hfcm-th-width"><?php esc_html_e( 'Post Count', '99robots-header-footer-code-manager' ); ?></th>
200
+ <td>
201
+ <select name="data[lp_count]">
202
+ <?php echo "<option value='{$i}'>{$i}</option>"; ?>
203
+ <?php
204
+ for ( $i = 1; $i <= 20; $i++ ) {
205
+ if ( $i === $lp_count ) {
206
+ echo "<option value='{$i}' selected>{$i}</option>";
207
+ } else {
208
+ echo "<option value='{$i}'>{$i}</option>";
209
+ }
210
+ }
211
+ ?>
212
+ </select>
213
+ </td>
214
+ </tr>
215
+ <?php
216
+ if ( in_array( $display_on, array( 's_posts', 's_pages', 's_categories', 's_custom_posts', 's_tags', 'latest_posts' ) ) ) {
217
+ $larray = array( 'header' => 'Header', 'before_content' => 'Before Content', 'after_content' => 'After Content', 'footer' => 'Footer' );
218
+ } else {
219
+ $larray = array( 'header' => 'Header', 'footer' => 'Footer' );
220
+ }
221
+ ?>
222
+ <tr id="locationtr" style="<?php echo $locationstyle; ?>">
223
+ <th class="hfcm-th-width"><?php esc_html_e( 'Location', '99robots-header-footer-code-manager' ); ?></th>
224
+ <td>
225
+ <select name="data[location]" id="data_location">
226
+ <?php
227
+ foreach ( $larray as $lkey => $statusv ) {
228
+ if ( $location === $lkey ) {
229
+ echo "<option value='" . $lkey . "' selected='selected'>" . $statusv . '</option>';
230
+ } else {
231
+ echo "<option value='" . $lkey . "'>" . $statusv . '</option>';
232
+ }
233
+ }
234
+ ?>
235
+ </select>
236
+ </td>
237
+ </tr>
238
+ <?php $devicetypearray = array( 'both' => 'Show on All Devices', 'desktop' => 'Only Desktop', 'mobile' => 'Only Mobile Devices' ) ?>
239
+ <?php $statusarray = array( 'active' => 'Active', 'inactive' => 'Inactive' ) ?>
240
+ <tr>
241
+ <th class="hfcm-th-width"><?php esc_html_e( 'Device Display', '99robots-header-footer-code-manager' ); ?></th>
242
+ <td>
243
+ <select name="data[device_type]">
244
+ <?php
245
+ foreach ( $devicetypearray as $smkey => $typev ) {
246
+ if ( $device_type === $smkey ) {
247
+ echo "<option value='" . $smkey . "' selected='selected'>" . $typev . '</option>';
248
+ } else {
249
+ echo "<option value='" . $smkey . "'>" . $typev . '</option>';
250
+ }
251
+ }
252
+ ?>
253
+ </select>
254
+ </td>
255
+ </tr>
256
+ <tr>
257
+ <th class="hfcm-th-width"><?php esc_html_e( 'Status', '99robots-header-footer-code-manager' ); ?></th>
258
+ <td>
259
+ <select name="data[status]">
260
+ <?php
261
+ foreach ( $statusarray as $skey => $statusv ) {
262
+ if ( $status === $skey ) {
263
+ echo "<option value='" . $skey . "' selected='selected'>" . $statusv . '</option>';
264
+ } else {
265
+ echo "<option value='" . $skey . "'>" . $statusv . '</option>';
266
+ }
267
+ }
268
+ ?>
269
+ </select>
270
+ </td>
271
+ </tr>
272
+ <?php if ( $update ) : ?>
273
+ <tr>
274
+ <th class="hfcm-th-width"><?php esc_html_e( 'Shortcode', '99robots-header-footer-code-manager' ); ?></th>
275
+ <td>
276
+ <p>[hfcm id="<?php echo $id; ?>"]</p>
277
+ </td>
278
+ </tr>
279
+ <tr>
280
+ <th class="hfcm-th-width"><?php esc_html_e( 'Changelog', '99robots-header-footer-code-manager' ); ?></th>
281
+ <td>
282
+ <p>
283
+ <?php esc_html_e( 'Snippet created by', '99robots-header-footer-code-manager' ); ?> <b><?php echo $createdby; ?></b> <?php echo __( '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 ) ) ?>
284
+ <br/>
285
+ <?php if ( ! empty( $lastmodifiedby ) ) : ?>
286
+ <?php esc_html_e( 'Last edited by', '99robots-header-footer-code-manager' ); ?> <b><?php echo $lastmodifiedby; ?></b> <?php echo __( '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 ) ) ?>
287
+ <?php endif; ?>
288
+ </p>
289
+ </td>
290
+ </tr>
291
+ <?php endif; ?>
292
+ </table>
293
+ <div class="wrap">
294
+ <h1><?php esc_html_e( 'Snippet', '99robots-header-footer-code-manager' ); ?> / <?php esc_html_e( 'Code', '99robots-header-footer-code-manager' ) ?></h1>
295
+ <div class="wrap">
296
+ <textarea name="data[snippet]" aria-describedby="newcontent-description" id="newcontent" name="newcontent" rows="10"><?php echo $snippet; ?></textarea>
297
+ <div class="wp-core-ui">
298
+ <input type="submit"
299
+ name="<?php echo $update ? 'update' : 'insert'; ?>"
300
+ value="<?php echo $update ? esc_html__( 'Update', '99robots-header-footer-code-manager' ) : esc_html__( 'Save', '99robots-header-footer-code-manager' ) ?>"
301
+ class="button button-primary button-large nnr-btnsave" >
302
+ </div>
303
+ </div>
304
+ </div>
305
+ </form>
306
+ </div>
includes/hfcm-create.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
-
3
- // function for submenu "Add snippet" page
4
- function hfcm_create() {
5
-
6
- // check user capabilities
7
- current_user_can( 'administrator' );
8
-
9
- // prepare variables for includes/hfcm-add-edit.php
10
- $name = '';
11
- $snippet = '';
12
- $device_type = '';
13
- $location = '';
14
- $display_on = '';
15
- $status = '';
16
- $lp_count = 5; // Default value
17
- $s_pages = array();
18
- $s_posts = array();
19
- $s_custom_posts = array();
20
- $s_categories = array();
21
- $s_tags = array();
22
-
23
- // Notify hfcm-add-edit.php NOT to make changes for update
24
- $update = false;
25
-
26
- require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
27
- }
1
+ <?php
2
+
3
+ // function for submenu "Add snippet" page
4
+ function hfcm_create() {
5
+
6
+ // check user capabilities
7
+ current_user_can( 'administrator' );
8
+
9
+ // prepare variables for includes/hfcm-add-edit.php
10
+ $name = '';
11
+ $snippet = '';
12
+ $device_type = '';
13
+ $location = '';
14
+ $display_on = '';
15
+ $status = '';
16
+ $lp_count = 5; // Default value
17
+ $s_pages = array();
18
+ $s_posts = array();
19
+ $s_custom_posts = array();
20
+ $s_categories = array();
21
+ $s_tags = array();
22
+
23
+ // Notify hfcm-add-edit.php NOT to make changes for update
24
+ $update = false;
25
+
26
+ require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
27
+ }
includes/hfcm-list.php CHANGED
@@ -1,469 +1,469 @@
1
- <?php
2
- if ( ! class_exists( 'WP_List_Table' ) ) {
3
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
- }
5
-
6
- class Hfcm_Snippets_List extends WP_List_Table {
7
-
8
- /** Class constructor */
9
- public function __construct() {
10
-
11
- parent::__construct(
12
- array(
13
- 'singular' => esc_html__( 'Snippet', '99robots-header-footer-code-manager' ),
14
- 'plural' => esc_html__( 'Snippets', '99robots-header-footer-code-manager' ),
15
- 'ajax' => false,
16
- )
17
- );
18
- }
19
-
20
- /**
21
- * Retrieve snippets data from the database
22
- *
23
- * @param int $per_page
24
- * @param int $page_number
25
- *
26
- * @return mixed
27
- */
28
- public static function get_snippets( $per_page = 5, $page_number = 1, $customvar = 'all' ) {
29
-
30
- global $wpdb;
31
- $table_name = "{$wpdb->prefix}hfcm_scripts";
32
- $sql = "SELECT * FROM $table_name";
33
-
34
- if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
35
- $sql .= " where status = '$customvar'";
36
- }
37
-
38
- if ( ! empty( $_REQUEST['orderby'] ) ) {
39
- $sql .= ' ORDER BY ' . esc_sql( $_REQUEST['orderby'] );
40
- $sql .= ! empty( $_REQUEST['order'] ) ? ' ' . esc_sql( $_REQUEST['order'] ) : ' ASC';
41
- }
42
-
43
- $sql .= " LIMIT $per_page";
44
- $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
45
-
46
- $result = $wpdb->get_results( $sql, 'ARRAY_A' );
47
- return $result;
48
- }
49
-
50
- /**
51
- * Delete a snipppet record.
52
- *
53
- * @param int $id snippet ID
54
- */
55
- public static function delete_snippet( $id ) {
56
-
57
- global $wpdb;
58
- $table_name = "{$wpdb->prefix}hfcm_scripts";
59
-
60
- $wpdb->delete(
61
- $table_name, array( 'script_id' => $id ), array( '%d' )
62
- );
63
- }
64
-
65
- /**
66
- * Activate a snipppet record.
67
- *
68
- * @param int $id snippet ID
69
- */
70
- public static function activate_snippet( $id ) {
71
-
72
- global $wpdb;
73
- $table_name = "{$wpdb->prefix}hfcm_scripts";
74
-
75
- $wpdb->update(
76
- $table_name, array(
77
- 'status' => 'active',
78
- ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
79
- );
80
- }
81
-
82
- /**
83
- * Deactivate a snipppet record.
84
- *
85
- * @param int $id snippet ID
86
- */
87
- public static function deactivate_snippet( $id ) {
88
-
89
- global $wpdb;
90
- $table_name = "{$wpdb->prefix}hfcm_scripts";
91
-
92
- $wpdb->update(
93
- $table_name, array(
94
- 'status' => 'inactive',
95
- ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
96
- );
97
- }
98
-
99
- /**
100
- * Returns the count of records in the database.
101
- *
102
- * @return null|string
103
- */
104
- public static function record_count( $customvar = 'all' ) {
105
-
106
- global $wpdb;
107
- $table_name = "{$wpdb->prefix}hfcm_scripts";
108
- $sql = "SELECT COUNT(*) FROM $table_name";
109
-
110
- if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
111
- $sql .= " where status = '$customvar'";
112
- }
113
-
114
- return $wpdb->get_var( $sql );
115
- }
116
-
117
- /** Text displayed when no snippet data is available */
118
- public function no_items() {
119
- esc_html_e( 'No Snippets avaliable.', '99robots-header-footer-code-manager' );
120
- }
121
-
122
- /**
123
- * Render a column when no column specific method exist.
124
- *
125
- * @param array $item
126
- * @param string $column_name
127
- *
128
- * @return mixed
129
- */
130
- public function column_default( $item, $column_name ) {
131
-
132
- switch ( $column_name ) {
133
- case 'name':
134
- return esc_html( $item[ $column_name ] );
135
-
136
- case 'display_on':
137
- $darray = array(
138
- 'All' => esc_html__( 'Site Wide', '99robots-header-footer-code-manager' ),
139
- 's_posts' => esc_html__( 'Specific Posts', '99robots-header-footer-code-manager' ),
140
- 's_pages' => esc_html__( 'Specific Pages', '99robots-header-footer-code-manager' ),
141
- 's_categories' => esc_html__( 'Specific Categories', '99robots-header-footer-code-manager' ),
142
- 's_custom_posts' => esc_html__( 'Specific Custom Post Types', '99robots-header-footer-code-manager' ),
143
- 's_tags' => esc_html__( 'Specific Tags', '99robots-header-footer-code-manager' ),
144
- 'latest_posts' => esc_html__( 'Latest Posts', '99robots-header-footer-code-manager' ),
145
- 'manual' => esc_html__( 'Shortcode Only', '99robots-header-footer-code-manager' ),
146
- );
147
-
148
- if ( 's_posts' === $item[ $column_name ] ) {
149
-
150
- $empty = 1;
151
- $s_posts = json_decode( $item['s_posts'] );
152
-
153
- foreach ( $s_posts as $id ) {
154
- if ( 'publish' === get_post_status( $id ) ) {
155
- $empty = 0;
156
- break;
157
- }
158
- }
159
- if ( $empty ) {
160
- return '<span class="hfcm-red">' . esc_html__( 'No post selected', '99robots-header-footer-code-manager' ) . '</span>';
161
- }
162
- }
163
-
164
- return esc_html( $darray[ $item[ $column_name ] ] );
165
-
166
- case 'location':
167
-
168
- if ( ! $item[ $column_name ] ) {
169
- return esc_html__( 'N/A', '99robots-header-footer-code-manager' );
170
- }
171
-
172
- $larray = array(
173
- 'header' => esc_html__( 'Header', '99robots-header-footer-code-manager' ),
174
- 'before_content' => esc_html__( 'Before Content', '99robots-header-footer-code-manager' ),
175
- 'after_content' => esc_html__( 'After Content', '99robots-header-footer-code-manager' ),
176
- 'footer' => esc_html__( 'Footer', '99robots-header-footer-code-manager' ),
177
- );
178
- return esc_html( $larray[ $item[ $column_name ] ] );
179
-
180
- case 'device_type':
181
-
182
- if ( 'both' === $item[ $column_name ] ) {
183
- return esc_html__( 'Show on All Devices', '99robots-header-footer-code-manager' );
184
- } elseif ( 'mobile' === $item[ $column_name ] ) {
185
- return esc_html__( 'Only Mobile Devices', '99robots-header-footer-code-manager' );
186
- } elseif ( 'desktop' === $item[ $column_name ] ) {
187
- return esc_html__( 'Only Desktop', '99robots-header-footer-code-manager' );
188
- } else {
189
- return esc_html( $item[ $column_name ] );
190
- }
191
-
192
- case 'status':
193
-
194
- if ( 'inactive' === $item[ $column_name ] ) {
195
- return '<div class="nnr-switch">
196
- <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
197
- <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" />
198
- <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
199
- <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
200
- </div>
201
- ';
202
- } elseif ( 'active' === $item[ $column_name ] ) {
203
- return '<div class="nnr-switch">
204
- <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
205
- <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" checked="checked" />
206
- <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
207
- <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
208
- </div>
209
- ';
210
- } else {
211
- return esc_html( $item[ $column_name ] );
212
- }
213
-
214
- case 'script_id':
215
- return esc_html( $item[ $column_name ] );
216
-
217
- case 'shortcode':
218
- return '[hfcm id="' . $item['script_id'] . '"]';
219
-
220
- default:
221
- return print_r( $item, true ); // Show the whole array for troubleshooting purposes
222
- }
223
- }
224
-
225
- /**
226
- * Render the bulk edit checkbox
227
- *
228
- * @param array $item
229
- *
230
- * @return string
231
- */
232
- function column_cb( $item ) {
233
- return sprintf(
234
- '<input type="checkbox" name="snippets[]" value="%s" />', $item['script_id']
235
- );
236
- }
237
-
238
- /**
239
- * Method for name column
240
- *
241
- * @param array $item an array of DB data
242
- *
243
- * @return string
244
- */
245
- function column_name( $item ) {
246
-
247
- $delete_nonce = wp_create_nonce( 'hfcm_delete_snippet' );
248
- $edit_nonce = wp_create_nonce( 'hfcm_edit_snippet' );
249
-
250
- $title = '<strong>' . $item['name'] . '</strong>';
251
-
252
- $actions = array(
253
- '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 ),
254
- 'delete' => sprintf( '<a href="?page=%s&action=%s&snippet=%s&_wpnonce=%s">' . esc_html__( 'Delete', '99robots-header-footer-code-manager' ) . '</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['script_id'] ), $delete_nonce ),
255
- );
256
-
257
- return $title . $this->row_actions( $actions );
258
- }
259
-
260
- /**
261
- * Associative array of columns
262
- *
263
- * @return array
264
- */
265
- function get_columns() {
266
- $columns = array(
267
- 'cb' => '<input type="checkbox" />',
268
- 'script_id' => esc_html__( 'ID', '99robots-header-footer-code-manager' ),
269
- 'status' => esc_html__( 'Status', '99robots-header-footer-code-manager' ),
270
- 'name' => esc_html__( 'Snippet Name', '99robots-header-footer-code-manager' ),
271
- 'display_on' => esc_html__( 'Display On', '99robots-header-footer-code-manager' ),
272
- 'location' => esc_html__( 'Location', '99robots-header-footer-code-manager' ),
273
- 'device_type' => esc_html__( 'Devices', '99robots-header-footer-code-manager' ),
274
- 'shortcode' => esc_html__( 'Shortcode', '99robots-header-footer-code-manager' ),
275
- );
276
-
277
- return $columns;
278
- }
279
-
280
- /**
281
- * Columns to make sortable.
282
- *
283
- * @return array
284
- */
285
- public function get_sortable_columns() {
286
-
287
- return array(
288
- 'name' => array( 'name', true ),
289
- 'script_id' => array( 'script_id', false ),
290
- );
291
- }
292
-
293
- /**
294
- * Returns an associative array containing the bulk action
295
- *
296
- * @return array
297
- */
298
- public function get_bulk_actions() {
299
-
300
- return array(
301
- 'bulk-activate' => esc_html__( 'Activate', '99robots-header-footer-code-manager' ),
302
- 'bulk-deactivate' => esc_html__( 'Deactivate', '99robots-header-footer-code-manager' ),
303
- 'bulk-delete' => esc_html__( 'Remove', '99robots-header-footer-code-manager' ),
304
- );
305
- }
306
-
307
- /**
308
- * Handles data query and filter, sorting, and pagination.
309
- */
310
- public function prepare_items() {
311
-
312
- $columns = $this->get_columns();
313
- $hidden = array();
314
- $sortable = $this->get_sortable_columns();
315
-
316
- //Retrieve $customvar for use in query to get items.
317
- $customvar = ( isset( $_REQUEST['customvar'] ) ? $_REQUEST['customvar'] : 'all');
318
- $this->_column_headers = array( $columns, $hidden, $sortable );
319
-
320
- /** Process bulk action */
321
- $this->process_bulk_action();
322
- $this->views();
323
- $per_page = $this->get_items_per_page( 'snippets_per_page', 5 );
324
- $current_page = $this->get_pagenum();
325
- $total_items = self::record_count();
326
-
327
- $this->set_pagination_args(array(
328
- 'total_items' => $total_items,
329
- 'per_page' => $per_page,
330
- ));
331
-
332
- $this->items = self::get_snippets( $per_page, $current_page, $customvar );
333
- }
334
-
335
- public function get_views() {
336
- $views = array();
337
- $current = ( ! empty( $_REQUEST['customvar'] ) ? $_REQUEST['customvar'] : 'all');
338
-
339
- //All link
340
- $class = 'all' === $current ? ' class="current"' : '';
341
- $all_url = remove_query_arg( 'customvar' );
342
- $views['all'] = "<a href='{$all_url }' {$class} >" . esc_html__( 'All', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count() . ')</a>';
343
-
344
- //Foo link
345
- $foo_url = add_query_arg( 'customvar', 'active' );
346
- $class = ( 'active' === $current ? ' class="current"' : '');
347
- $views['active'] = "<a href='{$foo_url}' {$class} >" . esc_html__( 'Active', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count( 'active' ) . ')</a>';
348
-
349
- //Bar link
350
- $bar_url = add_query_arg( 'customvar', 'inactive' );
351
- $class = ( 'inactive' === $current ? ' class="current"' : '');
352
- $views['inactive'] = "<a href='{$bar_url}' {$class} >" . esc_html__( 'Inactive', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count( 'inactive' ) . ')</a>';
353
-
354
- return $views;
355
- }
356
-
357
- public function process_bulk_action() {
358
-
359
- //Detect when a bulk action is being triggered...
360
- if ( 'delete' === $this->current_action() ) {
361
-
362
- // In our file that handles the request, verify the nonce.
363
- $nonce = esc_attr( $_REQUEST['_wpnonce'] );
364
-
365
- if ( ! wp_verify_nonce( $nonce, 'hfcm_delete_snippet' ) ) {
366
- die( 'Go get a life script kiddies' );
367
- } else {
368
- self::delete_snippet( absint( $_GET['snippet'] ) );
369
-
370
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
371
- return;
372
- }
373
- }
374
-
375
- // If the delete bulk action is triggered
376
- if (
377
- ( isset( $_POST['action'] ) && 'bulk-delete' === $_POST['action'] ) ||
378
- ( isset( $_POST['action2'] ) && 'bulk-delete' === $_POST['action2'] )
379
- ) {
380
- $delete_ids = esc_sql( $_POST['snippets'] );
381
-
382
- // loop over the array of record IDs and delete them
383
- foreach ( $delete_ids as $id ) {
384
- self::delete_snippet( $id );
385
- }
386
-
387
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
388
- return;
389
- } elseif (
390
- ( isset( $_POST['action'] ) && 'bulk-activate' === $_POST['action'] ) ||
391
- ( isset( $_POST['action2'] ) && 'bulk-activate' === $_POST['action2'] )
392
- ) {
393
-
394
- $activate_ids = esc_sql( $_POST['snippets'] );
395
-
396
- // loop over the array of record IDs and activate them
397
- foreach ( $activate_ids as $id ) {
398
- self::activate_snippet( $id );
399
- }
400
-
401
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
402
- return;
403
- } elseif (
404
- ( isset( $_POST['action'] ) && 'bulk-deactivate' === $_POST['action'] ) ||
405
- ( isset( $_POST['action2'] ) && 'bulk-deactivate' === $_POST['action2'] )
406
- ) {
407
-
408
- $delete_ids = esc_sql( $_POST['snippets'] );
409
-
410
- // loop over the array of record IDs and deactivate them
411
- foreach ( $delete_ids as $id ) {
412
- self::deactivate_snippet( $id );
413
- }
414
-
415
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
416
-
417
- return;
418
- }
419
- }
420
- }
421
-
422
- /** Generate list of all snippets */
423
- function hfcm_list() {
424
-
425
- global $wpdb;
426
- $table_name = $wpdb->prefix . 'hfcm_scripts';
427
- $activeclass = '';
428
- $inactiveclass = '';
429
- $allclass = 'current';
430
- $snippet_obj = new Hfcm_Snippets_List();
431
-
432
- if ( ! empty( $_GET['script_status'] ) && in_array( $_GET['script_status'], array( 'active', 'inactive' ) ) ) {
433
- $allclass = '';
434
- if ( 'active' === $_GET['script_status'] ) {
435
- $activeclass = 'current';
436
- }
437
- if ( 'inactive' === $_GET['script_status'] ) {
438
- $inactiveclass = 'current';
439
- }
440
- }
441
- ?>
442
- <div class="wrap">
443
- <h1><?php esc_html_e( 'Snippets', '99robots-header-footer-code-manager' ) ?>
444
- <a href="<?php echo admin_url( 'admin.php?page=hfcm-create' ) ?>" class="page-title-action"><?php esc_html_e( 'Add New Snippet', '99robots-header-footer-code-manager' ) ?></a>
445
- </h1>
446
-
447
- <form method="post">
448
- <?php
449
- $snippet_obj->prepare_items();
450
- $snippet_obj->display();
451
- ?>
452
- </form>
453
-
454
- </div>
455
- <?php
456
-
457
- // Register the script
458
- wp_register_script( 'hfcm_toggle', plugins_url( '../js/toggle.js', __FILE__ ) );
459
-
460
- // Localize the script with new data
461
- $translation_array = array(
462
- 'url' => admin_url( 'admin.php' ),
463
- 'security' => wp_create_nonce( 'hfcm-toggle-snippet' ),
464
- );
465
- wp_localize_script( 'hfcm_toggle', 'hfcm_ajax', $translation_array );
466
-
467
- // Enqueued script with localized data.
468
- wp_enqueue_script( 'hfcm_toggle' );
469
- }
1
+ <?php
2
+ if ( ! class_exists( 'WP_List_Table' ) ) {
3
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
4
+ }
5
+
6
+ class Hfcm_Snippets_List extends WP_List_Table {
7
+
8
+ /** Class constructor */
9
+ public function __construct() {
10
+
11
+ parent::__construct(
12
+ array(
13
+ 'singular' => esc_html__( 'Snippet', '99robots-header-footer-code-manager' ),
14
+ 'plural' => esc_html__( 'Snippets', '99robots-header-footer-code-manager' ),
15
+ 'ajax' => false,
16
+ )
17
+ );
18
+ }
19
+
20
+ /**
21
+ * Retrieve snippets data from the database
22
+ *
23
+ * @param int $per_page
24
+ * @param int $page_number
25
+ *
26
+ * @return mixed
27
+ */
28
+ public static function get_snippets( $per_page = 10, $page_number = 1, $customvar = 'all' ) {
29
+
30
+ global $wpdb;
31
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
32
+ $sql = "SELECT * FROM $table_name";
33
+
34
+ if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
35
+ $sql .= " where status = '$customvar'";
36
+ }
37
+
38
+ if ( ! empty( $_REQUEST['orderby'] ) ) {
39
+ $sql .= ' ORDER BY ' . esc_sql( $_REQUEST['orderby'] );
40
+ $sql .= ! empty( $_REQUEST['order'] ) ? ' ' . esc_sql( $_REQUEST['order'] ) : ' ASC';
41
+ }
42
+
43
+ $sql .= " LIMIT $per_page";
44
+ $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page;
45
+
46
+ $result = $wpdb->get_results( $sql, 'ARRAY_A' );
47
+ return $result;
48
+ }
49
+
50
+ /**
51
+ * Delete a snipppet record.
52
+ *
53
+ * @param int $id snippet ID
54
+ */
55
+ public static function delete_snippet( $id ) {
56
+
57
+ global $wpdb;
58
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
59
+
60
+ $wpdb->delete(
61
+ $table_name, array( 'script_id' => $id ), array( '%d' )
62
+ );
63
+ }
64
+
65
+ /**
66
+ * Activate a snipppet record.
67
+ *
68
+ * @param int $id snippet ID
69
+ */
70
+ public static function activate_snippet( $id ) {
71
+
72
+ global $wpdb;
73
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
74
+
75
+ $wpdb->update(
76
+ $table_name, array(
77
+ 'status' => 'active',
78
+ ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Deactivate a snipppet record.
84
+ *
85
+ * @param int $id snippet ID
86
+ */
87
+ public static function deactivate_snippet( $id ) {
88
+
89
+ global $wpdb;
90
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
91
+
92
+ $wpdb->update(
93
+ $table_name, array(
94
+ 'status' => 'inactive',
95
+ ), array( 'script_id' => $id ), array( '%s' ), array( '%d' )
96
+ );
97
+ }
98
+
99
+ /**
100
+ * Returns the count of records in the database.
101
+ *
102
+ * @return null|string
103
+ */
104
+ public static function record_count( $customvar = 'all' ) {
105
+
106
+ global $wpdb;
107
+ $table_name = "{$wpdb->prefix}hfcm_scripts";
108
+ $sql = "SELECT COUNT(*) FROM $table_name";
109
+
110
+ if ( in_array( $customvar, array( 'inactive', 'active' ) ) ) {
111
+ $sql .= " where status = '$customvar'";
112
+ }
113
+
114
+ return $wpdb->get_var( $sql );
115
+ }
116
+
117
+ /** Text displayed when no snippet data is available */
118
+ public function no_items() {
119
+ esc_html_e( 'No Snippets avaliable.', '99robots-header-footer-code-manager' );
120
+ }
121
+
122
+ /**
123
+ * Render a column when no column specific method exist.
124
+ *
125
+ * @param array $item
126
+ * @param string $column_name
127
+ *
128
+ * @return mixed
129
+ */
130
+ public function column_default( $item, $column_name ) {
131
+
132
+ switch ( $column_name ) {
133
+ case 'name':
134
+ return esc_html( $item[ $column_name ] );
135
+
136
+ case 'display_on':
137
+ $darray = array(
138
+ 'All' => esc_html__( 'Site Wide', '99robots-header-footer-code-manager' ),
139
+ 's_posts' => esc_html__( 'Specific Posts', '99robots-header-footer-code-manager' ),
140
+ 's_pages' => esc_html__( 'Specific Pages', '99robots-header-footer-code-manager' ),
141
+ 's_categories' => esc_html__( 'Specific Categories', '99robots-header-footer-code-manager' ),
142
+ 's_custom_posts' => esc_html__( 'Specific Custom Post Types', '99robots-header-footer-code-manager' ),
143
+ 's_tags' => esc_html__( 'Specific Tags', '99robots-header-footer-code-manager' ),
144
+ 'latest_posts' => esc_html__( 'Latest Posts', '99robots-header-footer-code-manager' ),
145
+ 'manual' => esc_html__( 'Shortcode Only', '99robots-header-footer-code-manager' ),
146
+ );
147
+
148
+ if ( 's_posts' === $item[ $column_name ] ) {
149
+
150
+ $empty = 1;
151
+ $s_posts = json_decode( $item['s_posts'] );
152
+
153
+ foreach ( $s_posts as $id ) {
154
+ if ( 'publish' === get_post_status( $id ) ) {
155
+ $empty = 0;
156
+ break;
157
+ }
158
+ }
159
+ if ( $empty ) {
160
+ return '<span class="hfcm-red">' . esc_html__( 'No post selected', '99robots-header-footer-code-manager' ) . '</span>';
161
+ }
162
+ }
163
+
164
+ return esc_html( $darray[ $item[ $column_name ] ] );
165
+
166
+ case 'location':
167
+
168
+ if ( ! $item[ $column_name ] ) {
169
+ return esc_html__( 'N/A', '99robots-header-footer-code-manager' );
170
+ }
171
+
172
+ $larray = array(
173
+ 'header' => esc_html__( 'Header', '99robots-header-footer-code-manager' ),
174
+ 'before_content' => esc_html__( 'Before Content', '99robots-header-footer-code-manager' ),
175
+ 'after_content' => esc_html__( 'After Content', '99robots-header-footer-code-manager' ),
176
+ 'footer' => esc_html__( 'Footer', '99robots-header-footer-code-manager' ),
177
+ );
178
+ return esc_html( $larray[ $item[ $column_name ] ] );
179
+
180
+ case 'device_type':
181
+
182
+ if ( 'both' === $item[ $column_name ] ) {
183
+ return esc_html__( 'Show on All Devices', '99robots-header-footer-code-manager' );
184
+ } elseif ( 'mobile' === $item[ $column_name ] ) {
185
+ return esc_html__( 'Only Mobile Devices', '99robots-header-footer-code-manager' );
186
+ } elseif ( 'desktop' === $item[ $column_name ] ) {
187
+ return esc_html__( 'Only Desktop', '99robots-header-footer-code-manager' );
188
+ } else {
189
+ return esc_html( $item[ $column_name ] );
190
+ }
191
+
192
+ case 'status':
193
+
194
+ if ( 'inactive' === $item[ $column_name ] ) {
195
+ return '<div class="nnr-switch">
196
+ <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
197
+ <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" />
198
+ <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
199
+ <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
200
+ </div>
201
+ ';
202
+ } elseif ( 'active' === $item[ $column_name ] ) {
203
+ return '<div class="nnr-switch">
204
+ <label for="nnr-round-toggle' . $item['script_id'] . '">OFF</label>
205
+ <input id="nnr-round-toggle' . $item['script_id'] . '" class="round-toggle round-toggle-round-flat" type="checkbox" data-id="' . $item['script_id'] . '" checked="checked" />
206
+ <label for="nnr-round-toggle' . $item['script_id'] . '"></label>
207
+ <label for="nnr-round-toggle' . $item['script_id'] . '">ON</label>
208
+ </div>
209
+ ';
210
+ } else {
211
+ return esc_html( $item[ $column_name ] );
212
+ }
213
+
214
+ case 'script_id':
215
+ return esc_html( $item[ $column_name ] );
216
+
217
+ case 'shortcode':
218
+ return '[hfcm id="' . $item['script_id'] . '"]';
219
+
220
+ default:
221
+ return print_r( $item, true ); // Show the whole array for troubleshooting purposes
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Render the bulk edit checkbox
227
+ *
228
+ * @param array $item
229
+ *
230
+ * @return string
231
+ */
232
+ function column_cb( $item ) {
233
+ return sprintf(
234
+ '<input type="checkbox" name="snippets[]" value="%s" />', $item['script_id']
235
+ );
236
+ }
237
+
238
+ /**
239
+ * Method for name column
240
+ *
241
+ * @param array $item an array of DB data
242
+ *
243
+ * @return string
244
+ */
245
+ function column_name( $item ) {
246
+
247
+ $delete_nonce = wp_create_nonce( 'hfcm_delete_snippet' );
248
+ $edit_nonce = wp_create_nonce( 'hfcm_edit_snippet' );
249
+
250
+ $title = '<strong>' . $item['name'] . '</strong>';
251
+
252
+ $actions = array(
253
+ '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 ),
254
+ 'delete' => sprintf( '<a href="?page=%s&action=%s&snippet=%s&_wpnonce=%s">' . esc_html__( 'Delete', '99robots-header-footer-code-manager' ) . '</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['script_id'] ), $delete_nonce ),
255
+ );
256
+
257
+ return $title . $this->row_actions( $actions );
258
+ }
259
+
260
+ /**
261
+ * Associative array of columns
262
+ *
263
+ * @return array
264
+ */
265
+ function get_columns() {
266
+ $columns = array(
267
+ 'cb' => '<input type="checkbox" />',
268
+ 'script_id' => esc_html__( 'ID', '99robots-header-footer-code-manager' ),
269
+ 'status' => esc_html__( 'Status', '99robots-header-footer-code-manager' ),
270
+ 'name' => esc_html__( 'Snippet Name', '99robots-header-footer-code-manager' ),
271
+ 'display_on' => esc_html__( 'Display On', '99robots-header-footer-code-manager' ),
272
+ 'location' => esc_html__( 'Location', '99robots-header-footer-code-manager' ),
273
+ 'device_type' => esc_html__( 'Devices', '99robots-header-footer-code-manager' ),
274
+ 'shortcode' => esc_html__( 'Shortcode', '99robots-header-footer-code-manager' ),
275
+ );
276
+
277
+ return $columns;
278
+ }
279
+
280
+ /**
281
+ * Columns to make sortable.
282
+ *
283
+ * @return array
284
+ */
285
+ public function get_sortable_columns() {
286
+
287
+ return array(
288
+ 'name' => array( 'name', true ),
289
+ 'script_id' => array( 'script_id', false ),
290
+ );
291
+ }
292
+
293
+ /**
294
+ * Returns an associative array containing the bulk action
295
+ *
296
+ * @return array
297
+ */
298
+ public function get_bulk_actions() {
299
+
300
+ return array(
301
+ 'bulk-activate' => esc_html__( 'Activate', '99robots-header-footer-code-manager' ),
302
+ 'bulk-deactivate' => esc_html__( 'Deactivate', '99robots-header-footer-code-manager' ),
303
+ 'bulk-delete' => esc_html__( 'Remove', '99robots-header-footer-code-manager' ),
304
+ );
305
+ }
306
+
307
+ /**
308
+ * Handles data query and filter, sorting, and pagination.
309
+ */
310
+ public function prepare_items() {
311
+
312
+ $columns = $this->get_columns();
313
+ $hidden = array();
314
+ $sortable = $this->get_sortable_columns();
315
+
316
+ //Retrieve $customvar for use in query to get items.
317
+ $customvar = ( isset( $_REQUEST['customvar'] ) ? $_REQUEST['customvar'] : 'all');
318
+ $this->_column_headers = array( $columns, $hidden, $sortable );
319
+
320
+ /** Process bulk action */
321
+ $this->process_bulk_action();
322
+ $this->views();
323
+ $per_page = $this->get_items_per_page( 'snippets_per_page', 10 );
324
+ $current_page = $this->get_pagenum();
325
+ $total_items = self::record_count();
326
+
327
+ $this->set_pagination_args(array(
328
+ 'total_items' => $total_items,
329
+ 'per_page' => $per_page,
330
+ ));
331
+
332
+ $this->items = self::get_snippets( $per_page, $current_page, $customvar );
333
+ }
334
+
335
+ public function get_views() {
336
+ $views = array();
337
+ $current = ( ! empty( $_REQUEST['customvar'] ) ? $_REQUEST['customvar'] : 'all');
338
+
339
+ //All link
340
+ $class = 'all' === $current ? ' class="current"' : '';
341
+ $all_url = remove_query_arg( 'customvar' );
342
+ $views['all'] = "<a href='{$all_url }' {$class} >" . esc_html__( 'All', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count() . ')</a>';
343
+
344
+ //Foo link
345
+ $foo_url = add_query_arg( 'customvar', 'active' );
346
+ $class = ( 'active' === $current ? ' class="current"' : '');
347
+ $views['active'] = "<a href='{$foo_url}' {$class} >" . esc_html__( 'Active', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count( 'active' ) . ')</a>';
348
+
349
+ //Bar link
350
+ $bar_url = add_query_arg( 'customvar', 'inactive' );
351
+ $class = ( 'inactive' === $current ? ' class="current"' : '');
352
+ $views['inactive'] = "<a href='{$bar_url}' {$class} >" . esc_html__( 'Inactive', '99robots-header-footer-code-manager' ) . ' (' . $this->record_count( 'inactive' ) . ')</a>';
353
+
354
+ return $views;
355
+ }
356
+
357
+ public function process_bulk_action() {
358
+
359
+ //Detect when a bulk action is being triggered...
360
+ if ( 'delete' === $this->current_action() ) {
361
+
362
+ // In our file that handles the request, verify the nonce.
363
+ $nonce = esc_attr( $_REQUEST['_wpnonce'] );
364
+
365
+ if ( ! wp_verify_nonce( $nonce, 'hfcm_delete_snippet' ) ) {
366
+ die( 'Go get a life script kiddies' );
367
+ } else {
368
+ self::delete_snippet( absint( $_GET['snippet'] ) );
369
+
370
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
371
+ return;
372
+ }
373
+ }
374
+
375
+ // If the delete bulk action is triggered
376
+ if (
377
+ ( isset( $_POST['action'] ) && 'bulk-delete' === $_POST['action'] ) ||
378
+ ( isset( $_POST['action2'] ) && 'bulk-delete' === $_POST['action2'] )
379
+ ) {
380
+ $delete_ids = esc_sql( $_POST['snippets'] );
381
+
382
+ // loop over the array of record IDs and delete them
383
+ foreach ( $delete_ids as $id ) {
384
+ self::delete_snippet( $id );
385
+ }
386
+
387
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
388
+ return;
389
+ } elseif (
390
+ ( isset( $_POST['action'] ) && 'bulk-activate' === $_POST['action'] ) ||
391
+ ( isset( $_POST['action2'] ) && 'bulk-activate' === $_POST['action2'] )
392
+ ) {
393
+
394
+ $activate_ids = esc_sql( $_POST['snippets'] );
395
+
396
+ // loop over the array of record IDs and activate them
397
+ foreach ( $activate_ids as $id ) {
398
+ self::activate_snippet( $id );
399
+ }
400
+
401
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
402
+ return;
403
+ } elseif (
404
+ ( isset( $_POST['action'] ) && 'bulk-deactivate' === $_POST['action'] ) ||
405
+ ( isset( $_POST['action2'] ) && 'bulk-deactivate' === $_POST['action2'] )
406
+ ) {
407
+
408
+ $delete_ids = esc_sql( $_POST['snippets'] );
409
+
410
+ // loop over the array of record IDs and deactivate them
411
+ foreach ( $delete_ids as $id ) {
412
+ self::deactivate_snippet( $id );
413
+ }
414
+
415
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-list' ) );
416
+
417
+ return;
418
+ }
419
+ }
420
+ }
421
+
422
+ /** Generate list of all snippets */
423
+ function hfcm_list() {
424
+
425
+ global $wpdb;
426
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
427
+ $activeclass = '';
428
+ $inactiveclass = '';
429
+ $allclass = 'current';
430
+ $snippet_obj = new Hfcm_Snippets_List();
431
+
432
+ if ( ! empty( $_GET['script_status'] ) && in_array( $_GET['script_status'], array( 'active', 'inactive' ) ) ) {
433
+ $allclass = '';
434
+ if ( 'active' === $_GET['script_status'] ) {
435
+ $activeclass = 'current';
436
+ }
437
+ if ( 'inactive' === $_GET['script_status'] ) {
438
+ $inactiveclass = 'current';
439
+ }
440
+ }
441
+ ?>
442
+ <div class="wrap">
443
+ <h1><?php esc_html_e( 'Snippets', '99robots-header-footer-code-manager' ) ?>
444
+ <a href="<?php echo admin_url( 'admin.php?page=hfcm-create' ) ?>" class="page-title-action"><?php esc_html_e( 'Add New Snippet', '99robots-header-footer-code-manager' ) ?></a>
445
+ </h1>
446
+
447
+ <form method="post">
448
+ <?php
449
+ $snippet_obj->prepare_items();
450
+ $snippet_obj->display();
451
+ ?>
452
+ </form>
453
+
454
+ </div>
455
+ <?php
456
+
457
+ // Register the script
458
+ wp_register_script( 'hfcm_toggle', plugins_url( '../js/toggle.js', __FILE__ ) );
459
+
460
+ // Localize the script with new data
461
+ $translation_array = array(
462
+ 'url' => admin_url( 'admin.php' ),
463
+ 'security' => wp_create_nonce( 'hfcm-toggle-snippet' ),
464
+ );
465
+ wp_localize_script( 'hfcm_toggle', 'hfcm_ajax', $translation_array );
466
+
467
+ // Enqueued script with localized data.
468
+ wp_enqueue_script( 'hfcm_toggle' );
469
+ }
includes/hfcm-request-handler.php CHANGED
@@ -1,217 +1,217 @@
1
- <?php
2
-
3
- function hfcm_request_handler() {
4
-
5
- // Check user capabilities
6
- current_user_can( 'administrator' );
7
-
8
- if ( isset( $_POST['insert'] ) ) {
9
- // Check nonce
10
- check_admin_referer( 'create-snippet' );
11
- } else {
12
- if ( ! isset( $_REQUEST['id'] ) ) {
13
- die( 'Missing ID parameter.' );
14
- }
15
- $id = (int) $_REQUEST['id'];
16
- }
17
- if ( isset( $_POST['update'] ) ) {
18
- // Check nonce
19
- check_admin_referer( 'update-snippet_' . $id );
20
- }
21
-
22
- // Handle AJAX on/off toggle for snippets
23
- if ( isset( $_REQUEST['toggle'] ) && ! empty( $_REQUEST['togvalue'] ) ) {
24
-
25
- // Check nonce
26
- check_ajax_referer( 'hfcm-toggle-snippet', 'security' );
27
-
28
- if ( 'on' === $_REQUEST['togvalue'] ) {
29
- $status = 'active';
30
- } else {
31
- $status = 'inactive';
32
- }
33
-
34
- // Global vars
35
- global $wpdb;
36
- $table_name = $wpdb->prefix . 'hfcm_scripts';
37
-
38
- $wpdb->update(
39
- $table_name, //table
40
- array( 'status' => $status ), //data
41
- array( 'script_id' => $id ), //where
42
- array( '%s', '%s', '%s', '%s', '%s', '%s' ), //data format
43
- array( '%s' ) //where format
44
- );
45
-
46
- } elseif ( isset( $_POST['insert'] ) || isset( $_POST['update'] ) ) {
47
-
48
- // Create / update snippet
49
-
50
- // Sanitize fields
51
- $name = hfcm_sanitize_text( 'name' );
52
- $snippet = hfcm_sanitize_text( 'snippet', false );
53
- $device_type = hfcm_sanitize_text( 'device_type' );
54
- $display_on = hfcm_sanitize_text( 'display_on' );
55
- $location = hfcm_sanitize_text( 'location' );
56
- $lp_count = hfcm_sanitize_text( 'lp_count' );
57
- $status = hfcm_sanitize_text( 'status' );
58
- $s_pages = hfcm_sanitize_array( 's_pages' );
59
- $s_posts = hfcm_sanitize_array( 's_posts' );
60
- $s_custom_posts = hfcm_sanitize_array( 's_custom_posts', 'string' );
61
- $s_categories = hfcm_sanitize_array( 's_categories' );
62
- $s_tags = hfcm_sanitize_array( 's_tags' );
63
-
64
- if ( 'manual' === $display_on ) {
65
- $location = '';
66
- }
67
- $lp_count = max( 1, (int) $lp_count );
68
-
69
- // Global vars
70
- global $wpdb;
71
- global $current_user;
72
- $table_name = $wpdb->prefix . 'hfcm_scripts';
73
-
74
- // Update snippet
75
- if ( isset( $id ) ) {
76
-
77
- $wpdb->update( $table_name, //table
78
- // Data
79
- array(
80
- 'name' => $name,
81
- 'snippet' => $snippet,
82
- 'device_type' => $device_type,
83
- 'location' => $location,
84
- 'display_on' => $display_on,
85
- 'status' => $status,
86
- 'lp_count' => $lp_count,
87
- 's_pages' => wp_json_encode( $s_pages ),
88
- 's_posts' => wp_json_encode( $s_posts ),
89
- 's_custom_posts' => wp_json_encode( $s_custom_posts ),
90
- 's_categories' => wp_json_encode( $s_categories ),
91
- 's_tags' => wp_json_encode( $s_tags ),
92
- 'last_revision_date' => current_time( 'Y-m-d H:i:s' ),
93
- 'last_modified_by' => sanitize_text_field( $current_user->display_name ),
94
- ),
95
- // Where
96
- array( 'script_id' => $id ),
97
- // Data format
98
- array(
99
- '%s',
100
- '%s',
101
- '%s',
102
- '%s',
103
- '%s',
104
- '%s',
105
- ),
106
- // Where format
107
- array( '%s' )
108
- );
109
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=1&id=' . $id ) );
110
- } else {
111
-
112
- // Create new snippet
113
- $wpdb->insert( $table_name, //table
114
- array(
115
- 'name' => $name,
116
- 'snippet' => $snippet,
117
- 'device_type' => $device_type,
118
- 'location' => $location,
119
- 'display_on' => $display_on,
120
- 'status' => $status,
121
- 'lp_count' => $lp_count,
122
- 's_pages' => wp_json_encode( $s_pages ),
123
- 's_posts' => wp_json_encode( $s_posts ),
124
- 's_custom_posts' => wp_json_encode( $s_custom_posts ),
125
- 's_categories' => wp_json_encode( $s_categories ),
126
- 's_tags' => wp_json_encode( $s_tags ),
127
- 'created' => current_time( 'Y-m-d H:i:s' ),
128
- 'created_by' => sanitize_text_field( $current_user->display_name ),
129
- ), array(
130
- '%s',
131
- '%s',
132
- '%s',
133
- '%s',
134
- '%s',
135
- '%s',
136
- '%d',
137
- '%s',
138
- '%s',
139
- '%s',
140
- '%s',
141
- '%s',
142
- '%s',
143
- '%s',
144
- )
145
- );
146
- $lastid = $wpdb->insert_id;
147
- hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=6&id=' . $lastid ) );
148
- }
149
- } elseif ( isset( $_POST['get_posts'] ) ) {
150
-
151
- // JSON return posts for AJAX
152
-
153
- // Check nonce
154
- check_ajax_referer( 'hfcm-get-posts', 'security' );
155
-
156
- // Global vars
157
- global $wpdb;
158
- $table_name = $wpdb->prefix . 'hfcm_scripts';
159
-
160
- // Get all selected posts
161
- if ( -1 === $id ) {
162
- $s_posts = array();
163
- } else {
164
-
165
- // Select value to update
166
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT s_posts from $table_name where script_id=%s", $id ) );
167
- foreach ( $script as $s ) {
168
- $s_posts = json_decode( $s->s_posts );
169
- if ( ! is_array( $s_posts ) ) {
170
- $s_posts = array();
171
- }
172
- }
173
- }
174
-
175
- // Get all posts
176
- $args = array(
177
- 'public' => true,
178
- '_builtin' => false,
179
- );
180
-
181
- $output = 'names'; // names or objects, note names is the default
182
- $operator = 'and'; // 'and' or 'or'
183
-
184
- $c_posttypes = get_post_types( $args, $output, $operator );
185
- $posttypes = array( 'post' );
186
- foreach ( $c_posttypes as $cpdata ) {
187
- $posttypes[] = $cpdata;
188
- }
189
- $posts = get_posts( array(
190
- 'post_type' => $posttypes,
191
- 'posts_per_page' => -1,
192
- 'numberposts' => -1,
193
- 'orderby' => 'title',
194
- 'order' => 'ASC',
195
- ) );
196
-
197
- $json_output = array(
198
- 'selected' => array(),
199
- 'posts' => array(),
200
- );
201
-
202
- foreach ( $posts as $pdata ) {
203
-
204
- if ( in_array( $pdata->ID, $s_posts ) ) {
205
- $json_output['selected'][] = $pdata->ID;
206
- }
207
-
208
- $json_output['posts'][] = array(
209
- 'text' => sanitize_text_field( $pdata->post_title ),
210
- 'value' => $pdata->ID,
211
- );
212
- }
213
-
214
- echo wp_json_encode( $json_output );
215
- wp_die();
216
- }
217
- }
1
+ <?php
2
+
3
+ function hfcm_request_handler() {
4
+
5
+ // Check user capabilities
6
+ current_user_can( 'administrator' );
7
+
8
+ if ( isset( $_POST['insert'] ) ) {
9
+ // Check nonce
10
+ check_admin_referer( 'create-snippet' );
11
+ } else {
12
+ if ( ! isset( $_REQUEST['id'] ) ) {
13
+ die( 'Missing ID parameter.' );
14
+ }
15
+ $id = (int) $_REQUEST['id'];
16
+ }
17
+ if ( isset( $_POST['update'] ) ) {
18
+ // Check nonce
19
+ check_admin_referer( 'update-snippet_' . $id );
20
+ }
21
+
22
+ // Handle AJAX on/off toggle for snippets
23
+ if ( isset( $_REQUEST['toggle'] ) && ! empty( $_REQUEST['togvalue'] ) ) {
24
+
25
+ // Check nonce
26
+ check_ajax_referer( 'hfcm-toggle-snippet', 'security' );
27
+
28
+ if ( 'on' === $_REQUEST['togvalue'] ) {
29
+ $status = 'active';
30
+ } else {
31
+ $status = 'inactive';
32
+ }
33
+
34
+ // Global vars
35
+ global $wpdb;
36
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
37
+
38
+ $wpdb->update(
39
+ $table_name, //table
40
+ array( 'status' => $status ), //data
41
+ array( 'script_id' => $id ), //where
42
+ array( '%s', '%s', '%s', '%s', '%s', '%s' ), //data format
43
+ array( '%s' ) //where format
44
+ );
45
+
46
+ } elseif ( isset( $_POST['insert'] ) || isset( $_POST['update'] ) ) {
47
+
48
+ // Create / update snippet
49
+
50
+ // Sanitize fields
51
+ $name = hfcm_sanitize_text( 'name' );
52
+ $snippet = hfcm_sanitize_text( 'snippet', false );
53
+ $device_type = hfcm_sanitize_text( 'device_type' );
54
+ $display_on = hfcm_sanitize_text( 'display_on' );
55
+ $location = hfcm_sanitize_text( 'location' );
56
+ $lp_count = hfcm_sanitize_text( 'lp_count' );
57
+ $status = hfcm_sanitize_text( 'status' );
58
+ $s_pages = hfcm_sanitize_array( 's_pages' );
59
+ $s_posts = hfcm_sanitize_array( 's_posts' );
60
+ $s_custom_posts = hfcm_sanitize_array( 's_custom_posts', 'string' );
61
+ $s_categories = hfcm_sanitize_array( 's_categories' );
62
+ $s_tags = hfcm_sanitize_array( 's_tags' );
63
+
64
+ if ( 'manual' === $display_on ) {
65
+ $location = '';
66
+ }
67
+ $lp_count = max( 1, (int) $lp_count );
68
+
69
+ // Global vars
70
+ global $wpdb;
71
+ global $current_user;
72
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
73
+
74
+ // Update snippet
75
+ if ( isset( $id ) ) {
76
+
77
+ $wpdb->update( $table_name, //table
78
+ // Data
79
+ array(
80
+ 'name' => $name,
81
+ 'snippet' => $snippet,
82
+ 'device_type' => $device_type,
83
+ 'location' => $location,
84
+ 'display_on' => $display_on,
85
+ 'status' => $status,
86
+ 'lp_count' => $lp_count,
87
+ 's_pages' => wp_json_encode( $s_pages ),
88
+ 's_posts' => wp_json_encode( $s_posts ),
89
+ 's_custom_posts' => wp_json_encode( $s_custom_posts ),
90
+ 's_categories' => wp_json_encode( $s_categories ),
91
+ 's_tags' => wp_json_encode( $s_tags ),
92
+ 'last_revision_date' => current_time( 'Y-m-d H:i:s' ),
93
+ 'last_modified_by' => sanitize_text_field( $current_user->display_name ),
94
+ ),
95
+ // Where
96
+ array( 'script_id' => $id ),
97
+ // Data format
98
+ array(
99
+ '%s',
100
+ '%s',
101
+ '%s',
102
+ '%s',
103
+ '%s',
104
+ '%s',
105
+ ),
106
+ // Where format
107
+ array( '%s' )
108
+ );
109
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=1&id=' . $id ) );
110
+ } else {
111
+
112
+ // Create new snippet
113
+ $wpdb->insert( $table_name, //table
114
+ array(
115
+ 'name' => $name,
116
+ 'snippet' => $snippet,
117
+ 'device_type' => $device_type,
118
+ 'location' => $location,
119
+ 'display_on' => $display_on,
120
+ 'status' => $status,
121
+ 'lp_count' => $lp_count,
122
+ 's_pages' => wp_json_encode( $s_pages ),
123
+ 's_posts' => wp_json_encode( $s_posts ),
124
+ 's_custom_posts' => wp_json_encode( $s_custom_posts ),
125
+ 's_categories' => wp_json_encode( $s_categories ),
126
+ 's_tags' => wp_json_encode( $s_tags ),
127
+ 'created' => current_time( 'Y-m-d H:i:s' ),
128
+ 'created_by' => sanitize_text_field( $current_user->display_name ),
129
+ ), array(
130
+ '%s',
131
+ '%s',
132
+ '%s',
133
+ '%s',
134
+ '%s',
135
+ '%s',
136
+ '%d',
137
+ '%s',
138
+ '%s',
139
+ '%s',
140
+ '%s',
141
+ '%s',
142
+ '%s',
143
+ '%s',
144
+ )
145
+ );
146
+ $lastid = $wpdb->insert_id;
147
+ hfcm_redirect( admin_url( 'admin.php?page=hfcm-update&message=6&id=' . $lastid ) );
148
+ }
149
+ } elseif ( isset( $_POST['get_posts'] ) ) {
150
+
151
+ // JSON return posts for AJAX
152
+
153
+ // Check nonce
154
+ check_ajax_referer( 'hfcm-get-posts', 'security' );
155
+
156
+ // Global vars
157
+ global $wpdb;
158
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
159
+
160
+ // Get all selected posts
161
+ if ( -1 === $id ) {
162
+ $s_posts = array();
163
+ } else {
164
+
165
+ // Select value to update
166
+ $script = $wpdb->get_results( $wpdb->prepare( "SELECT s_posts from $table_name where script_id=%s", $id ) );
167
+ foreach ( $script as $s ) {
168
+ $s_posts = json_decode( $s->s_posts );
169
+ if ( ! is_array( $s_posts ) ) {
170
+ $s_posts = array();
171
+ }
172
+ }
173
+ }
174
+
175
+ // Get all posts
176
+ $args = array(
177
+ 'public' => true,
178
+ '_builtin' => false,
179
+ );
180
+
181
+ $output = 'names'; // names or objects, note names is the default
182
+ $operator = 'and'; // 'and' or 'or'
183
+
184
+ $c_posttypes = get_post_types( $args, $output, $operator );
185
+ $posttypes = array( 'post' );
186
+ foreach ( $c_posttypes as $cpdata ) {
187
+ $posttypes[] = $cpdata;
188
+ }
189
+ $posts = get_posts( array(
190
+ 'post_type' => $posttypes,
191
+ 'posts_per_page' => -1,
192
+ 'numberposts' => -1,
193
+ 'orderby' => 'title',
194
+ 'order' => 'ASC',
195
+ ) );
196
+
197
+ $json_output = array(
198
+ 'selected' => array(),
199
+ 'posts' => array(),
200
+ );
201
+
202
+ foreach ( $posts as $pdata ) {
203
+
204
+ if ( in_array( $pdata->ID, $s_posts ) ) {
205
+ $json_output['selected'][] = $pdata->ID;
206
+ }
207
+
208
+ $json_output['posts'][] = array(
209
+ 'text' => sanitize_text_field( $pdata->post_title ),
210
+ 'value' => $pdata->ID,
211
+ );
212
+ }
213
+
214
+ echo wp_json_encode( $json_output );
215
+ wp_die();
216
+ }
217
+ }
includes/hfcm-update.php CHANGED
@@ -1,74 +1,74 @@
1
- <?php
2
-
3
- // Function for submenu "Update snippet" page
4
- function hfcm_update() {
5
-
6
- add_action( 'wp_enqueue_scripts', 'hfcm_selectize_enqueue' );
7
-
8
- // check user capabilities
9
- current_user_can( 'administrator' );
10
-
11
- if ( ! isset( $_GET['id'] ) ) {
12
- die( 'Missing ID parameter.' );
13
- }
14
- $id = $_GET['id'];
15
-
16
- global $wpdb;
17
- $table_name = $wpdb->prefix . 'hfcm_scripts';
18
-
19
- //selecting value to update
20
- $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where script_id=%s", $id ) );
21
- foreach ( $script as $s ) {
22
- $name = $s->name;
23
- $snippet = $s->snippet;
24
- $device_type = $s->device_type;
25
- $location = $s->location;
26
- $display_on = $s->display_on;
27
- $status = $s->status;
28
- $lp_count = $s->lp_count;
29
- $s_pages = json_decode( $s->s_pages );
30
-
31
- if ( ! is_array( $s_pages ) ) {
32
- $s_pages = array();
33
- }
34
-
35
- $s_posts = json_decode( $s->s_posts );
36
- if ( ! is_array( $s_posts ) ) {
37
- $s_posts = array();
38
- }
39
-
40
- $s_custom_posts = json_decode( $s->s_custom_posts );
41
- if ( ! is_array( $s_custom_posts ) ) {
42
- $s_custom_posts = array();
43
- }
44
-
45
- $s_categories = json_decode( $s->s_categories );
46
- if ( ! is_array( $s_categories ) ) {
47
- $s_categories = array();
48
- }
49
-
50
- $s_tags = json_decode( $s->s_tags );
51
- if ( ! is_array( $s_tags ) ) {
52
- $s_tags = array();
53
- }
54
-
55
- $createdby = esc_html( $s->created_by );
56
- $lastmodifiedby = esc_html( $s->last_modified_by );
57
- $createdon = esc_html( $s->created );
58
- $lastrevisiondate = esc_html( $s->last_revision_date );
59
- }
60
-
61
- // escape for html output
62
- $name = esc_textarea( $name );
63
- $snippet = esc_textarea( $snippet );
64
- $device_type = esc_html( $device_type );
65
- $location = esc_html( $location );
66
- $display_on = esc_html( $display_on );
67
- $status = esc_html( $status );
68
- $lp_count = esc_html( $lp_count );
69
-
70
- // Notify hfcm-add-edit.php to make necesary changes for update
71
- $update = true;
72
-
73
- require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
74
- }
1
+ <?php
2
+
3
+ // Function for submenu "Update snippet" page
4
+ function hfcm_update() {
5
+
6
+ add_action( 'wp_enqueue_scripts', 'hfcm_selectize_enqueue' );
7
+
8
+ // check user capabilities
9
+ current_user_can( 'administrator' );
10
+
11
+ if ( ! isset( $_GET['id'] ) ) {
12
+ die( 'Missing ID parameter.' );
13
+ }
14
+ $id = $_GET['id'];
15
+
16
+ global $wpdb;
17
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
18
+
19
+ //selecting value to update
20
+ $script = $wpdb->get_results( $wpdb->prepare( "SELECT * from $table_name where script_id=%s", $id ) );
21
+ foreach ( $script as $s ) {
22
+ $name = $s->name;
23
+ $snippet = $s->snippet;
24
+ $device_type = $s->device_type;
25
+ $location = $s->location;
26
+ $display_on = $s->display_on;
27
+ $status = $s->status;
28
+ $lp_count = $s->lp_count;
29
+ $s_pages = json_decode( $s->s_pages );
30
+
31
+ if ( ! is_array( $s_pages ) ) {
32
+ $s_pages = array();
33
+ }
34
+
35
+ $s_posts = json_decode( $s->s_posts );
36
+ if ( ! is_array( $s_posts ) ) {
37
+ $s_posts = array();
38
+ }
39
+
40
+ $s_custom_posts = json_decode( $s->s_custom_posts );
41
+ if ( ! is_array( $s_custom_posts ) ) {
42
+ $s_custom_posts = array();
43
+ }
44
+
45
+ $s_categories = json_decode( $s->s_categories );
46
+ if ( ! is_array( $s_categories ) ) {
47
+ $s_categories = array();
48
+ }
49
+
50
+ $s_tags = json_decode( $s->s_tags );
51
+ if ( ! is_array( $s_tags ) ) {
52
+ $s_tags = array();
53
+ }
54
+
55
+ $createdby = esc_html( $s->created_by );
56
+ $lastmodifiedby = esc_html( $s->last_modified_by );
57
+ $createdon = esc_html( $s->created );
58
+ $lastrevisiondate = esc_html( $s->last_revision_date );
59
+ }
60
+
61
+ // escape for html output
62
+ $name = esc_textarea( $name );
63
+ $snippet = esc_textarea( $snippet );
64
+ $device_type = esc_html( $device_type );
65
+ $location = esc_html( $location );
66
+ $display_on = esc_html( $display_on );
67
+ $status = esc_html( $status );
68
+ $lp_count = esc_html( $lp_count );
69
+ $i = esc_html( $lp_count );
70
+ // Notify hfcm-add-edit.php to make necesary changes for update
71
+ $update = true;
72
+
73
+ require_once( plugin_dir_path( __FILE__ ) . 'hfcm-add-edit.php' );
74
+ }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: 99robots, charliepatel
3
  Tags: header, footer, code manager, snippet, functions.php, tracking, google analytics, adsense, verification, pixel
4
  Requires at least: 4.0
5
- Tested up to: 4.8.0
6
- Stable tag: 1.0.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://99robots.com
@@ -66,6 +66,9 @@ Header Footer Code Manager by 99 Robots is a easy interface to add snippets to t
66
  * It can accept ANY code snippet (HTML / Javascript / CSS) from any service
67
  * and the list goes on and on...
68
 
 
 
 
69
  > #### Plugin Information
70
  > * [Plugin Site](https://www.99robots.com/header-footer-code-manager)
71
  > * [Plugin Documentation](https://www.99robots.com/docs/header-footer-code-manager)
@@ -78,6 +81,8 @@ Header Footer Code Manager by 99 Robots is a easy interface to add snippets to t
78
  1. Activate the plugin through the 'Plugins' menu in WordPress
79
  1. Go to plugins page to see instructions for shortcode and php template tags
80
 
 
 
81
  == Screenshots ==
82
 
83
  1. Dashboard - All Snippets
@@ -98,6 +103,16 @@ A. If your script is not supported, just let us know and we'll look into it imme
98
 
99
  == Changelog ==
100
 
 
 
 
 
 
 
 
 
 
 
101
  = 1.0.3 = 2017-06-09
102
  * Compatible with WordPress 4.8
103
 
2
  Contributors: 99robots, charliepatel
3
  Tags: header, footer, code manager, snippet, functions.php, tracking, google analytics, adsense, verification, pixel
4
  Requires at least: 4.0
5
+ Tested up to: 4.9.7
6
+ Stable tag: 1.0.6
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate link: https://99robots.com
66
  * It can accept ANY code snippet (HTML / Javascript / CSS) from any service
67
  * and the list goes on and on...
68
 
69
+ == MULTISITE NOTE ==
70
+ If using this plugin on a multisite network, please make sure that the plugin is activated on a subsite level only.
71
+
72
  > #### Plugin Information
73
  > * [Plugin Site](https://www.99robots.com/header-footer-code-manager)
74
  > * [Plugin Documentation](https://www.99robots.com/docs/header-footer-code-manager)
81
  1. Activate the plugin through the 'Plugins' menu in WordPress
82
  1. Go to plugins page to see instructions for shortcode and php template tags
83
 
84
+ NOTE: If using this plugin on a multisite network, please make sure that the plugin is activated on a subsite level only.
85
+
86
  == Screenshots ==
87
 
88
  1. Dashboard - All Snippets
103
 
104
  == Changelog ==
105
 
106
+ = 1.0.6 = 2018-07-10
107
+ * FIXED: Latest Posts dropdown selection always resets to 1 on save / update.
108
+
109
+ = 1.0.5 = 2018-06-14
110
+ * UPDATED: "All Snippets" page to show 10 snippets before pagination starts.
111
+
112
+ = 1.0.4 = 2018-05-23
113
+ * FIXED: style-admin.css not loading on "Add New Snippet" page.
114
+ * FIXED: Post List not loading when selecting "Specific Posts" in "Site Display" under Add New Snippet.
115
+
116
  = 1.0.3 = 2017-06-09
117
  * Compatible with WordPress 4.8
118
 
uninstall.php CHANGED
@@ -1,17 +1,17 @@
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
- // For site options in Multisite
11
- delete_site_option( $option_name );
12
-
13
- // Drop a custom db table
14
- global $wpdb;
15
- $table_name = $wpdb->prefix . 'hfcm_scripts';
16
-
17
- $wpdb->query( "DROP TABLE IF EXISTS $table_name" );
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
+ // For site options in Multisite
11
+ delete_site_option( $option_name );
12
+
13
+ // Drop a custom db table
14
+ global $wpdb;
15
+ $table_name = $wpdb->prefix . 'hfcm_scripts';
16
+
17
+ $wpdb->query( "DROP TABLE IF EXISTS $table_name" );