Version Description
Release date: June, 1st 2018
- Behavior change: Links to generate support requests migrated to the WordPress.org forums.
- New feature: Added support for Schema.org BreadcrumbList (microdata format) in the included widget.
- New feature: Added new Root Page support for author archives.
- New feature: Added REST API endpoint for posts, terms, and author archives.
- Bug fix: Corrected label for the Schema.org BreadcrumbList (RDFa format) option in the included widget.
- Bug fix: Fixed issue where a PHP warning would be thrown due to
get_term()
returning something other than an instance ofWP_Term
.
Download this release
Release Info
Developer | mtekk |
Plugin | Breadcrumb NavXT |
Version | 6.1.0 |
Comparing to | |
See all releases |
Code changes from version 6.0.4 to 6.1.0
- breadcrumb-navxt.php +571 -546
- class.bcn_admin.php +782 -773
- class.bcn_breadcrumb.php +271 -271
- class.bcn_breadcrumb_trail.php +1275 -1261
- class.bcn_network_admin.php +192 -192
- class.bcn_rest_controller.php +232 -0
- class.bcn_widget.php +140 -131
- includes/block_direct_access.php +26 -26
- includes/class.mtekk_adminkit.php +1194 -1194
- includes/class.mtekk_adminkit_message.php +98 -98
- includes/class.mtekk_adminkit_uninstaller.php +69 -69
- includes/mtekk_adminkit_engroups.js +36 -36
- includes/mtekk_adminkit_messages.js +10 -10
- includes/mtekk_adminkit_messages.min.js +10 -10
- includes/mtekk_adminkit_tabs.css +7 -7
- includes/mtekk_adminkit_tabs.js +39 -39
- includes/multibyte_supplicant.php +110 -110
- readme.txt +279 -269
- uninstall.php +123 -123
breadcrumb-navxt.php
CHANGED
@@ -1,546 +1,571 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Breadcrumb NavXT
|
4 |
-
Plugin URI: http://mtekk.us/code/breadcrumb-navxt/
|
5 |
-
Description: Adds a breadcrumb navigation showing the visitor's path to their current location. For details on how to use this plugin visit <a href="http://mtekk.us/code/breadcrumb-navxt/">Breadcrumb NavXT</a>.
|
6 |
-
Version: 6.0
|
7 |
-
Author: John Havlik
|
8 |
-
Author URI: http://mtekk.us/
|
9 |
-
License: GPL2
|
10 |
-
Text Domain: breadcrumb-navxt
|
11 |
-
Domain Path: /languages
|
12 |
-
*/
|
13 |
-
/*
|
14 |
-
Copyright 2007-2018 John Havlik (email : john.havlik@mtekk.us)
|
15 |
-
|
16 |
-
This program is free software; you can redistribute it and/or modify
|
17 |
-
it under the terms of the GNU General Public License as published by
|
18 |
-
the Free Software Foundation; either version 2 of the License, or
|
19 |
-
(at your option) any later version.
|
20 |
-
|
21 |
-
This program is distributed in the hope that it will be useful,
|
22 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24 |
-
GNU General Public License for more details.
|
25 |
-
|
26 |
-
You should have received a copy of the GNU General Public License
|
27 |
-
along with this program; if not, write to the Free Software
|
28 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
29 |
-
*/
|
30 |
-
//Do a PHP version check, require 5.3 or newer
|
31 |
-
if(version_compare(phpversion(), '5.3.0', '<'))
|
32 |
-
{
|
33 |
-
//Only purpose of this function is to echo out the PHP version error
|
34 |
-
function bcn_phpold()
|
35 |
-
{
|
36 |
-
printf('<div class="notice notice-error"><p>' . esc_html__('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.3.0');
|
37 |
-
}
|
38 |
-
//If we are in the admin, let's print a warning then return
|
39 |
-
if(is_admin())
|
40 |
-
{
|
41 |
-
add_action('admin_notices', 'bcn_phpold');
|
42 |
-
}
|
43 |
-
return;
|
44 |
-
}
|
45 |
-
require_once(dirname(__FILE__) . '/includes/multibyte_supplicant.php');
|
46 |
-
//Include admin base class
|
47 |
-
if(!class_exists('mtekk_adminKit'))
|
48 |
-
{
|
49 |
-
require_once(dirname(__FILE__) . '/includes/class.mtekk_adminkit.php');
|
50 |
-
}
|
51 |
-
//Include the breadcrumb class
|
52 |
-
require_once(dirname(__FILE__) . '/class.bcn_breadcrumb.php');
|
53 |
-
//Include the breadcrumb trail class
|
54 |
-
require_once(dirname(__FILE__) . '/class.bcn_breadcrumb_trail.php');
|
55 |
-
if(class_exists('WP_Widget'))
|
56 |
-
{
|
57 |
-
//Include the WP 2.8+ widget class
|
58 |
-
require_once(dirname(__FILE__) . '/class.bcn_widget.php');
|
59 |
-
}
|
60 |
-
$breadcrumb_navxt = null;
|
61 |
-
//TODO change to extends mtekk_plugKit
|
62 |
-
class breadcrumb_navxt
|
63 |
-
{
|
64 |
-
const version = '6.0
|
65 |
-
protected $name = 'Breadcrumb NavXT';
|
66 |
-
protected $identifier = 'breadcrumb-navxt';
|
67 |
-
protected $unique_prefix = 'bcn';
|
68 |
-
protected $plugin_basename = null;
|
69 |
-
protected $opt = null;
|
70 |
-
protected $breadcrumb_trail = null;
|
71 |
-
protected $admin = null;
|
72 |
-
|
73 |
-
|
74 |
-
*
|
75 |
-
*
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
add_action('
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
if(
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
'
|
129 |
-
'
|
130 |
-
'
|
131 |
-
'
|
132 |
-
'
|
133 |
-
'
|
134 |
-
'
|
135 |
-
'
|
136 |
-
'
|
137 |
-
'
|
138 |
-
'
|
139 |
-
'
|
140 |
-
|
141 |
-
|
142 |
-
'
|
143 |
-
'
|
144 |
-
'
|
145 |
-
'
|
146 |
-
'
|
147 |
-
'
|
148 |
-
'
|
149 |
-
|
150 |
-
|
151 |
-
'
|
152 |
-
'
|
153 |
-
'
|
154 |
-
'
|
155 |
-
'
|
156 |
-
'
|
157 |
-
'
|
158 |
-
'
|
159 |
-
'
|
160 |
-
'
|
161 |
-
'
|
162 |
-
'
|
163 |
-
|
164 |
-
|
165 |
-
'
|
166 |
-
'
|
167 |
-
'
|
168 |
-
'
|
169 |
-
'
|
170 |
-
'
|
171 |
-
'
|
172 |
-
|
173 |
-
|
174 |
-
'
|
175 |
-
'
|
176 |
-
'
|
177 |
-
'
|
178 |
-
'
|
179 |
-
'
|
180 |
-
'
|
181 |
-
'
|
182 |
-
'
|
183 |
-
'
|
184 |
-
'
|
185 |
-
|
186 |
-
|
187 |
-
'
|
188 |
-
'
|
189 |
-
'
|
190 |
-
'
|
191 |
-
'
|
192 |
-
'
|
193 |
-
'
|
194 |
-
|
195 |
-
|
196 |
-
'
|
197 |
-
'
|
198 |
-
'
|
199 |
-
'
|
200 |
-
'
|
201 |
-
'
|
202 |
-
'
|
203 |
-
'
|
204 |
-
'
|
205 |
-
'
|
206 |
-
'
|
207 |
-
|
208 |
-
|
209 |
-
'
|
210 |
-
'
|
211 |
-
'
|
212 |
-
'
|
213 |
-
'
|
214 |
-
'
|
215 |
-
'
|
216 |
-
|
217 |
-
|
218 |
-
'
|
219 |
-
'
|
220 |
-
'
|
221 |
-
'
|
222 |
-
'
|
223 |
-
'
|
224 |
-
'
|
225 |
-
'
|
226 |
-
'
|
227 |
-
'
|
228 |
-
'
|
229 |
-
|
230 |
-
|
231 |
-
'
|
232 |
-
'
|
233 |
-
'
|
234 |
-
'
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
{
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
$
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
{
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
*
|
368 |
-
*
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
*
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
}
|
458 |
-
/**
|
459 |
-
* Outputs the breadcrumb trail
|
460 |
-
*
|
461 |
-
* @
|
462 |
-
*
|
463 |
-
* @param bool $
|
464 |
-
*
|
465 |
-
* @
|
466 |
-
* @
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
*
|
518 |
-
*
|
519 |
-
* @return
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
*
|
537 |
-
*
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Breadcrumb NavXT
|
4 |
+
Plugin URI: http://mtekk.us/code/breadcrumb-navxt/
|
5 |
+
Description: Adds a breadcrumb navigation showing the visitor's path to their current location. For details on how to use this plugin visit <a href="http://mtekk.us/code/breadcrumb-navxt/">Breadcrumb NavXT</a>.
|
6 |
+
Version: 6.1.0
|
7 |
+
Author: John Havlik
|
8 |
+
Author URI: http://mtekk.us/
|
9 |
+
License: GPL2
|
10 |
+
Text Domain: breadcrumb-navxt
|
11 |
+
Domain Path: /languages
|
12 |
+
*/
|
13 |
+
/*
|
14 |
+
Copyright 2007-2018 John Havlik (email : john.havlik@mtekk.us)
|
15 |
+
|
16 |
+
This program is free software; you can redistribute it and/or modify
|
17 |
+
it under the terms of the GNU General Public License as published by
|
18 |
+
the Free Software Foundation; either version 2 of the License, or
|
19 |
+
(at your option) any later version.
|
20 |
+
|
21 |
+
This program is distributed in the hope that it will be useful,
|
22 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
23 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
24 |
+
GNU General Public License for more details.
|
25 |
+
|
26 |
+
You should have received a copy of the GNU General Public License
|
27 |
+
along with this program; if not, write to the Free Software
|
28 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
29 |
+
*/
|
30 |
+
//Do a PHP version check, require 5.3 or newer
|
31 |
+
if(version_compare(phpversion(), '5.3.0', '<'))
|
32 |
+
{
|
33 |
+
//Only purpose of this function is to echo out the PHP version error
|
34 |
+
function bcn_phpold()
|
35 |
+
{
|
36 |
+
printf('<div class="notice notice-error"><p>' . esc_html__('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.3.0');
|
37 |
+
}
|
38 |
+
//If we are in the admin, let's print a warning then return
|
39 |
+
if(is_admin())
|
40 |
+
{
|
41 |
+
add_action('admin_notices', 'bcn_phpold');
|
42 |
+
}
|
43 |
+
return;
|
44 |
+
}
|
45 |
+
require_once(dirname(__FILE__) . '/includes/multibyte_supplicant.php');
|
46 |
+
//Include admin base class
|
47 |
+
if(!class_exists('mtekk_adminKit'))
|
48 |
+
{
|
49 |
+
require_once(dirname(__FILE__) . '/includes/class.mtekk_adminkit.php');
|
50 |
+
}
|
51 |
+
//Include the breadcrumb class
|
52 |
+
require_once(dirname(__FILE__) . '/class.bcn_breadcrumb.php');
|
53 |
+
//Include the breadcrumb trail class
|
54 |
+
require_once(dirname(__FILE__) . '/class.bcn_breadcrumb_trail.php');
|
55 |
+
if(class_exists('WP_Widget'))
|
56 |
+
{
|
57 |
+
//Include the WP 2.8+ widget class
|
58 |
+
require_once(dirname(__FILE__) . '/class.bcn_widget.php');
|
59 |
+
}
|
60 |
+
$breadcrumb_navxt = null;
|
61 |
+
//TODO change to extends mtekk_plugKit
|
62 |
+
class breadcrumb_navxt
|
63 |
+
{
|
64 |
+
const version = '6.1.0';
|
65 |
+
protected $name = 'Breadcrumb NavXT';
|
66 |
+
protected $identifier = 'breadcrumb-navxt';
|
67 |
+
protected $unique_prefix = 'bcn';
|
68 |
+
protected $plugin_basename = null;
|
69 |
+
protected $opt = null;
|
70 |
+
protected $breadcrumb_trail = null;
|
71 |
+
protected $admin = null;
|
72 |
+
protected $rest_controller = null;
|
73 |
+
/**
|
74 |
+
* Constructor for a new breadcrumb_navxt object
|
75 |
+
*
|
76 |
+
* @param bcn_breadcrumb_trail $breadcrumb_trail An instance of a bcn_breadcrumb_trail object to use for everything
|
77 |
+
*/
|
78 |
+
public function __construct(bcn_breadcrumb_trail $breadcrumb_trail)
|
79 |
+
{
|
80 |
+
//We get our breadcrumb trail object from our constructor
|
81 |
+
$this->breadcrumb_trail = $breadcrumb_trail;
|
82 |
+
//Grab defaults from the breadcrumb_trail object
|
83 |
+
$this->opt = $this->breadcrumb_trail->opt;
|
84 |
+
//We set the plugin basename here
|
85 |
+
$this->plugin_basename = plugin_basename(__FILE__);
|
86 |
+
//We need to add in the defaults for CPTs and custom taxonomies after all other plugins are loaded
|
87 |
+
add_action('wp_loaded', array($this, 'wp_loaded'), 15);
|
88 |
+
add_action('init', array($this, 'init'));
|
89 |
+
//Register the WordPress 2.8 Widget
|
90 |
+
add_action('widgets_init', array($this, 'register_widget'));
|
91 |
+
//Load our network admin if in the network dashboard (yes is_network_admin() doesn't exist)
|
92 |
+
if(defined('WP_NETWORK_ADMIN') && WP_NETWORK_ADMIN)
|
93 |
+
{
|
94 |
+
require_once(dirname(__FILE__) . '/class.bcn_network_admin.php');
|
95 |
+
//Instantiate our new admin object
|
96 |
+
$this->admin = new bcn_network_admin($this->breadcrumb_trail, $this->plugin_basename);
|
97 |
+
}
|
98 |
+
//Load our main admin if in the dashboard, but only if we're not in the network dashboard (prevents goofy bugs)
|
99 |
+
else if(is_admin() || defined('WP_UNINSTALL_PLUGIN'))
|
100 |
+
{
|
101 |
+
require_once(dirname(__FILE__) . '/class.bcn_admin.php');
|
102 |
+
//Instantiate our new admin object
|
103 |
+
$this->admin = new bcn_admin($this->breadcrumb_trail, $this->plugin_basename);
|
104 |
+
}
|
105 |
+
}
|
106 |
+
public function init()
|
107 |
+
{
|
108 |
+
breadcrumb_navxt::setup_options($this->opt);
|
109 |
+
$this->get_settings();
|
110 |
+
add_filter('bcn_allowed_html', array($this, 'allowed_html'), 1, 1);
|
111 |
+
//We want to run late for using our breadcrumbs
|
112 |
+
add_filter('tha_breadcrumb_navigation', array($this, 'tha_compat'), 99);
|
113 |
+
//Only include the REST API if enabled
|
114 |
+
if(!defined('BCN_DISABLE_REST_API') || !BCN_DISABLE_REST_API)
|
115 |
+
{
|
116 |
+
require_once(dirname(__FILE__) . '/class.bcn_rest_controller.php');
|
117 |
+
$this->rest_controller = new bcn_rest_controller($this->breadcrumb_trail, $this->unique_prefix);
|
118 |
+
}
|
119 |
+
}
|
120 |
+
public function register_widget()
|
121 |
+
{
|
122 |
+
return register_widget($this->unique_prefix . '_widget');
|
123 |
+
}
|
124 |
+
public function allowed_html($tags)
|
125 |
+
{
|
126 |
+
$allowed_html = array(
|
127 |
+
'a' => array(
|
128 |
+
'href' => true,
|
129 |
+
'title' => true,
|
130 |
+
'class' => true,
|
131 |
+
'id' => true,
|
132 |
+
'media' => true,
|
133 |
+
'dir' => true,
|
134 |
+
'relList' => true,
|
135 |
+
'rel' => true,
|
136 |
+
'aria-hidden' => true,
|
137 |
+
'data-icon' => true,
|
138 |
+
'itemref' => true,
|
139 |
+
'itemid' => true,
|
140 |
+
'itemprop' => true,
|
141 |
+
'itemscope' => true,
|
142 |
+
'itemtype' => true,
|
143 |
+
'xmlns:v' => true,
|
144 |
+
'typeof' => true,
|
145 |
+
'property' => true,
|
146 |
+
'vocab' => true,
|
147 |
+
'translate' => true,
|
148 |
+
'lang' => true
|
149 |
+
),
|
150 |
+
'img' => array(
|
151 |
+
'alt' => true,
|
152 |
+
'align' => true,
|
153 |
+
'height' => true,
|
154 |
+
'width' => true,
|
155 |
+
'src' => true,
|
156 |
+
'srcset' => true,
|
157 |
+
'sizes' => true,
|
158 |
+
'id' => true,
|
159 |
+
'class' => true,
|
160 |
+
'aria-hidden' => true,
|
161 |
+
'data-icon' => true,
|
162 |
+
'itemref' => true,
|
163 |
+
'itemid' => true,
|
164 |
+
'itemprop' => true,
|
165 |
+
'itemscope' => true,
|
166 |
+
'itemtype' => true,
|
167 |
+
'xmlns:v' => true,
|
168 |
+
'typeof' => true,
|
169 |
+
'property' => true,
|
170 |
+
'vocab' => true,
|
171 |
+
'lang' => true
|
172 |
+
),
|
173 |
+
'span' => array(
|
174 |
+
'title' => true,
|
175 |
+
'class' => true,
|
176 |
+
'id' => true,
|
177 |
+
'dir' => true,
|
178 |
+
'align' => true,
|
179 |
+
'lang' => true,
|
180 |
+
'xml:lang' => true,
|
181 |
+
'aria-hidden' => true,
|
182 |
+
'data-icon' => true,
|
183 |
+
'itemref' => true,
|
184 |
+
'itemid' => true,
|
185 |
+
'itemprop' => true,
|
186 |
+
'itemscope' => true,
|
187 |
+
'itemtype' => true,
|
188 |
+
'xmlns:v' => true,
|
189 |
+
'typeof' => true,
|
190 |
+
'property' => true,
|
191 |
+
'vocab' => true,
|
192 |
+
'translate' => true,
|
193 |
+
'lang' => true
|
194 |
+
),
|
195 |
+
'h1' => array(
|
196 |
+
'title' => true,
|
197 |
+
'class' => true,
|
198 |
+
'id' => true,
|
199 |
+
'dir' => true,
|
200 |
+
'align' => true,
|
201 |
+
'lang' => true,
|
202 |
+
'xml:lang' => true,
|
203 |
+
'aria-hidden' => true,
|
204 |
+
'data-icon' => true,
|
205 |
+
'itemref' => true,
|
206 |
+
'itemid' => true,
|
207 |
+
'itemprop' => true,
|
208 |
+
'itemscope' => true,
|
209 |
+
'itemtype' => true,
|
210 |
+
'xmlns:v' => true,
|
211 |
+
'typeof' => true,
|
212 |
+
'property' => true,
|
213 |
+
'vocab' => true,
|
214 |
+
'translate' => true,
|
215 |
+
'lang' => true
|
216 |
+
),
|
217 |
+
'h2' => array(
|
218 |
+
'title' => true,
|
219 |
+
'class' => true,
|
220 |
+
'id' => true,
|
221 |
+
'dir' => true,
|
222 |
+
'align' => true,
|
223 |
+
'lang' => true,
|
224 |
+
'xml:lang' => true,
|
225 |
+
'aria-hidden' => true,
|
226 |
+
'data-icon' => true,
|
227 |
+
'itemref' => true,
|
228 |
+
'itemid' => true,
|
229 |
+
'itemprop' => true,
|
230 |
+
'itemscope' => true,
|
231 |
+
'itemtype' => true,
|
232 |
+
'xmlns:v' => true,
|
233 |
+
'typeof' => true,
|
234 |
+
'property' => true,
|
235 |
+
'vocab' => true,
|
236 |
+
'translate' => true,
|
237 |
+
'lang' => true
|
238 |
+
),
|
239 |
+
'meta' => array(
|
240 |
+
'content' => true,
|
241 |
+
'property' => true,
|
242 |
+
'vocab' => true,
|
243 |
+
'itemprop' => true
|
244 |
+
)
|
245 |
+
);
|
246 |
+
return mtekk_adminKit::array_merge_recursive($tags, $allowed_html);
|
247 |
+
}
|
248 |
+
public function get_version()
|
249 |
+
{
|
250 |
+
return self::version;
|
251 |
+
}
|
252 |
+
public function wp_loaded()
|
253 |
+
{
|
254 |
+
|
255 |
+
}
|
256 |
+
public function uninstall()
|
257 |
+
{
|
258 |
+
$this->admin->uninstall();
|
259 |
+
}
|
260 |
+
/**
|
261 |
+
* Sets up the extended options for any CPTs, taxonomies or extensions
|
262 |
+
*
|
263 |
+
* @param array $opt The options array, passed by reference
|
264 |
+
*/
|
265 |
+
static public function setup_options(&$opt)
|
266 |
+
{
|
267 |
+
//Add custom post types
|
268 |
+
breadcrumb_navxt::find_posttypes($opt);
|
269 |
+
//Add custom taxonomy types
|
270 |
+
breadcrumb_navxt::find_taxonomies($opt);
|
271 |
+
//Let others hook into our settings
|
272 |
+
$opt = apply_filters('bcn_settings_init', $opt);
|
273 |
+
}
|
274 |
+
/**
|
275 |
+
* Places settings into $opts array, if missing, for the registered post types
|
276 |
+
*
|
277 |
+
* @param array $opts
|
278 |
+
*/
|
279 |
+
static function find_posttypes(&$opts)
|
280 |
+
{
|
281 |
+
global $wp_post_types, $wp_taxonomies;
|
282 |
+
//Loop through all of the post types in the array
|
283 |
+
foreach($wp_post_types as $post_type)
|
284 |
+
{
|
285 |
+
//We only want custom post types
|
286 |
+
if(!$post_type->_builtin)
|
287 |
+
{
|
288 |
+
if(!isset($opts['bpost_' . $post_type->name . '_taxonomy_referer']))
|
289 |
+
{
|
290 |
+
//Default to not letting the refering page influence the referer
|
291 |
+
$opts['bpost_' . $post_type->name . '_taxonomy_referer'] = false;
|
292 |
+
}
|
293 |
+
//If the post type does not have settings in the options array yet, we need to load some defaults
|
294 |
+
if(!isset($opts['Hpost_' . $post_type->name . '_template']) || !$post_type->hierarchical && !isset($opts['Spost_' . $post_type->name . '_hierarchy_type']))
|
295 |
+
{
|
296 |
+
//Add the necessary option array members
|
297 |
+
$opts['Hpost_' . $post_type->name . '_template'] = bcn_breadcrumb::get_default_template();
|
298 |
+
$opts['Hpost_' . $post_type->name . '_template_no_anchor'] = bcn_breadcrumb::default_template_no_anchor;
|
299 |
+
if($post_type->has_archive == true || is_string($post_type->has_archive))
|
300 |
+
{
|
301 |
+
$opts['bpost_' . $post_type->name . '_archive_display'] = true;
|
302 |
+
}
|
303 |
+
else
|
304 |
+
{
|
305 |
+
$opts['bpost_' . $post_type->name . '_archive_display'] = false;
|
306 |
+
}
|
307 |
+
//Default to not showing a post_root
|
308 |
+
$opts['apost_' . $post_type->name . '_root'] = 0;
|
309 |
+
//Default to not displaying a taxonomy
|
310 |
+
$opts['bpost_' . $post_type->name . '_hierarchy_display'] = false;
|
311 |
+
//Loop through all of the possible taxonomies
|
312 |
+
foreach($wp_taxonomies as $taxonomy)
|
313 |
+
{
|
314 |
+
//Check for non-public taxonomies
|
315 |
+
if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, $post_type->name))
|
316 |
+
{
|
317 |
+
continue;
|
318 |
+
}
|
319 |
+
//Activate the first taxonomy valid for this post type and exit the loop
|
320 |
+
if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type))
|
321 |
+
{
|
322 |
+
$opts['bpost_' . $post_type->name . '_hierarchy_display'] = true;
|
323 |
+
$opts['Spost_' . $post_type->name . '_hierarchy_type'] = $taxonomy->name;
|
324 |
+
break;
|
325 |
+
}
|
326 |
+
}
|
327 |
+
//If there are no valid taxonomies for this type, setup our defaults
|
328 |
+
if(!isset($opts['Spost_' . $post_type->name . '_hierarchy_type']))
|
329 |
+
{
|
330 |
+
$opts['Spost_' . $post_type->name . '_hierarchy_type'] = 'BCN_DATE';
|
331 |
+
}
|
332 |
+
//Run through some filters, allowing extensions to directly influence the default hierarchy selection/display
|
333 |
+
$opts['Spost_' . $post_type->name . '_hierarchy_type'] = apply_filters('bcn_default_hierarchy_type', $opts['Spost_' . $post_type->name . '_hierarchy_type'], $post_type->name);
|
334 |
+
$opts['bpost_' . $post_type->name . '_hierarchy_display'] = apply_filters('bcn_default_hierarchy_display', $opts['bpost_' . $post_type->name . '_hierarchy_display'], $post_type->name, $opts['Spost_' . $post_type->name . '_hierarchy_type']);
|
335 |
+
}
|
336 |
+
}
|
337 |
+
}
|
338 |
+
}
|
339 |
+
/**
|
340 |
+
* Places settings into $opts array, if missing, for the registered taxonomies
|
341 |
+
*
|
342 |
+
* @param $opts
|
343 |
+
*/
|
344 |
+
static function find_taxonomies(&$opts)
|
345 |
+
{
|
346 |
+
global $wp_taxonomies;
|
347 |
+
//We'll add our custom taxonomy stuff at this time
|
348 |
+
foreach($wp_taxonomies as $taxonomy)
|
349 |
+
{
|
350 |
+
//We only want custom taxonomies
|
351 |
+
if(!$taxonomy->_builtin)
|
352 |
+
{
|
353 |
+
//If the taxonomy does not have settings in the options array yet, we need to load some defaults
|
354 |
+
if(!isset($opts['Htax_' . $taxonomy->name . '_template']))
|
355 |
+
{
|
356 |
+
//Add the necessary option array members
|
357 |
+
$opts['Htax_' . $taxonomy->name . '_template'] = __(sprintf('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %%title%% %s archives." href="%%link%%" class="%%type%%"><span property="name">%%htitle%%</span></a><meta property="position" content="%%position%%"></span>', $taxonomy->labels->singular_name), 'breadcrumb-navxt');
|
358 |
+
$opts['Htax_' . $taxonomy->name . '_template_no_anchor'] = __(sprintf('<span property="itemListElement" typeof="ListItem"><span property="name">%%htitle%%</span><meta property="position" content="%%position%%"></span>', $taxonomy->labels->singular_name), 'breadcrumb-navxt');
|
359 |
+
}
|
360 |
+
}
|
361 |
+
}
|
362 |
+
}
|
363 |
+
/**
|
364 |
+
* Hooks into the theme hook alliance tha_breadcrumb_navigation filter and replaces the trail
|
365 |
+
* with one generated by Breadcrumb NavXT
|
366 |
+
*
|
367 |
+
* @param string $bradcrumb_trail The string breadcrumb trail that we will replace
|
368 |
+
* @return string The Breadcrumb NavXT assembled breadcrumb trail
|
369 |
+
*/
|
370 |
+
public function tha_compat($breadcrumb_trail)
|
371 |
+
{
|
372 |
+
//Return our breadcrumb trail
|
373 |
+
return $this->display(true);
|
374 |
+
}
|
375 |
+
/**
|
376 |
+
* Function updates the breadcrumb_trail options array from the database in a semi intellegent manner
|
377 |
+
*
|
378 |
+
* @since 5.0.0
|
379 |
+
*/
|
380 |
+
private function get_settings()
|
381 |
+
{
|
382 |
+
//Grab the current settings for the current local site from the db
|
383 |
+
$this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $this->opt);
|
384 |
+
//If we're in multisite mode, look at the three BCN_SETTINGS globals
|
385 |
+
if(is_multisite())
|
386 |
+
{
|
387 |
+
if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK)
|
388 |
+
{
|
389 |
+
//Grab the current network wide settings
|
390 |
+
$this->breadcrumb_trail->opt = wp_parse_args(get_site_option('bcn_options'), $this->opt);
|
391 |
+
}
|
392 |
+
else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL)
|
393 |
+
{
|
394 |
+
//Grab the current settings for the current local site from the db
|
395 |
+
$this->breadcrumb_trail->opt = wp_parse_args(get_option('bcn_options'), $this->breadcrumb_trail->opt);
|
396 |
+
}
|
397 |
+
else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK)
|
398 |
+
{
|
399 |
+
//Grab the current settings from the db
|
400 |
+
$this->breadcrumb_trail->opt = wp_parse_args(get_site_option('bcn_options'), get_option('bcn_options'));
|
401 |
+
}
|
402 |
+
}
|
403 |
+
//Currently only support using post_parent for the page hierarchy
|
404 |
+
$this->breadcrumb_trail->opt['bpost_page_hierarchy_display'] = true;
|
405 |
+
$this->breadcrumb_trail->opt['Spost_page_hierarchy_type'] = 'BCN_POST_PARENT';
|
406 |
+
$this->breadcrumb_trail->opt['apost_page_root'] = get_option('page_on_front');
|
407 |
+
//This one isn't needed as it is performed in bcn_breadcrumb_trail::fill(), it's here for completeness only
|
408 |
+
$this->breadcrumb_trail->opt['apost_post_root'] = get_option('page_for_posts');
|
409 |
+
|
410 |
+
//Loop through all of the post types in the array, migrate automatically if necessary
|
411 |
+
foreach($GLOBALS['wp_post_types'] as $post_type)
|
412 |
+
{
|
413 |
+
if(isset($this->opt['Spost_' . $post_type->name . '_taxonomy_type']))
|
414 |
+
{
|
415 |
+
$this->opt['Spost_' . $post_type->name . '_hierarchy_type'] = $this->opt['Spost_' . $post_type->name . '_taxonomy_type'];
|
416 |
+
unset($this->opt['Spost_' . $post_type->name . '_taxonomy_type']);
|
417 |
+
}
|
418 |
+
if(isset($this->opt['Spost_' . $post_type->name . '_taxonomy_display']))
|
419 |
+
{
|
420 |
+
$this->opt['Spost_' . $post_type->name . '_hierarchy_display'] = $this->opt['Spost_' . $post_type->name . '_taxonomy_display'];
|
421 |
+
unset($this->opt['Spost_' . $post_type->name . '_taxonomy_display']);
|
422 |
+
}
|
423 |
+
}
|
424 |
+
}
|
425 |
+
/**
|
426 |
+
* Outputs the breadcrumb trail
|
427 |
+
*
|
428 |
+
* @param bool $return Whether to return or echo the trail.
|
429 |
+
* @param bool $linked Whether to allow hyperlinks in the trail or not.
|
430 |
+
* @param bool $reverse Whether to reverse the output or not.
|
431 |
+
* @param bool $force Whether or not to force the fill function to run.
|
432 |
+
* @param string $template The template to use for the string output.
|
433 |
+
*
|
434 |
+
* @return void Void if Option to print out breadcrumb trail was chosen.
|
435 |
+
* @return string String-Data of breadcrumb trail.
|
436 |
+
*/
|
437 |
+
public function display($return = false, $linked = true, $reverse = false, $force = false, $template = '%1$s%2$s')
|
438 |
+
{
|
439 |
+
//If we're being forced to fill the trail, clear it before calling fill
|
440 |
+
if($force)
|
441 |
+
{
|
442 |
+
$this->breadcrumb_trail->breadcrumbs = array();
|
443 |
+
}
|
444 |
+
//Generate the breadcrumb trail
|
445 |
+
$this->breadcrumb_trail->fill();
|
446 |
+
$trail_string = $this->breadcrumb_trail->display($linked, $reverse, $template);
|
447 |
+
if($return)
|
448 |
+
{
|
449 |
+
return $trail_string;
|
450 |
+
}
|
451 |
+
else
|
452 |
+
{
|
453 |
+
//Helps track issues, please don't remove it
|
454 |
+
$credits = "<!-- Breadcrumb NavXT " . $this::version . " -->\n";
|
455 |
+
echo $credits . $trail_string;
|
456 |
+
}
|
457 |
+
}
|
458 |
+
/**
|
459 |
+
* Outputs the breadcrumb trail with each element encapsulated with li tags
|
460 |
+
*
|
461 |
+
* @deprecated 6.0.0 No longer needed, superceeded by $template parameter in display
|
462 |
+
*
|
463 |
+
* @param bool $return Whether to return or echo the trail.
|
464 |
+
* @param bool $linked Whether to allow hyperlinks in the trail or not.
|
465 |
+
* @param bool $reverse Whether to reverse the output or not.
|
466 |
+
* @param bool $force Whether or not to force the fill function to run.
|
467 |
+
*
|
468 |
+
* @return void Void if Option to print out breadcrumb trail was chosen.
|
469 |
+
* @return string String-Data of breadcrumb trail.
|
470 |
+
*/
|
471 |
+
public function display_list($return = false, $linked = true, $reverse = false, $force = false)
|
472 |
+
{
|
473 |
+
_deprecated_function( __FUNCTION__, '6.0', 'breadcrumb_navxt::display');
|
474 |
+
return $this->display($return, $linked, $reverse, $force, "<li%3\$s>%1\$s</li>\n");
|
475 |
+
}
|
476 |
+
/**
|
477 |
+
* Outputs the breadcrumb trail in Schema.org BreadcrumbList compatible JSON-LD
|
478 |
+
*
|
479 |
+
* @param bool $return Whether to return or echo the trail.
|
480 |
+
* @param bool $reverse Whether to reverse the output or not.
|
481 |
+
* @param bool $force Whether or not to force the fill function to run.
|
482 |
+
*
|
483 |
+
* @return void Void if Option to print out breadcrumb trail was chosen.
|
484 |
+
* @return string String-Data of breadcrumb trail.
|
485 |
+
*/
|
486 |
+
public function display_json_ld($return = false, $reverse = false, $force = false)
|
487 |
+
{
|
488 |
+
//If we're being forced to fill the trail, clear it before calling fill
|
489 |
+
if($force)
|
490 |
+
{
|
491 |
+
$this->breadcrumb_trail->breadcrumbs = array();
|
492 |
+
}
|
493 |
+
//Generate the breadcrumb trail
|
494 |
+
$this->breadcrumb_trail->fill();
|
495 |
+
$trail_string = json_encode($this->breadcrumb_trail->display_json_ld($reverse), JSON_UNESCAPED_SLASHES);
|
496 |
+
if($return)
|
497 |
+
{
|
498 |
+
return $trail_string;
|
499 |
+
}
|
500 |
+
else
|
501 |
+
{
|
502 |
+
echo $trail_string;
|
503 |
+
}
|
504 |
+
}
|
505 |
+
}
|
506 |
+
//Have to bootstrap our startup so that other plugins can replace the bcn_breadcrumb_trail object if they need to
|
507 |
+
add_action('plugins_loaded', 'bcn_init', 15);
|
508 |
+
function bcn_init()
|
509 |
+
{
|
510 |
+
global $breadcrumb_navxt;
|
511 |
+
//Create an instance of bcn_breadcrumb_trail
|
512 |
+
$bcn_breadcrumb_trail = new bcn_breadcrumb_trail();
|
513 |
+
//Let's make an instance of our object that takes care of everything
|
514 |
+
$breadcrumb_navxt = new breadcrumb_navxt(apply_filters('bcn_breadcrumb_trail_object', $bcn_breadcrumb_trail));
|
515 |
+
}
|
516 |
+
/**
|
517 |
+
* Outputs the breadcrumb trail
|
518 |
+
*
|
519 |
+
* @param bool $return Whether to return or echo the trail. (optional)
|
520 |
+
* @param bool $linked Whether to allow hyperlinks in the trail or not. (optional)
|
521 |
+
* @param bool $reverse Whether to reverse the output or not. (optional)
|
522 |
+
* @param bool $force Whether or not to force the fill function to run. (optional)
|
523 |
+
*
|
524 |
+
* @return void Void if Option to print out breadcrumb trail was chosen.
|
525 |
+
* @return string String-Data of breadcrumb trail.
|
526 |
+
*/
|
527 |
+
function bcn_display($return = false, $linked = true, $reverse = false, $force = false)
|
528 |
+
{
|
529 |
+
global $breadcrumb_navxt;
|
530 |
+
if($breadcrumb_navxt !== null)
|
531 |
+
{
|
532 |
+
return $breadcrumb_navxt->display($return, $linked, $reverse, $force);
|
533 |
+
}
|
534 |
+
}
|
535 |
+
/**
|
536 |
+
* Outputs the breadcrumb trail with each element encapsulated with li tags
|
537 |
+
*
|
538 |
+
* @param bool $return Whether to return or echo the trail. (optional)
|
539 |
+
* @param bool $linked Whether to allow hyperlinks in the trail or not. (optional)
|
540 |
+
* @param bool $reverse Whether to reverse the output or not. (optional)
|
541 |
+
* @param bool $force Whether or not to force the fill function to run. (optional)
|
542 |
+
*
|
543 |
+
* @return void Void if Option to print out breadcrumb trail was chosen.
|
544 |
+
* @return string String-Data of breadcrumb trail.
|
545 |
+
*/
|
546 |
+
function bcn_display_list($return = false, $linked = true, $reverse = false, $force = false)
|
547 |
+
{
|
548 |
+
global $breadcrumb_navxt;
|
549 |
+
if($breadcrumb_navxt !== null)
|
550 |
+
{
|
551 |
+
return $breadcrumb_navxt->display($return, $linked, $reverse, $force, "<li%3\$s>%1\$s</li>\n");
|
552 |
+
}
|
553 |
+
}
|
554 |
+
/**
|
555 |
+
* Outputs the breadcrumb trail in Schema.org BreadcrumbList compatible JSON-LD
|
556 |
+
*
|
557 |
+
* @param bool $return Whether to return or echo the trail. (optional)
|
558 |
+
* @param bool $reverse Whether to reverse the output or not. (optional)
|
559 |
+
* @param bool $force Whether or not to force the fill function to run. (optional)
|
560 |
+
*
|
561 |
+
* @return void Void if Option to print out breadcrumb trail was chosen.
|
562 |
+
* @return string String-Data of breadcrumb trail.
|
563 |
+
*/
|
564 |
+
function bcn_display_json_ld($return = false, $reverse = false, $force = false)
|
565 |
+
{
|
566 |
+
global $breadcrumb_navxt;
|
567 |
+
if($breadcrumb_navxt !== null)
|
568 |
+
{
|
569 |
+
return $breadcrumb_navxt->display_json_ld($return, $reverse, $force);
|
570 |
+
}
|
571 |
+
}
|
class.bcn_admin.php
CHANGED
@@ -1,774 +1,783 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
-
//Do a PHP version check, require 5.3 or newer
|
21 |
-
if(version_compare(phpversion(), '5.3.0', '<'))
|
22 |
-
{
|
23 |
-
//Only purpose of this function is to echo out the PHP version error
|
24 |
-
function bcn_phpold()
|
25 |
-
{
|
26 |
-
printf('<div class="notice notice-error"><p>' . __('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.3.0');
|
27 |
-
}
|
28 |
-
//If we are in the admin, let's print a warning then return
|
29 |
-
if(is_admin())
|
30 |
-
{
|
31 |
-
add_action('admin_notices', 'bcn_phpold');
|
32 |
-
}
|
33 |
-
return;
|
34 |
-
}
|
35 |
-
//Include admin base class
|
36 |
-
if(!class_exists('mtekk_adminKit'))
|
37 |
-
{
|
38 |
-
require_once(dirname(__FILE__) . '/includes/class.mtekk_adminkit.php');
|
39 |
-
}
|
40 |
-
/**
|
41 |
-
* The administrative interface class
|
42 |
-
*
|
43 |
-
*/
|
44 |
-
class bcn_admin extends mtekk_adminKit
|
45 |
-
{
|
46 |
-
const version = '6.0
|
47 |
-
protected $full_name = 'Breadcrumb NavXT Settings';
|
48 |
-
protected $short_name = 'Breadcrumb NavXT';
|
49 |
-
protected $access_level = 'manage_options';
|
50 |
-
protected $identifier = 'breadcrumb-navxt';
|
51 |
-
protected $unique_prefix = 'bcn';
|
52 |
-
protected $plugin_basename = null;
|
53 |
-
protected $support_url = '
|
54 |
-
protected $breadcrumb_trail = null;
|
55 |
-
/**
|
56 |
-
* Administrative interface class default constructor
|
57 |
-
*
|
58 |
-
* @param bcn_breadcrumb_trail $breadcrumb_trail a breadcrumb trail object
|
59 |
-
* @param string $basename The basename of the plugin
|
60 |
-
*/
|
61 |
-
function __construct(bcn_breadcrumb_trail &$breadcrumb_trail, $basename)
|
62 |
-
{
|
63 |
-
$this->breadcrumb_trail =& $breadcrumb_trail;
|
64 |
-
$this->plugin_basename = $basename;
|
65 |
-
$this->full_name = esc_html__('Breadcrumb NavXT Settings', 'breadcrumb-navxt');
|
66 |
-
//Grab defaults from the breadcrumb_trail object
|
67 |
-
$this->opt =& $this->breadcrumb_trail->opt;
|
68 |
-
//We're going to make sure we load the parent's constructor
|
69 |
-
parent::__construct();
|
70 |
-
}
|
71 |
-
/**
|
72 |
-
* admin initialization callback function
|
73 |
-
*
|
74 |
-
* is bound to wordpress action 'admin_init' on instantiation
|
75 |
-
*
|
76 |
-
* @since 3.2.0
|
77 |
-
* @return void
|
78 |
-
*/
|
79 |
-
function init()
|
80 |
-
{
|
81 |
-
//We're going to make sure we run the parent's version of this function as well
|
82 |
-
parent::init();
|
83 |
-
}
|
84 |
-
function wp_loaded()
|
85 |
-
{
|
86 |
-
parent::wp_loaded();
|
87 |
-
breadcrumb_navxt::setup_options($this->opt);
|
88 |
-
}
|
89 |
-
/**
|
90 |
-
* Sets hard constants into the options array
|
91 |
-
*
|
92 |
-
* @param &$opts The options array to set hard constants into
|
93 |
-
*/
|
94 |
-
function opts_fix(&$opts)
|
95 |
-
{
|
96 |
-
$opts['bpost_page_hierarchy_display'] = true;
|
97 |
-
$opts['Spost_page_hierarchy_type'] = 'BCN_POST_PARENT';
|
98 |
-
$opts['apost_page_root'] = get_option('page_on_front');
|
99 |
-
}
|
100 |
-
/**
|
101 |
-
* Upgrades input options array, sets to $this->opt
|
102 |
-
*
|
103 |
-
* @param array $opts
|
104 |
-
* @param string $version the version of the passed in options
|
105 |
-
*/
|
106 |
-
function opts_upgrade($opts, $version)
|
107 |
-
{
|
108 |
-
global $wp_post_types, $wp_taxonomies;
|
109 |
-
//If our version is not the same as in the db, time to update
|
110 |
-
if(version_compare($version, $this::version, '<'))
|
111 |
-
{
|
112 |
-
//Upgrading to 3.8.1
|
113 |
-
if(version_compare($version, '3.8.1', '<'))
|
114 |
-
{
|
115 |
-
$opts['post_page_root'] = $this->get_option('page_on_front');
|
116 |
-
$opts['post_post_root'] = $this->get_option('page_for_posts');
|
117 |
-
}
|
118 |
-
//Upgrading to 4.0
|
119 |
-
if(version_compare($version, '4.0.0', '<'))
|
120 |
-
{
|
121 |
-
//Only migrate if we haven't migrated yet
|
122 |
-
if(isset($opts['current_item_linked']))
|
123 |
-
{
|
124 |
-
//Loop through the old options, migrate some of them
|
125 |
-
foreach($opts as $option => $value)
|
126 |
-
{
|
127 |
-
//Handle all of our boolean options first, they're real easy, just add a 'b'
|
128 |
-
if(strpos($option, 'display') > 0 || $option == 'current_item_linked')
|
129 |
-
{
|
130 |
-
$this->breadcrumb_trail->opt['b' . $option] = $value;
|
131 |
-
}
|
132 |
-
//Handle migration of anchor templates to the templates
|
133 |
-
else if(strpos($option, 'anchor') > 0)
|
134 |
-
{
|
135 |
-
$parts = explode('_', $option);
|
136 |
-
//Do excess slash removal sanitation
|
137 |
-
$this->breadcrumb_trail->opt['H' . $parts[0] . '_template'] = $value . '%htitle%</a>';
|
138 |
-
}
|
139 |
-
//Handle our abs integers
|
140 |
-
else if($option == 'max_title_length' || $option == 'post_post_root' || $option == 'post_page_root')
|
141 |
-
{
|
142 |
-
$this->breadcrumb_trail->opt['a' . $option] = $value;
|
143 |
-
}
|
144 |
-
//Now everything else, minus prefix and suffix
|
145 |
-
else if(strpos($option, 'prefix') === false && strpos($option, 'suffix') === false)
|
146 |
-
{
|
147 |
-
$this->breadcrumb_trail->opt['S' . $option] = $value;
|
148 |
-
}
|
149 |
-
}
|
150 |
-
}
|
151 |
-
//Add in the new settings for CPTs introduced in 4.0
|
152 |
-
foreach($wp_post_types as $post_type)
|
153 |
-
{
|
154 |
-
//We only want custom post types
|
155 |
-
if(!$post_type->_builtin)
|
156 |
-
{
|
157 |
-
//Add in the archive_display option
|
158 |
-
$this->breadcrumb_trail->opt['bpost_' . $post_type->name . '_archive_display'] = $post_type->has_archive;
|
159 |
-
}
|
160 |
-
}
|
161 |
-
$opts = $this->breadcrumb_trail->opt;
|
162 |
-
}
|
163 |
-
if(version_compare($version, '4.0.1', '<'))
|
164 |
-
{
|
165 |
-
if(isset($opts['Hcurrent_item_template_no_anchor']))
|
166 |
-
{
|
167 |
-
unset($opts['Hcurrent_item_template_no_anchor']);
|
168 |
-
}
|
169 |
-
if(isset($opts['Hcurrent_item_template']))
|
170 |
-
{
|
171 |
-
unset($opts['Hcurrent_item_template']);
|
172 |
-
}
|
173 |
-
}
|
174 |
-
//Upgrading to 4.3.0
|
175 |
-
if(version_compare($version, '4.3.0', '<'))
|
176 |
-
{
|
177 |
-
//Removed home_title
|
178 |
-
if(isset($opts['Shome_title']))
|
179 |
-
{
|
180 |
-
unset($opts['Shome_title']);
|
181 |
-
}
|
182 |
-
//Removed mainsite_title
|
183 |
-
if(isset($opts['Smainsite_title']))
|
184 |
-
{
|
185 |
-
unset($opts['Smainsite_title']);
|
186 |
-
}
|
187 |
-
}
|
188 |
-
//Upgrading to 5.1.0
|
189 |
-
if(version_compare($version, '5.1.0', '<'))
|
190 |
-
{
|
191 |
-
foreach($wp_taxonomies as $taxonomy)
|
192 |
-
{
|
193 |
-
//If we have the old options style for it, update
|
194 |
-
if($taxonomy->name !== 'post_format' && isset($opts['H' . $taxonomy->name . '_template']))
|
195 |
-
{
|
196 |
-
//Migrate to the new setting name
|
197 |
-
$opts['Htax_' . $taxonomy->name . '_template'] = $opts['H' . $taxonomy->name . '_template'];
|
198 |
-
$opts['Htax_' . $taxonomy->name . '_template_no_anchor'] = $opts['H' . $taxonomy->name . '_template_no_anchor'];
|
199 |
-
//Clean up old settings
|
200 |
-
unset($opts['H' . $taxonomy->name . '_template']);
|
201 |
-
unset($opts['H' . $taxonomy->name . '_template_no_anchor']);
|
202 |
-
}
|
203 |
-
}
|
204 |
-
}
|
205 |
-
//Upgrading to 5.4.0
|
206 |
-
if(version_compare($version, '5.4.0', '<'))
|
207 |
-
{
|
208 |
-
//Migrate users to schema.org breadcrumbs for author and search if still on the defaults for posts
|
209 |
-
if($opts['Hpost_post_template'] === bcn_breadcrumb::get_default_template() && $opts['Hpost_post_template_no_anchor'] === bcn_breadcrumb::default_template_no_anchor)
|
210 |
-
{
|
211 |
-
if($opts['Hpaged_template'] === 'Page %htitle%')
|
212 |
-
{
|
213 |
-
$opts['Hpaged_template'] = $this->opt['Hpaged_template'];
|
214 |
-
}
|
215 |
-
if($opts['Hsearch_template'] === 'Search results for '<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'' || $opts['Hsearch_template'] === 'Search results for '<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'')
|
216 |
-
{
|
217 |
-
$opts['Hsearch_template'] = $this->opt['Hsearch_template'];
|
218 |
-
}
|
219 |
-
if($opts['Hsearch_template_no_anchor'] === 'Search results for '%htitle%'' || $opts['Hsearch_template_no_anchor'] === 'Search results for '%htitle%'')
|
220 |
-
{
|
221 |
-
$opts['Hsearch_template_no_anchor'] = $this->opt['Hsearch_template_no_anchor'];
|
222 |
-
}
|
223 |
-
if($opts['Hauthor_template'] === 'Articles by: <a title="Go to the first page of posts by %title%." href="%link%" class="%type%">%htitle%</a>')
|
224 |
-
{
|
225 |
-
$opts['Hauthor_template'] = $this->opt['Hauthor_template'];
|
226 |
-
}
|
227 |
-
if($opts['Hauthor_template_no_anchor'] === 'Articles by: %htitle%')
|
228 |
-
{
|
229 |
-
$opts['Hauthor_template_no_anchor'] = $this->opt['Hauthor_template_no_anchor'];
|
230 |
-
}
|
231 |
-
}
|
232 |
-
}
|
233 |
-
//Upgrading to 5.5.0
|
234 |
-
if(version_compare($version, '5.5.0', '<'))
|
235 |
-
{
|
236 |
-
//Translate the old 'page' taxonomy type to BCN_POST_PARENT
|
237 |
-
if($this->opt['Spost_post_taxonomy_type'] === 'page')
|
238 |
-
{
|
239 |
-
$this->opt['Spost_post_taxonomy_type'] = 'BCN_POST_PARENT';
|
240 |
-
}
|
241 |
-
if(!isset($this->opt['Spost_post_taxonomy_referer']))
|
242 |
-
{
|
243 |
-
$this->opt['bpost_post_taxonomy_referer'] = false;
|
244 |
-
}
|
245 |
-
//Loop through all of the post types in the array
|
246 |
-
foreach($wp_post_types as $post_type)
|
247 |
-
{
|
248 |
-
//Check for non-public CPTs
|
249 |
-
if(!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name))
|
250 |
-
{
|
251 |
-
continue;
|
252 |
-
}
|
253 |
-
//We only want custom post types
|
254 |
-
if(!$post_type->_builtin)
|
255 |
-
{
|
256 |
-
//Translate the old 'page' taxonomy type to BCN_POST_PARENT
|
257 |
-
if($this->opt['Spost_' . $post_type->name . '_taxonomy_type'] === 'page')
|
258 |
-
{
|
259 |
-
$this->opt['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_POST_PARENT';
|
260 |
-
}
|
261 |
-
//Translate the old 'date' taxonomy type to BCN_DATE
|
262 |
-
if($this->opt['Spost_' . $post_type->name . '_taxonomy_type'] === 'date')
|
263 |
-
{
|
264 |
-
$this->opt['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_DATE';
|
265 |
-
}
|
266 |
-
if(!isset($this->opt['Spost_' . $post_type->name . '_taxonomy_referer']))
|
267 |
-
{
|
268 |
-
$this->opt['bpost_' . $post_type->name . '_taxonomy_referer'] = false;
|
269 |
-
}
|
270 |
-
}
|
271 |
-
}
|
272 |
-
}
|
273 |
-
//Upgrading to 6.0.0
|
274 |
-
if(version_compare($version, '6.0.0', '<'))
|
275 |
-
{
|
276 |
-
//Loop through all of the post types in the array
|
277 |
-
foreach($wp_post_types as $post_type)
|
278 |
-
{
|
279 |
-
if(isset($this->opt['Spost_' . $post_type->name . '_taxonomy_type']))
|
280 |
-
{
|
281 |
-
$this->opt['Spost_' . $post_type->name . '_hierarchy_type'] = $this->opt['Spost_' . $post_type->name . '_taxonomy_type'];
|
282 |
-
unset($this->opt['Spost_' . $post_type->name . '_taxonomy_type']);
|
283 |
-
}
|
284 |
-
if(isset($this->opt['Spost_' . $post_type->name . '_taxonomy_display']))
|
285 |
-
{
|
286 |
-
$this->opt['Spost_' . $post_type->name . '_hierarchy_display'] = $this->opt['Spost_' . $post_type->name . '_taxonomy_display'];
|
287 |
-
unset($this->opt['Spost_' . $post_type->name . '_taxonomy_display']);
|
288 |
-
}
|
289 |
-
}
|
290 |
-
}
|
291 |
-
//Set the max title length to 20 if we are not limiting the title and the length was 0
|
292 |
-
if(!$opts['blimit_title'] && $opts['amax_title_length'] == 0)
|
293 |
-
{
|
294 |
-
$opts['amax_title_length'] = 20;
|
295 |
-
}
|
296 |
-
}
|
297 |
-
//Save the passed in opts to the object's option array
|
298 |
-
$this->opt = $opts;
|
299 |
-
//End with resetting up the options
|
300 |
-
breadcrumb_navxt::setup_options($this->opt);
|
301 |
-
}
|
302 |
-
function opts_update_prebk(&$opts)
|
303 |
-
{
|
304 |
-
//This may no longer be needed
|
305 |
-
breadcrumb_navxt::setup_options($opts);
|
306 |
-
$opts = apply_filters('bcn_opts_update_prebk', $opts);
|
307 |
-
}
|
308 |
-
/**
|
309 |
-
* help action hook function
|
310 |
-
*
|
311 |
-
* @return string
|
312 |
-
*
|
313 |
-
*/
|
314 |
-
function help()
|
315 |
-
{
|
316 |
-
$screen = get_current_screen();
|
317 |
-
//Exit early if the add_help_tab function doesn't exist
|
318 |
-
if(!method_exists($screen, 'add_help_tab'))
|
319 |
-
{
|
320 |
-
return;
|
321 |
-
}
|
322 |
-
//Add contextual help on current screen
|
323 |
-
if($screen->id == 'settings_page_' . $this->identifier)
|
324 |
-
{
|
325 |
-
$general_tab = '<p>' . esc_html__('Tips for the settings are located below select options.', 'breadcrumb-navxt') .
|
326 |
-
'</p><h5>' . esc_html__('Resources', 'breadcrumb-navxt') . '</h5><ul><li>' .
|
327 |
-
sprintf(esc_html__("%sTutorials and How Tos%s: There are several guides, tutorials, and how tos available on the author's website.", 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to the Breadcrumb NavXT tag archive.', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/tag/breadcrumb-navxt">', '</a>') . '</li><li>' .
|
328 |
-
sprintf(esc_html__('%sOnline Documentation%s: Check out the documentation for more indepth technical information.', 'breadcrumb-navxt'), '<a title="' . esc_attr__('Go to the Breadcrumb NavXT online documentation', 'breadcrumb-navxt') . '" href="https://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/">', '</a>') . '</li><li>' .
|
329 |
-
sprintf(esc_html__('%sReport a Bug%s: If you think you have found a bug, please include your WordPress version and details on how to reproduce the bug.', 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to the Breadcrumb NavXT support post for your version.', 'breadcrumb-navxt') . '" href="https://
|
330 |
-
'<h5>' . esc_html__('Giving Back', 'breadcrumb-navxt') . '</h5><ul><li>' .
|
331 |
-
sprintf(esc_html__('%sDonate%s: Love Breadcrumb NavXT and want to help development? Consider buying the author a beer.', 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to PayPal to give a donation to Breadcrumb NavXT.', 'breadcrumb-navxt') . '" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=FD5XEU783BR8U&lc=US&item_name=Breadcrumb%20NavXT%20Donation¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">', '</a>') . '</li><li>' .
|
332 |
-
sprintf(esc_html__('%sTranslate%s: Is your language not available? Visit the Breadcrumb NavXT translation project on WordPress.org to start translating.', 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to the Breadcrumb NavXT translation project.', 'breadcrumb-navxt') . '" href="https://translate.wordpress.org/projects/wp-plugins/breadcrumb-navxt">', '</a>') . '</li></ul>';
|
333 |
-
|
334 |
-
$screen->add_help_tab(
|
335 |
-
array(
|
336 |
-
'id' => $this->identifier . '-base',
|
337 |
-
'title' => __('General', 'breadcrumb-navxt'),
|
338 |
-
'content' => $general_tab
|
339 |
-
));
|
340 |
-
$quickstart_tab = '<p>' . esc_html__('For the settings on this page to take effect, you must either use the included Breadcrumb NavXT widget, or place either of the code sections below into your theme.', 'breadcrumb-navxt') .
|
341 |
-
'</p><h5>' . esc_html__('Breadcrumb trail with separators', 'breadcrumb-navxt') . '</h5><pre><code><div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">' . "
|
342 |
-
<?php if(function_exists('bcn_display'))
|
343 |
-
{
|
344 |
-
bcn_display();
|
345 |
-
}?>
|
346 |
-
</div></code></pre>" .
|
347 |
-
'<h5>' . esc_html__('Breadcrumb trail in list form', 'breadcrumb-navxt').'</h5><pre><code><ol class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">'."
|
348 |
-
<?php if(function_exists('bcn_display_list'))
|
349 |
-
{
|
350 |
-
bcn_display_list();
|
351 |
-
}?>
|
352 |
-
</ol></code></pre>";
|
353 |
-
$screen->add_help_tab(
|
354 |
-
array(
|
355 |
-
'id' => $this->identifier . '-quick-start',
|
356 |
-
'title' => __('Quick Start', 'breadcrumb-navxt'),
|
357 |
-
'content' => $quickstart_tab
|
358 |
-
));
|
359 |
-
$styling_tab = '<p>' . esc_html__('Using the code from the Quick Start section above, the following CSS can be used as base for styling your breadcrumb trail.', 'breadcrumb-navxt') . '</p>' .
|
360 |
-
'<pre><code>.breadcrumbs
|
361 |
-
{
|
362 |
-
font-size: 1.1em;
|
363 |
-
color: #fff;
|
364 |
-
margin: 30px 0 0 10px;
|
365 |
-
position: relative;
|
366 |
-
float: left;
|
367 |
-
}</code></pre>';
|
368 |
-
$screen->add_help_tab(
|
369 |
-
array(
|
370 |
-
'id' => $this->identifier . '-styling',
|
371 |
-
'title' => __('Styling', 'breadcrumb-navxt'),
|
372 |
-
'content' => $styling_tab
|
373 |
-
));
|
374 |
-
$screen->add_help_tab(
|
375 |
-
array(
|
376 |
-
'id' => $this->identifier . '-import-export-reset',
|
377 |
-
'title' => __('Import/Export/Reset', 'breadcrumb-navxt'),
|
378 |
-
'content' => $this->import_form()
|
379 |
-
));
|
380 |
-
}
|
381 |
-
}
|
382 |
-
/**
|
383 |
-
* enqueue's the tab style sheet on the settings page
|
384 |
-
*/
|
385 |
-
function admin_styles()
|
386 |
-
{
|
387 |
-
wp_enqueue_style('mtekk_adminkit_tabs');
|
388 |
-
}
|
389 |
-
/**
|
390 |
-
* enqueue's the tab js and translation js on the settings page
|
391 |
-
*/
|
392 |
-
function admin_scripts()
|
393 |
-
{
|
394 |
-
//Enqueue ui-tabs
|
395 |
-
wp_enqueue_script('jquery-ui-tabs');
|
396 |
-
//Enqueue the admin tabs javascript
|
397 |
-
wp_enqueue_script('mtekk_adminkit_tabs');
|
398 |
-
//Load the translations for the tabs
|
399 |
-
wp_localize_script('mtekk_adminkit_tabs', 'objectL10n', array(
|
400 |
-
'mtad_uid' => 'bcn_admin',
|
401 |
-
'mtad_import' => __('Import', 'breadcrumb-navxt'),
|
402 |
-
'mtad_export' => __('Export', 'breadcrumb-navxt'),
|
403 |
-
'mtad_reset' => __('Reset', 'breadcrumb-navxt'),
|
404 |
-
));
|
405 |
-
//Enqueue the admin enable/disable groups javascript
|
406 |
-
wp_enqueue_script('mtekk_adminkit_engroups');
|
407 |
-
}
|
408 |
-
/**
|
409 |
-
* A message function that checks for the BCN_SETTINGS_* define statement
|
410 |
-
*/
|
411 |
-
function multisite_settings_warn()
|
412 |
-
{
|
413 |
-
if(is_multisite())
|
414 |
-
{
|
415 |
-
if(defined('BCN_SETTINGS_USE_LOCAL') && BCN_SETTINGS_USE_LOCAL)
|
416 |
-
{
|
417 |
-
|
418 |
-
}
|
419 |
-
else if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK)
|
420 |
-
{
|
421 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Your network settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nsiteoveride');
|
422 |
-
}
|
423 |
-
else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL)
|
424 |
-
{
|
425 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Your network settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_isitemayoveride');
|
426 |
-
}
|
427 |
-
else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK)
|
428 |
-
{
|
429 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Your network settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nsitemayoveride');
|
430 |
-
}
|
431 |
-
//Fall through if no settings mode was set
|
432 |
-
else
|
433 |
-
{
|
434 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: No BCN_SETTINGS_* define statement found, defaulting to BCN_SETTINGS_USE_LOCAL.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nosetting');
|
435 |
-
}
|
436 |
-
}
|
437 |
-
}
|
438 |
-
/**
|
439 |
-
* A message function that checks for deprecated settings that are set and warns the user
|
440 |
-
*/
|
441 |
-
function deprecated_settings_warn()
|
442 |
-
{
|
443 |
-
//We're deprecating the limit title length setting, let the user know the new method of accomplishing this
|
444 |
-
if(isset($this->opt['blimit_title']) && $this->opt['blimit_title'])
|
445 |
-
{
|
446 |
-
$this->messages[] = new mtekk_adminKit_message(sprintf(esc_html__('Warning: Your are using a deprecated setting "Title Length" (see Miscellaneous > Deprecated), please %1$suse CSS instead%2$s.', 'breadcrumb-navxt'), '<a title="' . __('Go to the guide on trimming breadcrumb title lengths with CSS', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/guides/trimming-breadcrumb-title-lengths-with-css/">', '</a>'), 'warning');
|
447 |
-
}
|
448 |
-
}
|
449 |
-
/**
|
450 |
-
* Function checks the current site to see if the blog options should be disabled
|
451 |
-
*
|
452 |
-
* @return boool Whether or not the blog options should be disabled
|
453 |
-
*/
|
454 |
-
function maybe_disable_blog_options()
|
455 |
-
{
|
456 |
-
return (get_option('show_on_front') !== 'page' || get_option('page_for_posts') < 1);
|
457 |
-
}
|
458 |
-
/**
|
459 |
-
* Function checks the current site to see if the mainsite options should be disabled
|
460 |
-
*
|
461 |
-
* @return bool Whether or not the mainsite options should be disabled
|
462 |
-
*/
|
463 |
-
function maybe_disable_mainsite_options()
|
464 |
-
{
|
465 |
-
return !is_multisite();
|
466 |
-
}
|
467 |
-
/**
|
468 |
-
* The administrative page for Breadcrumb NavXT
|
469 |
-
*/
|
470 |
-
function admin_page()
|
471 |
-
{
|
472 |
-
global $wp_taxonomies, $wp_post_types;
|
473 |
-
$this->security();
|
474 |
-
//Do a check on deprecated settings
|
475 |
-
$this->deprecated_settings_warn();
|
476 |
-
//Do a check for multisite settings mode
|
477 |
-
$this->multisite_settings_warn();
|
478 |
-
do_action($this->unique_prefix . '_settings_pre_messages', $this->opt);
|
479 |
-
//Display our messages
|
480 |
-
$this->messages();
|
481 |
-
?>
|
482 |
-
<div class="wrap"><h2><?php echo $this->full_name; ?></h2>
|
483 |
-
<?php
|
484 |
-
//We exit after the version check if there is an action the user needs to take before saving settings
|
485 |
-
if(!$this->version_check($this->get_option($this->unique_prefix . '_version')))
|
486 |
-
{
|
487 |
-
return;
|
488 |
-
}
|
489 |
-
?>
|
490 |
-
<form action="<?php echo $this->admin_url(); ?>" method="post" id="bcn_admin-options">
|
491 |
-
<?php settings_fields('bcn_options');?>
|
492 |
-
<div id="hasadmintabs">
|
493 |
-
<fieldset id="general" class="bcn_options">
|
494 |
-
<h3 class="tab-title" title="<?php _e('A collection of settings most likely to be modified are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('General', 'breadcrumb-navxt'); ?></h3>
|
495 |
-
<h3><?php _e('General', 'breadcrumb-navxt'); ?></h3>
|
496 |
-
<table class="form-table">
|
497 |
-
<?php
|
498 |
-
$this->textbox(__('Breadcrumb Separator', 'breadcrumb-navxt'), 'hseparator', '2', false, __('Placed in between each breadcrumb.', 'breadcrumb-navxt'));
|
499 |
-
do_action($this->unique_prefix . '_settings_general', $this->opt);
|
500 |
-
?>
|
501 |
-
</table>
|
502 |
-
<h3><?php _e('Current Item', 'breadcrumb-navxt'); ?></h3>
|
503 |
-
<table class="form-table adminkit-enset-top">
|
504 |
-
<?php
|
505 |
-
$this->input_check(__('Link Current Item', 'breadcrumb-navxt'), 'bcurrent_item_linked', __('Yes', 'breadcrumb-navxt'));
|
506 |
-
$this->input_check(_x('Paged Breadcrumb', 'Paged as in when on an archive or post that is split into multiple pages', 'breadcrumb-navxt'), 'bpaged_display', __('Place the page number breadcrumb in the trail.', 'breadcrumb-navxt'), false, __('Indicates that the user is on a page other than the first of a paginated archive or post.', 'breadcrumb-navxt'), 'adminkit-enset-ctrl adminkit-enset');
|
507 |
-
$this->textbox(_x('Paged Template', 'Paged as in when on an archive or post that is split into multiple pages', 'breadcrumb-navxt'), 'Hpaged_template', '4', false, __('The template for paged breadcrumbs.', 'breadcrumb-navxt'), 'adminkit-enset');
|
508 |
-
do_action($this->unique_prefix . '_settings_current_item', $this->opt);
|
509 |
-
?>
|
510 |
-
</table>
|
511 |
-
<h3><?php _e('Home Breadcrumb', 'breadcrumb-navxt'); ?></h3>
|
512 |
-
<table class="form-table adminkit-enset-top">
|
513 |
-
<?php
|
514 |
-
$this->input_check(__('Home Breadcrumb', 'breadcrumb-navxt'), 'bhome_display', __('Place the home breadcrumb in the trail.', 'breadcrumb-navxt'), false, '', 'adminkit-enset-ctrl adminkit-enset');
|
515 |
-
$this->textbox(__('Home Template', 'breadcrumb-navxt'), 'Hhome_template', '6', false, __('The template for the home breadcrumb.', 'breadcrumb-navxt'), 'adminkit-enset');
|
516 |
-
$this->textbox(__('Home Template (Unlinked)', 'breadcrumb-navxt'), 'Hhome_template_no_anchor', '4', false, __('The template for the home breadcrumb, used when the breadcrumb is not linked.', 'breadcrumb-navxt'), 'adminkit-enset');
|
517 |
-
do_action($this->unique_prefix . '_settings_home', $this->opt);
|
518 |
-
?>
|
519 |
-
</table>
|
520 |
-
<h3><?php _e('Blog Breadcrumb', 'breadcrumb-navxt'); ?></h3>
|
521 |
-
<table class="form-table adminkit-enset-top">
|
522 |
-
<?php
|
523 |
-
$this->input_check(__('Blog Breadcrumb', 'breadcrumb-navxt'), 'bblog_display', __('Place the blog breadcrumb in the trail.', 'breadcrumb-navxt'), $this->maybe_disable_blog_options(), '', 'adminkit-enset-ctrl adminkit-enset');
|
524 |
-
do_action($this->unique_prefix . '_settings_blog', $this->opt);
|
525 |
-
?>
|
526 |
-
</table>
|
527 |
-
<h3><?php _e('Mainsite Breadcrumb', 'breadcrumb-navxt'); ?></h3>
|
528 |
-
<table class="form-table adminkit-enset-top">
|
529 |
-
<?php
|
530 |
-
$this->input_check(__('Main Site Breadcrumb', 'breadcrumb-navxt'), 'bmainsite_display', __('Place the main site home breadcrumb in the trail in an multisite setup.', 'breadcrumb-navxt'), $this->maybe_disable_mainsite_options(), '', 'adminkit-enset-ctrl adminkit-enset');
|
531 |
-
$this->textbox(__('Main Site Home Template', 'breadcrumb-navxt'), 'Hmainsite_template', '6', $this->maybe_disable_mainsite_options(), __('The template for the main site home breadcrumb, used only in multisite environments.', 'breadcrumb-navxt'), 'adminkit-enset');
|
532 |
-
$this->textbox(__('Main Site Home Template (Unlinked)', 'breadcrumb-navxt'), 'Hmainsite_template_no_anchor', '4', $this->maybe_disable_mainsite_options(), __('The template for the main site home breadcrumb, used only in multisite environments and when the breadcrumb is not linked.', 'breadcrumb-navxt'), 'adminkit-enset');
|
533 |
-
do_action($this->unique_prefix . '_settings_mainsite', $this->opt);
|
534 |
-
?>
|
535 |
-
</table>
|
536 |
-
<?php do_action($this->unique_prefix . '_after_settings_tab_general', $this->opt); ?>
|
537 |
-
</fieldset>
|
538 |
-
<fieldset id="post" class="bcn_options">
|
539 |
-
<h3 class="tab-title" title="<?php _e('The settings for all post types (Posts, Pages, and Custom Post Types) are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('Post Types', 'breadcrumb-navxt'); ?></h3>
|
540 |
-
<h3><?php _e('Posts', 'breadcrumb-navxt'); ?></h3>
|
541 |
-
<table class="form-table adminkit-enset-top">
|
542 |
-
<?php
|
543 |
-
$this->textbox(__('Post Template', 'breadcrumb-navxt'), 'Hpost_post_template', '6', false, __('The template for post breadcrumbs.', 'breadcrumb-navxt'));
|
544 |
-
$this->textbox(__('Post Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_post_template_no_anchor', '4', false, __('The template for post breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
545 |
-
$this->input_check(__('Post Hierarchy Display', 'breadcrumb-navxt'), 'bpost_post_hierarchy_display', __('Show the hierarchy (specified below) leading to a post in the breadcrumb trail.', 'breadcrumb-navxt'), false, '', 'adminkit-enset-ctrl adminkit-enset');
|
546 |
-
$this->input_check(__('Post Hierarchy Referer Influence', 'breadcrumb-navxt'), 'bpost_post_taxonomy_referer', __('Allow the referring page to influence the taxonomy selected for the hierarchy.', 'breadcrumb-navxt'), false, '', 'adminkit-enset');
|
547 |
-
?>
|
548 |
-
<tr valign="top">
|
549 |
-
<th scope="row">
|
550 |
-
<?php _e('Post Hierarchy', 'breadcrumb-navxt'); ?>
|
551 |
-
</th>
|
552 |
-
<td>
|
553 |
-
<?php
|
554 |
-
$this->input_radio('Spost_post_hierarchy_type', 'category', __('Categories'), false, 'adminkit-enset');
|
555 |
-
$this->input_radio('Spost_post_hierarchy_type', 'BCN_DATE', __('Dates', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
556 |
-
$this->input_radio('Spost_post_hierarchy_type', 'post_tag', __('Tags'), false, 'adminkit-enset');
|
557 |
-
//We use the value 'page' but really, this will follow the parent post hierarchy
|
558 |
-
$this->input_radio('Spost_post_hierarchy_type', 'BCN_POST_PARENT', __('Post Parent', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
559 |
-
//Loop through all of the taxonomies in the array
|
560 |
-
foreach($wp_taxonomies as $taxonomy)
|
561 |
-
{
|
562 |
-
//Check for non-public taxonomies
|
563 |
-
if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, 'post'))
|
564 |
-
{
|
565 |
-
continue;
|
566 |
-
}
|
567 |
-
//We only want custom taxonomies
|
568 |
-
if(($taxonomy->object_type == 'post' || is_array($taxonomy->object_type) && in_array('post', $taxonomy->object_type)) && !$taxonomy->_builtin)
|
569 |
-
{
|
570 |
-
$this->input_radio('Spost_post_hierarchy_type', $taxonomy->name, mb_convert_case($taxonomy->label, MB_CASE_TITLE, 'UTF-8'), false, 'adminkit-enset');
|
571 |
-
}
|
572 |
-
}
|
573 |
-
?>
|
574 |
-
<p class="description"><?php esc_html_e('The hierarchy which the breadcrumb trail will show. Note that the "Post Parent" option may require an additional plugin to behave as expected since this is a non-hierarchical post type.', 'breadcrumb-navxt'); ?></p>
|
575 |
-
</td>
|
576 |
-
</tr>
|
577 |
-
</table>
|
578 |
-
<h3><?php _e('Pages', 'breadcrumb-navxt'); ?></h3>
|
579 |
-
<table class="form-table">
|
580 |
-
<?php
|
581 |
-
$this->textbox(__('Page Template', 'breadcrumb-navxt'), 'Hpost_page_template', '6', false, __('The template for page breadcrumbs.', 'breadcrumb-navxt'));
|
582 |
-
$this->textbox(__('Page Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_page_template_no_anchor', '4', false, __('The template for page breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
583 |
-
$this->input_hidden('bpost_page_hierarchy_display');
|
584 |
-
$this->input_hidden('Spost_page_hierarchy_type');
|
585 |
-
?>
|
586 |
-
</table>
|
587 |
-
<h3><?php _e('Attachments', 'breadcrumb-navxt'); ?></h3>
|
588 |
-
<table class="form-table">
|
589 |
-
<?php
|
590 |
-
$this->textbox(__('Attachment Template', 'breadcrumb-navxt'), 'Hpost_attachment_template', '6', false, __('The template for attachment breadcrumbs.', 'breadcrumb-navxt'));
|
591 |
-
$this->textbox(__('Attachment Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_attachment_template_no_anchor', '4', false, __('The template for attachment breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
592 |
-
?>
|
593 |
-
</table>
|
594 |
-
<?php
|
595 |
-
//Loop through all of the post types in the array
|
596 |
-
foreach($wp_post_types as $post_type)
|
597 |
-
{
|
598 |
-
//Check for non-public CPTs
|
599 |
-
if(!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name))
|
600 |
-
{
|
601 |
-
continue;
|
602 |
-
}
|
603 |
-
//We only want custom post types
|
604 |
-
if(!$post_type->_builtin)
|
605 |
-
{
|
606 |
-
$singular_name_lc = mb_strtolower($post_type->labels->singular_name, 'UTF-8');
|
607 |
-
?>
|
608 |
-
<h3><?php echo $post_type->labels->singular_name; ?></h3>
|
609 |
-
<table class="form-table adminkit-enset-top">
|
610 |
-
<?php
|
611 |
-
$this->textbox(sprintf(__('%s Template', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'Hpost_' . $post_type->name . '_template', '6', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt'), $singular_name_lc));
|
612 |
-
$this->textbox(sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'Hpost_' . $post_type->name . '_template_no_anchor', '4', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'), $singular_name_lc));
|
613 |
-
$optid = mtekk_adminKit::get_valid_id('apost_' . $post_type->name . '_root');
|
614 |
-
?>
|
615 |
-
<tr valign="top">
|
616 |
-
<th scope="row">
|
617 |
-
<label for="<?php echo $optid;?>"><?php printf(esc_html__('%s Root Page', 'breadcrumb-navxt'), $post_type->labels->singular_name);?></label>
|
618 |
-
</th>
|
619 |
-
<td>
|
620 |
-
<?php wp_dropdown_pages(array('name' => $this->unique_prefix . '_options[apost_' . $post_type->name . '_root]', 'id' => $optid, 'echo' => 1, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => $this->opt['apost_' . $post_type->name . '_root']));?>
|
621 |
-
</td>
|
622 |
-
</tr>
|
623 |
-
<?php
|
624 |
-
$this->input_check(sprintf(__('%s Archive Display', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'bpost_' . $post_type->name . '_archive_display', sprintf(__('Show the breadcrumb for the %s post type archives in the breadcrumb trail.', 'breadcrumb-navxt'), $singular_name_lc), !$post_type->has_archive);
|
625 |
-
$this->input_check(sprintf(__('%s Hierarchy Display', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'bpost_' . $post_type->name . '_hierarchy_display', sprintf(__('Show the hierarchy (specified below) leading to a %s in the breadcrumb trail.', 'breadcrumb-navxt'), $singular_name_lc), false, '', 'adminkit-enset-ctrl adminkit-enset');
|
626 |
-
$this->input_check(sprintf(__('%s Hierarchy Referer Influence', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'bpost_' . $post_type->name . '_taxonomy_referer', __('Allow the referring page to influence the taxonomy selected for the hierarchy.', 'breadcrumb-navxt'), false, '', 'adminkit-enset');
|
627 |
-
?>
|
628 |
-
<tr valign="top">
|
629 |
-
<th scope="row">
|
630 |
-
<?php printf(__('%s Hierarchy', 'breadcrumb-navxt'), $post_type->labels->singular_name); ?>
|
631 |
-
</th>
|
632 |
-
<td>
|
633 |
-
<?php
|
634 |
-
//We use the value 'page' but really, this will follow the parent post hierarchy
|
635 |
-
$this->input_radio('Spost_' . $post_type->name . '_hierarchy_type', 'BCN_POST_PARENT', __('Post Parent', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
636 |
-
$this->input_radio('Spost_' . $post_type->name . '_hierarchy_type', 'BCN_DATE', __('Dates', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
637 |
-
//Loop through all of the taxonomies in the array
|
638 |
-
foreach($wp_taxonomies as $taxonomy)
|
639 |
-
{
|
640 |
-
//Check for non-public taxonomies
|
641 |
-
if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, $post_type->name))
|
642 |
-
{
|
643 |
-
continue;
|
644 |
-
}
|
645 |
-
//We only want custom taxonomies
|
646 |
-
if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type))
|
647 |
-
{
|
648 |
-
$this->input_radio('Spost_' . $post_type->name . '_hierarchy_type', $taxonomy->name, $taxonomy->labels->singular_name, false, 'adminkit-enset');
|
649 |
-
}
|
650 |
-
}
|
651 |
-
?>
|
652 |
-
<p class="description">
|
653 |
-
<?php
|
654 |
-
if($post_type->hierarchical)
|
655 |
-
{
|
656 |
-
esc_html_e('The hierarchy which the breadcrumb trail will show.', 'breadcrumb-navxt');
|
657 |
-
}
|
658 |
-
else
|
659 |
-
{
|
660 |
-
esc_html_e('The hierarchy which the breadcrumb trail will show. Note that the "Post Parent" option may require an additional plugin to behave as expected since this is a non-hierarchical post type.', 'breadcrumb-navxt');
|
661 |
-
}
|
662 |
-
?>
|
663 |
-
</p>
|
664 |
-
</td>
|
665 |
-
</tr>
|
666 |
-
</table>
|
667 |
-
<?php
|
668 |
-
}
|
669 |
-
}
|
670 |
-
do_action($this->unique_prefix . '_after_settings_tab_post', $this->opt);
|
671 |
-
?>
|
672 |
-
</fieldset>
|
673 |
-
<fieldset id="tax" class="bcn_options alttab">
|
674 |
-
<h3 class="tab-title" title="<?php _e('The settings for all taxonomies (including Categories, Tags, and custom taxonomies) are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('Taxonomies', 'breadcrumb-navxt'); ?></h3>
|
675 |
-
<h3><?php _e('Categories', 'breadcrumb-navxt'); ?></h3>
|
676 |
-
<table class="form-table">
|
677 |
-
<?php
|
678 |
-
$this->textbox(__('Category Template', 'breadcrumb-navxt'), 'Htax_category_template', '6', false, __('The template for category breadcrumbs.', 'breadcrumb-navxt'));
|
679 |
-
$this->textbox(__('Category Template (Unlinked)', 'breadcrumb-navxt'), 'Htax_category_template_no_anchor', '4', false, __('The template for category breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
680 |
-
?>
|
681 |
-
</table>
|
682 |
-
<h3><?php _e('Tags', 'breadcrumb-navxt'); ?></h3>
|
683 |
-
<table class="form-table">
|
684 |
-
<?php
|
685 |
-
$this->textbox(__('Tag Template', 'breadcrumb-navxt'), 'Htax_post_tag_template', '6', false, __('The template for tag breadcrumbs.', 'breadcrumb-navxt'));
|
686 |
-
$this->textbox(__('Tag Template (Unlinked)', 'breadcrumb-navxt'), 'Htax_post_tag_template_no_anchor', '4', false, __('The template for tag breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
687 |
-
?>
|
688 |
-
</table>
|
689 |
-
<h3><?php _e('Post Formats', 'breadcrumb-navxt'); ?></h3>
|
690 |
-
<table class="form-table">
|
691 |
-
<?php
|
692 |
-
$this->textbox(__('Post Format Template', 'breadcrumb-navxt'), 'Htax_post_format_template', '6', false, __('The template for post format breadcrumbs.', 'breadcrumb-navxt'));
|
693 |
-
$this->textbox(__('Post Format Template (Unlinked)', 'breadcrumb-navxt'), 'Htax_post_format_template_no_anchor', '4', false, __('The template for post_format breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
694 |
-
?>
|
695 |
-
</table>
|
696 |
-
<?php
|
697 |
-
//Loop through all of the taxonomies in the array
|
698 |
-
foreach($wp_taxonomies as $taxonomy)
|
699 |
-
{
|
700 |
-
//Check for non-public taxonomies
|
701 |
-
if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, null))
|
702 |
-
{
|
703 |
-
continue;
|
704 |
-
}
|
705 |
-
//We only want custom taxonomies
|
706 |
-
if(!$taxonomy->_builtin)
|
707 |
-
{
|
708 |
-
$label_lc = mb_strtolower($taxonomy->label, 'UTF-8');
|
709 |
-
?>
|
710 |
-
<h3><?php echo mb_convert_case($taxonomy->label, MB_CASE_TITLE, 'UTF-8'); ?></h3>
|
711 |
-
<table class="form-table">
|
712 |
-
<?php
|
713 |
-
$this->textbox(sprintf(__('%s Template', 'breadcrumb-navxt'), $taxonomy->labels->singular_name), 'Htax_' . $taxonomy->name . '_template', '6', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt'), $label_lc));
|
714 |
-
$this->textbox(sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $taxonomy->labels->singular_name), 'Htax_' . $taxonomy->name . '_template_no_anchor', '4', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'), $label_lc));
|
715 |
-
?>
|
716 |
-
</table>
|
717 |
-
<?php
|
718 |
-
}
|
719 |
-
}
|
720 |
-
do_action($this->unique_prefix . '_after_settings_tab_taxonomy', $this->opt); ?>
|
721 |
-
</fieldset>
|
722 |
-
<fieldset id="miscellaneous" class="bcn_options">
|
723 |
-
<h3 class="tab-title" title="<?php _e('The settings for author and date archives, searches, and 404 pages are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('Miscellaneous', 'breadcrumb-navxt'); ?></h3>
|
724 |
-
<h3><?php _e('Author Archives', 'breadcrumb-navxt'); ?></h3>
|
725 |
-
<table class="form-table">
|
726 |
-
<?php
|
727 |
-
$this->textbox(__('Author Template', 'breadcrumb-navxt'), 'Hauthor_template', '6', false, __('The template for author breadcrumbs.', 'breadcrumb-navxt'));
|
728 |
-
$this->textbox(__('Author Template (Unlinked)', 'breadcrumb-navxt'), 'Hauthor_template_no_anchor', '4', false, __('The template for author breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
729 |
-
$this->input_select(__('Author Display Format', 'breadcrumb-navxt'), 'Sauthor_name', array("display_name", "nickname", "first_name", "last_name"), false, __('display_name uses the name specified in "Display name publicly as" under the user profile the others correspond to options in the user profile.', 'breadcrumb-navxt'));
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
774 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
+
//Do a PHP version check, require 5.3 or newer
|
21 |
+
if(version_compare(phpversion(), '5.3.0', '<'))
|
22 |
+
{
|
23 |
+
//Only purpose of this function is to echo out the PHP version error
|
24 |
+
function bcn_phpold()
|
25 |
+
{
|
26 |
+
printf('<div class="notice notice-error"><p>' . __('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.3.0');
|
27 |
+
}
|
28 |
+
//If we are in the admin, let's print a warning then return
|
29 |
+
if(is_admin())
|
30 |
+
{
|
31 |
+
add_action('admin_notices', 'bcn_phpold');
|
32 |
+
}
|
33 |
+
return;
|
34 |
+
}
|
35 |
+
//Include admin base class
|
36 |
+
if(!class_exists('mtekk_adminKit'))
|
37 |
+
{
|
38 |
+
require_once(dirname(__FILE__) . '/includes/class.mtekk_adminkit.php');
|
39 |
+
}
|
40 |
+
/**
|
41 |
+
* The administrative interface class
|
42 |
+
*
|
43 |
+
*/
|
44 |
+
class bcn_admin extends mtekk_adminKit
|
45 |
+
{
|
46 |
+
const version = '6.1.0';
|
47 |
+
protected $full_name = 'Breadcrumb NavXT Settings';
|
48 |
+
protected $short_name = 'Breadcrumb NavXT';
|
49 |
+
protected $access_level = 'manage_options';
|
50 |
+
protected $identifier = 'breadcrumb-navxt';
|
51 |
+
protected $unique_prefix = 'bcn';
|
52 |
+
protected $plugin_basename = null;
|
53 |
+
protected $support_url = 'https://wordpress.org/support/plugin/breadcrumb-navxt/';
|
54 |
+
protected $breadcrumb_trail = null;
|
55 |
+
/**
|
56 |
+
* Administrative interface class default constructor
|
57 |
+
*
|
58 |
+
* @param bcn_breadcrumb_trail $breadcrumb_trail a breadcrumb trail object
|
59 |
+
* @param string $basename The basename of the plugin
|
60 |
+
*/
|
61 |
+
function __construct(bcn_breadcrumb_trail &$breadcrumb_trail, $basename)
|
62 |
+
{
|
63 |
+
$this->breadcrumb_trail =& $breadcrumb_trail;
|
64 |
+
$this->plugin_basename = $basename;
|
65 |
+
$this->full_name = esc_html__('Breadcrumb NavXT Settings', 'breadcrumb-navxt');
|
66 |
+
//Grab defaults from the breadcrumb_trail object
|
67 |
+
$this->opt =& $this->breadcrumb_trail->opt;
|
68 |
+
//We're going to make sure we load the parent's constructor
|
69 |
+
parent::__construct();
|
70 |
+
}
|
71 |
+
/**
|
72 |
+
* admin initialization callback function
|
73 |
+
*
|
74 |
+
* is bound to wordpress action 'admin_init' on instantiation
|
75 |
+
*
|
76 |
+
* @since 3.2.0
|
77 |
+
* @return void
|
78 |
+
*/
|
79 |
+
function init()
|
80 |
+
{
|
81 |
+
//We're going to make sure we run the parent's version of this function as well
|
82 |
+
parent::init();
|
83 |
+
}
|
84 |
+
function wp_loaded()
|
85 |
+
{
|
86 |
+
parent::wp_loaded();
|
87 |
+
breadcrumb_navxt::setup_options($this->opt);
|
88 |
+
}
|
89 |
+
/**
|
90 |
+
* Sets hard constants into the options array
|
91 |
+
*
|
92 |
+
* @param &$opts The options array to set hard constants into
|
93 |
+
*/
|
94 |
+
function opts_fix(&$opts)
|
95 |
+
{
|
96 |
+
$opts['bpost_page_hierarchy_display'] = true;
|
97 |
+
$opts['Spost_page_hierarchy_type'] = 'BCN_POST_PARENT';
|
98 |
+
$opts['apost_page_root'] = get_option('page_on_front');
|
99 |
+
}
|
100 |
+
/**
|
101 |
+
* Upgrades input options array, sets to $this->opt
|
102 |
+
*
|
103 |
+
* @param array $opts
|
104 |
+
* @param string $version the version of the passed in options
|
105 |
+
*/
|
106 |
+
function opts_upgrade($opts, $version)
|
107 |
+
{
|
108 |
+
global $wp_post_types, $wp_taxonomies;
|
109 |
+
//If our version is not the same as in the db, time to update
|
110 |
+
if(version_compare($version, $this::version, '<'))
|
111 |
+
{
|
112 |
+
//Upgrading to 3.8.1
|
113 |
+
if(version_compare($version, '3.8.1', '<'))
|
114 |
+
{
|
115 |
+
$opts['post_page_root'] = $this->get_option('page_on_front');
|
116 |
+
$opts['post_post_root'] = $this->get_option('page_for_posts');
|
117 |
+
}
|
118 |
+
//Upgrading to 4.0
|
119 |
+
if(version_compare($version, '4.0.0', '<'))
|
120 |
+
{
|
121 |
+
//Only migrate if we haven't migrated yet
|
122 |
+
if(isset($opts['current_item_linked']))
|
123 |
+
{
|
124 |
+
//Loop through the old options, migrate some of them
|
125 |
+
foreach($opts as $option => $value)
|
126 |
+
{
|
127 |
+
//Handle all of our boolean options first, they're real easy, just add a 'b'
|
128 |
+
if(strpos($option, 'display') > 0 || $option == 'current_item_linked')
|
129 |
+
{
|
130 |
+
$this->breadcrumb_trail->opt['b' . $option] = $value;
|
131 |
+
}
|
132 |
+
//Handle migration of anchor templates to the templates
|
133 |
+
else if(strpos($option, 'anchor') > 0)
|
134 |
+
{
|
135 |
+
$parts = explode('_', $option);
|
136 |
+
//Do excess slash removal sanitation
|
137 |
+
$this->breadcrumb_trail->opt['H' . $parts[0] . '_template'] = $value . '%htitle%</a>';
|
138 |
+
}
|
139 |
+
//Handle our abs integers
|
140 |
+
else if($option == 'max_title_length' || $option == 'post_post_root' || $option == 'post_page_root')
|
141 |
+
{
|
142 |
+
$this->breadcrumb_trail->opt['a' . $option] = $value;
|
143 |
+
}
|
144 |
+
//Now everything else, minus prefix and suffix
|
145 |
+
else if(strpos($option, 'prefix') === false && strpos($option, 'suffix') === false)
|
146 |
+
{
|
147 |
+
$this->breadcrumb_trail->opt['S' . $option] = $value;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
}
|
151 |
+
//Add in the new settings for CPTs introduced in 4.0
|
152 |
+
foreach($wp_post_types as $post_type)
|
153 |
+
{
|
154 |
+
//We only want custom post types
|
155 |
+
if(!$post_type->_builtin)
|
156 |
+
{
|
157 |
+
//Add in the archive_display option
|
158 |
+
$this->breadcrumb_trail->opt['bpost_' . $post_type->name . '_archive_display'] = $post_type->has_archive;
|
159 |
+
}
|
160 |
+
}
|
161 |
+
$opts = $this->breadcrumb_trail->opt;
|
162 |
+
}
|
163 |
+
if(version_compare($version, '4.0.1', '<'))
|
164 |
+
{
|
165 |
+
if(isset($opts['Hcurrent_item_template_no_anchor']))
|
166 |
+
{
|
167 |
+
unset($opts['Hcurrent_item_template_no_anchor']);
|
168 |
+
}
|
169 |
+
if(isset($opts['Hcurrent_item_template']))
|
170 |
+
{
|
171 |
+
unset($opts['Hcurrent_item_template']);
|
172 |
+
}
|
173 |
+
}
|
174 |
+
//Upgrading to 4.3.0
|
175 |
+
if(version_compare($version, '4.3.0', '<'))
|
176 |
+
{
|
177 |
+
//Removed home_title
|
178 |
+
if(isset($opts['Shome_title']))
|
179 |
+
{
|
180 |
+
unset($opts['Shome_title']);
|
181 |
+
}
|
182 |
+
//Removed mainsite_title
|
183 |
+
if(isset($opts['Smainsite_title']))
|
184 |
+
{
|
185 |
+
unset($opts['Smainsite_title']);
|
186 |
+
}
|
187 |
+
}
|
188 |
+
//Upgrading to 5.1.0
|
189 |
+
if(version_compare($version, '5.1.0', '<'))
|
190 |
+
{
|
191 |
+
foreach($wp_taxonomies as $taxonomy)
|
192 |
+
{
|
193 |
+
//If we have the old options style for it, update
|
194 |
+
if($taxonomy->name !== 'post_format' && isset($opts['H' . $taxonomy->name . '_template']))
|
195 |
+
{
|
196 |
+
//Migrate to the new setting name
|
197 |
+
$opts['Htax_' . $taxonomy->name . '_template'] = $opts['H' . $taxonomy->name . '_template'];
|
198 |
+
$opts['Htax_' . $taxonomy->name . '_template_no_anchor'] = $opts['H' . $taxonomy->name . '_template_no_anchor'];
|
199 |
+
//Clean up old settings
|
200 |
+
unset($opts['H' . $taxonomy->name . '_template']);
|
201 |
+
unset($opts['H' . $taxonomy->name . '_template_no_anchor']);
|
202 |
+
}
|
203 |
+
}
|
204 |
+
}
|
205 |
+
//Upgrading to 5.4.0
|
206 |
+
if(version_compare($version, '5.4.0', '<'))
|
207 |
+
{
|
208 |
+
//Migrate users to schema.org breadcrumbs for author and search if still on the defaults for posts
|
209 |
+
if($opts['Hpost_post_template'] === bcn_breadcrumb::get_default_template() && $opts['Hpost_post_template_no_anchor'] === bcn_breadcrumb::default_template_no_anchor)
|
210 |
+
{
|
211 |
+
if($opts['Hpaged_template'] === 'Page %htitle%')
|
212 |
+
{
|
213 |
+
$opts['Hpaged_template'] = $this->opt['Hpaged_template'];
|
214 |
+
}
|
215 |
+
if($opts['Hsearch_template'] === 'Search results for '<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'' || $opts['Hsearch_template'] === 'Search results for '<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'')
|
216 |
+
{
|
217 |
+
$opts['Hsearch_template'] = $this->opt['Hsearch_template'];
|
218 |
+
}
|
219 |
+
if($opts['Hsearch_template_no_anchor'] === 'Search results for '%htitle%'' || $opts['Hsearch_template_no_anchor'] === 'Search results for '%htitle%'')
|
220 |
+
{
|
221 |
+
$opts['Hsearch_template_no_anchor'] = $this->opt['Hsearch_template_no_anchor'];
|
222 |
+
}
|
223 |
+
if($opts['Hauthor_template'] === 'Articles by: <a title="Go to the first page of posts by %title%." href="%link%" class="%type%">%htitle%</a>')
|
224 |
+
{
|
225 |
+
$opts['Hauthor_template'] = $this->opt['Hauthor_template'];
|
226 |
+
}
|
227 |
+
if($opts['Hauthor_template_no_anchor'] === 'Articles by: %htitle%')
|
228 |
+
{
|
229 |
+
$opts['Hauthor_template_no_anchor'] = $this->opt['Hauthor_template_no_anchor'];
|
230 |
+
}
|
231 |
+
}
|
232 |
+
}
|
233 |
+
//Upgrading to 5.5.0
|
234 |
+
if(version_compare($version, '5.5.0', '<'))
|
235 |
+
{
|
236 |
+
//Translate the old 'page' taxonomy type to BCN_POST_PARENT
|
237 |
+
if($this->opt['Spost_post_taxonomy_type'] === 'page')
|
238 |
+
{
|
239 |
+
$this->opt['Spost_post_taxonomy_type'] = 'BCN_POST_PARENT';
|
240 |
+
}
|
241 |
+
if(!isset($this->opt['Spost_post_taxonomy_referer']))
|
242 |
+
{
|
243 |
+
$this->opt['bpost_post_taxonomy_referer'] = false;
|
244 |
+
}
|
245 |
+
//Loop through all of the post types in the array
|
246 |
+
foreach($wp_post_types as $post_type)
|
247 |
+
{
|
248 |
+
//Check for non-public CPTs
|
249 |
+
if(!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name))
|
250 |
+
{
|
251 |
+
continue;
|
252 |
+
}
|
253 |
+
//We only want custom post types
|
254 |
+
if(!$post_type->_builtin)
|
255 |
+
{
|
256 |
+
//Translate the old 'page' taxonomy type to BCN_POST_PARENT
|
257 |
+
if($this->opt['Spost_' . $post_type->name . '_taxonomy_type'] === 'page')
|
258 |
+
{
|
259 |
+
$this->opt['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_POST_PARENT';
|
260 |
+
}
|
261 |
+
//Translate the old 'date' taxonomy type to BCN_DATE
|
262 |
+
if($this->opt['Spost_' . $post_type->name . '_taxonomy_type'] === 'date')
|
263 |
+
{
|
264 |
+
$this->opt['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_DATE';
|
265 |
+
}
|
266 |
+
if(!isset($this->opt['Spost_' . $post_type->name . '_taxonomy_referer']))
|
267 |
+
{
|
268 |
+
$this->opt['bpost_' . $post_type->name . '_taxonomy_referer'] = false;
|
269 |
+
}
|
270 |
+
}
|
271 |
+
}
|
272 |
+
}
|
273 |
+
//Upgrading to 6.0.0
|
274 |
+
if(version_compare($version, '6.0.0', '<'))
|
275 |
+
{
|
276 |
+
//Loop through all of the post types in the array
|
277 |
+
foreach($wp_post_types as $post_type)
|
278 |
+
{
|
279 |
+
if(isset($this->opt['Spost_' . $post_type->name . '_taxonomy_type']))
|
280 |
+
{
|
281 |
+
$this->opt['Spost_' . $post_type->name . '_hierarchy_type'] = $this->opt['Spost_' . $post_type->name . '_taxonomy_type'];
|
282 |
+
unset($this->opt['Spost_' . $post_type->name . '_taxonomy_type']);
|
283 |
+
}
|
284 |
+
if(isset($this->opt['Spost_' . $post_type->name . '_taxonomy_display']))
|
285 |
+
{
|
286 |
+
$this->opt['Spost_' . $post_type->name . '_hierarchy_display'] = $this->opt['Spost_' . $post_type->name . '_taxonomy_display'];
|
287 |
+
unset($this->opt['Spost_' . $post_type->name . '_taxonomy_display']);
|
288 |
+
}
|
289 |
+
}
|
290 |
+
}
|
291 |
+
//Set the max title length to 20 if we are not limiting the title and the length was 0
|
292 |
+
if(!$opts['blimit_title'] && $opts['amax_title_length'] == 0)
|
293 |
+
{
|
294 |
+
$opts['amax_title_length'] = 20;
|
295 |
+
}
|
296 |
+
}
|
297 |
+
//Save the passed in opts to the object's option array
|
298 |
+
$this->opt = $opts;
|
299 |
+
//End with resetting up the options
|
300 |
+
breadcrumb_navxt::setup_options($this->opt);
|
301 |
+
}
|
302 |
+
function opts_update_prebk(&$opts)
|
303 |
+
{
|
304 |
+
//This may no longer be needed
|
305 |
+
breadcrumb_navxt::setup_options($opts);
|
306 |
+
$opts = apply_filters('bcn_opts_update_prebk', $opts);
|
307 |
+
}
|
308 |
+
/**
|
309 |
+
* help action hook function
|
310 |
+
*
|
311 |
+
* @return string
|
312 |
+
*
|
313 |
+
*/
|
314 |
+
function help()
|
315 |
+
{
|
316 |
+
$screen = get_current_screen();
|
317 |
+
//Exit early if the add_help_tab function doesn't exist
|
318 |
+
if(!method_exists($screen, 'add_help_tab'))
|
319 |
+
{
|
320 |
+
return;
|
321 |
+
}
|
322 |
+
//Add contextual help on current screen
|
323 |
+
if($screen->id == 'settings_page_' . $this->identifier)
|
324 |
+
{
|
325 |
+
$general_tab = '<p>' . esc_html__('Tips for the settings are located below select options.', 'breadcrumb-navxt') .
|
326 |
+
'</p><h5>' . esc_html__('Resources', 'breadcrumb-navxt') . '</h5><ul><li>' .
|
327 |
+
sprintf(esc_html__("%sTutorials and How Tos%s: There are several guides, tutorials, and how tos available on the author's website.", 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to the Breadcrumb NavXT tag archive.', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/tag/breadcrumb-navxt">', '</a>') . '</li><li>' .
|
328 |
+
sprintf(esc_html__('%sOnline Documentation%s: Check out the documentation for more indepth technical information.', 'breadcrumb-navxt'), '<a title="' . esc_attr__('Go to the Breadcrumb NavXT online documentation', 'breadcrumb-navxt') . '" href="https://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/">', '</a>') . '</li><li>' .
|
329 |
+
sprintf(esc_html__('%sReport a Bug%s: If you think you have found a bug, please include your WordPress version and details on how to reproduce the bug.', 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to the Breadcrumb NavXT support post for your version.', 'breadcrumb-navxt') . '" href="https://wordpress.org/support/plugin/breadcrumb-navxt/">', '</a>') . '</li></ul>' .
|
330 |
+
'<h5>' . esc_html__('Giving Back', 'breadcrumb-navxt') . '</h5><ul><li>' .
|
331 |
+
sprintf(esc_html__('%sDonate%s: Love Breadcrumb NavXT and want to help development? Consider buying the author a beer.', 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to PayPal to give a donation to Breadcrumb NavXT.', 'breadcrumb-navxt') . '" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=FD5XEU783BR8U&lc=US&item_name=Breadcrumb%20NavXT%20Donation¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">', '</a>') . '</li><li>' .
|
332 |
+
sprintf(esc_html__('%sTranslate%s: Is your language not available? Visit the Breadcrumb NavXT translation project on WordPress.org to start translating.', 'breadcrumb-navxt'),'<a title="' . esc_attr__('Go to the Breadcrumb NavXT translation project.', 'breadcrumb-navxt') . '" href="https://translate.wordpress.org/projects/wp-plugins/breadcrumb-navxt">', '</a>') . '</li></ul>';
|
333 |
+
|
334 |
+
$screen->add_help_tab(
|
335 |
+
array(
|
336 |
+
'id' => $this->identifier . '-base',
|
337 |
+
'title' => __('General', 'breadcrumb-navxt'),
|
338 |
+
'content' => $general_tab
|
339 |
+
));
|
340 |
+
$quickstart_tab = '<p>' . esc_html__('For the settings on this page to take effect, you must either use the included Breadcrumb NavXT widget, or place either of the code sections below into your theme.', 'breadcrumb-navxt') .
|
341 |
+
'</p><h5>' . esc_html__('Breadcrumb trail with separators', 'breadcrumb-navxt') . '</h5><pre><code><div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">' . "
|
342 |
+
<?php if(function_exists('bcn_display'))
|
343 |
+
{
|
344 |
+
bcn_display();
|
345 |
+
}?>
|
346 |
+
</div></code></pre>" .
|
347 |
+
'<h5>' . esc_html__('Breadcrumb trail in list form', 'breadcrumb-navxt').'</h5><pre><code><ol class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">'."
|
348 |
+
<?php if(function_exists('bcn_display_list'))
|
349 |
+
{
|
350 |
+
bcn_display_list();
|
351 |
+
}?>
|
352 |
+
</ol></code></pre>";
|
353 |
+
$screen->add_help_tab(
|
354 |
+
array(
|
355 |
+
'id' => $this->identifier . '-quick-start',
|
356 |
+
'title' => __('Quick Start', 'breadcrumb-navxt'),
|
357 |
+
'content' => $quickstart_tab
|
358 |
+
));
|
359 |
+
$styling_tab = '<p>' . esc_html__('Using the code from the Quick Start section above, the following CSS can be used as base for styling your breadcrumb trail.', 'breadcrumb-navxt') . '</p>' .
|
360 |
+
'<pre><code>.breadcrumbs
|
361 |
+
{
|
362 |
+
font-size: 1.1em;
|
363 |
+
color: #fff;
|
364 |
+
margin: 30px 0 0 10px;
|
365 |
+
position: relative;
|
366 |
+
float: left;
|
367 |
+
}</code></pre>';
|
368 |
+
$screen->add_help_tab(
|
369 |
+
array(
|
370 |
+
'id' => $this->identifier . '-styling',
|
371 |
+
'title' => __('Styling', 'breadcrumb-navxt'),
|
372 |
+
'content' => $styling_tab
|
373 |
+
));
|
374 |
+
$screen->add_help_tab(
|
375 |
+
array(
|
376 |
+
'id' => $this->identifier . '-import-export-reset',
|
377 |
+
'title' => __('Import/Export/Reset', 'breadcrumb-navxt'),
|
378 |
+
'content' => $this->import_form()
|
379 |
+
));
|
380 |
+
}
|
381 |
+
}
|
382 |
+
/**
|
383 |
+
* enqueue's the tab style sheet on the settings page
|
384 |
+
*/
|
385 |
+
function admin_styles()
|
386 |
+
{
|
387 |
+
wp_enqueue_style('mtekk_adminkit_tabs');
|
388 |
+
}
|
389 |
+
/**
|
390 |
+
* enqueue's the tab js and translation js on the settings page
|
391 |
+
*/
|
392 |
+
function admin_scripts()
|
393 |
+
{
|
394 |
+
//Enqueue ui-tabs
|
395 |
+
wp_enqueue_script('jquery-ui-tabs');
|
396 |
+
//Enqueue the admin tabs javascript
|
397 |
+
wp_enqueue_script('mtekk_adminkit_tabs');
|
398 |
+
//Load the translations for the tabs
|
399 |
+
wp_localize_script('mtekk_adminkit_tabs', 'objectL10n', array(
|
400 |
+
'mtad_uid' => 'bcn_admin',
|
401 |
+
'mtad_import' => __('Import', 'breadcrumb-navxt'),
|
402 |
+
'mtad_export' => __('Export', 'breadcrumb-navxt'),
|
403 |
+
'mtad_reset' => __('Reset', 'breadcrumb-navxt'),
|
404 |
+
));
|
405 |
+
//Enqueue the admin enable/disable groups javascript
|
406 |
+
wp_enqueue_script('mtekk_adminkit_engroups');
|
407 |
+
}
|
408 |
+
/**
|
409 |
+
* A message function that checks for the BCN_SETTINGS_* define statement
|
410 |
+
*/
|
411 |
+
function multisite_settings_warn()
|
412 |
+
{
|
413 |
+
if(is_multisite())
|
414 |
+
{
|
415 |
+
if(defined('BCN_SETTINGS_USE_LOCAL') && BCN_SETTINGS_USE_LOCAL)
|
416 |
+
{
|
417 |
+
|
418 |
+
}
|
419 |
+
else if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK)
|
420 |
+
{
|
421 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Your network settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nsiteoveride');
|
422 |
+
}
|
423 |
+
else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL)
|
424 |
+
{
|
425 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Your network settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_isitemayoveride');
|
426 |
+
}
|
427 |
+
else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK)
|
428 |
+
{
|
429 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Your network settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nsitemayoveride');
|
430 |
+
}
|
431 |
+
//Fall through if no settings mode was set
|
432 |
+
else
|
433 |
+
{
|
434 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: No BCN_SETTINGS_* define statement found, defaulting to BCN_SETTINGS_USE_LOCAL.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_is_nosetting');
|
435 |
+
}
|
436 |
+
}
|
437 |
+
}
|
438 |
+
/**
|
439 |
+
* A message function that checks for deprecated settings that are set and warns the user
|
440 |
+
*/
|
441 |
+
function deprecated_settings_warn()
|
442 |
+
{
|
443 |
+
//We're deprecating the limit title length setting, let the user know the new method of accomplishing this
|
444 |
+
if(isset($this->opt['blimit_title']) && $this->opt['blimit_title'])
|
445 |
+
{
|
446 |
+
$this->messages[] = new mtekk_adminKit_message(sprintf(esc_html__('Warning: Your are using a deprecated setting "Title Length" (see Miscellaneous > Deprecated), please %1$suse CSS instead%2$s.', 'breadcrumb-navxt'), '<a title="' . __('Go to the guide on trimming breadcrumb title lengths with CSS', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/guides/trimming-breadcrumb-title-lengths-with-css/">', '</a>'), 'warning');
|
447 |
+
}
|
448 |
+
}
|
449 |
+
/**
|
450 |
+
* Function checks the current site to see if the blog options should be disabled
|
451 |
+
*
|
452 |
+
* @return boool Whether or not the blog options should be disabled
|
453 |
+
*/
|
454 |
+
function maybe_disable_blog_options()
|
455 |
+
{
|
456 |
+
return (get_option('show_on_front') !== 'page' || get_option('page_for_posts') < 1);
|
457 |
+
}
|
458 |
+
/**
|
459 |
+
* Function checks the current site to see if the mainsite options should be disabled
|
460 |
+
*
|
461 |
+
* @return bool Whether or not the mainsite options should be disabled
|
462 |
+
*/
|
463 |
+
function maybe_disable_mainsite_options()
|
464 |
+
{
|
465 |
+
return !is_multisite();
|
466 |
+
}
|
467 |
+
/**
|
468 |
+
* The administrative page for Breadcrumb NavXT
|
469 |
+
*/
|
470 |
+
function admin_page()
|
471 |
+
{
|
472 |
+
global $wp_taxonomies, $wp_post_types;
|
473 |
+
$this->security();
|
474 |
+
//Do a check on deprecated settings
|
475 |
+
$this->deprecated_settings_warn();
|
476 |
+
//Do a check for multisite settings mode
|
477 |
+
$this->multisite_settings_warn();
|
478 |
+
do_action($this->unique_prefix . '_settings_pre_messages', $this->opt);
|
479 |
+
//Display our messages
|
480 |
+
$this->messages();
|
481 |
+
?>
|
482 |
+
<div class="wrap"><h2><?php echo $this->full_name; ?></h2>
|
483 |
+
<?php
|
484 |
+
//We exit after the version check if there is an action the user needs to take before saving settings
|
485 |
+
if(!$this->version_check($this->get_option($this->unique_prefix . '_version')))
|
486 |
+
{
|
487 |
+
return;
|
488 |
+
}
|
489 |
+
?>
|
490 |
+
<form action="<?php echo $this->admin_url(); ?>" method="post" id="bcn_admin-options">
|
491 |
+
<?php settings_fields('bcn_options');?>
|
492 |
+
<div id="hasadmintabs">
|
493 |
+
<fieldset id="general" class="bcn_options">
|
494 |
+
<h3 class="tab-title" title="<?php _e('A collection of settings most likely to be modified are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('General', 'breadcrumb-navxt'); ?></h3>
|
495 |
+
<h3><?php _e('General', 'breadcrumb-navxt'); ?></h3>
|
496 |
+
<table class="form-table">
|
497 |
+
<?php
|
498 |
+
$this->textbox(__('Breadcrumb Separator', 'breadcrumb-navxt'), 'hseparator', '2', false, __('Placed in between each breadcrumb.', 'breadcrumb-navxt'));
|
499 |
+
do_action($this->unique_prefix . '_settings_general', $this->opt);
|
500 |
+
?>
|
501 |
+
</table>
|
502 |
+
<h3><?php _e('Current Item', 'breadcrumb-navxt'); ?></h3>
|
503 |
+
<table class="form-table adminkit-enset-top">
|
504 |
+
<?php
|
505 |
+
$this->input_check(__('Link Current Item', 'breadcrumb-navxt'), 'bcurrent_item_linked', __('Yes', 'breadcrumb-navxt'));
|
506 |
+
$this->input_check(_x('Paged Breadcrumb', 'Paged as in when on an archive or post that is split into multiple pages', 'breadcrumb-navxt'), 'bpaged_display', __('Place the page number breadcrumb in the trail.', 'breadcrumb-navxt'), false, __('Indicates that the user is on a page other than the first of a paginated archive or post.', 'breadcrumb-navxt'), 'adminkit-enset-ctrl adminkit-enset');
|
507 |
+
$this->textbox(_x('Paged Template', 'Paged as in when on an archive or post that is split into multiple pages', 'breadcrumb-navxt'), 'Hpaged_template', '4', false, __('The template for paged breadcrumbs.', 'breadcrumb-navxt'), 'adminkit-enset');
|
508 |
+
do_action($this->unique_prefix . '_settings_current_item', $this->opt);
|
509 |
+
?>
|
510 |
+
</table>
|
511 |
+
<h3><?php _e('Home Breadcrumb', 'breadcrumb-navxt'); ?></h3>
|
512 |
+
<table class="form-table adminkit-enset-top">
|
513 |
+
<?php
|
514 |
+
$this->input_check(__('Home Breadcrumb', 'breadcrumb-navxt'), 'bhome_display', __('Place the home breadcrumb in the trail.', 'breadcrumb-navxt'), false, '', 'adminkit-enset-ctrl adminkit-enset');
|
515 |
+
$this->textbox(__('Home Template', 'breadcrumb-navxt'), 'Hhome_template', '6', false, __('The template for the home breadcrumb.', 'breadcrumb-navxt'), 'adminkit-enset');
|
516 |
+
$this->textbox(__('Home Template (Unlinked)', 'breadcrumb-navxt'), 'Hhome_template_no_anchor', '4', false, __('The template for the home breadcrumb, used when the breadcrumb is not linked.', 'breadcrumb-navxt'), 'adminkit-enset');
|
517 |
+
do_action($this->unique_prefix . '_settings_home', $this->opt);
|
518 |
+
?>
|
519 |
+
</table>
|
520 |
+
<h3><?php _e('Blog Breadcrumb', 'breadcrumb-navxt'); ?></h3>
|
521 |
+
<table class="form-table adminkit-enset-top">
|
522 |
+
<?php
|
523 |
+
$this->input_check(__('Blog Breadcrumb', 'breadcrumb-navxt'), 'bblog_display', __('Place the blog breadcrumb in the trail.', 'breadcrumb-navxt'), $this->maybe_disable_blog_options(), '', 'adminkit-enset-ctrl adminkit-enset');
|
524 |
+
do_action($this->unique_prefix . '_settings_blog', $this->opt);
|
525 |
+
?>
|
526 |
+
</table>
|
527 |
+
<h3><?php _e('Mainsite Breadcrumb', 'breadcrumb-navxt'); ?></h3>
|
528 |
+
<table class="form-table adminkit-enset-top">
|
529 |
+
<?php
|
530 |
+
$this->input_check(__('Main Site Breadcrumb', 'breadcrumb-navxt'), 'bmainsite_display', __('Place the main site home breadcrumb in the trail in an multisite setup.', 'breadcrumb-navxt'), $this->maybe_disable_mainsite_options(), '', 'adminkit-enset-ctrl adminkit-enset');
|
531 |
+
$this->textbox(__('Main Site Home Template', 'breadcrumb-navxt'), 'Hmainsite_template', '6', $this->maybe_disable_mainsite_options(), __('The template for the main site home breadcrumb, used only in multisite environments.', 'breadcrumb-navxt'), 'adminkit-enset');
|
532 |
+
$this->textbox(__('Main Site Home Template (Unlinked)', 'breadcrumb-navxt'), 'Hmainsite_template_no_anchor', '4', $this->maybe_disable_mainsite_options(), __('The template for the main site home breadcrumb, used only in multisite environments and when the breadcrumb is not linked.', 'breadcrumb-navxt'), 'adminkit-enset');
|
533 |
+
do_action($this->unique_prefix . '_settings_mainsite', $this->opt);
|
534 |
+
?>
|
535 |
+
</table>
|
536 |
+
<?php do_action($this->unique_prefix . '_after_settings_tab_general', $this->opt); ?>
|
537 |
+
</fieldset>
|
538 |
+
<fieldset id="post" class="bcn_options">
|
539 |
+
<h3 class="tab-title" title="<?php _e('The settings for all post types (Posts, Pages, and Custom Post Types) are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('Post Types', 'breadcrumb-navxt'); ?></h3>
|
540 |
+
<h3><?php _e('Posts', 'breadcrumb-navxt'); ?></h3>
|
541 |
+
<table class="form-table adminkit-enset-top">
|
542 |
+
<?php
|
543 |
+
$this->textbox(__('Post Template', 'breadcrumb-navxt'), 'Hpost_post_template', '6', false, __('The template for post breadcrumbs.', 'breadcrumb-navxt'));
|
544 |
+
$this->textbox(__('Post Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_post_template_no_anchor', '4', false, __('The template for post breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
545 |
+
$this->input_check(__('Post Hierarchy Display', 'breadcrumb-navxt'), 'bpost_post_hierarchy_display', __('Show the hierarchy (specified below) leading to a post in the breadcrumb trail.', 'breadcrumb-navxt'), false, '', 'adminkit-enset-ctrl adminkit-enset');
|
546 |
+
$this->input_check(__('Post Hierarchy Referer Influence', 'breadcrumb-navxt'), 'bpost_post_taxonomy_referer', __('Allow the referring page to influence the taxonomy selected for the hierarchy.', 'breadcrumb-navxt'), false, '', 'adminkit-enset');
|
547 |
+
?>
|
548 |
+
<tr valign="top">
|
549 |
+
<th scope="row">
|
550 |
+
<?php _e('Post Hierarchy', 'breadcrumb-navxt'); ?>
|
551 |
+
</th>
|
552 |
+
<td>
|
553 |
+
<?php
|
554 |
+
$this->input_radio('Spost_post_hierarchy_type', 'category', __('Categories'), false, 'adminkit-enset');
|
555 |
+
$this->input_radio('Spost_post_hierarchy_type', 'BCN_DATE', __('Dates', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
556 |
+
$this->input_radio('Spost_post_hierarchy_type', 'post_tag', __('Tags'), false, 'adminkit-enset');
|
557 |
+
//We use the value 'page' but really, this will follow the parent post hierarchy
|
558 |
+
$this->input_radio('Spost_post_hierarchy_type', 'BCN_POST_PARENT', __('Post Parent', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
559 |
+
//Loop through all of the taxonomies in the array
|
560 |
+
foreach($wp_taxonomies as $taxonomy)
|
561 |
+
{
|
562 |
+
//Check for non-public taxonomies
|
563 |
+
if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, 'post'))
|
564 |
+
{
|
565 |
+
continue;
|
566 |
+
}
|
567 |
+
//We only want custom taxonomies
|
568 |
+
if(($taxonomy->object_type == 'post' || is_array($taxonomy->object_type) && in_array('post', $taxonomy->object_type)) && !$taxonomy->_builtin)
|
569 |
+
{
|
570 |
+
$this->input_radio('Spost_post_hierarchy_type', $taxonomy->name, mb_convert_case($taxonomy->label, MB_CASE_TITLE, 'UTF-8'), false, 'adminkit-enset');
|
571 |
+
}
|
572 |
+
}
|
573 |
+
?>
|
574 |
+
<p class="description"><?php esc_html_e('The hierarchy which the breadcrumb trail will show. Note that the "Post Parent" option may require an additional plugin to behave as expected since this is a non-hierarchical post type.', 'breadcrumb-navxt'); ?></p>
|
575 |
+
</td>
|
576 |
+
</tr>
|
577 |
+
</table>
|
578 |
+
<h3><?php _e('Pages', 'breadcrumb-navxt'); ?></h3>
|
579 |
+
<table class="form-table">
|
580 |
+
<?php
|
581 |
+
$this->textbox(__('Page Template', 'breadcrumb-navxt'), 'Hpost_page_template', '6', false, __('The template for page breadcrumbs.', 'breadcrumb-navxt'));
|
582 |
+
$this->textbox(__('Page Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_page_template_no_anchor', '4', false, __('The template for page breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
583 |
+
$this->input_hidden('bpost_page_hierarchy_display');
|
584 |
+
$this->input_hidden('Spost_page_hierarchy_type');
|
585 |
+
?>
|
586 |
+
</table>
|
587 |
+
<h3><?php _e('Attachments', 'breadcrumb-navxt'); ?></h3>
|
588 |
+
<table class="form-table">
|
589 |
+
<?php
|
590 |
+
$this->textbox(__('Attachment Template', 'breadcrumb-navxt'), 'Hpost_attachment_template', '6', false, __('The template for attachment breadcrumbs.', 'breadcrumb-navxt'));
|
591 |
+
$this->textbox(__('Attachment Template (Unlinked)', 'breadcrumb-navxt'), 'Hpost_attachment_template_no_anchor', '4', false, __('The template for attachment breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
592 |
+
?>
|
593 |
+
</table>
|
594 |
+
<?php
|
595 |
+
//Loop through all of the post types in the array
|
596 |
+
foreach($wp_post_types as $post_type)
|
597 |
+
{
|
598 |
+
//Check for non-public CPTs
|
599 |
+
if(!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name))
|
600 |
+
{
|
601 |
+
continue;
|
602 |
+
}
|
603 |
+
//We only want custom post types
|
604 |
+
if(!$post_type->_builtin)
|
605 |
+
{
|
606 |
+
$singular_name_lc = mb_strtolower($post_type->labels->singular_name, 'UTF-8');
|
607 |
+
?>
|
608 |
+
<h3><?php echo $post_type->labels->singular_name; ?></h3>
|
609 |
+
<table class="form-table adminkit-enset-top">
|
610 |
+
<?php
|
611 |
+
$this->textbox(sprintf(__('%s Template', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'Hpost_' . $post_type->name . '_template', '6', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt'), $singular_name_lc));
|
612 |
+
$this->textbox(sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'Hpost_' . $post_type->name . '_template_no_anchor', '4', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'), $singular_name_lc));
|
613 |
+
$optid = mtekk_adminKit::get_valid_id('apost_' . $post_type->name . '_root');
|
614 |
+
?>
|
615 |
+
<tr valign="top">
|
616 |
+
<th scope="row">
|
617 |
+
<label for="<?php echo $optid;?>"><?php printf(esc_html__('%s Root Page', 'breadcrumb-navxt'), $post_type->labels->singular_name);?></label>
|
618 |
+
</th>
|
619 |
+
<td>
|
620 |
+
<?php wp_dropdown_pages(array('name' => $this->unique_prefix . '_options[apost_' . $post_type->name . '_root]', 'id' => $optid, 'echo' => 1, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => $this->opt['apost_' . $post_type->name . '_root']));?>
|
621 |
+
</td>
|
622 |
+
</tr>
|
623 |
+
<?php
|
624 |
+
$this->input_check(sprintf(__('%s Archive Display', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'bpost_' . $post_type->name . '_archive_display', sprintf(__('Show the breadcrumb for the %s post type archives in the breadcrumb trail.', 'breadcrumb-navxt'), $singular_name_lc), !$post_type->has_archive);
|
625 |
+
$this->input_check(sprintf(__('%s Hierarchy Display', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'bpost_' . $post_type->name . '_hierarchy_display', sprintf(__('Show the hierarchy (specified below) leading to a %s in the breadcrumb trail.', 'breadcrumb-navxt'), $singular_name_lc), false, '', 'adminkit-enset-ctrl adminkit-enset');
|
626 |
+
$this->input_check(sprintf(__('%s Hierarchy Referer Influence', 'breadcrumb-navxt'), $post_type->labels->singular_name), 'bpost_' . $post_type->name . '_taxonomy_referer', __('Allow the referring page to influence the taxonomy selected for the hierarchy.', 'breadcrumb-navxt'), false, '', 'adminkit-enset');
|
627 |
+
?>
|
628 |
+
<tr valign="top">
|
629 |
+
<th scope="row">
|
630 |
+
<?php printf(__('%s Hierarchy', 'breadcrumb-navxt'), $post_type->labels->singular_name); ?>
|
631 |
+
</th>
|
632 |
+
<td>
|
633 |
+
<?php
|
634 |
+
//We use the value 'page' but really, this will follow the parent post hierarchy
|
635 |
+
$this->input_radio('Spost_' . $post_type->name . '_hierarchy_type', 'BCN_POST_PARENT', __('Post Parent', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
636 |
+
$this->input_radio('Spost_' . $post_type->name . '_hierarchy_type', 'BCN_DATE', __('Dates', 'breadcrumb-navxt'), false, 'adminkit-enset');
|
637 |
+
//Loop through all of the taxonomies in the array
|
638 |
+
foreach($wp_taxonomies as $taxonomy)
|
639 |
+
{
|
640 |
+
//Check for non-public taxonomies
|
641 |
+
if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, $post_type->name))
|
642 |
+
{
|
643 |
+
continue;
|
644 |
+
}
|
645 |
+
//We only want custom taxonomies
|
646 |
+
if($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type))
|
647 |
+
{
|
648 |
+
$this->input_radio('Spost_' . $post_type->name . '_hierarchy_type', $taxonomy->name, $taxonomy->labels->singular_name, false, 'adminkit-enset');
|
649 |
+
}
|
650 |
+
}
|
651 |
+
?>
|
652 |
+
<p class="description">
|
653 |
+
<?php
|
654 |
+
if($post_type->hierarchical)
|
655 |
+
{
|
656 |
+
esc_html_e('The hierarchy which the breadcrumb trail will show.', 'breadcrumb-navxt');
|
657 |
+
}
|
658 |
+
else
|
659 |
+
{
|
660 |
+
esc_html_e('The hierarchy which the breadcrumb trail will show. Note that the "Post Parent" option may require an additional plugin to behave as expected since this is a non-hierarchical post type.', 'breadcrumb-navxt');
|
661 |
+
}
|
662 |
+
?>
|
663 |
+
</p>
|
664 |
+
</td>
|
665 |
+
</tr>
|
666 |
+
</table>
|
667 |
+
<?php
|
668 |
+
}
|
669 |
+
}
|
670 |
+
do_action($this->unique_prefix . '_after_settings_tab_post', $this->opt);
|
671 |
+
?>
|
672 |
+
</fieldset>
|
673 |
+
<fieldset id="tax" class="bcn_options alttab">
|
674 |
+
<h3 class="tab-title" title="<?php _e('The settings for all taxonomies (including Categories, Tags, and custom taxonomies) are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('Taxonomies', 'breadcrumb-navxt'); ?></h3>
|
675 |
+
<h3><?php _e('Categories', 'breadcrumb-navxt'); ?></h3>
|
676 |
+
<table class="form-table">
|
677 |
+
<?php
|
678 |
+
$this->textbox(__('Category Template', 'breadcrumb-navxt'), 'Htax_category_template', '6', false, __('The template for category breadcrumbs.', 'breadcrumb-navxt'));
|
679 |
+
$this->textbox(__('Category Template (Unlinked)', 'breadcrumb-navxt'), 'Htax_category_template_no_anchor', '4', false, __('The template for category breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
680 |
+
?>
|
681 |
+
</table>
|
682 |
+
<h3><?php _e('Tags', 'breadcrumb-navxt'); ?></h3>
|
683 |
+
<table class="form-table">
|
684 |
+
<?php
|
685 |
+
$this->textbox(__('Tag Template', 'breadcrumb-navxt'), 'Htax_post_tag_template', '6', false, __('The template for tag breadcrumbs.', 'breadcrumb-navxt'));
|
686 |
+
$this->textbox(__('Tag Template (Unlinked)', 'breadcrumb-navxt'), 'Htax_post_tag_template_no_anchor', '4', false, __('The template for tag breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
687 |
+
?>
|
688 |
+
</table>
|
689 |
+
<h3><?php _e('Post Formats', 'breadcrumb-navxt'); ?></h3>
|
690 |
+
<table class="form-table">
|
691 |
+
<?php
|
692 |
+
$this->textbox(__('Post Format Template', 'breadcrumb-navxt'), 'Htax_post_format_template', '6', false, __('The template for post format breadcrumbs.', 'breadcrumb-navxt'));
|
693 |
+
$this->textbox(__('Post Format Template (Unlinked)', 'breadcrumb-navxt'), 'Htax_post_format_template_no_anchor', '4', false, __('The template for post_format breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
694 |
+
?>
|
695 |
+
</table>
|
696 |
+
<?php
|
697 |
+
//Loop through all of the taxonomies in the array
|
698 |
+
foreach($wp_taxonomies as $taxonomy)
|
699 |
+
{
|
700 |
+
//Check for non-public taxonomies
|
701 |
+
if(!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name, null))
|
702 |
+
{
|
703 |
+
continue;
|
704 |
+
}
|
705 |
+
//We only want custom taxonomies
|
706 |
+
if(!$taxonomy->_builtin)
|
707 |
+
{
|
708 |
+
$label_lc = mb_strtolower($taxonomy->label, 'UTF-8');
|
709 |
+
?>
|
710 |
+
<h3><?php echo mb_convert_case($taxonomy->label, MB_CASE_TITLE, 'UTF-8'); ?></h3>
|
711 |
+
<table class="form-table">
|
712 |
+
<?php
|
713 |
+
$this->textbox(sprintf(__('%s Template', 'breadcrumb-navxt'), $taxonomy->labels->singular_name), 'Htax_' . $taxonomy->name . '_template', '6', false, sprintf(__('The template for %s breadcrumbs.', 'breadcrumb-navxt'), $label_lc));
|
714 |
+
$this->textbox(sprintf(__('%s Template (Unlinked)', 'breadcrumb-navxt'), $taxonomy->labels->singular_name), 'Htax_' . $taxonomy->name . '_template_no_anchor', '4', false, sprintf(__('The template for %s breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'), $label_lc));
|
715 |
+
?>
|
716 |
+
</table>
|
717 |
+
<?php
|
718 |
+
}
|
719 |
+
}
|
720 |
+
do_action($this->unique_prefix . '_after_settings_tab_taxonomy', $this->opt); ?>
|
721 |
+
</fieldset>
|
722 |
+
<fieldset id="miscellaneous" class="bcn_options">
|
723 |
+
<h3 class="tab-title" title="<?php _e('The settings for author and date archives, searches, and 404 pages are located under this tab.', 'breadcrumb-navxt');?>"><?php _e('Miscellaneous', 'breadcrumb-navxt'); ?></h3>
|
724 |
+
<h3><?php _e('Author Archives', 'breadcrumb-navxt'); ?></h3>
|
725 |
+
<table class="form-table">
|
726 |
+
<?php
|
727 |
+
$this->textbox(__('Author Template', 'breadcrumb-navxt'), 'Hauthor_template', '6', false, __('The template for author breadcrumbs.', 'breadcrumb-navxt'));
|
728 |
+
$this->textbox(__('Author Template (Unlinked)', 'breadcrumb-navxt'), 'Hauthor_template_no_anchor', '4', false, __('The template for author breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
729 |
+
$this->input_select(__('Author Display Format', 'breadcrumb-navxt'), 'Sauthor_name', array("display_name", "nickname", "first_name", "last_name"), false, __('display_name uses the name specified in "Display name publicly as" under the user profile the others correspond to options in the user profile.', 'breadcrumb-navxt'));
|
730 |
+
$optid = mtekk_adminKit::get_valid_id('aauthor_root');
|
731 |
+
?>
|
732 |
+
<tr valign="top">
|
733 |
+
<th scope="row">
|
734 |
+
<label for="<?php echo $optid;?>"><?php esc_html_e('Author Root Page', 'breadcrumb-navxt');?></label>
|
735 |
+
</th>
|
736 |
+
<td>
|
737 |
+
<?php wp_dropdown_pages(array('name' => $this->unique_prefix . '_options[aauthor_root]', 'id' => $optid, 'echo' => 1, 'show_option_none' => __( '— Select —' ), 'option_none_value' => '0', 'selected' => $this->opt['aauthor_root']));?>
|
738 |
+
</td>
|
739 |
+
</tr>
|
740 |
+
</table>
|
741 |
+
<h3><?php _e('Miscellaneous', 'breadcrumb-navxt'); ?></h3>
|
742 |
+
<table class="form-table">
|
743 |
+
<?php
|
744 |
+
$this->textbox(__('Date Template', 'breadcrumb-navxt'), 'Hdate_template', '6', false, __('The template for date breadcrumbs.', 'breadcrumb-navxt'));
|
745 |
+
$this->textbox(__('Date Template (Unlinked)', 'breadcrumb-navxt'), 'Hdate_template_no_anchor', '4', false, __('The template for date breadcrumbs, used only when the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
746 |
+
$this->textbox(__('Search Template', 'breadcrumb-navxt'), 'Hsearch_template', '6', false, __('The anchor template for search breadcrumbs, used only when the search results span several pages.', 'breadcrumb-navxt'));
|
747 |
+
$this->textbox(__('Search Template (Unlinked)', 'breadcrumb-navxt'), 'Hsearch_template_no_anchor', '4', false, __('The anchor template for search breadcrumbs, used only when the search results span several pages and the breadcrumb is not linked.', 'breadcrumb-navxt'));
|
748 |
+
$this->input_text(__('404 Title', 'breadcrumb-navxt'), 'S404_title', 'regular-text');
|
749 |
+
$this->textbox(__('404 Template', 'breadcrumb-navxt'), 'H404_template', '4', false, __('The template for 404 breadcrumbs.', 'breadcrumb-navxt'));
|
750 |
+
?>
|
751 |
+
</table>
|
752 |
+
<h3><?php _e('Deprecated', 'breadcrumb-navxt'); ?></h3>
|
753 |
+
<table class="form-table">
|
754 |
+
<tr valign="top">
|
755 |
+
<th scope="row">
|
756 |
+
<?php esc_html_e('Title Length', 'breadcrumb-navxt'); ?>
|
757 |
+
</th>
|
758 |
+
<td>
|
759 |
+
<label>
|
760 |
+
<input name="bcn_options[blimit_title]" type="checkbox" id="blimit_title" value="true" <?php checked(true, $this->opt['blimit_title']); ?> />
|
761 |
+
<?php printf(esc_html__('Limit the length of the breadcrumb title. (Deprecated, %suse CSS instead%s)', 'breadcrumb-navxt'), '<a title="' . esc_attr__('Go to the guide on trimming breadcrumb title lengths with CSS', 'breadcrumb-navxt') . '" href="https://mtekk.us/archives/guides/trimming-breadcrumb-title-lengths-with-css/">', '</a>');?>
|
762 |
+
</label><br />
|
763 |
+
<ul>
|
764 |
+
<li>
|
765 |
+
<label for="amax_title_length">
|
766 |
+
<?php esc_html_e('Max Title Length: ','breadcrumb-navxt');?>
|
767 |
+
<input type="number" name="bcn_options[amax_title_length]" id="amax_title_length" min="1" step="1" value="<?php echo esc_html($this->opt['amax_title_length'], ENT_COMPAT, 'UTF-8'); ?>" class="small-text" />
|
768 |
+
</label>
|
769 |
+
</li>
|
770 |
+
</ul>
|
771 |
+
</td>
|
772 |
+
</tr>
|
773 |
+
</table>
|
774 |
+
<?php do_action($this->unique_prefix . '_after_settings_tab_miscellaneous', $this->opt); ?>
|
775 |
+
</fieldset>
|
776 |
+
<?php do_action($this->unique_prefix . '_after_settings_tabs', $this->opt); ?>
|
777 |
+
</div>
|
778 |
+
<p class="submit"><input type="submit" class="button-primary" name="bcn_admin_options" value="<?php esc_attr_e('Save Changes') ?>" /></p>
|
779 |
+
</form>
|
780 |
+
</div>
|
781 |
+
<?php
|
782 |
+
}
|
783 |
}
|
class.bcn_breadcrumb.php
CHANGED
@@ -1,272 +1,272 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2007-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
-
//The breadcrumb class
|
21 |
-
class bcn_breadcrumb
|
22 |
-
{
|
23 |
-
//Our member variables
|
24 |
-
const version = '6.0
|
25 |
-
//The main text that will be shown
|
26 |
-
protected $title;
|
27 |
-
//The breadcrumb's template, used durring assembly
|
28 |
-
protected $template;
|
29 |
-
//The breadcrumb's no anchor template, used durring assembly when there won't be an anchor
|
30 |
-
protected $template_no_anchor;
|
31 |
-
//Boolean, is this element linked
|
32 |
-
protected $linked = false;
|
33 |
-
//The link the breadcrumb leads to, null if $linked == false
|
34 |
-
protected $url;
|
35 |
-
//The corresponding resource ID
|
36 |
-
protected $id = null;
|
37 |
-
private $_title = null;
|
38 |
-
//The type of this breadcrumb
|
39 |
-
protected $type;
|
40 |
-
protected $allowed_html = array();
|
41 |
-
const default_template_no_anchor = '<span property="itemListElement" typeof="ListItem"><span property="name">%htitle%</span><meta property="position" content="%position%"></span>';
|
42 |
-
/**
|
43 |
-
* The enhanced default constructor, ends up setting all parameters via the set_ functions
|
44 |
-
*
|
45 |
-
* @param string $title (optional) The title of the breadcrumb
|
46 |
-
* @param string $template (optional) The html template for the breadcrumb
|
47 |
-
* @param string $type (optional) The breadcrumb type
|
48 |
-
* @param string $url (optional) The url the breadcrumb links to
|
49 |
-
*/
|
50 |
-
public function __construct($title = '', $template = '', array $type = array(), $url = '', $id = null)
|
51 |
-
{
|
52 |
-
//Filter allowed_html array to allow others to add acceptable tags
|
53 |
-
$this->allowed_html = apply_filters('bcn_allowed_html', wp_kses_allowed_html('post'));
|
54 |
-
//The breadcrumb type
|
55 |
-
$this->type = $type;
|
56 |
-
//Set the resource id
|
57 |
-
$this->set_id($id);
|
58 |
-
//Set the title
|
59 |
-
$this->set_title($title);
|
60 |
-
//Set the default anchorless templates value
|
61 |
-
$this->template_no_anchor = bcn_breadcrumb::default_template_no_anchor;
|
62 |
-
//If we didn't get a good template, use a default template
|
63 |
-
if($template == null)
|
64 |
-
{
|
65 |
-
$this->set_template(bcn_breadcrumb::get_default_template());
|
66 |
-
}
|
67 |
-
//If something was passed in template wise, update the appropriate internal template
|
68 |
-
else
|
69 |
-
{
|
70 |
-
//Loose comparison, evaluates to true if URL is '' or null
|
71 |
-
if($url == null)
|
72 |
-
{
|
73 |
-
$this->template_no_anchor = wp_kses(apply_filters('bcn_breadcrumb_template_no_anchor', $template, $this->type, $this->id), $this->allowed_html);
|
74 |
-
$this->set_template(bcn_breadcrumb::get_default_template());
|
75 |
-
}
|
76 |
-
else
|
77 |
-
{
|
78 |
-
$this->set_template($template);
|
79 |
-
}
|
80 |
-
}
|
81 |
-
//Always null if unlinked
|
82 |
-
$this->set_url($url);
|
83 |
-
}
|
84 |
-
/**
|
85 |
-
* Function to return the translated default template
|
86 |
-
*
|
87 |
-
* @return string The default breadcrumb template
|
88 |
-
*/
|
89 |
-
static public function get_default_template()
|
90 |
-
{
|
91 |
-
return __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt');
|
92 |
-
}
|
93 |
-
/**
|
94 |
-
* Function to set the protected title member
|
95 |
-
*
|
96 |
-
* @param string $title The title of the breadcrumb
|
97 |
-
*/
|
98 |
-
public function set_title($title)
|
99 |
-
{
|
100 |
-
//Set the title
|
101 |
-
$this->title = apply_filters('bcn_breadcrumb_title', $title, $this->type, $this->id);
|
102 |
-
$this->_title = $this->title;
|
103 |
-
}
|
104 |
-
/**
|
105 |
-
* Function to get the protected title member
|
106 |
-
*
|
107 |
-
* @return $this->title
|
108 |
-
*/
|
109 |
-
public function get_title()
|
110 |
-
{
|
111 |
-
//Return the title
|
112 |
-
return $this->title;
|
113 |
-
}
|
114 |
-
/**
|
115 |
-
* Function to set the internal URL variable
|
116 |
-
*
|
117 |
-
* @param string $url the url to link to
|
118 |
-
*/
|
119 |
-
public function set_url($url)
|
120 |
-
{
|
121 |
-
$url = trim($url);
|
122 |
-
$this->url = apply_filters('bcn_breadcrumb_url', $url, $this->type, $this->id);
|
123 |
-
//If the URL seemed nullish, we are not linked
|
124 |
-
if($this->url === '')
|
125 |
-
{
|
126 |
-
$this->linked = false;
|
127 |
-
}
|
128 |
-
else
|
129 |
-
{
|
130 |
-
$this->linked = true;
|
131 |
-
}
|
132 |
-
}
|
133 |
-
/**
|
134 |
-
* Function to set the internal breadcrumb template
|
135 |
-
*
|
136 |
-
* @param string $template the template to use durring assebly
|
137 |
-
*/
|
138 |
-
public function set_template($template)
|
139 |
-
{
|
140 |
-
//Assign the breadcrumb template
|
141 |
-
$this->template = wp_kses(apply_filters('bcn_breadcrumb_template', $template, $this->type, $this->id), $this->allowed_html);
|
142 |
-
}
|
143 |
-
/**
|
144 |
-
* Function to set the internal breadcrumb ID
|
145 |
-
*
|
146 |
-
* @param int $id the id of the resource this breadcrumb represents
|
147 |
-
*/
|
148 |
-
public function set_id($id)
|
149 |
-
{
|
150 |
-
$this->id = $id;
|
151 |
-
}
|
152 |
-
/**
|
153 |
-
* Function to get the internal breadcrumb ID
|
154 |
-
*
|
155 |
-
* @return int the id of the resource this breadcrumb represents
|
156 |
-
*/
|
157 |
-
public function get_id()
|
158 |
-
{
|
159 |
-
return $this->id;
|
160 |
-
}
|
161 |
-
/**
|
162 |
-
* Append a type entry to the type array
|
163 |
-
*
|
164 |
-
* @param string $type the type to append
|
165 |
-
*/
|
166 |
-
public function add_type($type)
|
167 |
-
{
|
168 |
-
$this->type[] = $type;
|
169 |
-
}
|
170 |
-
/**
|
171 |
-
* Return the type array
|
172 |
-
*
|
173 |
-
* @return array The type array
|
174 |
-
*/
|
175 |
-
public function get_types()
|
176 |
-
{
|
177 |
-
return $this->type;
|
178 |
-
}
|
179 |
-
/**
|
180 |
-
* This function will intelligently trim the title to the value passed in through $max_length. This function is deprecated, do not call.
|
181 |
-
*
|
182 |
-
* @param int $max_length of the title.
|
183 |
-
* @deprecated since 5.2.0
|
184 |
-
*/
|
185 |
-
public function title_trim($max_length)
|
186 |
-
{
|
187 |
-
_deprecated_function(__FUNCTION__, '5.2.0');
|
188 |
-
//To preserve HTML entities, must decode before splitting
|
189 |
-
$this->title = html_entity_decode($this->title, ENT_COMPAT, 'UTF-8');
|
190 |
-
$title_length = mb_strlen($this->title);
|
191 |
-
//Make sure that we are not making it longer with that ellipse
|
192 |
-
if($title_length > $max_length && ($title_length + 2) > $max_length)
|
193 |
-
{
|
194 |
-
//Trim the title
|
195 |
-
$this->title = mb_substr($this->title, 0, $max_length - 1);
|
196 |
-
//Make sure we can split, but we want to limmit to cutting at max an additional 25%
|
197 |
-
if(mb_strpos($this->title, ' ', .75 * $max_length) > 0)
|
198 |
-
{
|
199 |
-
//Don't split mid word
|
200 |
-
while(mb_substr($this->title,-1) != ' ')
|
201 |
-
{
|
202 |
-
$this->title = mb_substr($this->title, 0, -1);
|
203 |
-
}
|
204 |
-
}
|
205 |
-
//Remove the whitespace at the end and add the hellip
|
206 |
-
$this->title = rtrim($this->title) . html_entity_decode('…', ENT_COMPAT, 'UTF-8');
|
207 |
-
}
|
208 |
-
//Return to the encoded version of all HTML entities (keep standards complance)
|
209 |
-
$this->title = force_balance_tags(htmlentities($this->title, ENT_COMPAT, 'UTF-8'));
|
210 |
-
}
|
211 |
-
/**
|
212 |
-
* Assembles the parts of the breadcrumb into a html string
|
213 |
-
*
|
214 |
-
* @param bool $linked Allow the output to contain anchors?
|
215 |
-
* @param int $position The position of the breadcrumb in the trail (between 1 and n when there are n breadcrumbs in the trail)
|
216 |
-
*
|
217 |
-
* @return string The compiled breadcrumb string
|
218 |
-
*/
|
219 |
-
public function assemble($linked, $position)
|
220 |
-
{
|
221 |
-
//Build our replacements array
|
222 |
-
$replacements = array(
|
223 |
-
'%title%' => esc_attr(strip_tags($this->title)),
|
224 |
-
'%link%' => esc_url($this->url),
|
225 |
-
'%htitle%' => $this->title,
|
226 |
-
'%type%' => apply_filters('bcn_breadcrumb_types', $this->type, $this->id),
|
227 |
-
'%ftitle%' => esc_attr(strip_tags($this->_title)),
|
228 |
-
'%fhtitle%' => $this->_title,
|
229 |
-
'%position%' => $position
|
230 |
-
);
|
231 |
-
//The type may be an array, implode it if that is the case
|
232 |
-
if(is_array($replacements['%type%']))
|
233 |
-
{
|
234 |
-
array_walk($replacements['%type%'], 'sanitize_html_class');
|
235 |
-
$replacements['%type%'] = esc_attr(implode(' ', $replacements['%type%']));
|
236 |
-
}
|
237 |
-
else
|
238 |
-
{
|
239 |
-
_doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('bcn_breadcrumb::type must be an array', 'breadcrumb-navxt'), '6.0.2');
|
240 |
-
}
|
241 |
-
$replacements = apply_filters('bcn_template_tags', $replacements, $this->type, $this->id);
|
242 |
-
//If we are linked we'll need to use the normal template
|
243 |
-
if($this->linked && $linked)
|
244 |
-
{
|
245 |
-
//Return the assembled breadcrumb string
|
246 |
-
return str_replace(array_keys($replacements), $replacements, $this->template);
|
247 |
-
}
|
248 |
-
//Otherwise we use the no anchor template
|
249 |
-
else
|
250 |
-
{
|
251 |
-
//Return the assembled breadcrumb string
|
252 |
-
return str_replace(array_keys($replacements), $replacements, $this->template_no_anchor);
|
253 |
-
}
|
254 |
-
}
|
255 |
-
/**
|
256 |
-
* Assembles the parts of the breadcrumb into a JSON-LD ready object-array
|
257 |
-
*
|
258 |
-
* @param int $position The position of the breadcrumb in the trail (between 1 and n when there are n breadcrumbs in the trail)
|
259 |
-
*
|
260 |
-
* @return array(object) The prepared array object ready to pass into json_encode
|
261 |
-
*/
|
262 |
-
public function assemble_json_ld($position)
|
263 |
-
{
|
264 |
-
return (object)array(
|
265 |
-
'@type' => 'ListItem',
|
266 |
-
'position' => $position,
|
267 |
-
'item' => (object)array(
|
268 |
-
'@id' => esc_url($this->url),
|
269 |
-
'name' => esc_attr($this->title))
|
270 |
-
);
|
271 |
-
}
|
272 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2007-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
+
//The breadcrumb class
|
21 |
+
class bcn_breadcrumb
|
22 |
+
{
|
23 |
+
//Our member variables
|
24 |
+
const version = '6.1.0';
|
25 |
+
//The main text that will be shown
|
26 |
+
protected $title;
|
27 |
+
//The breadcrumb's template, used durring assembly
|
28 |
+
protected $template;
|
29 |
+
//The breadcrumb's no anchor template, used durring assembly when there won't be an anchor
|
30 |
+
protected $template_no_anchor;
|
31 |
+
//Boolean, is this element linked
|
32 |
+
protected $linked = false;
|
33 |
+
//The link the breadcrumb leads to, null if $linked == false
|
34 |
+
protected $url;
|
35 |
+
//The corresponding resource ID
|
36 |
+
protected $id = null;
|
37 |
+
private $_title = null;
|
38 |
+
//The type of this breadcrumb
|
39 |
+
protected $type;
|
40 |
+
protected $allowed_html = array();
|
41 |
+
const default_template_no_anchor = '<span property="itemListElement" typeof="ListItem"><span property="name">%htitle%</span><meta property="position" content="%position%"></span>';
|
42 |
+
/**
|
43 |
+
* The enhanced default constructor, ends up setting all parameters via the set_ functions
|
44 |
+
*
|
45 |
+
* @param string $title (optional) The title of the breadcrumb
|
46 |
+
* @param string $template (optional) The html template for the breadcrumb
|
47 |
+
* @param string $type (optional) The breadcrumb type
|
48 |
+
* @param string $url (optional) The url the breadcrumb links to
|
49 |
+
*/
|
50 |
+
public function __construct($title = '', $template = '', array $type = array(), $url = '', $id = null)
|
51 |
+
{
|
52 |
+
//Filter allowed_html array to allow others to add acceptable tags
|
53 |
+
$this->allowed_html = apply_filters('bcn_allowed_html', wp_kses_allowed_html('post'));
|
54 |
+
//The breadcrumb type
|
55 |
+
$this->type = $type;
|
56 |
+
//Set the resource id
|
57 |
+
$this->set_id($id);
|
58 |
+
//Set the title
|
59 |
+
$this->set_title($title);
|
60 |
+
//Set the default anchorless templates value
|
61 |
+
$this->template_no_anchor = bcn_breadcrumb::default_template_no_anchor;
|
62 |
+
//If we didn't get a good template, use a default template
|
63 |
+
if($template == null)
|
64 |
+
{
|
65 |
+
$this->set_template(bcn_breadcrumb::get_default_template());
|
66 |
+
}
|
67 |
+
//If something was passed in template wise, update the appropriate internal template
|
68 |
+
else
|
69 |
+
{
|
70 |
+
//Loose comparison, evaluates to true if URL is '' or null
|
71 |
+
if($url == null)
|
72 |
+
{
|
73 |
+
$this->template_no_anchor = wp_kses(apply_filters('bcn_breadcrumb_template_no_anchor', $template, $this->type, $this->id), $this->allowed_html);
|
74 |
+
$this->set_template(bcn_breadcrumb::get_default_template());
|
75 |
+
}
|
76 |
+
else
|
77 |
+
{
|
78 |
+
$this->set_template($template);
|
79 |
+
}
|
80 |
+
}
|
81 |
+
//Always null if unlinked
|
82 |
+
$this->set_url($url);
|
83 |
+
}
|
84 |
+
/**
|
85 |
+
* Function to return the translated default template
|
86 |
+
*
|
87 |
+
* @return string The default breadcrumb template
|
88 |
+
*/
|
89 |
+
static public function get_default_template()
|
90 |
+
{
|
91 |
+
return __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to %title%." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt');
|
92 |
+
}
|
93 |
+
/**
|
94 |
+
* Function to set the protected title member
|
95 |
+
*
|
96 |
+
* @param string $title The title of the breadcrumb
|
97 |
+
*/
|
98 |
+
public function set_title($title)
|
99 |
+
{
|
100 |
+
//Set the title
|
101 |
+
$this->title = apply_filters('bcn_breadcrumb_title', $title, $this->type, $this->id);
|
102 |
+
$this->_title = $this->title;
|
103 |
+
}
|
104 |
+
/**
|
105 |
+
* Function to get the protected title member
|
106 |
+
*
|
107 |
+
* @return $this->title
|
108 |
+
*/
|
109 |
+
public function get_title()
|
110 |
+
{
|
111 |
+
//Return the title
|
112 |
+
return $this->title;
|
113 |
+
}
|
114 |
+
/**
|
115 |
+
* Function to set the internal URL variable
|
116 |
+
*
|
117 |
+
* @param string $url the url to link to
|
118 |
+
*/
|
119 |
+
public function set_url($url)
|
120 |
+
{
|
121 |
+
$url = trim($url);
|
122 |
+
$this->url = apply_filters('bcn_breadcrumb_url', $url, $this->type, $this->id);
|
123 |
+
//If the URL seemed nullish, we are not linked
|
124 |
+
if($this->url === '')
|
125 |
+
{
|
126 |
+
$this->linked = false;
|
127 |
+
}
|
128 |
+
else
|
129 |
+
{
|
130 |
+
$this->linked = true;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
/**
|
134 |
+
* Function to set the internal breadcrumb template
|
135 |
+
*
|
136 |
+
* @param string $template the template to use durring assebly
|
137 |
+
*/
|
138 |
+
public function set_template($template)
|
139 |
+
{
|
140 |
+
//Assign the breadcrumb template
|
141 |
+
$this->template = wp_kses(apply_filters('bcn_breadcrumb_template', $template, $this->type, $this->id), $this->allowed_html);
|
142 |
+
}
|
143 |
+
/**
|
144 |
+
* Function to set the internal breadcrumb ID
|
145 |
+
*
|
146 |
+
* @param int $id the id of the resource this breadcrumb represents
|
147 |
+
*/
|
148 |
+
public function set_id($id)
|
149 |
+
{
|
150 |
+
$this->id = $id;
|
151 |
+
}
|
152 |
+
/**
|
153 |
+
* Function to get the internal breadcrumb ID
|
154 |
+
*
|
155 |
+
* @return int the id of the resource this breadcrumb represents
|
156 |
+
*/
|
157 |
+
public function get_id()
|
158 |
+
{
|
159 |
+
return $this->id;
|
160 |
+
}
|
161 |
+
/**
|
162 |
+
* Append a type entry to the type array
|
163 |
+
*
|
164 |
+
* @param string $type the type to append
|
165 |
+
*/
|
166 |
+
public function add_type($type)
|
167 |
+
{
|
168 |
+
$this->type[] = $type;
|
169 |
+
}
|
170 |
+
/**
|
171 |
+
* Return the type array
|
172 |
+
*
|
173 |
+
* @return array The type array
|
174 |
+
*/
|
175 |
+
public function get_types()
|
176 |
+
{
|
177 |
+
return $this->type;
|
178 |
+
}
|
179 |
+
/**
|
180 |
+
* This function will intelligently trim the title to the value passed in through $max_length. This function is deprecated, do not call.
|
181 |
+
*
|
182 |
+
* @param int $max_length of the title.
|
183 |
+
* @deprecated since 5.2.0
|
184 |
+
*/
|
185 |
+
public function title_trim($max_length)
|
186 |
+
{
|
187 |
+
_deprecated_function(__FUNCTION__, '5.2.0');
|
188 |
+
//To preserve HTML entities, must decode before splitting
|
189 |
+
$this->title = html_entity_decode($this->title, ENT_COMPAT, 'UTF-8');
|
190 |
+
$title_length = mb_strlen($this->title);
|
191 |
+
//Make sure that we are not making it longer with that ellipse
|
192 |
+
if($title_length > $max_length && ($title_length + 2) > $max_length)
|
193 |
+
{
|
194 |
+
//Trim the title
|
195 |
+
$this->title = mb_substr($this->title, 0, $max_length - 1);
|
196 |
+
//Make sure we can split, but we want to limmit to cutting at max an additional 25%
|
197 |
+
if(mb_strpos($this->title, ' ', .75 * $max_length) > 0)
|
198 |
+
{
|
199 |
+
//Don't split mid word
|
200 |
+
while(mb_substr($this->title,-1) != ' ')
|
201 |
+
{
|
202 |
+
$this->title = mb_substr($this->title, 0, -1);
|
203 |
+
}
|
204 |
+
}
|
205 |
+
//Remove the whitespace at the end and add the hellip
|
206 |
+
$this->title = rtrim($this->title) . html_entity_decode('…', ENT_COMPAT, 'UTF-8');
|
207 |
+
}
|
208 |
+
//Return to the encoded version of all HTML entities (keep standards complance)
|
209 |
+
$this->title = force_balance_tags(htmlentities($this->title, ENT_COMPAT, 'UTF-8'));
|
210 |
+
}
|
211 |
+
/**
|
212 |
+
* Assembles the parts of the breadcrumb into a html string
|
213 |
+
*
|
214 |
+
* @param bool $linked Allow the output to contain anchors?
|
215 |
+
* @param int $position The position of the breadcrumb in the trail (between 1 and n when there are n breadcrumbs in the trail)
|
216 |
+
*
|
217 |
+
* @return string The compiled breadcrumb string
|
218 |
+
*/
|
219 |
+
public function assemble($linked, $position)
|
220 |
+
{
|
221 |
+
//Build our replacements array
|
222 |
+
$replacements = array(
|
223 |
+
'%title%' => esc_attr(strip_tags($this->title)),
|
224 |
+
'%link%' => esc_url($this->url),
|
225 |
+
'%htitle%' => $this->title,
|
226 |
+
'%type%' => apply_filters('bcn_breadcrumb_types', $this->type, $this->id),
|
227 |
+
'%ftitle%' => esc_attr(strip_tags($this->_title)),
|
228 |
+
'%fhtitle%' => $this->_title,
|
229 |
+
'%position%' => $position
|
230 |
+
);
|
231 |
+
//The type may be an array, implode it if that is the case
|
232 |
+
if(is_array($replacements['%type%']))
|
233 |
+
{
|
234 |
+
array_walk($replacements['%type%'], 'sanitize_html_class');
|
235 |
+
$replacements['%type%'] = esc_attr(implode(' ', $replacements['%type%']));
|
236 |
+
}
|
237 |
+
else
|
238 |
+
{
|
239 |
+
_doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('bcn_breadcrumb::type must be an array', 'breadcrumb-navxt'), '6.0.2');
|
240 |
+
}
|
241 |
+
$replacements = apply_filters('bcn_template_tags', $replacements, $this->type, $this->id);
|
242 |
+
//If we are linked we'll need to use the normal template
|
243 |
+
if($this->linked && $linked)
|
244 |
+
{
|
245 |
+
//Return the assembled breadcrumb string
|
246 |
+
return str_replace(array_keys($replacements), $replacements, $this->template);
|
247 |
+
}
|
248 |
+
//Otherwise we use the no anchor template
|
249 |
+
else
|
250 |
+
{
|
251 |
+
//Return the assembled breadcrumb string
|
252 |
+
return str_replace(array_keys($replacements), $replacements, $this->template_no_anchor);
|
253 |
+
}
|
254 |
+
}
|
255 |
+
/**
|
256 |
+
* Assembles the parts of the breadcrumb into a JSON-LD ready object-array
|
257 |
+
*
|
258 |
+
* @param int $position The position of the breadcrumb in the trail (between 1 and n when there are n breadcrumbs in the trail)
|
259 |
+
*
|
260 |
+
* @return array(object) The prepared array object ready to pass into json_encode
|
261 |
+
*/
|
262 |
+
public function assemble_json_ld($position)
|
263 |
+
{
|
264 |
+
return (object)array(
|
265 |
+
'@type' => 'ListItem',
|
266 |
+
'position' => $position,
|
267 |
+
'item' => (object)array(
|
268 |
+
'@id' => esc_url($this->url),
|
269 |
+
'name' => esc_attr($this->title))
|
270 |
+
);
|
271 |
+
}
|
272 |
}
|
class.bcn_breadcrumb_trail.php
CHANGED
@@ -1,1265 +1,1279 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
-
//The trail class
|
21 |
-
class bcn_breadcrumb_trail
|
22 |
-
{
|
23 |
-
//Our member variables
|
24 |
-
const version = '6.0
|
25 |
-
//An array of breadcrumbs
|
26 |
-
public $breadcrumbs = array();
|
27 |
-
public $trail = array();
|
28 |
-
//The options
|
29 |
-
public $opt;
|
30 |
-
//Default constructor
|
31 |
-
public function __construct()
|
32 |
-
{
|
33 |
-
//@see https://core.trac.wordpress.org/ticket/10527
|
34 |
-
if(!is_textdomain_loaded('breadcrumb-navxt'))
|
35 |
-
{
|
36 |
-
load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages');
|
37 |
-
}
|
38 |
-
$this->trail = &$this->breadcrumbs;
|
39 |
-
//Initilize with default option values
|
40 |
-
$this->opt = array(
|
41 |
-
//Should the mainsite be shown
|
42 |
-
'bmainsite_display' => true,
|
43 |
-
//The breadcrumb template for the main site
|
44 |
-
'Hmainsite_template' => bcn_breadcrumb::get_default_template(),
|
45 |
-
//The breadcrumb template for the main site, used when an anchor is not needed
|
46 |
-
'Hmainsite_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
47 |
-
//Should the home page be shown
|
48 |
-
'bhome_display' => true,
|
49 |
-
//The breadcrumb template for the home page
|
50 |
-
'Hhome_template' => bcn_breadcrumb::get_default_template(),
|
51 |
-
//The breadcrumb template for the home page, used when an anchor is not needed
|
52 |
-
'Hhome_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
53 |
-
//Should the blog page be shown globally
|
54 |
-
'bblog_display' => true,
|
55 |
-
//Separator that is placed between each item in the breadcrumb trial, but not placed before
|
56 |
-
//the first and not after the last breadcrumb
|
57 |
-
'hseparator' => ' > ',
|
58 |
-
//Whether or not we should trim the breadcrumb titles
|
59 |
-
'blimit_title' => false,
|
60 |
-
//The maximum title length
|
61 |
-
'amax_title_length' => 20,
|
62 |
-
//Current item options
|
63 |
-
'bcurrent_item_linked' => false,
|
64 |
-
//Static page options
|
65 |
-
//Should the trail include the hierarchy of the page
|
66 |
-
'bpost_page_hierarchy_display' => true,
|
67 |
-
//What hierarchy should be shown leading to the page
|
68 |
-
'Spost_page_hierarchy_type' => 'BCN_POST_PARENT',
|
69 |
-
//The anchor template for page breadcrumbs
|
70 |
-
'Hpost_page_template' => bcn_breadcrumb::get_default_template(),
|
71 |
-
//The anchor template for page breadcrumbs, used when an anchor is not needed
|
72 |
-
'Hpost_page_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
73 |
-
//Just a link to the page on front property
|
74 |
-
'apost_page_root' => get_option('page_on_front'),
|
75 |
-
//Paged options
|
76 |
-
//The template for paged breadcrumb
|
77 |
-
'Hpaged_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Page %htitle%</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
78 |
-
//Should we try filling out paged information
|
79 |
-
'bpaged_display' => false,
|
80 |
-
//The post options previously singleblogpost
|
81 |
-
//The breadcrumb template for post breadcrumbs
|
82 |
-
'Hpost_post_template' => bcn_breadcrumb::get_default_template(),
|
83 |
-
//The breadcrumb template for post breadcrumbs, used when an anchor is not needed
|
84 |
-
'Hpost_post_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
85 |
-
//Just a link for the page for posts
|
86 |
-
'apost_post_root' => get_option('page_for_posts'),
|
87 |
-
//Should the trail include the hierarchy of the post
|
88 |
-
'bpost_post_hierarchy_display' => true,
|
89 |
-
//Should the trail reflect the referer taxonomy or not
|
90 |
-
'bpost_post_taxonomy_referer' => false,
|
91 |
-
//What hierarchy should be shown leading to the post, tag or category
|
92 |
-
'Spost_post_hierarchy_type' => 'category',
|
93 |
-
//Attachment settings
|
94 |
-
'bpost_attachment_hierarchy_display' => true,
|
95 |
-
//What hierarchy should be shown leading to the attachment
|
96 |
-
'Spost_attachment_hierarchy_type' => 'BCN_POST_PARENT',
|
97 |
-
//Give an invlaid page ID for the attachement root
|
98 |
-
'apost_attachment_root' => 0,
|
99 |
-
//The breadcrumb template for attachment breadcrumbs
|
100 |
-
'Hpost_attachment_template' => bcn_breadcrumb::get_default_template(),
|
101 |
-
//The breadcrumb template for attachment breadcrumbs, used when an anchor is not needed
|
102 |
-
'Hpost_attachment_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
103 |
-
//404 page settings
|
104 |
-
//The template for 404 breadcrumbs
|
105 |
-
'H404_template' => bcn_breadcrumb::default_template_no_anchor,
|
106 |
-
//The text to be shown in the breadcrumb for a 404 page
|
107 |
-
'S404_title' => __('404', 'breadcrumb-navxt'),
|
108 |
-
//Search page options
|
109 |
-
//The breadcrumb template for search breadcrumbs
|
110 |
-
'Hsearch_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Search results for '<a property="item" typeof="WebPage" title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
111 |
-
//The breadcrumb template for search breadcrumbs, used when an anchor is not necessary
|
112 |
-
'Hsearch_template_no_anchor' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Search results for '%htitle%'</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
113 |
-
//Tag related stuff
|
114 |
-
//The breadcrumb template for tag breadcrumbs
|
115 |
-
'Htax_post_tag_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% tag archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
116 |
-
//The breadcrumb template for tag breadcrumbs, used when an anchor is not necessary
|
117 |
-
'Htax_post_tag_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
118 |
-
//Post format related stuff
|
119 |
-
//The breadcrumb template for post format breadcrumbs, used when an anchor is not necessary
|
120 |
-
'Htax_post_format_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
121 |
-
//The breadcrumb template for post format breadcrumbs
|
122 |
-
'Htax_post_format_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
123 |
-
//Author page stuff
|
124 |
-
//The anchor template for author breadcrumbs
|
125 |
-
'Hauthor_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Articles by: <a title="Go to the first page of posts by %title%." href="%link%" class="%type%">%htitle%</a>', 'breadcrumb-navxt'),
|
126 |
-
//The anchor template for author breadcrumbs, used when anchors are not needed
|
127 |
-
'Hauthor_template_no_anchor' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Articles by: %htitle%</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
128 |
-
//Which of the various WordPress display types should the author breadcrumb display
|
129 |
-
'Sauthor_name' => 'display_name',
|
130 |
-
//
|
131 |
-
|
132 |
-
|
133 |
-
//The breadcrumb template for category breadcrumbs
|
134 |
-
'
|
135 |
-
//The breadcrumb template for
|
136 |
-
'
|
137 |
-
//The breadcrumb template for date breadcrumbs
|
138 |
-
'
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
*
|
145 |
-
*
|
146 |
-
* @
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
*
|
157 |
-
*
|
158 |
-
* @
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
*
|
170 |
-
*
|
171 |
-
*
|
172 |
-
*
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
//
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
//
|
184 |
-
$breadcrumb->
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
*
|
191 |
-
*
|
192 |
-
*
|
193 |
-
*
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
//
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
//
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
*
|
217 |
-
*
|
218 |
-
* @
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
*
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
//
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
//
|
256 |
-
$bcn_wp
|
257 |
-
$
|
258 |
-
$
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
*
|
275 |
-
*
|
276 |
-
* @param
|
277 |
-
*
|
278 |
-
* @
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
*
|
307 |
-
*
|
308 |
-
*
|
309 |
-
*
|
310 |
-
* @param int $
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
$
|
323 |
-
$this->
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
//
|
333 |
-
$parent = $
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
//
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
if
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
//
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
*
|
387 |
-
*
|
388 |
-
*
|
389 |
-
*
|
390 |
-
*
|
391 |
-
*
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
//
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
*
|
425 |
-
*
|
426 |
-
*
|
427 |
-
*
|
428 |
-
*
|
429 |
-
* @
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
//
|
436 |
-
$
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
//
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
*
|
536 |
-
*
|
537 |
-
* This
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
$breadcrumb
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
*
|
784 |
-
*
|
785 |
-
*
|
786 |
-
*
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
*
|
796 |
-
*
|
797 |
-
* @
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
*
|
831 |
-
*
|
832 |
-
* @
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
{
|
884 |
-
//
|
885 |
-
$
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
}
|
945 |
-
/**
|
946 |
-
* A Breadcrumb Trail Filling Function
|
947 |
-
*
|
948 |
-
* This functions fills a breadcrumb for
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
*
|
959 |
-
*
|
960 |
-
*
|
961 |
-
*/
|
962 |
-
|
963 |
-
{
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
976 |
{
|
977 |
$this->opt['apost_post_root'] = false;
|
978 |
-
}
|
979 |
-
//Do any actions if necessary, we past through the current object instance to keep life simple
|
980 |
-
do_action('bcn_before_fill', $this);
|
981 |
-
$type = $wp_query->get_queried_object();
|
982 |
-
//Do specific opperations for the various page types
|
983 |
-
//Check if this isn't the first of a multi paged item
|
984 |
-
if($this->opt['bpaged_display'] && (is_paged() || is_singular() && get_query_var('page') > 1))
|
985 |
-
{
|
986 |
-
//Need to switch between paged and page for archives and singular (posts)
|
987 |
-
if(get_query_var('paged') > 0)
|
988 |
-
{
|
989 |
-
//Can use simple type hinting here to int since we already checked for greater than 0
|
990 |
-
$page_number = (int) abs(get_query_var('paged'));
|
991 |
-
}
|
992 |
-
else
|
993 |
-
{
|
994 |
-
$page_number = (int) abs(get_query_var('page'));
|
995 |
-
}
|
996 |
-
$this->do_paged($page_number);
|
997 |
-
}
|
998 |
-
//For the front page, as it may also validate as a page, do it first
|
999 |
-
if(is_front_page())
|
1000 |
-
{
|
1001 |
-
//Must have two seperate branches so that we don't evaluate it as a page
|
1002 |
-
if($this->opt['bhome_display'])
|
1003 |
-
{
|
1004 |
-
$this->do_home(false, is_paged());
|
1005 |
-
}
|
1006 |
-
}
|
1007 |
-
//For posts
|
1008 |
-
else if(is_singular())
|
1009 |
-
{
|
1010 |
-
$this->do_post(get_post(), false, (get_query_var('page') > 1));
|
1011 |
-
//If this is an attachment then we need to change the queried object to the parent post
|
1012 |
-
if(is_attachment())
|
1013 |
-
{
|
1014 |
-
//Could use the $post global, but we can't really trust it
|
1015 |
-
$post = get_post();
|
1016 |
-
$type = get_post($post->post_parent); //TODO check for WP_Error?
|
1017 |
-
}
|
1018 |
-
$this->do_root($type->post_type, $this->opt['apost_' . $type->post_type . '_root'], is_paged(), false);
|
1019 |
-
}
|
1020 |
-
//For searches
|
1021 |
-
else if(is_search())
|
1022 |
-
{
|
1023 |
-
$this->do_search(get_search_query(), is_paged());
|
1024 |
-
}
|
1025 |
-
//For author pages
|
1026 |
-
else if(is_author())
|
1027 |
-
{
|
1028 |
-
$this->do_author($type, is_paged());
|
1029 |
-
$this->do_root('post',
|
1030 |
-
}
|
1031 |
-
//For archives
|
1032 |
-
else if(is_archive())
|
1033 |
-
{
|
1034 |
-
//We need the type for later, so save it
|
1035 |
-
$type_str = get_query_var('post_type');
|
1036 |
-
//May be an array, if so, rewind the iterator and grab first item
|
1037 |
-
if(is_array($type_str))
|
1038 |
-
{
|
1039 |
-
$type_str = reset($type_str);
|
1040 |
-
}
|
1041 |
-
//For date based archives
|
1042 |
-
if(is_date())
|
1043 |
-
{
|
1044 |
-
//First deal with the day breadcrumb
|
1045 |
-
if(is_day())
|
1046 |
-
{
|
1047 |
-
$this->do_day(get_post(), $this->get_type_string_query_var(), is_paged(), true);
|
1048 |
-
}
|
1049 |
-
//Now deal with the month breadcrumb
|
1050 |
-
if(is_month() || is_day())
|
1051 |
-
{
|
1052 |
-
$this->do_month(get_post(), $this->get_type_string_query_var(), is_paged(), is_month());
|
1053 |
-
}
|
1054 |
-
$this->do_year(get_post(), $this->get_type_string_query_var(), is_paged(), is_year());
|
1055 |
-
$type_str = $this->get_type_string_query_var();
|
1056 |
-
$this->type_archive($type, $type_str);
|
1057 |
-
}
|
1058 |
-
//If we have a post type archive, and it does not have a root page generate the archive
|
1059 |
-
else if(is_post_type_archive() && !isset($type->taxonomy)
|
1060 |
-
&& (!is_numeric($this->opt['apost_' . $type_str . '_root']) || $this->opt['bpost_' . $type_str . '_archive_display']))
|
1061 |
-
{
|
1062 |
-
$this->do_archive_by_post_type($this->get_type_string_query_var(), is_paged());
|
1063 |
-
}
|
1064 |
-
//For taxonomy based archives
|
1065 |
-
else if(is_category() || is_tag() || is_tax())
|
1066 |
-
{
|
1067 |
-
$this->do_archive_by_term($type, is_paged());
|
1068 |
-
$this->type_archive($type);
|
1069 |
-
$type_str = $this->get_type_string_query_var($GLOBALS['wp_taxonomies'][$type->taxonomy]->object_type[0]);
|
1070 |
-
}
|
1071 |
-
else
|
1072 |
-
{
|
1073 |
-
$this->type_archive($type);
|
1074 |
-
}
|
1075 |
-
$this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str));
|
1076 |
-
}
|
1077 |
-
//For 404 pages
|
1078 |
-
else if(is_404())
|
1079 |
-
{
|
1080 |
-
$this->do_404();
|
1081 |
-
}
|
1082 |
-
else
|
1083 |
-
{
|
1084 |
-
//If it looks, walks, and quacks like a taxonomy, treat is as one
|
1085 |
-
if(isset($type->taxonomy))
|
1086 |
-
{
|
1087 |
-
$this->do_archive_by_term($type, is_paged());
|
1088 |
-
$this->type_archive($type);
|
1089 |
-
$type_str = $this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0]);
|
1090 |
-
}
|
1091 |
-
//Otherwise, it's likely the blog page
|
1092 |
-
else if($this->opt['bblog_display'] || is_home())
|
1093 |
-
{
|
1094 |
-
$type_str = 'post';
|
1095 |
-
}
|
1096 |
-
if(isset($this->opt['apost_' . $type_str . '_root']))
|
1097 |
-
{
|
1098 |
-
$this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str));
|
1099 |
-
}
|
1100 |
-
}
|
1101 |
-
//We always do the home link last, unless on the frontpage
|
1102 |
-
if(!is_front_page())
|
1103 |
-
{
|
1104 |
-
$this->do_home(true, false, false);
|
1105 |
-
}
|
1106 |
-
//Do any actions if necessary, we past through the current object instance to keep life simple
|
1107 |
-
do_action('bcn_after_fill', $this);
|
1108 |
-
}
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
-
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
1122 |
-
else
|
1123 |
-
{
|
1124 |
-
|
1125 |
-
|
1126 |
-
|
1127 |
-
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
}
|
1150 |
-
else
|
1151 |
-
{
|
1152 |
-
//
|
1153 |
-
$
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
*
|
1159 |
-
*
|
1160 |
-
* @
|
1161 |
-
*
|
1162 |
-
*
|
1163 |
-
* @
|
1164 |
-
* @
|
1165 |
-
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
return $
|
1173 |
-
}
|
1174 |
-
/**
|
1175 |
-
* This
|
1176 |
-
*
|
1177 |
-
* @
|
1178 |
-
*
|
1179 |
-
* @param
|
1180 |
-
*
|
1181 |
-
*
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
$
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1200 |
{
|
1201 |
$separator = '';
|
1202 |
-
}
|
1203 |
-
//Filter li_attributes adding attributes to the li element
|
1204 |
-
$attribs = apply_filters_deprecated('bcn_li_attributes', array($class, $breadcrumb->get_types(), $breadcrumb->get_id()), '6.0.0', 'bcn_display_attributes');
|
1205 |
-
$attribs = apply_filters('bcn_display_attributes', $class, $breadcrumb->get_types(), $breadcrumb->get_id());
|
1206 |
-
//Trim titles, if requested
|
1207 |
-
if($this->opt['blimit_title'] && $this->opt['amax_title_length'] > 0)
|
1208 |
-
{
|
1209 |
-
//Trim the breadcrumb's title
|
1210 |
-
$breadcrumb->title_trim($this->opt['amax_title_length']);
|
1211 |
-
}
|
1212 |
-
//Assemble the breadrumb and wrap with li's
|
1213 |
-
$trail_str .= sprintf($template, $breadcrumb->assemble($linked, $position), $separator, $attribs);
|
1214 |
-
$position++;
|
1215 |
-
}
|
1216 |
-
return $trail_str;
|
1217 |
-
}
|
1218 |
-
/**
|
1219 |
-
* This functions outputs or returns the breadcrumb trail in Schema.org BreadcrumbList compliant JSON-LD
|
1220 |
-
*
|
1221 |
-
* @param bool $
|
1222 |
-
*
|
1223 |
-
*
|
1224 |
-
* @return
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
1230 |
-
$
|
1231 |
-
|
1232 |
-
|
1233 |
-
|
1234 |
-
|
1235 |
-
|
1236 |
-
|
1237 |
-
|
1238 |
-
|
1239 |
-
|
1240 |
-
|
1241 |
-
|
1242 |
-
|
1243 |
-
|
1244 |
-
|
1245 |
-
|
1246 |
-
|
1247 |
-
|
1248 |
-
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
{
|
1255 |
-
$postion = 1;
|
1256 |
-
$breadcrumbs = array();
|
1257 |
-
//Loop around our breadcrumbs, call the JSON-LD assembler
|
1258 |
-
foreach($this->breadcrumbs as $breadcrumb)
|
1259 |
-
{
|
1260 |
-
$breadcrumbs[] = $breadcrumb->assemble_json_ld($postion);
|
1261 |
-
$postion++;
|
1262 |
-
}
|
1263 |
-
return $breadcrumbs;
|
1264 |
-
}
|
1265 |
-
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
+
//The trail class
|
21 |
+
class bcn_breadcrumb_trail
|
22 |
+
{
|
23 |
+
//Our member variables
|
24 |
+
const version = '6.1.0';
|
25 |
+
//An array of breadcrumbs
|
26 |
+
public $breadcrumbs = array();
|
27 |
+
public $trail = array();
|
28 |
+
//The options
|
29 |
+
public $opt;
|
30 |
+
//Default constructor
|
31 |
+
public function __construct()
|
32 |
+
{
|
33 |
+
//@see https://core.trac.wordpress.org/ticket/10527
|
34 |
+
if(!is_textdomain_loaded('breadcrumb-navxt'))
|
35 |
+
{
|
36 |
+
load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages');
|
37 |
+
}
|
38 |
+
$this->trail = &$this->breadcrumbs;
|
39 |
+
//Initilize with default option values
|
40 |
+
$this->opt = array(
|
41 |
+
//Should the mainsite be shown
|
42 |
+
'bmainsite_display' => true,
|
43 |
+
//The breadcrumb template for the main site
|
44 |
+
'Hmainsite_template' => bcn_breadcrumb::get_default_template(),
|
45 |
+
//The breadcrumb template for the main site, used when an anchor is not needed
|
46 |
+
'Hmainsite_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
47 |
+
//Should the home page be shown
|
48 |
+
'bhome_display' => true,
|
49 |
+
//The breadcrumb template for the home page
|
50 |
+
'Hhome_template' => bcn_breadcrumb::get_default_template(),
|
51 |
+
//The breadcrumb template for the home page, used when an anchor is not needed
|
52 |
+
'Hhome_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
53 |
+
//Should the blog page be shown globally
|
54 |
+
'bblog_display' => true,
|
55 |
+
//Separator that is placed between each item in the breadcrumb trial, but not placed before
|
56 |
+
//the first and not after the last breadcrumb
|
57 |
+
'hseparator' => ' > ',
|
58 |
+
//Whether or not we should trim the breadcrumb titles
|
59 |
+
'blimit_title' => false,
|
60 |
+
//The maximum title length
|
61 |
+
'amax_title_length' => 20,
|
62 |
+
//Current item options
|
63 |
+
'bcurrent_item_linked' => false,
|
64 |
+
//Static page options
|
65 |
+
//Should the trail include the hierarchy of the page
|
66 |
+
'bpost_page_hierarchy_display' => true,
|
67 |
+
//What hierarchy should be shown leading to the page
|
68 |
+
'Spost_page_hierarchy_type' => 'BCN_POST_PARENT',
|
69 |
+
//The anchor template for page breadcrumbs
|
70 |
+
'Hpost_page_template' => bcn_breadcrumb::get_default_template(),
|
71 |
+
//The anchor template for page breadcrumbs, used when an anchor is not needed
|
72 |
+
'Hpost_page_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
73 |
+
//Just a link to the page on front property
|
74 |
+
'apost_page_root' => get_option('page_on_front'),
|
75 |
+
//Paged options
|
76 |
+
//The template for paged breadcrumb
|
77 |
+
'Hpaged_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Page %htitle%</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
78 |
+
//Should we try filling out paged information
|
79 |
+
'bpaged_display' => false,
|
80 |
+
//The post options previously singleblogpost
|
81 |
+
//The breadcrumb template for post breadcrumbs
|
82 |
+
'Hpost_post_template' => bcn_breadcrumb::get_default_template(),
|
83 |
+
//The breadcrumb template for post breadcrumbs, used when an anchor is not needed
|
84 |
+
'Hpost_post_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
85 |
+
//Just a link for the page for posts
|
86 |
+
'apost_post_root' => get_option('page_for_posts'),
|
87 |
+
//Should the trail include the hierarchy of the post
|
88 |
+
'bpost_post_hierarchy_display' => true,
|
89 |
+
//Should the trail reflect the referer taxonomy or not
|
90 |
+
'bpost_post_taxonomy_referer' => false,
|
91 |
+
//What hierarchy should be shown leading to the post, tag or category
|
92 |
+
'Spost_post_hierarchy_type' => 'category',
|
93 |
+
//Attachment settings
|
94 |
+
'bpost_attachment_hierarchy_display' => true,
|
95 |
+
//What hierarchy should be shown leading to the attachment
|
96 |
+
'Spost_attachment_hierarchy_type' => 'BCN_POST_PARENT',
|
97 |
+
//Give an invlaid page ID for the attachement root
|
98 |
+
'apost_attachment_root' => 0,
|
99 |
+
//The breadcrumb template for attachment breadcrumbs
|
100 |
+
'Hpost_attachment_template' => bcn_breadcrumb::get_default_template(),
|
101 |
+
//The breadcrumb template for attachment breadcrumbs, used when an anchor is not needed
|
102 |
+
'Hpost_attachment_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
103 |
+
//404 page settings
|
104 |
+
//The template for 404 breadcrumbs
|
105 |
+
'H404_template' => bcn_breadcrumb::default_template_no_anchor,
|
106 |
+
//The text to be shown in the breadcrumb for a 404 page
|
107 |
+
'S404_title' => __('404', 'breadcrumb-navxt'),
|
108 |
+
//Search page options
|
109 |
+
//The breadcrumb template for search breadcrumbs
|
110 |
+
'Hsearch_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Search results for '<a property="item" typeof="WebPage" title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>'</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
111 |
+
//The breadcrumb template for search breadcrumbs, used when an anchor is not necessary
|
112 |
+
'Hsearch_template_no_anchor' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Search results for '%htitle%'</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
113 |
+
//Tag related stuff
|
114 |
+
//The breadcrumb template for tag breadcrumbs
|
115 |
+
'Htax_post_tag_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% tag archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
116 |
+
//The breadcrumb template for tag breadcrumbs, used when an anchor is not necessary
|
117 |
+
'Htax_post_tag_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
118 |
+
//Post format related stuff
|
119 |
+
//The breadcrumb template for post format breadcrumbs, used when an anchor is not necessary
|
120 |
+
'Htax_post_format_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
121 |
+
//The breadcrumb template for post format breadcrumbs
|
122 |
+
'Htax_post_format_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
123 |
+
//Author page stuff
|
124 |
+
//The anchor template for author breadcrumbs
|
125 |
+
'Hauthor_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Articles by: <a title="Go to the first page of posts by %title%." href="%link%" class="%type%">%htitle%</a>', 'breadcrumb-navxt'),
|
126 |
+
//The anchor template for author breadcrumbs, used when anchors are not needed
|
127 |
+
'Hauthor_template_no_anchor' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Articles by: %htitle%</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
128 |
+
//Which of the various WordPress display types should the author breadcrumb display
|
129 |
+
'Sauthor_name' => 'display_name',
|
130 |
+
//Give an invlaid page ID for the author root
|
131 |
+
'aauthor_root' => 0,
|
132 |
+
//Category stuff
|
133 |
+
//The breadcrumb template for category breadcrumbs
|
134 |
+
'Htax_category_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% category archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
135 |
+
//The breadcrumb template for category breadcrumbs, used when anchors are not needed
|
136 |
+
'Htax_category_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor,
|
137 |
+
//The breadcrumb template for date breadcrumbs
|
138 |
+
'Hdate_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'),
|
139 |
+
//The breadcrumb template for date breadcrumbs, used when anchors are not needed
|
140 |
+
'Hdate_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor
|
141 |
+
);
|
142 |
+
}
|
143 |
+
/**
|
144 |
+
* This returns the internal version
|
145 |
+
*
|
146 |
+
* @deprecated 5.2.0 No longer needed, superceeded bcn_breadcrumb_trail::version
|
147 |
+
*
|
148 |
+
* @return string internal version of the Breadcrumb trail
|
149 |
+
*/
|
150 |
+
public function get_version()
|
151 |
+
{
|
152 |
+
_deprecated_function( __FUNCTION__, '5.2', 'bcn_breadcrumb_trail::version' );
|
153 |
+
return self::version;
|
154 |
+
}
|
155 |
+
/**
|
156 |
+
* Adds a breadcrumb to the breadcrumb trail
|
157 |
+
*
|
158 |
+
* @param bcn_breadcrumb $object Breadcrumb to add to the trail
|
159 |
+
*
|
160 |
+
* @return pointer to the just added Breadcrumb
|
161 |
+
*/
|
162 |
+
public function &add(bcn_breadcrumb $object)
|
163 |
+
{
|
164 |
+
$this->breadcrumbs[] = $object;
|
165 |
+
//Return the just added object
|
166 |
+
return $this->breadcrumbs[count($this->breadcrumbs) - 1];
|
167 |
+
}
|
168 |
+
/**
|
169 |
+
* A Breadcrumb Trail Filling Function
|
170 |
+
*
|
171 |
+
* This functions fills a breadcrumb for a search page
|
172 |
+
*
|
173 |
+
* @param string $search_query The search query that was performed
|
174 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
175 |
+
*/
|
176 |
+
protected function do_search($search_query, $is_paged = false)
|
177 |
+
{
|
178 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
179 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($search_query, $this->opt['Hsearch_template_no_anchor'], array('search', 'current-item')));
|
180 |
+
//If we're paged, or allowing the current item to be linked, let's link to the first page
|
181 |
+
if($this->opt['bcurrent_item_linked'] || ($is_paged && $this->opt['bpaged_display']))
|
182 |
+
{
|
183 |
+
//Since we are paged and are linking the root breadcrumb, time to change to the regular template
|
184 |
+
$breadcrumb->set_template($this->opt['Hsearch_template']);
|
185 |
+
//Figure out the anchor for the search
|
186 |
+
$breadcrumb->set_url(get_search_link($search_query));
|
187 |
+
}
|
188 |
+
}
|
189 |
+
/**
|
190 |
+
* A Breadcrumb Trail Filling Function
|
191 |
+
*
|
192 |
+
* This functions fills a breadcrumb for an author page
|
193 |
+
*
|
194 |
+
* @param string $author_data The author to generate the breadcrumb for
|
195 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
196 |
+
*/
|
197 |
+
protected function do_author($author_data, $is_paged = false)
|
198 |
+
{
|
199 |
+
//Setup array of valid author_name values
|
200 |
+
$valid_author_name = array('display_name', 'nickname', 'first_name', 'last_name');
|
201 |
+
//Make sure user picks only safe values
|
202 |
+
if(in_array($this->opt['Sauthor_name'], $valid_author_name))
|
203 |
+
{
|
204 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
205 |
+
$breadcrumb = $this->add(new bcn_breadcrumb(get_the_author_meta($this->opt['Sauthor_name'], $author_data->ID), $this->opt['Hauthor_template_no_anchor'], array('author', 'current-item'), null, $author_data->ID));
|
206 |
+
//If we're paged, or allowing the current item to be linked, let's link to the first page
|
207 |
+
if($this->opt['bcurrent_item_linked'] || ($is_paged && $this->opt['bpaged_display']))
|
208 |
+
{
|
209 |
+
//Set the template to our one containing an anchor
|
210 |
+
$breadcrumb->set_template($this->opt['Hauthor_template']);
|
211 |
+
$breadcrumb->set_url(get_author_posts_url($author_data->ID));
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
/**
|
216 |
+
* Determines the taxonomy name represented by the specified query var
|
217 |
+
*
|
218 |
+
* @param string $query_var The query var to attempt to find the corresponding taxonomy
|
219 |
+
*
|
220 |
+
* @return string|bool Either the name of the taxonomy corresponding to the query_var or false if no taxonomy exists for the specified query_var
|
221 |
+
*/
|
222 |
+
protected function query_var_to_taxonomy($query_var)
|
223 |
+
{
|
224 |
+
global $wp_taxonomies;
|
225 |
+
foreach($wp_taxonomies as $taxonomy)
|
226 |
+
{
|
227 |
+
if($taxonomy->query_var === $query_var)
|
228 |
+
{
|
229 |
+
return $taxonomy->name;
|
230 |
+
}
|
231 |
+
}
|
232 |
+
return false;
|
233 |
+
}
|
234 |
+
/**
|
235 |
+
* Determines the referer taxonomy
|
236 |
+
*
|
237 |
+
* @return string|bool Either the name of the taxonomy to use or false if a referer taxonomy wasn't found
|
238 |
+
*/
|
239 |
+
protected function determine_taxonomy()
|
240 |
+
{
|
241 |
+
global $wp;
|
242 |
+
//Backup the server request variable
|
243 |
+
$bk_req = $_SERVER['REQUEST_URI'];
|
244 |
+
//Now set the request URL to the referrer URL
|
245 |
+
//Could just chain the [1] selection, but that's not PHP5.3 compatible
|
246 |
+
$url_split = explode(home_url(), esc_url(wp_get_referer()));
|
247 |
+
if(isset($url_split[1]))
|
248 |
+
{
|
249 |
+
$_SERVER['REQUEST_URI'] = $url_split[1];
|
250 |
+
}
|
251 |
+
else
|
252 |
+
{
|
253 |
+
return false;
|
254 |
+
}
|
255 |
+
//Create our own new instance of WP, and have it parse our faux request
|
256 |
+
$bcn_wp = new WP();
|
257 |
+
//Copy over the current global wp object's query_vars since CPTs and taxonomies are added directly to the global $wp
|
258 |
+
$bcn_wp->public_query_vars = $wp->public_query_vars;
|
259 |
+
$bcn_wp->parse_request();
|
260 |
+
$_SERVER['REQUEST_URI'] = $bk_req;
|
261 |
+
if(is_array($bcn_wp->query_vars))
|
262 |
+
{
|
263 |
+
foreach($bcn_wp->query_vars as $query_var => $value)
|
264 |
+
{
|
265 |
+
if($taxonomy = $this->query_var_to_taxonomy($query_var))
|
266 |
+
{
|
267 |
+
return $taxonomy;
|
268 |
+
}
|
269 |
+
}
|
270 |
+
}
|
271 |
+
return false;
|
272 |
+
}
|
273 |
+
/**
|
274 |
+
* This function selects the term that should be used for a post's hierarchy
|
275 |
+
*
|
276 |
+
* @param int $id The ID of the post to find the term for
|
277 |
+
* @param string $type The post type of the post to figure out the taxonomy for
|
278 |
+
* @param string $taxonomy The taxonomy to use
|
279 |
+
*
|
280 |
+
* @return WP_Term|bool The term object to use for the post hierarchy or false if no suitable term was found
|
281 |
+
*/
|
282 |
+
protected function pick_post_term($id, $type, $taxonomy)
|
283 |
+
{
|
284 |
+
//Fill a temporary object with the terms
|
285 |
+
$bcn_object = get_the_terms($id, $taxonomy);
|
286 |
+
$potential_parent = 0;
|
287 |
+
//Make sure we have an non-empty array
|
288 |
+
if(is_array($bcn_object))
|
289 |
+
{
|
290 |
+
//Now try to find the deepest term of those that we know of
|
291 |
+
$bcn_use_term = key($bcn_object);
|
292 |
+
foreach($bcn_object as $key => $object)
|
293 |
+
{
|
294 |
+
//Can't use the next($bcn_object) trick since order is unknown
|
295 |
+
if($object->parent > 0 && ($potential_parent === 0 || $object->parent === $potential_parent))
|
296 |
+
{
|
297 |
+
$bcn_use_term = $key;
|
298 |
+
$potential_parent = $object->term_id;
|
299 |
+
}
|
300 |
+
}
|
301 |
+
return $bcn_object[$bcn_use_term];
|
302 |
+
}
|
303 |
+
return false;
|
304 |
+
}
|
305 |
+
/**
|
306 |
+
* A Breadcrumb Trail Filling Function
|
307 |
+
*
|
308 |
+
* This function fills breadcrumbs for any post taxonomy
|
309 |
+
*
|
310 |
+
* @param int $id The id of the post to figure out the taxonomy for
|
311 |
+
* @param string $type The post type of the post to figure out the taxonomy for
|
312 |
+
* @param int $parent (optional) The id of the parent of the current post, used if hiearchal posts will be the "taxonomy" for the current post
|
313 |
+
*/
|
314 |
+
protected function post_hierarchy($id, $type, $parent = null)
|
315 |
+
{
|
316 |
+
//Check to see if breadcrumbs for the hierarchy of the post needs to be generated
|
317 |
+
if($this->opt['bpost_' . $type . '_hierarchy_display'])
|
318 |
+
{
|
319 |
+
//Check if we have a date 'taxonomy' request
|
320 |
+
if($this->opt['Spost_' . $type . '_hierarchy_type'] === 'BCN_DATE')
|
321 |
+
{
|
322 |
+
$post = get_post($id);
|
323 |
+
$this->do_day($post, $type, false, false);
|
324 |
+
$this->do_month($post, $type, false, false);
|
325 |
+
$this->do_year($post, $type, false, false);
|
326 |
+
}
|
327 |
+
//Handle the use of hierarchical posts as the 'taxonomy'
|
328 |
+
else if($this->opt['Spost_' . $type . '_hierarchy_type'] === 'BCN_POST_PARENT')
|
329 |
+
{
|
330 |
+
if($parent == null)
|
331 |
+
{
|
332 |
+
//We have to grab the post to find its parent, can't use $post for this one
|
333 |
+
$parent = get_post($id);
|
334 |
+
//TODO should we check that we have a WP_Post object here?
|
335 |
+
$parent = $parent->post_parent;
|
336 |
+
}
|
337 |
+
//Grab the frontpage, we'll need it shortly
|
338 |
+
$frontpage = get_option('page_on_front');
|
339 |
+
//If there is a parent page let's find it
|
340 |
+
if($parent > 0 && $id != $parent && $frontpage != $parent)
|
341 |
+
{
|
342 |
+
$parent = $this->post_parents($parent, $frontpage);
|
343 |
+
}
|
344 |
+
}
|
345 |
+
else
|
346 |
+
{
|
347 |
+
$taxonomy = $this->opt['Spost_' . $type . '_hierarchy_type'];
|
348 |
+
//Possibly let the referer influence the taxonomy used
|
349 |
+
if($this->opt['bpost_' . $type . '_taxonomy_referer'] && $referrer_taxonomy = $this->determine_taxonomy())
|
350 |
+
{
|
351 |
+
//See if there were any terms, if so, we can use the referrer influenced taxonomy
|
352 |
+
$terms = get_the_terms($id, $referrer_taxonomy);
|
353 |
+
if(is_array($terms))
|
354 |
+
{
|
355 |
+
$taxonomy = $referrer_taxonomy;
|
356 |
+
}
|
357 |
+
}
|
358 |
+
//Handle all hierarchical taxonomies, including categories
|
359 |
+
if(is_taxonomy_hierarchical($taxonomy))
|
360 |
+
{
|
361 |
+
//Filter the results of post_pick_term
|
362 |
+
$term = apply_filters('bcn_pick_post_term', $this->pick_post_term($id, $type, $taxonomy), $id, $type, $taxonomy);
|
363 |
+
//Only do something if we found a term
|
364 |
+
if($term instanceof WP_Term)
|
365 |
+
{
|
366 |
+
//Fill out the term hiearchy
|
367 |
+
$parent = $this->term_parents($term->term_id, $taxonomy);
|
368 |
+
}
|
369 |
+
}
|
370 |
+
//Handle the rest of the taxonomies, including tags
|
371 |
+
else
|
372 |
+
{
|
373 |
+
$this->post_terms($id, $taxonomy);
|
374 |
+
}
|
375 |
+
}
|
376 |
+
}
|
377 |
+
//If we never got a good parent for the type_archive, make it now
|
378 |
+
if(!($parent instanceof WP_Post))
|
379 |
+
{
|
380 |
+
$parent = get_post($id);
|
381 |
+
}
|
382 |
+
//Finish off with trying to find the type archive
|
383 |
+
$this->type_archive($parent, $type);
|
384 |
+
}
|
385 |
+
/**
|
386 |
+
* A Breadcrumb Trail Filling Function
|
387 |
+
*
|
388 |
+
* This functions fills a breadcrumb for the terms of a post
|
389 |
+
*
|
390 |
+
* @param int $id The id of the post to find the terms for
|
391 |
+
* @param string $taxonomy The name of the taxonomy that the term belongs to
|
392 |
+
*
|
393 |
+
* TODO Need to implement this cleaner
|
394 |
+
*/
|
395 |
+
protected function post_terms($id, $taxonomy)
|
396 |
+
{
|
397 |
+
//Apply a filter to the terms for the post referred to by ID
|
398 |
+
$bcn_terms = apply_filters('bcn_post_terms', get_the_terms($id, $taxonomy), $taxonomy, $id);
|
399 |
+
//Only process if we have terms
|
400 |
+
if(is_array($bcn_terms))
|
401 |
+
{
|
402 |
+
$title = '';
|
403 |
+
$is_first = true;
|
404 |
+
//Loop through all of the term results
|
405 |
+
foreach($bcn_terms as $term)
|
406 |
+
{
|
407 |
+
//Everything but the first term needs a comma separator
|
408 |
+
if($is_first == false)
|
409 |
+
{
|
410 |
+
$title .= ', ';
|
411 |
+
}
|
412 |
+
//This is a bit hackish, but it compiles the term anchor and appends it to the current breadcrumb title
|
413 |
+
$title .= str_replace(
|
414 |
+
array('%title%', '%link%', '%htitle%', '%type%'),
|
415 |
+
array($term->name, $this->maybe_add_post_type_arg(get_term_link($term), null, $term->taxonomy), $term->name, $term->taxonomy),
|
416 |
+
$this->opt['Htax_' . $term->taxonomy . '_template']);
|
417 |
+
$is_first = false;
|
418 |
+
}
|
419 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return
|
420 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($title, '%htitle%', array('taxonomy', $taxonomy)));
|
421 |
+
}
|
422 |
+
}
|
423 |
+
/**
|
424 |
+
* A Breadcrumb Trail Filling Function
|
425 |
+
*
|
426 |
+
* This recursive functions fills the trail with breadcrumbs for parent terms
|
427 |
+
*
|
428 |
+
* @param int $id The id of the term
|
429 |
+
* @param string $taxonomy The name of the taxonomy that the term belongs to
|
430 |
+
*
|
431 |
+
* @return WP_Term|WP_Error The term we stopped at
|
432 |
+
*/
|
433 |
+
protected function term_parents($id, $taxonomy)
|
434 |
+
{
|
435 |
+
//Get the current category object, filter applied within this call
|
436 |
+
$term = get_term($id, $taxonomy);
|
437 |
+
if($term instanceof WP_Term)
|
438 |
+
{
|
439 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return
|
440 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($term->name, $this->opt['Htax_' . $taxonomy . '_template'], array('taxonomy', $taxonomy), $this->maybe_add_post_type_arg(get_term_link($term), null, $taxonomy), $id));
|
441 |
+
//Make sure the id is valid, and that we won't end up spinning in a loop
|
442 |
+
if($term->parent && $term->parent != $id)
|
443 |
+
{
|
444 |
+
//Figure out the rest of the term hiearchy via recursion
|
445 |
+
$ret_term = $this->term_parents($term->parent, $taxonomy);
|
446 |
+
//May end up with WP_Error, don't update the term if that's the case
|
447 |
+
if($ret_term instanceof WP_Term)
|
448 |
+
{
|
449 |
+
$term = $ret_term;
|
450 |
+
}
|
451 |
+
}
|
452 |
+
}
|
453 |
+
return $term;
|
454 |
+
}
|
455 |
+
/**
|
456 |
+
* A Breadcrumb Trail Filling Function
|
457 |
+
*
|
458 |
+
* This recursive functions fills the trail with breadcrumbs for parent posts/pages
|
459 |
+
*
|
460 |
+
* @param int $id The id of the parent page
|
461 |
+
* @param int $frontpage The id of the front page
|
462 |
+
*
|
463 |
+
* @return WP_Post The parent we stopped at
|
464 |
+
*/
|
465 |
+
protected function post_parents($id, $frontpage)
|
466 |
+
{
|
467 |
+
//Use WordPress API, though a bit heavier than the old method, this will ensure compatibility with other plug-ins
|
468 |
+
$parent = get_post($id);
|
469 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return
|
470 |
+
$breadcrumb = $this->add(new bcn_breadcrumb(get_the_title($id), $this->opt['Hpost_' . $parent->post_type . '_template'], array('post', 'post-' . $parent->post_type), get_permalink($id), $id));
|
471 |
+
//Make sure the id is valid, and that we won't end up spinning in a loop
|
472 |
+
if($parent->post_parent > 0 && $id != $parent->post_parent && $frontpage != $parent->post_parent)
|
473 |
+
{
|
474 |
+
//If valid, recursively call this function
|
475 |
+
$parent = $this->post_parents($parent->post_parent, $frontpage);
|
476 |
+
}
|
477 |
+
return $parent;
|
478 |
+
}
|
479 |
+
/**
|
480 |
+
* A Breadcrumb Trail Filling Function
|
481 |
+
*
|
482 |
+
* This functions fills a breadcrumb for posts
|
483 |
+
*
|
484 |
+
* @param WP_Post $post Instance of WP_Post object to create a breadcrumb for
|
485 |
+
* @param bool $force_link Whether or not to force this breadcrumb to be linked
|
486 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
487 |
+
* @param bool $is_current_item Whether or not the breadcrumb being generated is the current item
|
488 |
+
*/
|
489 |
+
protected function do_post($post, $force_link = false, $is_paged = false, $is_current_item = true)
|
490 |
+
{
|
491 |
+
//If we did not get a WP_Post object, warn developer and return early
|
492 |
+
if(!($post instanceof WP_Post))
|
493 |
+
{
|
494 |
+
_doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('$post global is not of type WP_Post', 'breadcrumb-navxt'), '5.1.1');
|
495 |
+
return;
|
496 |
+
}
|
497 |
+
//Place the breadcrumb in the trail, uses the bcn_breadcrumb constructor to set the title, template, and type
|
498 |
+
$breadcrumb = $this->add(new bcn_breadcrumb(get_the_title($post), $this->opt['Hpost_' . $post->post_type . '_template_no_anchor'], array('post', 'post-' . $post->post_type), null, $post->ID));
|
499 |
+
if($is_current_item)
|
500 |
+
{
|
501 |
+
$breadcrumb->add_type('current-item');
|
502 |
+
}
|
503 |
+
//Under a couple of circumstances we will want to link this breadcrumb
|
504 |
+
if($force_link || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display']))
|
505 |
+
{
|
506 |
+
//Change the template over to the normal, linked one
|
507 |
+
$breadcrumb->set_template($this->opt['Hpost_' . $post->post_type . '_template']);
|
508 |
+
//Add the link
|
509 |
+
$breadcrumb->set_url(get_permalink($post));
|
510 |
+
}
|
511 |
+
//If we have an attachment, run through the post again
|
512 |
+
if($post->post_type === 'attachment')
|
513 |
+
{
|
514 |
+
//Done with the current item, now on to the parents
|
515 |
+
$frontpage = get_option('page_on_front');
|
516 |
+
//Make sure the id is valid, and that we won't end up spinning in a loop
|
517 |
+
if($post->post_parent > 0 && $post->ID != $post->post_parent && $frontpage != $post->post_parent)
|
518 |
+
{
|
519 |
+
//Get the parent's information
|
520 |
+
$parent = get_post($post->post_parent);
|
521 |
+
//Take care of the parent's breadcrumb
|
522 |
+
$this->do_post($parent, true, false, false);
|
523 |
+
}
|
524 |
+
}
|
525 |
+
//Otherwise we need the follow the hiearchy tree
|
526 |
+
else
|
527 |
+
{
|
528 |
+
//Handle the post's hiearchy
|
529 |
+
$this->post_hierarchy($post->ID, $post->post_type, $post->post_parent);
|
530 |
+
}
|
531 |
+
}
|
532 |
+
/**
|
533 |
+
* A Breadcrumb Trail Filling Function
|
534 |
+
*
|
535 |
+
* @deprecated 6.0.0 No longer needed, superceeded by do_post
|
536 |
+
*
|
537 |
+
* This functions fills a breadcrumb for an attachment page.
|
538 |
+
*/
|
539 |
+
protected function do_attachment()
|
540 |
+
{
|
541 |
+
_deprecated_function( __FUNCTION__, '6.0', 'bcn_breadcrumb_trail::do_post');
|
542 |
+
$this->do_post(get_post());
|
543 |
+
}
|
544 |
+
/**
|
545 |
+
* A Breadcrumb Trail Filling Function
|
546 |
+
*
|
547 |
+
* This function fills a breadcrumb for any taxonomy archive, was previously two separate functions
|
548 |
+
*
|
549 |
+
* @param WP_Term $term The term object to generate the breadcrumb for
|
550 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
551 |
+
*/
|
552 |
+
protected function do_archive_by_term($term, $is_paged = false)
|
553 |
+
{
|
554 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, get a pointer to it in return
|
555 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($term->name, $this->opt['Htax_' . $term->taxonomy . '_template_no_anchor'], array('archive', 'taxonomy', $term->taxonomy, 'current-item'), null, $term->term_id));
|
556 |
+
//If we're paged, let's link to the first page
|
557 |
+
if($this->opt['bcurrent_item_linked'] || ($is_paged && $this->opt['bpaged_display']))
|
558 |
+
{
|
559 |
+
$breadcrumb->set_template($this->opt['Htax_' . $term->taxonomy . '_template']);
|
560 |
+
//Figure out the anchor for current category
|
561 |
+
$breadcrumb->set_url($this->maybe_add_post_type_arg(get_term_link($term), null, $term->taxonomy));
|
562 |
+
}
|
563 |
+
//Get parents of current term
|
564 |
+
if($term->parent)
|
565 |
+
{
|
566 |
+
$this->term_parents($term->parent, $term->taxonomy);
|
567 |
+
}
|
568 |
+
}
|
569 |
+
/**
|
570 |
+
* A Breadcrumb Trail Filling Function
|
571 |
+
*
|
572 |
+
* This functions fills a breadcrumb for day date archives
|
573 |
+
*
|
574 |
+
* @param WP_Post $post Instance of WP_Post object to create a breadcrumb for
|
575 |
+
* @param string $type The name of the CPT to generate the archive breadcrumb for
|
576 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
577 |
+
* @param bool $is_current_item Whether or not the breadcrumb being generated is the current item
|
578 |
+
*/
|
579 |
+
protected function do_day($post, $type, $is_paged = false, $is_current_item = true)
|
580 |
+
{
|
581 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
582 |
+
$breadcrumb = $this->add(new bcn_breadcrumb(get_the_time(_x('d', 'day archive breadcrumb date format', 'breadcrumb-navxt'), $post), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-day')));
|
583 |
+
//If this is a day archive, add current-item type
|
584 |
+
if($is_current_item)
|
585 |
+
{
|
586 |
+
$breadcrumb->add_type('current-item');
|
587 |
+
}
|
588 |
+
//If we're paged, let's link to the first page
|
589 |
+
if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display']))
|
590 |
+
{
|
591 |
+
//We're linking, so set the linked template
|
592 |
+
$breadcrumb->set_template($this->opt['Hdate_template']);
|
593 |
+
$url = get_day_link(get_the_time('Y'), get_the_time('m'), get_the_time('d'));
|
594 |
+
//Deal with the anchor
|
595 |
+
$breadcrumb->set_url($this->maybe_add_post_type_arg($url, $type));
|
596 |
+
}
|
597 |
+
}
|
598 |
+
/**
|
599 |
+
* A Breadcrumb Trail Filling Function
|
600 |
+
*
|
601 |
+
* This functions fills a breadcrumb for month date archives
|
602 |
+
*
|
603 |
+
* @param WP_Post $post Instance of WP_Post object to create a breadcrumb for
|
604 |
+
* @param string $type The name of the CPT to generate the archive breadcrumb for
|
605 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
606 |
+
* @param bool $is_current_item Whether or not the breadcrumb being generated is the current item
|
607 |
+
*/
|
608 |
+
protected function do_month($post, $type, $is_paged = false, $is_current_item = true)
|
609 |
+
{
|
610 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
611 |
+
$breadcrumb = $this->add(new bcn_breadcrumb(get_the_time(_x('F', 'month archive breadcrumb date format', 'breadcrumb-navxt'), $post), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-month')));
|
612 |
+
//If this is a month archive, add current-item type
|
613 |
+
if($is_current_item)
|
614 |
+
{
|
615 |
+
$breadcrumb->add_type('current-item');
|
616 |
+
}
|
617 |
+
//If we're paged, or not in the archive by month let's link to the first archive by month page
|
618 |
+
if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display']))
|
619 |
+
{
|
620 |
+
//We're linking, so set the linked template
|
621 |
+
$breadcrumb->set_template($this->opt['Hdate_template']);
|
622 |
+
$url = get_month_link(get_the_time('Y'), get_the_time('m'));
|
623 |
+
//Deal with the anchor
|
624 |
+
$breadcrumb->set_url($this->maybe_add_post_type_arg($url, $type));
|
625 |
+
}
|
626 |
+
}
|
627 |
+
/**
|
628 |
+
* A Breadcrumb Trail Filling Function
|
629 |
+
*
|
630 |
+
* This functions fills a breadcrumb for year date archives
|
631 |
+
*
|
632 |
+
* @param WP_Post $post Instance of WP_Post object to create a breadcrumb for
|
633 |
+
* @param string $type The name of the CPT to generate the archive breadcrumb for
|
634 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
635 |
+
* @param bool $is_current_item Whether or not the breadcrumb being generated is the current item
|
636 |
+
*/
|
637 |
+
protected function do_year($post, $type, $is_paged = false, $is_current_item = true)
|
638 |
+
{
|
639 |
+
//Place the year breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
640 |
+
$breadcrumb = $this->add(new bcn_breadcrumb(get_the_time(_x('Y', 'year archive breadcrumb date format', 'breadcrumb-navxt'), $post), $this->opt['Hdate_template_no_anchor'], array('archive', 'date-year')));
|
641 |
+
//If this is a year archive, add current-item type
|
642 |
+
if($is_current_item)
|
643 |
+
{
|
644 |
+
$breadcrumb->add_type('current-item');
|
645 |
+
}
|
646 |
+
//If we're paged, or not in the archive by year let's link to the first archive by year page
|
647 |
+
if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display']))
|
648 |
+
{
|
649 |
+
//We're linking, so set the linked template
|
650 |
+
$breadcrumb->set_template($this->opt['Hdate_template']);
|
651 |
+
$url = get_year_link(get_the_time('Y'));
|
652 |
+
//Deal with the anchor
|
653 |
+
$breadcrumb->set_url($this->maybe_add_post_type_arg($url, $type));
|
654 |
+
}
|
655 |
+
}
|
656 |
+
/**
|
657 |
+
* A Breadcrumb Trail Filling Function
|
658 |
+
*
|
659 |
+
* This functions fills a breadcrumb for a date archive.
|
660 |
+
*
|
661 |
+
* @param string $type The type to restrict the date archives to
|
662 |
+
*
|
663 |
+
* @deprecated 6.0.0 No longer needed, superceeded by do_day, do_month, and/or do_year
|
664 |
+
*/
|
665 |
+
protected function do_archive_by_date($type)
|
666 |
+
{
|
667 |
+
_deprecated_function( __FUNCTION__, '6.0', 'bcn_breadcrumb_trail::do_day, bcn_breadcrumb_trail::do_month, and/or bcn_breadcrumb_trail::do_year');
|
668 |
+
//First deal with the day breadcrumb
|
669 |
+
if(is_day() || is_single())
|
670 |
+
{
|
671 |
+
$this->do_day(get_post(), $type, is_paged(), is_day());
|
672 |
+
}
|
673 |
+
//Now deal with the month breadcrumb
|
674 |
+
if(is_month() || is_day() || is_single())
|
675 |
+
{
|
676 |
+
$this->do_month(get_post(), $type, is_paged(), is_month());
|
677 |
+
}
|
678 |
+
$this->do_year(get_post(), $type, is_paged(), is_year());
|
679 |
+
}
|
680 |
+
/**
|
681 |
+
* A Breadcrumb Trail Filling Function
|
682 |
+
*
|
683 |
+
* This functions fills a breadcrumb for a post type archive (WP 3.1 feature)
|
684 |
+
*
|
685 |
+
* @param string type_str The name of the CPT to generate the archive breadcrumb for
|
686 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
687 |
+
*/
|
688 |
+
protected function do_archive_by_post_type($type_str, $is_paged = false)
|
689 |
+
{
|
690 |
+
//Manually grabbing the post type object insted of post_type_archive_title('', false) to remove get_query_var() dependancy
|
691 |
+
$post_type_obj = get_post_type_object($type_str);
|
692 |
+
$title = apply_filters('post_type_archive_title', $post_type_obj->labels->name, $type_str);
|
693 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
694 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($title, $this->opt['Hpost_' . $type_str . '_template_no_anchor'], array('archive', 'post-' . $type_str . '-archive', 'current-item')));
|
695 |
+
if($this->opt['bcurrent_item_linked'] || ($is_paged && $this->opt['bpaged_display']))
|
696 |
+
{
|
697 |
+
|
698 |
+
$breadcrumb->set_template($this->opt['Hpost_' . $type_str . '_template']);
|
699 |
+
//Deal with the anchor
|
700 |
+
$breadcrumb->set_url(get_post_type_archive_link($type_str));
|
701 |
+
}
|
702 |
+
}
|
703 |
+
/**
|
704 |
+
* A Breadcrumb Trail Filling Function
|
705 |
+
*
|
706 |
+
* This functions fills a breadcrumb for the front page
|
707 |
+
*
|
708 |
+
* @param bool $force_link Whether or not to force this breadcrumb to be linked
|
709 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
710 |
+
* @param bool $is_current_item Whether or not the breadcrumb being generated is the current item
|
711 |
+
*/
|
712 |
+
protected function do_home($force_link = false, $is_paged = false, $is_current_item = true)
|
713 |
+
{
|
714 |
+
global $current_site;
|
715 |
+
//Exit early if we're not displaying the home breadcrumb
|
716 |
+
if(!$this->opt['bhome_display'])
|
717 |
+
{
|
718 |
+
return;
|
719 |
+
}
|
720 |
+
//Get the site name
|
721 |
+
$site_name = get_option('blogname');
|
722 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
723 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($site_name, $this->opt['Hhome_template_no_anchor'], array('home')));
|
724 |
+
if($is_current_item)
|
725 |
+
{
|
726 |
+
$breadcrumb->add_type('current-item');
|
727 |
+
}
|
728 |
+
//Under a couple of circumstances we will want to link this breadcrumb
|
729 |
+
if($force_link || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display']))
|
730 |
+
{
|
731 |
+
$breadcrumb->set_template($this->opt['Hhome_template']);
|
732 |
+
//Figure out the anchor for home page
|
733 |
+
$breadcrumb->set_url(get_home_url());
|
734 |
+
}
|
735 |
+
//If we have a multi site and are not on the main site we may need to add a breadcrumb for the main site
|
736 |
+
if($this->opt['bmainsite_display'] && !is_main_site())
|
737 |
+
{
|
738 |
+
//Get the site name
|
739 |
+
$site_name = get_site_option('site_name');
|
740 |
+
//Place the main site breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
741 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($site_name, $this->opt['Hmainsite_template'], array('main-home'), get_home_url($current_site->blog_id)));
|
742 |
+
}
|
743 |
+
}
|
744 |
+
/**
|
745 |
+
* A modified version of WordPress' function of the same name
|
746 |
+
*
|
747 |
+
* @param object $object the post or taxonomy object used to attempt to find the title
|
748 |
+
*
|
749 |
+
* @return string the title
|
750 |
+
*/
|
751 |
+
protected function post_type_archive_title($object)
|
752 |
+
{
|
753 |
+
if(isset($object->labels->name))
|
754 |
+
{
|
755 |
+
//Core filter use here is ok for time being
|
756 |
+
//TODO: Recheck validitiy prior to each release
|
757 |
+
return apply_filters('post_type_archive_title', $object->labels->name, $object->name);
|
758 |
+
}
|
759 |
+
}
|
760 |
+
/**
|
761 |
+
* Determines if a post type is a built in type or not
|
762 |
+
*
|
763 |
+
* @param string $post_type the name of the post type
|
764 |
+
*
|
765 |
+
* @return bool
|
766 |
+
*/
|
767 |
+
protected function is_builtin($post_type)
|
768 |
+
{
|
769 |
+
$type = get_post_type_object($post_type);
|
770 |
+
//If we get a null, that means either then type wasn't found, or we had 'any' as a type, treat as builtin
|
771 |
+
if($type === null)
|
772 |
+
{
|
773 |
+
return true;
|
774 |
+
}
|
775 |
+
else
|
776 |
+
{
|
777 |
+
return $type->_builtin;
|
778 |
+
}
|
779 |
+
}
|
780 |
+
/**
|
781 |
+
* Determines if the current location is a for a root page or not
|
782 |
+
*
|
783 |
+
* @param string $post_type the name of the post type
|
784 |
+
* @return bool
|
785 |
+
*
|
786 |
+
* TODO: Remove dependancies to current state (state should be passed in)
|
787 |
+
*/
|
788 |
+
protected function treat_as_root_page($post_type)
|
789 |
+
{
|
790 |
+
return (is_home() || (is_post_type_archive() && !$this->opt['bpost_' . $post_type . '_archive_display']));
|
791 |
+
}
|
792 |
+
/**
|
793 |
+
* Determines if a post type has archives enabled or not
|
794 |
+
*
|
795 |
+
* @param string $post_type the name of the post type
|
796 |
+
*
|
797 |
+
* @return bool
|
798 |
+
*/
|
799 |
+
protected function has_archive($post_type)
|
800 |
+
{
|
801 |
+
$type = get_post_type_object($post_type); //TODO need a check on this for WP_Error?
|
802 |
+
return $type->has_archive;
|
803 |
+
}
|
804 |
+
/**
|
805 |
+
* Retrieves the query var for 'post_type', sets default to post, and escapes
|
806 |
+
*
|
807 |
+
* @param string $default[optional] The default value to return if nothing was found/set or if post_type was an array
|
808 |
+
*
|
809 |
+
* @return string The post type string found in the post_type query var
|
810 |
+
*/
|
811 |
+
protected function get_type_string_query_var($default = 'post')
|
812 |
+
{
|
813 |
+
$type_str = get_query_var('post_type', $default);
|
814 |
+
if($type_str === '' || is_array($type_str))
|
815 |
+
{
|
816 |
+
//If we didn't get a type, or it was an array, try the the first post
|
817 |
+
$post = get_post();
|
818 |
+
if($post instanceof WP_Post)
|
819 |
+
{
|
820 |
+
$type_str = $post->post_type;
|
821 |
+
}
|
822 |
+
else
|
823 |
+
{
|
824 |
+
$type_str = $default;
|
825 |
+
}
|
826 |
+
}
|
827 |
+
return esc_attr($type_str);
|
828 |
+
}
|
829 |
+
/**
|
830 |
+
* Retrieves the query var for 'post_type', and returns whether or not it is an array
|
831 |
+
*
|
832 |
+
* @return bool Whether or not the post_type query var is an array
|
833 |
+
*/
|
834 |
+
protected function is_type_query_var_array()
|
835 |
+
{
|
836 |
+
return is_array(get_query_var('post_type'));
|
837 |
+
}
|
838 |
+
/**
|
839 |
+
* Adds the post type argument to the URL iff the passed in type is not post
|
840 |
+
*
|
841 |
+
* @param string $url The URL to possibly add the post_type argument to
|
842 |
+
* @param string $type[optional] The type to possibly add to the URL
|
843 |
+
* @param string $taxonomy[optional] If we're dealing with a taxonomy term, the taxonomy of that term
|
844 |
+
*
|
845 |
+
* @return string The possibly modified URL
|
846 |
+
*/
|
847 |
+
protected function maybe_add_post_type_arg($url, $type = null, $taxonomy = null)
|
848 |
+
{
|
849 |
+
global $wp_taxonomies;
|
850 |
+
//Rather than default to post, we should try to find the type
|
851 |
+
if($type == null)
|
852 |
+
{
|
853 |
+
$type = $this->get_type_string_query_var();
|
854 |
+
}
|
855 |
+
//Add a query arg if we are not on the default post type for the archive in question and the post type is not post
|
856 |
+
$add_query_arg = (!($taxonomy && $type === $wp_taxonomies[$taxonomy]->object_type[0]) && $type !== 'post');
|
857 |
+
//Filter the add_query_arg logic, only add the query arg if necessary
|
858 |
+
if(apply_filters('bcn_add_post_type_arg', $add_query_arg, $type, $taxonomy))
|
859 |
+
{
|
860 |
+
$url = add_query_arg(array('post_type' => $type), $url);
|
861 |
+
}
|
862 |
+
return $url;
|
863 |
+
}
|
864 |
+
/**
|
865 |
+
* A Breadcrumb Trail Filling Function
|
866 |
+
*
|
867 |
+
* Deals with the post type archive and taxonomy archives
|
868 |
+
*
|
869 |
+
* @param WP_Post|WP_Taxonomy $type The post or taxonomy to generate the archive breadcrumb for
|
870 |
+
* @param string $type_str The type string for the archive
|
871 |
+
*
|
872 |
+
* TODO: Remove dependancies to current state (state should be passed in)
|
873 |
+
*/
|
874 |
+
protected function type_archive($type, $type_str = false)
|
875 |
+
{
|
876 |
+
global $wp_taxonomies;
|
877 |
+
if(!isset($type->taxonomy) && $type_str === false) //TODO could probably check the class type here
|
878 |
+
{
|
879 |
+
$type_str = $this->get_type_string_query_var();
|
880 |
+
}
|
881 |
+
//If this is a custom post type with a post type archive, add it
|
882 |
+
if($type_str && !$this->is_builtin($type_str) && $this->opt['bpost_' . $type_str . '_archive_display'] && $this->has_archive($type_str))
|
883 |
+
{
|
884 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
885 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($this->post_type_archive_title(get_post_type_object($type_str)), $this->opt['Hpost_' . $type_str . '_template'], array('post', 'post-' . $type_str . '-archive'), get_post_type_archive_link($type_str)));
|
886 |
+
}
|
887 |
+
//Otherwise, if this is a custom taxonomy with an archive, add it
|
888 |
+
else if(isset($type->taxonomy) && isset($wp_taxonomies[$type->taxonomy]->object_type[0])
|
889 |
+
&& !$this->is_builtin($this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0]))
|
890 |
+
&& $this->opt['bpost_' . $this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0]) . '_archive_display']
|
891 |
+
&& $this->has_archive($this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0]))
|
892 |
+
&& !$this->is_type_query_var_array())
|
893 |
+
{
|
894 |
+
//We end up using the post type in several places, give it a variable
|
895 |
+
$post_type = apply_filters('bcn_type_archive_post_type', $this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0]));
|
896 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, prefix, and suffix, get a pointer to it in return
|
897 |
+
$breadcrumb = $this->add(new bcn_breadcrumb($this->post_type_archive_title(get_post_type_object($post_type)), $this->opt['Hpost_' . $post_type . '_template'], array('post', 'post-' . $post_type . '-archive'), get_post_type_archive_link($post_type)));
|
898 |
+
}
|
899 |
+
}
|
900 |
+
/**
|
901 |
+
* A Breadcrumb Trail Filling Function
|
902 |
+
*
|
903 |
+
* Handles only the root page stuff for post types, including the "page for posts"
|
904 |
+
*
|
905 |
+
* @param string $type_str The type string variable
|
906 |
+
* @param int $root_id The ID for the post type root
|
907 |
+
* @param bool $is_paged Whether or not the current resource is on a page other than page 1
|
908 |
+
* @param bool $is_current_item Whether or not the breadcrumb being generated is the current item
|
909 |
+
*/
|
910 |
+
protected function do_root($type_str, $root_id, $is_paged = false, $is_current_item = true)
|
911 |
+
{
|
912 |
+
//Nothing to do for the page post type, exit early
|
913 |
+
if($type_str === 'page')
|
914 |
+
{
|
915 |
+
return;
|
916 |
+
}
|
917 |
+
$frontpage_id = get_option('page_on_front');
|
918 |
+
//Retrieve the post for the root_id as we will need it eventually
|
919 |
+
$bcn_post = get_post($root_id);
|
920 |
+
//We'll have to check if this ID is valid, e.g. user has specified a posts page
|
921 |
+
if($bcn_post instanceof WP_Post && $root_id > 0 && $root_id != $frontpage_id)
|
922 |
+
{
|
923 |
+
//Place the breadcrumb in the trail, uses the constructor to set the title, template, and type, we get a pointer to it in return
|
924 |
+
$breadcrumb = $this->add(new bcn_breadcrumb(get_the_title($root_id), $this->opt['Hpost_' . $type_str . '_template_no_anchor'], array($type_str . '-root', 'post', 'post-' . $type_str), null, $root_id));
|
925 |
+
//If we are at home, or any root page archive then we need to add the current item type
|
926 |
+
if($is_current_item)
|
927 |
+
{
|
928 |
+
$breadcrumb->add_type('current-item');
|
929 |
+
}
|
930 |
+
//If we're not on the current item we need to setup the anchor
|
931 |
+
if(!$is_current_item || ($is_current_item && $this->opt['bcurrent_item_linked']) || ($is_paged && $this->opt['bpaged_display']))
|
932 |
+
{
|
933 |
+
$breadcrumb->set_template($this->opt['Hpost_' . $type_str . '_template']);
|
934 |
+
//Figure out the anchor for home page
|
935 |
+
$breadcrumb->set_url(get_permalink($root_id));
|
936 |
+
}
|
937 |
+
//Done with the "root", now on to the parents
|
938 |
+
//If there is a parent post let's find it
|
939 |
+
if($bcn_post->post_parent > 0 && $bcn_post->ID != $bcn_post->post_parent && $frontpage_id != $bcn_post->post_parent)
|
940 |
+
{
|
941 |
+
$this->post_parents($bcn_post->post_parent, $frontpage_id);
|
942 |
+
}
|
943 |
+
}
|
944 |
+
}
|
945 |
+
/**
|
946 |
+
* A Breadcrumb Trail Filling Function
|
947 |
+
*
|
948 |
+
* This functions fills a breadcrumb for 404 pages.
|
949 |
+
*/
|
950 |
+
protected function do_404()
|
951 |
+
{
|
952 |
+
//Place the breadcrumb in the trail, uses the bcn_breadcrumb constructor to set the title, prefix, and suffix
|
953 |
+
$this->breadcrumbs[] = new bcn_breadcrumb($this->opt['S404_title'], $this->opt['H404_template'], array('404', 'current-item'));
|
954 |
+
}
|
955 |
+
/**
|
956 |
+
* A Breadcrumb Trail Filling Function
|
957 |
+
*
|
958 |
+
* This functions fills a breadcrumb for paged pages
|
959 |
+
*
|
960 |
+
* @param int $page_number The page number to create a breadcrumb for
|
961 |
+
*/
|
962 |
+
protected function do_paged($page_number)
|
963 |
+
{
|
964 |
+
//Place the breadcrumb in the trail, uses the bcn_breadcrumb constructor to set the title, prefix, and suffix
|
965 |
+
$this->breadcrumbs[] = new bcn_breadcrumb((string) $page_number, $this->opt['Hpaged_template'], array('paged'));
|
966 |
+
}
|
967 |
+
/**
|
968 |
+
* Breadcrumb Trail Filling Function
|
969 |
+
*
|
970 |
+
* This functions fills the breadcrumb trail.
|
971 |
+
*/
|
972 |
+
public function fill()
|
973 |
+
{
|
974 |
+
global $wpdb, $wp_query, $wp;
|
975 |
+
//Check to see if the trail is already populated
|
976 |
+
if(count($this->breadcrumbs) > 0)
|
977 |
+
{
|
978 |
+
//Exit early since we have breadcrumbs in the trail
|
979 |
+
return null;
|
980 |
+
}
|
981 |
+
if($this->opt['bblog_display'])
|
982 |
+
{
|
983 |
+
$this->opt['apost_post_root'] = get_option('page_for_posts');
|
984 |
+
}
|
985 |
+
else
|
986 |
{
|
987 |
$this->opt['apost_post_root'] = false;
|
988 |
+
}
|
989 |
+
//Do any actions if necessary, we past through the current object instance to keep life simple
|
990 |
+
do_action('bcn_before_fill', $this);
|
991 |
+
$type = $wp_query->get_queried_object();
|
992 |
+
//Do specific opperations for the various page types
|
993 |
+
//Check if this isn't the first of a multi paged item
|
994 |
+
if($this->opt['bpaged_display'] && (is_paged() || is_singular() && get_query_var('page') > 1))
|
995 |
+
{
|
996 |
+
//Need to switch between paged and page for archives and singular (posts)
|
997 |
+
if(get_query_var('paged') > 0)
|
998 |
+
{
|
999 |
+
//Can use simple type hinting here to int since we already checked for greater than 0
|
1000 |
+
$page_number = (int) abs(get_query_var('paged'));
|
1001 |
+
}
|
1002 |
+
else
|
1003 |
+
{
|
1004 |
+
$page_number = (int) abs(get_query_var('page'));
|
1005 |
+
}
|
1006 |
+
$this->do_paged($page_number);
|
1007 |
+
}
|
1008 |
+
//For the front page, as it may also validate as a page, do it first
|
1009 |
+
if(is_front_page())
|
1010 |
+
{
|
1011 |
+
//Must have two seperate branches so that we don't evaluate it as a page
|
1012 |
+
if($this->opt['bhome_display'])
|
1013 |
+
{
|
1014 |
+
$this->do_home(false, is_paged());
|
1015 |
+
}
|
1016 |
+
}
|
1017 |
+
//For posts
|
1018 |
+
else if(is_singular())
|
1019 |
+
{
|
1020 |
+
$this->do_post(get_post(), false, (get_query_var('page') > 1));
|
1021 |
+
//If this is an attachment then we need to change the queried object to the parent post
|
1022 |
+
if(is_attachment())
|
1023 |
+
{
|
1024 |
+
//Could use the $post global, but we can't really trust it
|
1025 |
+
$post = get_post();
|
1026 |
+
$type = get_post($post->post_parent); //TODO check for WP_Error?
|
1027 |
+
}
|
1028 |
+
$this->do_root($type->post_type, $this->opt['apost_' . $type->post_type . '_root'], is_paged(), false);
|
1029 |
+
}
|
1030 |
+
//For searches
|
1031 |
+
else if(is_search())
|
1032 |
+
{
|
1033 |
+
$this->do_search(get_search_query(), is_paged());
|
1034 |
+
}
|
1035 |
+
//For author pages
|
1036 |
+
else if(is_author())
|
1037 |
+
{
|
1038 |
+
$this->do_author($type, is_paged());
|
1039 |
+
$this->do_root('post', $this->opt['aauthor_root'], is_paged(), false);
|
1040 |
+
}
|
1041 |
+
//For archives
|
1042 |
+
else if(is_archive())
|
1043 |
+
{
|
1044 |
+
//We need the type for later, so save it
|
1045 |
+
$type_str = get_query_var('post_type');
|
1046 |
+
//May be an array, if so, rewind the iterator and grab first item
|
1047 |
+
if(is_array($type_str))
|
1048 |
+
{
|
1049 |
+
$type_str = reset($type_str);
|
1050 |
+
}
|
1051 |
+
//For date based archives
|
1052 |
+
if(is_date())
|
1053 |
+
{
|
1054 |
+
//First deal with the day breadcrumb
|
1055 |
+
if(is_day())
|
1056 |
+
{
|
1057 |
+
$this->do_day(get_post(), $this->get_type_string_query_var(), is_paged(), true);
|
1058 |
+
}
|
1059 |
+
//Now deal with the month breadcrumb
|
1060 |
+
if(is_month() || is_day())
|
1061 |
+
{
|
1062 |
+
$this->do_month(get_post(), $this->get_type_string_query_var(), is_paged(), is_month());
|
1063 |
+
}
|
1064 |
+
$this->do_year(get_post(), $this->get_type_string_query_var(), is_paged(), is_year());
|
1065 |
+
$type_str = $this->get_type_string_query_var();
|
1066 |
+
$this->type_archive($type, $type_str);
|
1067 |
+
}
|
1068 |
+
//If we have a post type archive, and it does not have a root page generate the archive
|
1069 |
+
else if(is_post_type_archive() && !isset($type->taxonomy)
|
1070 |
+
&& (!is_numeric($this->opt['apost_' . $type_str . '_root']) || $this->opt['bpost_' . $type_str . '_archive_display']))
|
1071 |
+
{
|
1072 |
+
$this->do_archive_by_post_type($this->get_type_string_query_var(), is_paged());
|
1073 |
+
}
|
1074 |
+
//For taxonomy based archives
|
1075 |
+
else if(is_category() || is_tag() || is_tax())
|
1076 |
+
{
|
1077 |
+
$this->do_archive_by_term($type, is_paged());
|
1078 |
+
$this->type_archive($type);
|
1079 |
+
$type_str = $this->get_type_string_query_var($GLOBALS['wp_taxonomies'][$type->taxonomy]->object_type[0]);
|
1080 |
+
}
|
1081 |
+
else
|
1082 |
+
{
|
1083 |
+
$this->type_archive($type);
|
1084 |
+
}
|
1085 |
+
$this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str));
|
1086 |
+
}
|
1087 |
+
//For 404 pages
|
1088 |
+
else if(is_404())
|
1089 |
+
{
|
1090 |
+
$this->do_404();
|
1091 |
+
}
|
1092 |
+
else
|
1093 |
+
{
|
1094 |
+
//If it looks, walks, and quacks like a taxonomy, treat is as one
|
1095 |
+
if(isset($type->taxonomy))
|
1096 |
+
{
|
1097 |
+
$this->do_archive_by_term($type, is_paged());
|
1098 |
+
$this->type_archive($type);
|
1099 |
+
$type_str = $this->get_type_string_query_var($wp_taxonomies[$type->taxonomy]->object_type[0]);
|
1100 |
+
}
|
1101 |
+
//Otherwise, it's likely the blog page
|
1102 |
+
else if($this->opt['bblog_display'] || is_home())
|
1103 |
+
{
|
1104 |
+
$type_str = 'post';
|
1105 |
+
}
|
1106 |
+
if(isset($this->opt['apost_' . $type_str . '_root']))
|
1107 |
+
{
|
1108 |
+
$this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str));
|
1109 |
+
}
|
1110 |
+
}
|
1111 |
+
//We always do the home link last, unless on the frontpage
|
1112 |
+
if(!is_front_page())
|
1113 |
+
{
|
1114 |
+
$this->do_home(true, false, false);
|
1115 |
+
}
|
1116 |
+
//Do any actions if necessary, we past through the current object instance to keep life simple
|
1117 |
+
do_action('bcn_after_fill', $this);
|
1118 |
+
}
|
1119 |
+
public function fill_REST($item)
|
1120 |
+
{
|
1121 |
+
if($item instanceof WP_Error || $item === null)
|
1122 |
+
{
|
1123 |
+
return;
|
1124 |
+
}
|
1125 |
+
//Handle Posts
|
1126 |
+
if($item instanceof WP_Post)
|
1127 |
+
{
|
1128 |
+
$this->do_post($item, false, true);
|
1129 |
+
$this->do_root($item->post_type, $this->opt['apost_' . $item->post_type . '_root'], false, false);
|
1130 |
+
}
|
1131 |
+
//Handle Terms
|
1132 |
+
else if($item instanceof WP_Term)
|
1133 |
+
{
|
1134 |
+
$this->do_archive_by_term($item, true);
|
1135 |
+
$this->type_archive($item);
|
1136 |
+
$type_str = $this->get_type_string_query_var($GLOBALS['wp_taxonomies'][$item->taxonomy]->object_type[0]);
|
1137 |
+
$this->do_root($type_str, $this->opt['apost_' . $type_str . '_root'], is_paged(), $this->treat_as_root_page($type_str));
|
1138 |
+
}
|
1139 |
+
//Handle Author Archives
|
1140 |
+
else if($item instanceof WP_User)
|
1141 |
+
{
|
1142 |
+
$this->do_author($item, true);
|
1143 |
+
$this->do_root('post', $this->opt['aauthor_root'], false, false);
|
1144 |
+
}
|
1145 |
+
$this->do_home(true, false, false);
|
1146 |
+
}
|
1147 |
+
/**
|
1148 |
+
* This function will either set the order of the trail to reverse key
|
1149 |
+
* order, or make sure it is forward key ordered.
|
1150 |
+
*
|
1151 |
+
* @param bool $reverse[optional] Whether to reverse the trail or not.
|
1152 |
+
*/
|
1153 |
+
protected function order($reverse = false)
|
1154 |
+
{
|
1155 |
+
if($reverse)
|
1156 |
+
{
|
1157 |
+
//Since there may be multiple calls our trail may be in a non-standard order
|
1158 |
+
ksort($this->breadcrumbs);
|
1159 |
+
}
|
1160 |
+
else
|
1161 |
+
{
|
1162 |
+
//For normal opperation we must reverse the array by key
|
1163 |
+
krsort($this->breadcrumbs);
|
1164 |
+
}
|
1165 |
+
}
|
1166 |
+
/**
|
1167 |
+
* This functions outputs or returns the breadcrumb trail in string form.
|
1168 |
+
*
|
1169 |
+
* @param bool $linked[optional] Whether to allow hyperlinks in the trail or not.
|
1170 |
+
* @param bool $reverse[optional] Whether to reverse the output or not.
|
1171 |
+
* @param string $template The template to use for the string output.
|
1172 |
+
*
|
1173 |
+
* @return void Void if Option to print out breadcrumb trail was chosen.
|
1174 |
+
* @return string String-Data of breadcrumb trail.
|
1175 |
+
*/
|
1176 |
+
public function display($linked = true, $reverse = false, $template = '%1$s%2$s')
|
1177 |
+
{
|
1178 |
+
//Set trail order based on reverse flag
|
1179 |
+
$this->order($reverse);
|
1180 |
+
//The main compiling loop
|
1181 |
+
$trail_str = $this->display_loop($linked, $reverse, $template);
|
1182 |
+
return $trail_str;
|
1183 |
+
}
|
1184 |
+
/**
|
1185 |
+
* This functions outputs or returns the breadcrumb trail in list form.
|
1186 |
+
*
|
1187 |
+
* @deprecated 6.0.0 No longer needed, superceeded by $template parameter in display
|
1188 |
+
*
|
1189 |
+
* @param bool $linked[optional] Whether to allow hyperlinks in the trail or not.
|
1190 |
+
* @param bool $reverse[optional] Whether to reverse the output or not.
|
1191 |
+
*
|
1192 |
+
* @return void Void if option to print out breadcrumb trail was chosen.
|
1193 |
+
* @return string String version of the breadcrumb trail.
|
1194 |
+
*/
|
1195 |
+
public function display_list($linked = true, $reverse = false)
|
1196 |
+
{
|
1197 |
+
_deprecated_function( __FUNCTION__, '6.0', 'bcn_breadcrumb_trail::display');
|
1198 |
+
return $this->display($return, $linked, $reverse, "<li%3\$s>%1\$s</li>\n");
|
1199 |
+
}
|
1200 |
+
/**
|
1201 |
+
* This function assembles the breadcrumbs in the breadcrumb trail in accordance with the passed in template
|
1202 |
+
*
|
1203 |
+
* @param bool $linked Whether to allow hyperlinks in the trail or not.
|
1204 |
+
* @param bool $reverse Whether to reverse the output or not.
|
1205 |
+
* @param string $template The template to use for the string output.
|
1206 |
+
*
|
1207 |
+
* @return string String-Data of breadcrumb trail.
|
1208 |
+
*/
|
1209 |
+
protected function display_loop($linked, $reverse, $template)
|
1210 |
+
{
|
1211 |
+
$position = 1;
|
1212 |
+
$last_position = count($this->breadcrumbs);
|
1213 |
+
//Initilize the string which will hold the assembled trail
|
1214 |
+
$trail_str = '';
|
1215 |
+
foreach($this->breadcrumbs as $key => $breadcrumb)
|
1216 |
+
{
|
1217 |
+
$types = $breadcrumb->get_types();
|
1218 |
+
array_walk($types, 'sanitize_html_class');
|
1219 |
+
$class = sprintf(' class="%s"', esc_attr(implode(' ', $types)));
|
1220 |
+
//Deal with the separator
|
1221 |
+
if($position < $last_position)
|
1222 |
+
{
|
1223 |
+
$separator = $this->opt['hseparator'];
|
1224 |
+
}
|
1225 |
+
else
|
1226 |
{
|
1227 |
$separator = '';
|
1228 |
+
}
|
1229 |
+
//Filter li_attributes adding attributes to the li element
|
1230 |
+
$attribs = apply_filters_deprecated('bcn_li_attributes', array($class, $breadcrumb->get_types(), $breadcrumb->get_id()), '6.0.0', 'bcn_display_attributes');
|
1231 |
+
$attribs = apply_filters('bcn_display_attributes', $class, $breadcrumb->get_types(), $breadcrumb->get_id());
|
1232 |
+
//Trim titles, if requested
|
1233 |
+
if($this->opt['blimit_title'] && $this->opt['amax_title_length'] > 0)
|
1234 |
+
{
|
1235 |
+
//Trim the breadcrumb's title
|
1236 |
+
$breadcrumb->title_trim($this->opt['amax_title_length']);
|
1237 |
+
}
|
1238 |
+
//Assemble the breadrumb and wrap with li's
|
1239 |
+
$trail_str .= sprintf($template, $breadcrumb->assemble($linked, $position), $separator, $attribs);
|
1240 |
+
$position++;
|
1241 |
+
}
|
1242 |
+
return $trail_str;
|
1243 |
+
}
|
1244 |
+
/**
|
1245 |
+
* This functions outputs or returns the breadcrumb trail in Schema.org BreadcrumbList compliant JSON-LD
|
1246 |
+
*
|
1247 |
+
* @param bool $reverse[optional] Whether to reverse the output or not.
|
1248 |
+
*
|
1249 |
+
* @return void Void if option to print out breadcrumb trail was chosen.
|
1250 |
+
* @return object basic object version of the breadcrumb trail ready for json_encode.
|
1251 |
+
*/
|
1252 |
+
public function display_json_ld($reverse = false)
|
1253 |
+
{
|
1254 |
+
//Set trail order based on reverse flag
|
1255 |
+
$this->order($reverse);
|
1256 |
+
$trail_str = (object)array(
|
1257 |
+
'@context' => 'http://schema.org',
|
1258 |
+
'@type' => 'BreadcrumbList',
|
1259 |
+
'itemListElement' => $this->json_ld_loop());
|
1260 |
+
return $trail_str;
|
1261 |
+
}
|
1262 |
+
/**
|
1263 |
+
* This function assembles all of the breadcrumbs into an object ready for json_encode
|
1264 |
+
*
|
1265 |
+
* @return array The array of breadcrumbs prepared for JSON-LD
|
1266 |
+
*/
|
1267 |
+
protected function json_ld_loop()
|
1268 |
+
{
|
1269 |
+
$postion = 1;
|
1270 |
+
$breadcrumbs = array();
|
1271 |
+
//Loop around our breadcrumbs, call the JSON-LD assembler
|
1272 |
+
foreach($this->breadcrumbs as $breadcrumb)
|
1273 |
+
{
|
1274 |
+
$breadcrumbs[] = $breadcrumb->assemble_json_ld($postion);
|
1275 |
+
$postion++;
|
1276 |
+
}
|
1277 |
+
return $breadcrumbs;
|
1278 |
+
}
|
1279 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class.bcn_network_admin.php
CHANGED
@@ -1,193 +1,193 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
-
//Include admin base class
|
21 |
-
if(!class_exists('bcn_admin'))
|
22 |
-
{
|
23 |
-
require_once(dirname(__FILE__) . '/class.bcn_admin.php');
|
24 |
-
}
|
25 |
-
/**
|
26 |
-
* The administrative interface class
|
27 |
-
*
|
28 |
-
*/
|
29 |
-
class bcn_network_admin extends bcn_admin
|
30 |
-
{
|
31 |
-
const version = '6.0
|
32 |
-
protected $full_name = 'Breadcrumb NavXT Network Settings';
|
33 |
-
protected $access_level = 'manage_network_options';
|
34 |
-
/**
|
35 |
-
* Administrative interface class default constructor
|
36 |
-
* @param bcn_breadcrumb_trail $breadcrumb_trail a breadcrumb trail object
|
37 |
-
* @param string $basename The basename of the plugin
|
38 |
-
*/
|
39 |
-
function __construct(bcn_breadcrumb_trail &$breadcrumb_trail, $basename)
|
40 |
-
{
|
41 |
-
//We're going to make sure we load the parent's constructor
|
42 |
-
parent::__construct($breadcrumb_trail, $basename);
|
43 |
-
//Change to the proper name
|
44 |
-
$this->full_name = __('Breadcrumb NavXT Network Settings', 'breadcrumb-navxt');
|
45 |
-
//Remove the hook added by the parent as we don't want this classes settings page everywhere
|
46 |
-
remove_action('admin_menu', array($this, 'add_page'));
|
47 |
-
//Replace with the network_admin hook
|
48 |
-
add_action('network_admin_menu', array($this, 'add_page'));
|
49 |
-
}
|
50 |
-
/**
|
51 |
-
* admin initialization callback function
|
52 |
-
*
|
53 |
-
* is bound to wordpress action 'admin_init' on instantiation
|
54 |
-
*
|
55 |
-
* @since 3.2.0
|
56 |
-
* @return void
|
57 |
-
*/
|
58 |
-
function init()
|
59 |
-
{
|
60 |
-
//We're going to make sure we run the parent's version of this function as well
|
61 |
-
parent::init();
|
62 |
-
}
|
63 |
-
function wp_loaded()
|
64 |
-
{
|
65 |
-
parent::wp_loaded();
|
66 |
-
}
|
67 |
-
/**
|
68 |
-
* Return the URL of the settings page for the plugin
|
69 |
-
*/
|
70 |
-
function admin_url()
|
71 |
-
{
|
72 |
-
return admin_url('network/settings.php?page=' . $this->identifier);
|
73 |
-
}
|
74 |
-
/**
|
75 |
-
* Adds the adminpage the menu and the nice little settings link
|
76 |
-
*/
|
77 |
-
function add_page()
|
78 |
-
{
|
79 |
-
//Add the submenu page to "settings" menu
|
80 |
-
$hookname = add_submenu_page('settings.php', $this->full_name, $this->short_name, $this->access_level, $this->identifier, array($this, 'admin_page'));
|
81 |
-
// check capability of user to manage options (access control)
|
82 |
-
if(current_user_can($this->access_level))
|
83 |
-
{
|
84 |
-
//Register admin_head-$hookname callback
|
85 |
-
add_action('admin_head-' . $hookname, array($this, 'admin_head'));
|
86 |
-
//Register admin_print_styles-$hookname callback
|
87 |
-
add_action('admin_print_styles-' . $hookname, array($this, 'admin_styles'));
|
88 |
-
//Register admin_print_scripts-$hookname callback
|
89 |
-
add_action('admin_print_scripts-' . $hookname, array($this, 'admin_scripts'));
|
90 |
-
//Register Help Output
|
91 |
-
add_action('load-' . $hookname, array($this, 'help'));
|
92 |
-
}
|
93 |
-
}
|
94 |
-
/**
|
95 |
-
* Have to hook into get_option and replace with network wide alternate
|
96 |
-
*
|
97 |
-
* @param string $option The name of the option to retrieve
|
98 |
-
* @return mixed The value of the option
|
99 |
-
*/
|
100 |
-
function get_option($option)
|
101 |
-
{
|
102 |
-
return get_site_option($option);
|
103 |
-
}
|
104 |
-
/**
|
105 |
-
* Have to hook into update_option and replace with network wide alternate
|
106 |
-
*
|
107 |
-
* @param string $option The name of the option to update
|
108 |
-
* @param mixed $newvalue The new value to set the option to
|
109 |
-
*
|
110 |
-
*/
|
111 |
-
function update_option($option, $newvalue)
|
112 |
-
{
|
113 |
-
return update_site_option($option, $newvalue);
|
114 |
-
}
|
115 |
-
/**
|
116 |
-
* Have to hook into add_option and replace with network wide alternate
|
117 |
-
*
|
118 |
-
* @param string $option The name of the option to update
|
119 |
-
* @param mixed $value The new value to set the option to
|
120 |
-
* @param null $deprecated Deprecated parameter
|
121 |
-
* @param string $autoload Whether or not to autoload the option, it's a string because WP is special
|
122 |
-
*
|
123 |
-
*/
|
124 |
-
function add_option($option, $value = '', $deprecated = '', $autoload = 'yes')
|
125 |
-
{
|
126 |
-
return add_site_option($option, $value);
|
127 |
-
}
|
128 |
-
/**
|
129 |
-
* Have to hook into delete_option and replace with network wide alternate
|
130 |
-
*
|
131 |
-
* @param string $option The name of the option to delete
|
132 |
-
*/
|
133 |
-
function delete_option($option)
|
134 |
-
{
|
135 |
-
return delete_site_option($option);
|
136 |
-
}
|
137 |
-
/**
|
138 |
-
* A message function that checks for the BCN_SETTINGS_* define statement
|
139 |
-
*/
|
140 |
-
function multisite_settings_warn()
|
141 |
-
{
|
142 |
-
if(is_multisite())
|
143 |
-
{
|
144 |
-
if(defined('BCN_SETTINGS_USE_LOCAL') && BCN_SETTINGS_USE_LOCAL)
|
145 |
-
{
|
146 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride');
|
147 |
-
}
|
148 |
-
else if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK)
|
149 |
-
{
|
150 |
-
|
151 |
-
}
|
152 |
-
else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL)
|
153 |
-
{
|
154 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isitemayoveride');
|
155 |
-
}
|
156 |
-
else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK)
|
157 |
-
{
|
158 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nsmayoveride');
|
159 |
-
}
|
160 |
-
//Fall through if no settings mode was set
|
161 |
-
else
|
162 |
-
{
|
163 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: No BCN_SETTINGS_* define statement found, defaulting to BCN_SETTINGS_USE_LOCAL.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nosetting');
|
164 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride');
|
165 |
-
}
|
166 |
-
}
|
167 |
-
}
|
168 |
-
/**
|
169 |
-
* A message function that checks for deprecated settings that are set and warns the user
|
170 |
-
*/
|
171 |
-
function deprecated_settings_warn()
|
172 |
-
{
|
173 |
-
parent::deprecated_settings_warn();
|
174 |
-
}
|
175 |
-
/**
|
176 |
-
* Function checks the current site to see if the blog options should be disabled
|
177 |
-
*
|
178 |
-
* @return boool Whether or not the blog options should be disabled
|
179 |
-
*/
|
180 |
-
function maybe_disable_blog_options()
|
181 |
-
{
|
182 |
-
return false;
|
183 |
-
}
|
184 |
-
/**
|
185 |
-
* Function checks the current site to see if the mainsite options should be disabled
|
186 |
-
*
|
187 |
-
* @return bool Whether or not the mainsite options should be disabled
|
188 |
-
*/
|
189 |
-
function maybe_disable_mainsite_options()
|
190 |
-
{
|
191 |
-
return false;
|
192 |
-
}
|
193 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
+
//Include admin base class
|
21 |
+
if(!class_exists('bcn_admin'))
|
22 |
+
{
|
23 |
+
require_once(dirname(__FILE__) . '/class.bcn_admin.php');
|
24 |
+
}
|
25 |
+
/**
|
26 |
+
* The administrative interface class
|
27 |
+
*
|
28 |
+
*/
|
29 |
+
class bcn_network_admin extends bcn_admin
|
30 |
+
{
|
31 |
+
const version = '6.1.0';
|
32 |
+
protected $full_name = 'Breadcrumb NavXT Network Settings';
|
33 |
+
protected $access_level = 'manage_network_options';
|
34 |
+
/**
|
35 |
+
* Administrative interface class default constructor
|
36 |
+
* @param bcn_breadcrumb_trail $breadcrumb_trail a breadcrumb trail object
|
37 |
+
* @param string $basename The basename of the plugin
|
38 |
+
*/
|
39 |
+
function __construct(bcn_breadcrumb_trail &$breadcrumb_trail, $basename)
|
40 |
+
{
|
41 |
+
//We're going to make sure we load the parent's constructor
|
42 |
+
parent::__construct($breadcrumb_trail, $basename);
|
43 |
+
//Change to the proper name
|
44 |
+
$this->full_name = __('Breadcrumb NavXT Network Settings', 'breadcrumb-navxt');
|
45 |
+
//Remove the hook added by the parent as we don't want this classes settings page everywhere
|
46 |
+
remove_action('admin_menu', array($this, 'add_page'));
|
47 |
+
//Replace with the network_admin hook
|
48 |
+
add_action('network_admin_menu', array($this, 'add_page'));
|
49 |
+
}
|
50 |
+
/**
|
51 |
+
* admin initialization callback function
|
52 |
+
*
|
53 |
+
* is bound to wordpress action 'admin_init' on instantiation
|
54 |
+
*
|
55 |
+
* @since 3.2.0
|
56 |
+
* @return void
|
57 |
+
*/
|
58 |
+
function init()
|
59 |
+
{
|
60 |
+
//We're going to make sure we run the parent's version of this function as well
|
61 |
+
parent::init();
|
62 |
+
}
|
63 |
+
function wp_loaded()
|
64 |
+
{
|
65 |
+
parent::wp_loaded();
|
66 |
+
}
|
67 |
+
/**
|
68 |
+
* Return the URL of the settings page for the plugin
|
69 |
+
*/
|
70 |
+
function admin_url()
|
71 |
+
{
|
72 |
+
return admin_url('network/settings.php?page=' . $this->identifier);
|
73 |
+
}
|
74 |
+
/**
|
75 |
+
* Adds the adminpage the menu and the nice little settings link
|
76 |
+
*/
|
77 |
+
function add_page()
|
78 |
+
{
|
79 |
+
//Add the submenu page to "settings" menu
|
80 |
+
$hookname = add_submenu_page('settings.php', $this->full_name, $this->short_name, $this->access_level, $this->identifier, array($this, 'admin_page'));
|
81 |
+
// check capability of user to manage options (access control)
|
82 |
+
if(current_user_can($this->access_level))
|
83 |
+
{
|
84 |
+
//Register admin_head-$hookname callback
|
85 |
+
add_action('admin_head-' . $hookname, array($this, 'admin_head'));
|
86 |
+
//Register admin_print_styles-$hookname callback
|
87 |
+
add_action('admin_print_styles-' . $hookname, array($this, 'admin_styles'));
|
88 |
+
//Register admin_print_scripts-$hookname callback
|
89 |
+
add_action('admin_print_scripts-' . $hookname, array($this, 'admin_scripts'));
|
90 |
+
//Register Help Output
|
91 |
+
add_action('load-' . $hookname, array($this, 'help'));
|
92 |
+
}
|
93 |
+
}
|
94 |
+
/**
|
95 |
+
* Have to hook into get_option and replace with network wide alternate
|
96 |
+
*
|
97 |
+
* @param string $option The name of the option to retrieve
|
98 |
+
* @return mixed The value of the option
|
99 |
+
*/
|
100 |
+
function get_option($option)
|
101 |
+
{
|
102 |
+
return get_site_option($option);
|
103 |
+
}
|
104 |
+
/**
|
105 |
+
* Have to hook into update_option and replace with network wide alternate
|
106 |
+
*
|
107 |
+
* @param string $option The name of the option to update
|
108 |
+
* @param mixed $newvalue The new value to set the option to
|
109 |
+
*
|
110 |
+
*/
|
111 |
+
function update_option($option, $newvalue)
|
112 |
+
{
|
113 |
+
return update_site_option($option, $newvalue);
|
114 |
+
}
|
115 |
+
/**
|
116 |
+
* Have to hook into add_option and replace with network wide alternate
|
117 |
+
*
|
118 |
+
* @param string $option The name of the option to update
|
119 |
+
* @param mixed $value The new value to set the option to
|
120 |
+
* @param null $deprecated Deprecated parameter
|
121 |
+
* @param string $autoload Whether or not to autoload the option, it's a string because WP is special
|
122 |
+
*
|
123 |
+
*/
|
124 |
+
function add_option($option, $value = '', $deprecated = '', $autoload = 'yes')
|
125 |
+
{
|
126 |
+
return add_site_option($option, $value);
|
127 |
+
}
|
128 |
+
/**
|
129 |
+
* Have to hook into delete_option and replace with network wide alternate
|
130 |
+
*
|
131 |
+
* @param string $option The name of the option to delete
|
132 |
+
*/
|
133 |
+
function delete_option($option)
|
134 |
+
{
|
135 |
+
return delete_site_option($option);
|
136 |
+
}
|
137 |
+
/**
|
138 |
+
* A message function that checks for the BCN_SETTINGS_* define statement
|
139 |
+
*/
|
140 |
+
function multisite_settings_warn()
|
141 |
+
{
|
142 |
+
if(is_multisite())
|
143 |
+
{
|
144 |
+
if(defined('BCN_SETTINGS_USE_LOCAL') && BCN_SETTINGS_USE_LOCAL)
|
145 |
+
{
|
146 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride');
|
147 |
+
}
|
148 |
+
else if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK)
|
149 |
+
{
|
150 |
+
|
151 |
+
}
|
152 |
+
else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL)
|
153 |
+
{
|
154 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isitemayoveride');
|
155 |
+
}
|
156 |
+
else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK)
|
157 |
+
{
|
158 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nsmayoveride');
|
159 |
+
}
|
160 |
+
//Fall through if no settings mode was set
|
161 |
+
else
|
162 |
+
{
|
163 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: No BCN_SETTINGS_* define statement found, defaulting to BCN_SETTINGS_USE_LOCAL.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nosetting');
|
164 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride');
|
165 |
+
}
|
166 |
+
}
|
167 |
+
}
|
168 |
+
/**
|
169 |
+
* A message function that checks for deprecated settings that are set and warns the user
|
170 |
+
*/
|
171 |
+
function deprecated_settings_warn()
|
172 |
+
{
|
173 |
+
parent::deprecated_settings_warn();
|
174 |
+
}
|
175 |
+
/**
|
176 |
+
* Function checks the current site to see if the blog options should be disabled
|
177 |
+
*
|
178 |
+
* @return boool Whether or not the blog options should be disabled
|
179 |
+
*/
|
180 |
+
function maybe_disable_blog_options()
|
181 |
+
{
|
182 |
+
return false;
|
183 |
+
}
|
184 |
+
/**
|
185 |
+
* Function checks the current site to see if the mainsite options should be disabled
|
186 |
+
*
|
187 |
+
* @return bool Whether or not the mainsite options should be disabled
|
188 |
+
*/
|
189 |
+
function maybe_disable_mainsite_options()
|
190 |
+
{
|
191 |
+
return false;
|
192 |
+
}
|
193 |
}
|
class.bcn_rest_controller.php
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
+
//Do a PHP version check, require 5.3 or newer
|
21 |
+
if(version_compare(phpversion(), '5.3.0', '<'))
|
22 |
+
{
|
23 |
+
//Only purpose of this function is to echo out the PHP version error
|
24 |
+
function bcn_phpold()
|
25 |
+
{
|
26 |
+
printf('<div class="notice notice-error"><p>' . __('Your PHP version is too old, please upgrade to a newer version. Your version is %1$s, Breadcrumb NavXT requires %2$s', 'breadcrumb-navxt') . '</p></div>', phpversion(), '5.3.0');
|
27 |
+
}
|
28 |
+
//If we are in the admin, let's print a warning then return
|
29 |
+
if(is_admin())
|
30 |
+
{
|
31 |
+
add_action('admin_notices', 'bcn_phpold');
|
32 |
+
}
|
33 |
+
return;
|
34 |
+
}
|
35 |
+
class bcn_rest_controller
|
36 |
+
{
|
37 |
+
const version = '1';
|
38 |
+
protected $unique_prefix = 'bcn';
|
39 |
+
protected $breadcrumb_trail = null;
|
40 |
+
protected $methods = array('GET', 'OPTIONS');
|
41 |
+
/**
|
42 |
+
* Default constructor
|
43 |
+
*
|
44 |
+
* @param bcn_breadcrumb_trail $breadcrumb_trail An instance of a bcn_breadcrumb_trail object to use for everything
|
45 |
+
* @param string $unique_prefix The unique prefix to use for the API endpoint
|
46 |
+
*/
|
47 |
+
public function __construct(bcn_breadcrumb_trail $breadcrumb_trail, $unique_prefix)
|
48 |
+
{
|
49 |
+
$this->breadcrumb_trail = $breadcrumb_trail;
|
50 |
+
$this->unique_prefix = $unique_prefix;
|
51 |
+
add_action('rest_api_init', array($this, 'register_routes'));
|
52 |
+
}
|
53 |
+
public function register_routes()
|
54 |
+
{
|
55 |
+
register_rest_route( $this->unique_prefix . '/v' . $this::version, '/post/(?P<id>[\d]+)', array(
|
56 |
+
'args' => array(
|
57 |
+
'id' => array(
|
58 |
+
'description' => __('The ID of the post (any type) to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'),
|
59 |
+
'type' => 'integer',
|
60 |
+
'required' => true,
|
61 |
+
'validate_callback' => array($this, 'validate_id')
|
62 |
+
)
|
63 |
+
),
|
64 |
+
'methods' => $this->methods,
|
65 |
+
'callback' => array($this, 'display_rest_post'),
|
66 |
+
'permission_callback' => array($this, 'display_rest_post_permissions_check')
|
67 |
+
)
|
68 |
+
);
|
69 |
+
register_rest_route( $this->unique_prefix . '/v' . $this::version, '/term/(?P<taxonomy>[\w-]+)/(?P<id>[\d]+)', array(
|
70 |
+
'args' => array(
|
71 |
+
'id' => array(
|
72 |
+
'description' => __('The ID of the term to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'),
|
73 |
+
'type' => 'integer',
|
74 |
+
'required' => true,
|
75 |
+
'validate_callback' => array($this, 'validate_id')
|
76 |
+
),
|
77 |
+
'taxonomy' => array(
|
78 |
+
'description' => __('The taxonomy of the term to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'),
|
79 |
+
'type' => 'string',
|
80 |
+
'required' => true,
|
81 |
+
'validate_callback' => array($this, 'validate_taxonomy')
|
82 |
+
)
|
83 |
+
),
|
84 |
+
'methods' => $this->methods,
|
85 |
+
'callback' => array($this, 'display_rest_term')
|
86 |
+
)
|
87 |
+
);
|
88 |
+
register_rest_route( $this->unique_prefix . '/v' . $this::version, '/author/(?P<id>\d+)', array(
|
89 |
+
'args' => array(
|
90 |
+
'id' => array(
|
91 |
+
'description' => __('The ID of the author to retrieve the breadcrumb trail for.', 'breadcrumb-navxt'),
|
92 |
+
'type' => 'integer',
|
93 |
+
'required' => true,
|
94 |
+
'validate_callback' => array($this, 'validate_id')
|
95 |
+
)
|
96 |
+
),
|
97 |
+
'methods' => $this->methods,
|
98 |
+
'callback' => array($this, 'display_rest_author')
|
99 |
+
)
|
100 |
+
);
|
101 |
+
}
|
102 |
+
/**
|
103 |
+
* Checks to see if the request ID looks like it could be an ID (numeric and greater than 0)
|
104 |
+
*
|
105 |
+
* @param mixed $param The parameter to validate
|
106 |
+
* @param WP_REST_Request $request REST API request data
|
107 |
+
* @param string $key The paramter key
|
108 |
+
* @return bool Whether or not the ID is valid (or atleast looks valid)
|
109 |
+
*/
|
110 |
+
public function validate_id($param, $request, $key)
|
111 |
+
{
|
112 |
+
return is_numeric($param) && absint($param) > 0;
|
113 |
+
}
|
114 |
+
/**
|
115 |
+
* Checks to see if the request taxonomy is a valid taxonomy
|
116 |
+
*
|
117 |
+
* @param mixed $param The parameter to validate
|
118 |
+
* @param WP_REST_Request $request REST API request data
|
119 |
+
* @param string $key The paramter key
|
120 |
+
* @return bool Whether or not the ID is valid (or atleast looks valid)
|
121 |
+
*/
|
122 |
+
public function validate_taxonomy($param, $request, $key)
|
123 |
+
{
|
124 |
+
return taxonomy_exists(esc_attr($param));
|
125 |
+
}
|
126 |
+
/**
|
127 |
+
* Check permissions for the post
|
128 |
+
*
|
129 |
+
* @param WP_REST_Request $request The request to check the permissions on
|
130 |
+
* @return bool | WP_Error Whether or not the user can view the requested post
|
131 |
+
*/
|
132 |
+
public function display_rest_post_permissions_check(WP_REST_Request $request)
|
133 |
+
{
|
134 |
+
$post = get_post(absint($request->get_param('id')));
|
135 |
+
if($post === null)
|
136 |
+
{
|
137 |
+
return true;
|
138 |
+
}
|
139 |
+
return $this->check_post_read_permission($post);
|
140 |
+
}
|
141 |
+
/**
|
142 |
+
* Check to ensure the current user can read the post (and subsequently view its breadcrumb trail)
|
143 |
+
*
|
144 |
+
* @param WP_Post $post The post to check if the current user can view the breadcrumb trail for
|
145 |
+
* @return bool Whether or not the post should be readable
|
146 |
+
*/
|
147 |
+
public function check_post_read_permission($post)
|
148 |
+
{
|
149 |
+
if(!($post instanceof WP_Post))
|
150 |
+
{
|
151 |
+
return false;
|
152 |
+
}
|
153 |
+
$post_type = get_post_type_object($post->post_type);
|
154 |
+
if(empty($post_type) || empty($post_type->show_in_rest))
|
155 |
+
{
|
156 |
+
return false;
|
157 |
+
}
|
158 |
+
if($post->post_status === 'publish' || current_user_can($post_type->cap->read_post, $post->ID))
|
159 |
+
{
|
160 |
+
return true;
|
161 |
+
}
|
162 |
+
$post_status_obj = get_post_status_object($post->post_status);
|
163 |
+
if($post_status_obj && $post_status_obj->public)
|
164 |
+
{
|
165 |
+
return true;
|
166 |
+
}
|
167 |
+
if($post->post_status === 'inherit' && $post->post_parent > 0)
|
168 |
+
{
|
169 |
+
$parent = get_post($post->post_parent);
|
170 |
+
if($parent)
|
171 |
+
{
|
172 |
+
return $this->check_post_read_permission($parent);
|
173 |
+
}
|
174 |
+
}
|
175 |
+
if($post->post_status === 'inherit')
|
176 |
+
{
|
177 |
+
return true;
|
178 |
+
}
|
179 |
+
return false;
|
180 |
+
}
|
181 |
+
/**
|
182 |
+
* Breadcrumb trail handler for REST requests for post breadcrumb trails
|
183 |
+
*
|
184 |
+
* @param WP_REST_Request $request REST API request data
|
185 |
+
* @return STD_Object Basic object data of the Schema.org Breadcrumb List compatible breadcrumb trail
|
186 |
+
*/
|
187 |
+
public function display_rest_post(WP_REST_Request $request)
|
188 |
+
{
|
189 |
+
$post = get_post(absint($request->get_param('id')));
|
190 |
+
if($post instanceof WP_Post)
|
191 |
+
{
|
192 |
+
$this->breadcrumb_trail->breadcrumbs = array();
|
193 |
+
//Generate the breadcrumb trail
|
194 |
+
$this->breadcrumb_trail->fill_REST($post);
|
195 |
+
return $this->breadcrumb_trail->display_json_ld(false);
|
196 |
+
}
|
197 |
+
}
|
198 |
+
/**
|
199 |
+
* Breadcrumb trail handler for REST requests for term breadcrumb trails
|
200 |
+
*
|
201 |
+
* @param WP_REST_Request $request REST API request data
|
202 |
+
* @return STD_Object Basic object data of the Schema.org Breadcrumb List compatible breadcrumb trail
|
203 |
+
*/
|
204 |
+
public function display_rest_term(WP_REST_Request $request)
|
205 |
+
{
|
206 |
+
$term = get_term(absint($request->get_param('id')), esc_attr($request->get_param('taxonomy')));
|
207 |
+
if($term instanceof WP_Term)
|
208 |
+
{
|
209 |
+
$this->breadcrumb_trail->breadcrumbs = array();
|
210 |
+
//Generate the breadcrumb trail
|
211 |
+
$this->breadcrumb_trail->fill_REST($term);
|
212 |
+
return $this->breadcrumb_trail->display_json_ld(false);
|
213 |
+
}
|
214 |
+
}
|
215 |
+
/**
|
216 |
+
* Breadcrumb trail handler for REST requests for term breadcrumb trails
|
217 |
+
*
|
218 |
+
* @param WP_REST_Request $request REST API request data
|
219 |
+
* @return STD_Object Basic object data of the Schema.org Breadcrumb List compatible breadcrumb trail
|
220 |
+
*/
|
221 |
+
public function display_rest_author(WP_REST_Request $request)
|
222 |
+
{
|
223 |
+
$user = get_user_by('ID', absint($request->get_param('id')), esc_attr($request->get_param('taxonomy')));
|
224 |
+
if($user instanceof WP_User)
|
225 |
+
{
|
226 |
+
$this->breadcrumb_trail->breadcrumbs = array();
|
227 |
+
//Generate the breadcrumb trail
|
228 |
+
$this->breadcrumb_trail->fill_REST($user);
|
229 |
+
return $this->breadcrumb_trail->display_json_ld(false);
|
230 |
+
}
|
231 |
+
}
|
232 |
+
}
|
class.bcn_widget.php
CHANGED
@@ -1,132 +1,141 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
-
class bcn_widget extends WP_Widget
|
21 |
-
{
|
22 |
-
const version = '6.0
|
23 |
-
protected $allowed_html = array();
|
24 |
-
protected $defaults = array('title' => '', 'pretext' => '', 'type' => 'microdata', 'linked' => true, 'reverse' => false, 'front' => false, 'force' => false);
|
25 |
-
//Default constructor
|
26 |
-
function __construct()
|
27 |
-
{
|
28 |
-
//Filter allowed_html array to allow others to add acceptable tags
|
29 |
-
$this->allowed_html = apply_filters('bcn_allowed_html', wp_kses_allowed_html('post'));
|
30 |
-
//@see https://core.trac.wordpress.org/ticket/10527
|
31 |
-
if(!is_textdomain_loaded('breadcrumb-navxt'))
|
32 |
-
{
|
33 |
-
load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages');
|
34 |
-
}
|
35 |
-
$ops = array('classname' => 'widget_breadcrumb_navxt', 'description' => __('Adds a breadcrumb trail to your sidebar', 'breadcrumb-navxt'));
|
36 |
-
parent::__construct('bcn_widget', 'Breadcrumb NavXT', $ops);
|
37 |
-
}
|
38 |
-
function widget($args, $instance)
|
39 |
-
{
|
40 |
-
//Make sure we grab defaults in the case of out of date instance settings being sent
|
41 |
-
$instance = wp_parse_args((array) $instance, $this->defaults);
|
42 |
-
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
|
43 |
-
$instance['pretext'] = apply_filters('widget_text', $instance['pretext'], $instance);
|
44 |
-
$
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
echo wp_kses($instance['pretext'], $this->allowed_html);
|
77 |
-
//Display the regular output breadcrumb
|
78 |
-
bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']);
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
$
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
<p>
|
112 |
-
<label for="<?php echo esc_attr($this->get_field_id('
|
113 |
-
<
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
<
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
|
20 |
+
class bcn_widget extends WP_Widget
|
21 |
+
{
|
22 |
+
const version = '6.1.0';
|
23 |
+
protected $allowed_html = array();
|
24 |
+
protected $defaults = array('title' => '', 'pretext' => '', 'type' => 'microdata', 'linked' => true, 'reverse' => false, 'front' => false, 'force' => false);
|
25 |
+
//Default constructor
|
26 |
+
function __construct()
|
27 |
+
{
|
28 |
+
//Filter allowed_html array to allow others to add acceptable tags
|
29 |
+
$this->allowed_html = apply_filters('bcn_allowed_html', wp_kses_allowed_html('post'));
|
30 |
+
//@see https://core.trac.wordpress.org/ticket/10527
|
31 |
+
if(!is_textdomain_loaded('breadcrumb-navxt'))
|
32 |
+
{
|
33 |
+
load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages');
|
34 |
+
}
|
35 |
+
$ops = array('classname' => 'widget_breadcrumb_navxt', 'description' => __('Adds a breadcrumb trail to your sidebar', 'breadcrumb-navxt'));
|
36 |
+
parent::__construct('bcn_widget', 'Breadcrumb NavXT', $ops);
|
37 |
+
}
|
38 |
+
function widget($args, $instance)
|
39 |
+
{
|
40 |
+
//Make sure we grab defaults in the case of out of date instance settings being sent
|
41 |
+
$instance = wp_parse_args((array) $instance, $this->defaults);
|
42 |
+
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
|
43 |
+
$instance['pretext'] = apply_filters('widget_text', $instance['pretext'], $instance);
|
44 |
+
$instance['pretext'] = apply_filters('bcn_widget_pretext', $instance['pretext'], $instance);
|
45 |
+
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
|
46 |
+
//A bit of a hack but we need the DB settings to know if we should exit early
|
47 |
+
$opt = get_option('bcn_options');
|
48 |
+
//If we are on the front page and don't display on the front, return early
|
49 |
+
if($instance['front'] && is_front_page() && !(is_paged() && $opt['bpaged_display']))
|
50 |
+
{
|
51 |
+
return;
|
52 |
+
}
|
53 |
+
//Manditory before widget junk
|
54 |
+
echo $args['before_widget'];
|
55 |
+
if(!empty($title))
|
56 |
+
{
|
57 |
+
echo $args['before_title'] . $title . $args['after_title'];
|
58 |
+
}
|
59 |
+
//We'll want to switch between the two breadcrumb output types
|
60 |
+
if($instance['type'] === 'list')
|
61 |
+
{
|
62 |
+
//Display the list output breadcrumb
|
63 |
+
echo wp_kses($instance['pretext'], $this->allowed_html) . '<ol class="breadcrumb_trail breadcrumbs">';
|
64 |
+
bcn_display_list(false, $instance['linked'], $instance['reverse'], $instance['force']);
|
65 |
+
echo '</ol>';
|
66 |
+
}
|
67 |
+
else if($instance['type'] === 'microdata' || $instance['type'] === 'breadcrumblist_rdfa')
|
68 |
+
{
|
69 |
+
echo '<div class="breadcrumbs" vocab="https://schema.org/" typeof="BreadcrumbList">' . wp_kses($instance['pretext'], $this->allowed_html);
|
70 |
+
//Display the regular output breadcrumb
|
71 |
+
bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']);
|
72 |
+
echo '</div>';
|
73 |
+
}
|
74 |
+
else if($instance['type'] === 'breadcrumblist_microdata')
|
75 |
+
{
|
76 |
+
echo '<div class="breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">' . wp_kses($instance['pretext'], $this->allowed_html);
|
77 |
+
//Display the regular output breadcrumb
|
78 |
+
bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']);
|
79 |
+
echo '</div>';
|
80 |
+
}
|
81 |
+
else if($instance['type'] === 'plain')
|
82 |
+
{
|
83 |
+
//Display the pretext
|
84 |
+
echo wp_kses($instance['pretext'], $this->allowed_html);
|
85 |
+
//Display the regular output breadcrumb
|
86 |
+
bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']);
|
87 |
+
}
|
88 |
+
else
|
89 |
+
{
|
90 |
+
//If we recieved a type that is not of the built in displays, it must be relegated to an extension plugin
|
91 |
+
do_action('bcn_widget_display_trail', $instance);
|
92 |
+
}
|
93 |
+
//Manditory after widget junk
|
94 |
+
echo $args['after_widget'];
|
95 |
+
}
|
96 |
+
function update($new_instance, $old_instance)
|
97 |
+
{
|
98 |
+
//Filter out anything that could be invalid
|
99 |
+
$old_instance['title'] = strip_tags($new_instance['title']);
|
100 |
+
$old_instance['pretext'] = wp_kses($new_instance['pretext'], $this->allowed_html);
|
101 |
+
$old_instance['type'] = strip_tags($new_instance['type']);
|
102 |
+
$old_instance['linked'] = isset($new_instance['linked']);
|
103 |
+
$old_instance['reverse'] = isset($new_instance['reverse']);
|
104 |
+
$old_instance['front'] = isset($new_instance['front']);
|
105 |
+
$old_instance['force'] = isset($new_instance['force']);
|
106 |
+
return $old_instance;
|
107 |
+
}
|
108 |
+
function form($instance)
|
109 |
+
{
|
110 |
+
$instance = wp_parse_args((array) $instance, $this->defaults);?>
|
111 |
+
<p>
|
112 |
+
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"> <?php _e('Title:', 'breadcrumb-navxt'); ?></label>
|
113 |
+
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('title')); ?>" id="<?php echo esc_attr($this->get_field_id('title')); ?>" value="<?php echo esc_attr($instance['title']);?>" />
|
114 |
+
</p>
|
115 |
+
<p>
|
116 |
+
<label for="<?php echo esc_attr($this->get_field_id('pretext')); ?>"> <?php _e('Text to show before the trail:', 'breadcrumb-navxt'); ?></label>
|
117 |
+
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('pretext')); ?>" id="<?php echo esc_attr($this->get_field_id('pretext')); ?>" value="<?php echo esc_attr($instance['pretext']);?>" />
|
118 |
+
</p>
|
119 |
+
<p>
|
120 |
+
<label for="<?php echo esc_attr($this->get_field_id('type')); ?>"> <?php _e('Output trail as:', 'breadcrumb-navxt'); ?></label>
|
121 |
+
<select name="<?php echo esc_attr($this->get_field_name('type')); ?>" id="<?php echo esc_attr($this->get_field_id('type')); ?>">
|
122 |
+
<option value="list" <?php selected('list', $instance['type']);?>><?php _e('List', 'breadcrumb-navxt'); ?></option>
|
123 |
+
<option value="microdata" <?php selected('microdata', $instance['type']);?>><?php _e('Schema.org BreadcrumbList (RDFa)', 'breadcrumb-navxt'); ?></option>
|
124 |
+
<option value="breadcrumblist_microdata" <?php selected('breadcrumblist_microdata', $instance['type']);?>><?php _e('Schema.org BreadcrumbList (microdata)', 'breadcrumb-navxt'); ?></option>
|
125 |
+
<option value="plain" <?php selected('plain', $instance['type']);?>><?php _e('Plain', 'breadcrumb-navxt'); ?></option>
|
126 |
+
<?php do_action('bcn_widget_display_types', $instance);?>
|
127 |
+
</select>
|
128 |
+
</p>
|
129 |
+
<p>
|
130 |
+
<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('linked')); ?>" id="<?php echo esc_attr($this->get_field_id('linked')); ?>" value="true" <?php checked(true, $instance['linked']);?> />
|
131 |
+
<label for="<?php echo esc_attr($this->get_field_id('linked')); ?>"> <?php _e('Link the breadcrumbs', 'breadcrumb-navxt'); ?></label><br />
|
132 |
+
<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('reverse')); ?>" id="<?php echo esc_attr($this->get_field_id('reverse')); ?>" value="true" <?php checked(true, $instance['reverse']);?> />
|
133 |
+
<label for="<?php echo esc_attr($this->get_field_id('reverse')); ?>"> <?php _e('Reverse the order of the trail', 'breadcrumb-navxt'); ?></label><br />
|
134 |
+
<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('front')); ?>" id="<?php echo esc_attr($this->get_field_id('front')); ?>" value="true" <?php checked(true, $instance['front']);?> />
|
135 |
+
<label for="<?php echo esc_attr($this->get_field_id('front')); ?>"> <?php _e('Hide the trail on the front page', 'breadcrumb-navxt'); ?></label><br />
|
136 |
+
<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('force')); ?>" id="<?php echo esc_attr($this->get_field_id('force')); ?>" value="true" <?php checked(true, $instance['force']);?> />
|
137 |
+
<label for="<?php echo esc_attr($this->get_field_id('force')); ?>"> <?php _e('Ignore breadcrumb cache', 'breadcrumb-navxt'); ?></label><br />
|
138 |
+
</p>
|
139 |
+
<?php
|
140 |
+
}
|
141 |
}
|
includes/block_direct_access.php
CHANGED
@@ -1,27 +1,27 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
//If this file is included directly (e.g. WordPress isn't running), return 404
|
20 |
-
if(!defined('ABSPATH'))
|
21 |
-
{
|
22 |
-
//First catches the Apache users
|
23 |
-
header("HTTP/1.0 404 Not Found");
|
24 |
-
//This should catch FastCGI users
|
25 |
-
header("Status: 404 Not Found");
|
26 |
-
die();
|
27 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
//If this file is included directly (e.g. WordPress isn't running), return 404
|
20 |
+
if(!defined('ABSPATH'))
|
21 |
+
{
|
22 |
+
//First catches the Apache users
|
23 |
+
header("HTTP/1.0 404 Not Found");
|
24 |
+
//This should catch FastCGI users
|
25 |
+
header("Status: 404 Not Found");
|
26 |
+
die();
|
27 |
}
|
includes/class.mtekk_adminkit.php
CHANGED
@@ -1,1195 +1,1195 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
20 |
-
//Include admin base class
|
21 |
-
if(!class_exists('mtekk_adminKit_message'))
|
22 |
-
{
|
23 |
-
require_once(dirname(__FILE__) . '/class.mtekk_adminkit_message.php');
|
24 |
-
}
|
25 |
-
abstract class mtekk_adminKit
|
26 |
-
{
|
27 |
-
const version = '2.0.1';
|
28 |
-
protected $full_name;
|
29 |
-
protected $short_name;
|
30 |
-
protected $plugin_basename;
|
31 |
-
protected $access_level = 'manage_options';
|
32 |
-
protected $identifier;
|
33 |
-
protected $unique_prefix;
|
34 |
-
protected $opt = array();
|
35 |
-
protected $messages;
|
36 |
-
protected $message;
|
37 |
-
protected $support_url;
|
38 |
-
protected $allowed_html;
|
39 |
-
function __construct()
|
40 |
-
{
|
41 |
-
$this->message = array();
|
42 |
-
$this->messages = array();
|
43 |
-
//Admin Init Hook
|
44 |
-
add_action('admin_init', array($this, 'init'));
|
45 |
-
//WordPress Admin interface hook
|
46 |
-
add_action('admin_menu', array($this, 'add_page'));
|
47 |
-
//Installation Script hook
|
48 |
-
add_action('activate_' . $this->plugin_basename, array($this, 'install'));
|
49 |
-
//Initilizes l10n domain
|
50 |
-
$this->local();
|
51 |
-
add_action('wp_loaded', array($this, 'wp_loaded'));
|
52 |
-
//Register Help Output
|
53 |
-
//add_action('add_screen_help_and_options', array($this, 'help'));
|
54 |
-
}
|
55 |
-
function wp_loaded()
|
56 |
-
{
|
57 |
-
//Filter our allowed html tags
|
58 |
-
$this->allowed_html = apply_filters($this->unique_prefix . '_allowed_html', wp_kses_allowed_html('post'));
|
59 |
-
}
|
60 |
-
/**
|
61 |
-
* Returns the internal mtekk_admin_class version
|
62 |
-
*/
|
63 |
-
function get_admin_class_version()
|
64 |
-
{
|
65 |
-
return mtekk_adminKit::version;
|
66 |
-
}
|
67 |
-
/**
|
68 |
-
* Return the URL of the settings page for the plugin
|
69 |
-
*/
|
70 |
-
function admin_url()
|
71 |
-
{
|
72 |
-
return admin_url('options-general.php?page=' . $this->identifier);
|
73 |
-
}
|
74 |
-
/**
|
75 |
-
* A wrapper for nonced_anchor returns a nonced anchor for admin pages
|
76 |
-
*
|
77 |
-
* @param string $mode The nonce "mode", a unique string at the end of the standardized nonce identifier
|
78 |
-
* @param string $title (optional) The text to use in the title portion of the anchor
|
79 |
-
* @param string $text (optional) The text that will be surrounded by the anchor tags
|
80 |
-
* @return string the assembled anchor
|
81 |
-
*/
|
82 |
-
function admin_anchor($mode, $title = '', $text = '')
|
83 |
-
{
|
84 |
-
return $this->nonced_anchor($this->admin_url(), 'admin_' . $mode, 'true', $title, $text);
|
85 |
-
}
|
86 |
-
/**
|
87 |
-
* Returns a properly formed nonced anchor to the specified URI
|
88 |
-
*
|
89 |
-
* @param string $uri The URI that the anchor should be for
|
90 |
-
* @param string $mode The nonce "mode", a unique string at the end of the standardized nonce identifier
|
91 |
-
* @param mixed $value (optional) The value to place in the query string
|
92 |
-
* @param string $title (optional) The text to use in the title portion of the anchor
|
93 |
-
* @param string $text (optional) The text that will be surrounded by the anchor tags
|
94 |
-
* @param string $anchor_extras (optional) This text is placed within the opening anchor tag, good for adding id, classe, rel field
|
95 |
-
* @return string the assembled anchor
|
96 |
-
*/
|
97 |
-
function nonced_anchor($uri, $mode, $value = 'true', $title = '', $text = '', $anchor_extras = '')
|
98 |
-
{
|
99 |
-
//Assemble our url, nonce and all
|
100 |
-
$url = wp_nonce_url(add_query_arg($this->unique_prefix . '_' . $mode, $value, $uri), $this->unique_prefix . '_' . $mode);
|
101 |
-
//Return a valid anchor
|
102 |
-
return ' <a title="' . esc_attr($title) . '" href="' . $url . '" '. $anchor_extras . '>' . esc_html($text) . '</a>';
|
103 |
-
}
|
104 |
-
/**
|
105 |
-
* Abstracts the check_admin_referer so that all the end user has to supply is the mode
|
106 |
-
*
|
107 |
-
* @param string $mode The specific nonce "mode" (see nonced_anchor) that is being checked
|
108 |
-
*/
|
109 |
-
function check_nonce($mode)
|
110 |
-
{
|
111 |
-
check_admin_referer($this->unique_prefix . '_' . $mode);
|
112 |
-
}
|
113 |
-
/**
|
114 |
-
* Makes sure the current user can manage options to proceed
|
115 |
-
*/
|
116 |
-
function security()
|
117 |
-
{
|
118 |
-
//If the user can not manage options we will die on them
|
119 |
-
if(!current_user_can($this->access_level))
|
120 |
-
{
|
121 |
-
wp_die(__('Insufficient privileges to proceed.', $this->identifier));
|
122 |
-
}
|
123 |
-
}
|
124 |
-
function init()
|
125 |
-
{
|
126 |
-
//Admin Options reset hook
|
127 |
-
if(isset($_POST[$this->unique_prefix . '_admin_reset']))
|
128 |
-
{
|
129 |
-
//Run the reset function on init if reset form has been submitted
|
130 |
-
$this->opts_reset();
|
131 |
-
}
|
132 |
-
//Admin Options export hook
|
133 |
-
else if(isset($_POST[$this->unique_prefix . '_admin_export']))
|
134 |
-
{
|
135 |
-
//Run the export function on init if export form has been submitted
|
136 |
-
$this->opts_export();
|
137 |
-
}
|
138 |
-
//Admin Options import hook
|
139 |
-
else if(isset($_FILES[$this->unique_prefix . '_admin_import_file']) && !empty($_FILES[$this->unique_prefix . '_admin_import_file']['name']))
|
140 |
-
{
|
141 |
-
//Run the import function on init if import form has been submitted
|
142 |
-
$this->opts_import();
|
143 |
-
}
|
144 |
-
//Admin Options rollback hook
|
145 |
-
else if(isset($_GET[$this->unique_prefix . '_admin_undo']))
|
146 |
-
{
|
147 |
-
//Run the rollback function on init if undo button has been pressed
|
148 |
-
$this->opts_undo();
|
149 |
-
}
|
150 |
-
//Admin Options upgrade hook
|
151 |
-
else if(isset($_GET[$this->unique_prefix . '_admin_upgrade']))
|
152 |
-
{
|
153 |
-
//Run the upgrade function on init if upgrade button has been pressed
|
154 |
-
$this->opts_upgrade_wrapper();
|
155 |
-
}
|
156 |
-
//Admin Options fix hook
|
157 |
-
else if(isset($_GET[$this->unique_prefix . '_admin_fix']))
|
158 |
-
{
|
159 |
-
//Run the options fix function on init if fix button has been pressed
|
160 |
-
$this->opts_upgrade_wrapper();
|
161 |
-
}
|
162 |
-
//Admin Options update hook
|
163 |
-
else if(isset($_POST[$this->unique_prefix . '_admin_options']))
|
164 |
-
{
|
165 |
-
//Temporarily add update function on init if form has been submitted
|
166 |
-
$this->opts_update();
|
167 |
-
}
|
168 |
-
//Add in the nice "settings" link to the plugins page
|
169 |
-
add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
|
170 |
-
if(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG)
|
171 |
-
{
|
172 |
-
$suffix = '';
|
173 |
-
}
|
174 |
-
else
|
175 |
-
{
|
176 |
-
$suffix = '.min';
|
177 |
-
}
|
178 |
-
//Register JS for more permanently dismissing messages
|
179 |
-
wp_register_script('mtekk_adminkit_messages', plugins_url('/mtekk_adminkit_messages' . $suffix . '.js', dirname(__FILE__) . '/mtekk_adminkit_messages' . $suffix . '.js'), array('jquery'), self::version, true);
|
180 |
-
//Register JS for enable/disable settings groups
|
181 |
-
wp_register_script('mtekk_adminkit_engroups', plugins_url('/mtekk_adminkit_engroups' . $suffix . '.js', dirname(__FILE__) . '/mtekk_adminkit_engroups' . $suffix . '.js'), array('jquery'), self::version, true);
|
182 |
-
//Register JS for tabs
|
183 |
-
wp_register_script('mtekk_adminkit_tabs', plugins_url('/mtekk_adminkit_tabs' . $suffix . '.js', dirname(__FILE__) . '/mtekk_adminkit_tabs' . $suffix . '.js'), array('jquery-ui-tabs'), self::version, true);
|
184 |
-
//Register CSS for tabs
|
185 |
-
wp_register_style('mtekk_adminkit_tabs', plugins_url('/mtekk_adminkit_tabs' . $suffix . '.css', dirname(__FILE__) . '/mtekk_adminkit_tabs' . $suffix . '.css'));
|
186 |
-
//Register options
|
187 |
-
register_setting($this->unique_prefix . '_options', $this->unique_prefix . '_options', '');
|
188 |
-
//Synchronize up our settings with the database as we're done modifying them now
|
189 |
-
$this->opt = $this::parse_args($this->get_option($this->unique_prefix . '_options'), $this->opt);
|
190 |
-
//Run the opts fix filter
|
191 |
-
$this->opts_fix($this->opt);
|
192 |
-
add_action('wp_ajax_mtekk_admin_message_dismiss', array($this, 'dismiss_message'));
|
193 |
-
}
|
194 |
-
/**
|
195 |
-
* Adds the adminpage the menu and the nice little settings link
|
196 |
-
* TODO: make this more generic for easier extension
|
197 |
-
*/
|
198 |
-
function add_page()
|
199 |
-
{
|
200 |
-
//Add the submenu page to "settings" menu
|
201 |
-
$hookname = add_submenu_page('options-general.php', $this->full_name, $this->short_name, $this->access_level, $this->identifier, array($this, 'admin_page'));
|
202 |
-
// check capability of user to manage options (access control)
|
203 |
-
if(current_user_can($this->access_level))
|
204 |
-
{
|
205 |
-
//Register admin_head-$hookname callback
|
206 |
-
add_action('admin_head-' . $hookname, array($this, 'admin_head'));
|
207 |
-
//Register admin_print_styles-$hookname callback
|
208 |
-
add_action('admin_print_styles-' . $hookname, array($this, 'admin_styles'));
|
209 |
-
//Register admin_print_scripts-$hookname callback
|
210 |
-
add_action('admin_print_scripts-' . $hookname, array($this, 'admin_scripts'));
|
211 |
-
//Register Help Output
|
212 |
-
add_action('load-' . $hookname, array($this, 'help'));
|
213 |
-
}
|
214 |
-
}
|
215 |
-
/**
|
216 |
-
* Initilizes localization textdomain for translations (if applicable)
|
217 |
-
*
|
218 |
-
* Will conditionally load the textdomain for translations. This is here for
|
219 |
-
* plugins that span multiple files and have localization in more than one file
|
220 |
-
*
|
221 |
-
* @return void
|
222 |
-
*/
|
223 |
-
function local()
|
224 |
-
{
|
225 |
-
global $l10n;
|
226 |
-
// the global and the check might become obsolete in
|
227 |
-
// further wordpress versions
|
228 |
-
// @see https://core.trac.wordpress.org/ticket/10527
|
229 |
-
if(!isset($l10n[$this->identifier]))
|
230 |
-
{
|
231 |
-
load_plugin_textdomain($this->identifier, false, $this->identifier . '/languages');
|
232 |
-
}
|
233 |
-
}
|
234 |
-
/**
|
235 |
-
* Places in a link to the settings page in the plugins listing entry
|
236 |
-
*
|
237 |
-
* @param array $links An array of links that are output in the listing
|
238 |
-
* @param string $file The file that is currently in processing
|
239 |
-
* @return array Array of links that are output in the listing.
|
240 |
-
*/
|
241 |
-
function filter_plugin_actions($links, $file)
|
242 |
-
{
|
243 |
-
//Make sure we are adding only for the current plugin
|
244 |
-
if($file == $this->plugin_basename)
|
245 |
-
{
|
246 |
-
//Add our link to the end of the array to better integrate into the WP 2.8 plugins page
|
247 |
-
$links[] = '<a href="' . $this->admin_url() . '">' . esc_html__('Settings') . '</a>';
|
248 |
-
}
|
249 |
-
return $links;
|
250 |
-
}
|
251 |
-
/**
|
252 |
-
* Checks to see if the plugin has been fully installed
|
253 |
-
*
|
254 |
-
* @return bool whether or not the plugin has been installed
|
255 |
-
*/
|
256 |
-
function is_installed()
|
257 |
-
{
|
258 |
-
|
259 |
-
}
|
260 |
-
/**
|
261 |
-
* This sets up and upgrades the database settings, runs on every activation
|
262 |
-
*/
|
263 |
-
function install()
|
264 |
-
{
|
265 |
-
//Call our little security function
|
266 |
-
$this->security();
|
267 |
-
//Try retrieving the options from the database
|
268 |
-
$opts = $this->get_option($this->unique_prefix . '_options');
|
269 |
-
//If there are no settings, copy over the default settings
|
270 |
-
if(!is_array($opts))
|
271 |
-
{
|
272 |
-
//Grab defaults from the object
|
273 |
-
$opts = $this->opt;
|
274 |
-
//Add the options
|
275 |
-
$this->add_option($this->unique_prefix . '_options', $opts);
|
276 |
-
$this->add_option($this->unique_prefix . '_options_bk', $opts, '', 'no');
|
277 |
-
//Add the version, no need to autoload the db version
|
278 |
-
$this->add_option($this->unique_prefix . '_version', $this::version, '', 'no');
|
279 |
-
}
|
280 |
-
else
|
281 |
-
{
|
282 |
-
//Retrieve the database version
|
283 |
-
$db_version = $this->get_option($this->unique_prefix . '_version');
|
284 |
-
if($this::version !== $db_version)
|
285 |
-
{
|
286 |
-
//Run the settings update script
|
287 |
-
$this->opts_upgrade($opts, $db_version);
|
288 |
-
//Always have to update the version
|
289 |
-
$this->update_option($this->unique_prefix . '_version', $this::version);
|
290 |
-
//Store the options
|
291 |
-
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
292 |
-
}
|
293 |
-
}
|
294 |
-
}
|
295 |
-
/**
|
296 |
-
* This removes database settings upon deletion of the plugin from WordPress
|
297 |
-
*/
|
298 |
-
function uninstall()
|
299 |
-
{
|
300 |
-
//Remove the option array setting
|
301 |
-
$this->delete_option($this->unique_prefix . '_options');
|
302 |
-
//Remove the option backup array setting
|
303 |
-
$this->delete_option($this->unique_prefix . '_options_bk');
|
304 |
-
//Remove the version setting
|
305 |
-
$this->delete_option($this->unique_prefix . '_version');
|
306 |
-
}
|
307 |
-
/**
|
308 |
-
* Compares the supplided version with the internal version, places an upgrade warning if there is a missmatch
|
309 |
-
* TODO: change this to being auto called in admin_init action
|
310 |
-
*/
|
311 |
-
function version_check($version)
|
312 |
-
{
|
313 |
-
//If we didn't get a version, setup
|
314 |
-
if($version === false)
|
315 |
-
{
|
316 |
-
//Add the version, no need to autoload the db version
|
317 |
-
$this->add_option($this->unique_prefix . '_version', $this::version, '', 'no');
|
318 |
-
}
|
319 |
-
//Do a quick version check
|
320 |
-
if($version && version_compare($version, $this::version, '<') && is_array($this->opt))
|
321 |
-
{
|
322 |
-
//Throw an error since the DB version is out of date
|
323 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Your settings are for an older version of this plugin and need to be migrated.', $this->identifier)
|
324 |
-
. $this->admin_anchor('upgrade', __('Migrate the settings now.', $this->identifier), __('Migrate now.', $this->identifier)), 'warning');
|
325 |
-
//Output any messages that there may be
|
326 |
-
$this->messages();
|
327 |
-
return false;
|
328 |
-
}
|
329 |
-
//Do a quick version check
|
330 |
-
else if($version && version_compare($version, $this::version, '>') && is_array($this->opt))
|
331 |
-
{
|
332 |
-
//Let the user know that their settings are for a newer version
|
333 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Your settings are for a newer version of this plugin.', $this->identifier)
|
334 |
-
. $this->admin_anchor('upgrade', __('Migrate the settings now.', $this->identifier), __('Attempt back migration now.', $this->identifier)), 'warning');
|
335 |
-
//Output any messages that there may be
|
336 |
-
$this->messages();
|
337 |
-
return true;
|
338 |
-
}
|
339 |
-
else if(!is_array($this->opt))
|
340 |
-
{
|
341 |
-
//Throw an error since it appears the options were never registered
|
342 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Your plugin install is incomplete.', $this->identifier)
|
343 |
-
. $this->admin_anchor('upgrade', __('Load default settings now.', $this->identifier), __('Complete now.', $this->identifier)), 'error');
|
344 |
-
//Output any messages that there may be
|
345 |
-
$this->messages();
|
346 |
-
return false;
|
347 |
-
}
|
348 |
-
else if(!$this->opts_validate($this->opt))
|
349 |
-
{
|
350 |
-
//Throw an error since it appears the options contain invalid data
|
351 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('One or more of your plugin settings are invalid.', $this->identifier)
|
352 |
-
. $this->admin_anchor('fix', __('Attempt to fix settings now.', $this->identifier), __('Fix now.', $this->identifier)), 'error');
|
353 |
-
//Output any messages that there may be
|
354 |
-
$this->messages();
|
355 |
-
return false;
|
356 |
-
}
|
357 |
-
return true;
|
358 |
-
}
|
359 |
-
/**
|
360 |
-
* A prototype function. End user should override if they need this feature.
|
361 |
-
*/
|
362 |
-
function opts_validate(&$opts)
|
363 |
-
{
|
364 |
-
return true;
|
365 |
-
}
|
366 |
-
/**
|
367 |
-
* A prototype function. End user should override if they need this feature.
|
368 |
-
*
|
369 |
-
* @param array $opts
|
370 |
-
*/
|
371 |
-
function opts_fix(&$opts)
|
372 |
-
{
|
373 |
-
}
|
374 |
-
/**
|
375 |
-
* Synchronizes the backup options entry with the current options entry
|
376 |
-
*/
|
377 |
-
function opts_backup()
|
378 |
-
{
|
379 |
-
//Set the backup options in the DB to the current options
|
380 |
-
$this->update_option($this->unique_prefix . '_options_bk', $this->get_option($this->unique_prefix . '_options'));
|
381 |
-
}
|
382 |
-
/**
|
383 |
-
* Runs recursivly through the opts array, sanitizing and merging in updates from the $input array
|
384 |
-
*
|
385 |
-
* @param array $opts good, clean array
|
386 |
-
* @param array $input unsanitzed input array, not trusted at all
|
387 |
-
* @todo This function should probably get a filter thrown within it to be more extensible
|
388 |
-
*/
|
389 |
-
protected function opts_update_loop(&$opts, $input)
|
390 |
-
{
|
391 |
-
//Loop through all of the existing options (avoids random setting injection)
|
392 |
-
foreach($opts as $option => $value)
|
393 |
-
{
|
394 |
-
//If we have an array, dive into another recursive loop
|
395 |
-
if(isset($input[$option]) && is_array($value))
|
396 |
-
{
|
397 |
-
$this->opts_update_loop($opts[$option], $input[$option]);
|
398 |
-
}
|
399 |
-
//We must check for unset settings, but booleans are ok to be unset
|
400 |
-
else if(isset($input[$option]) || $option[0] == 'b')
|
401 |
-
{
|
402 |
-
switch($option[0])
|
403 |
-
{
|
404 |
-
//Handle the boolean options
|
405 |
-
case 'b':
|
406 |
-
$opts[$option] = isset($input[$option]);
|
407 |
-
break;
|
408 |
-
//Handle the integer options
|
409 |
-
case 'i':
|
410 |
-
$opts[$option] = (int) $input[$option];
|
411 |
-
break;
|
412 |
-
//Handle the absolute integer options
|
413 |
-
case 'a':
|
414 |
-
$opts[$option] = (int) abs($input[$option]);
|
415 |
-
break;
|
416 |
-
//Handle the floating point options
|
417 |
-
case 'f':
|
418 |
-
$opts[$option] = (float) $input[$option];
|
419 |
-
break;
|
420 |
-
//Handle the HTML options
|
421 |
-
case 'h':
|
422 |
-
$opts[$option] = wp_kses(stripslashes($input[$option]), $this->allowed_html);
|
423 |
-
break;
|
424 |
-
//Handle the HTML options that must not be null
|
425 |
-
case 'H':
|
426 |
-
if(isset($input[$option]))
|
427 |
-
{
|
428 |
-
$opts[$option] = wp_kses(stripslashes($input[$option]), $this->allowed_html);
|
429 |
-
}
|
430 |
-
break;
|
431 |
-
//Handle the text options that must not be null
|
432 |
-
case 'S':
|
433 |
-
if(isset($input[$option]))
|
434 |
-
{
|
435 |
-
$opts[$option] = esc_html($input[$option]);
|
436 |
-
}
|
437 |
-
break;
|
438 |
-
//Deal with strings that can be null
|
439 |
-
case 's':
|
440 |
-
$opts[$option] = esc_html($input[$option]);
|
441 |
-
break;
|
442 |
-
//Deal with enumerated types
|
443 |
-
case 'E':
|
444 |
-
$opts[$option] = $this->opts_sanitize_enum($input[$option], $option);
|
445 |
-
break;
|
446 |
-
//By default we have nothing to do, allows for internal settings
|
447 |
-
default:
|
448 |
-
break;
|
449 |
-
}
|
450 |
-
}
|
451 |
-
}
|
452 |
-
}
|
453 |
-
/**
|
454 |
-
* Simple sanitization function for enumerated types, end users should overload this
|
455 |
-
* with something more usefull
|
456 |
-
*
|
457 |
-
* @param string $value The input value from the form
|
458 |
-
* @param string $option The option name
|
459 |
-
* @return string The sanitized enumerated string
|
460 |
-
*/
|
461 |
-
private function opts_sanitize_enum($value, $option)
|
462 |
-
{
|
463 |
-
return esc_html($value);
|
464 |
-
}
|
465 |
-
/**
|
466 |
-
* A better version of parse_args, will recrusivly follow arrays
|
467 |
-
*
|
468 |
-
* @param mixed $args The arguments to be parsed
|
469 |
-
* @param mixed $defaults (optional) The default values to validate against
|
470 |
-
* @return mixed
|
471 |
-
*/
|
472 |
-
static function parse_args($args, $defaults = '')
|
473 |
-
{
|
474 |
-
if(is_object($args))
|
475 |
-
{
|
476 |
-
$r = get_object_vars($args);
|
477 |
-
}
|
478 |
-
else if(is_array($args))
|
479 |
-
{
|
480 |
-
$r =& $args;
|
481 |
-
}
|
482 |
-
else
|
483 |
-
{
|
484 |
-
wp_parse_str($args, $r);
|
485 |
-
}
|
486 |
-
if(is_array($defaults))
|
487 |
-
{
|
488 |
-
return mtekk_adminKit::array_merge_recursive($defaults, $r);
|
489 |
-
}
|
490 |
-
return $r;
|
491 |
-
}
|
492 |
-
/**
|
493 |
-
* An alternate version of array_merge_recursive, less flexible
|
494 |
-
* still recursive, ~2x faster than the more flexible version
|
495 |
-
*
|
496 |
-
* @param array $arg1 first array
|
497 |
-
* @param array $arg2 second array to merge into $arg1
|
498 |
-
* @return array
|
499 |
-
*/
|
500 |
-
static function array_merge_recursive($arg1, $arg2)
|
501 |
-
{
|
502 |
-
foreach($arg2 as $key => $value)
|
503 |
-
{
|
504 |
-
if(array_key_exists($key, $arg1) && is_array($value))
|
505 |
-
{
|
506 |
-
$arg1[$key] = mtekk_adminKit::array_merge_recursive($arg1[$key], $value);
|
507 |
-
}
|
508 |
-
else
|
509 |
-
{
|
510 |
-
$arg1[$key] = $value;
|
511 |
-
}
|
512 |
-
}
|
513 |
-
return $arg1;
|
514 |
-
}
|
515 |
-
/**
|
516 |
-
* An action that fires just before the options backup, use to add in dynamically detected options
|
517 |
-
*
|
518 |
-
* @param array $opts the options array, passed in by reference
|
519 |
-
* @return null
|
520 |
-
*/
|
521 |
-
function opts_update_prebk(&$opts)
|
522 |
-
{
|
523 |
-
//Just a prototype function
|
524 |
-
}
|
525 |
-
/**
|
526 |
-
* Updates the database settings from the webform
|
527 |
-
*/
|
528 |
-
function opts_update()
|
529 |
-
{
|
530 |
-
//Do some security related thigns as we are not using the normal WP settings API
|
531 |
-
$this->security();
|
532 |
-
//Do a nonce check, prevent malicious link/form problems
|
533 |
-
check_admin_referer($this->unique_prefix . '_options-options');
|
534 |
-
//Update local options from database
|
535 |
-
$this->opt = $this::parse_args($this->get_option($this->unique_prefix . '_options'), $this->opt);
|
536 |
-
$this->opts_update_prebk($this->opt);
|
537 |
-
//Update our backup options
|
538 |
-
$this->update_option($this->unique_prefix . '_options_bk', $this->opt);
|
539 |
-
$opt_prev = $this->opt;
|
540 |
-
//Grab our incomming array (the data is dirty)
|
541 |
-
$input = $_POST[$this->unique_prefix . '_options'];
|
542 |
-
//Run the update loop
|
543 |
-
$this->opts_update_loop($this->opt, $input);
|
544 |
-
//Commit the option changes
|
545 |
-
$updated = $this->update_option($this->unique_prefix . '_options', $this->opt);
|
546 |
-
//Check if known settings match attempted save
|
547 |
-
if($updated && count(array_diff_key($input, $this->opt)) == 0)
|
548 |
-
{
|
549 |
-
//Let the user know everything went ok
|
550 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully saved.', $this->identifier)
|
551 |
-
. $this->admin_anchor('undo', __('Undo the options save.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
552 |
-
}
|
553 |
-
else if(!$updated && count(array_diff_key($opt_prev, $this->opt)) == 0)
|
554 |
-
{
|
555 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings did not change, nothing to save.', $this->identifier), 'info');
|
556 |
-
}
|
557 |
-
else if(!$updated)
|
558 |
-
{
|
559 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings were not saved.', $this->identifier), 'error');
|
560 |
-
}
|
561 |
-
else
|
562 |
-
{
|
563 |
-
//Let the user know the following were not saved
|
564 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Some settings were not saved.', $this->identifier)
|
565 |
-
. $this->admin_anchor('undo', __('Undo the options save.', $this->identifier), __('Undo', $this->identifier)), 'warning');
|
566 |
-
$temp = esc_html__('The following settings were not saved:', $this->identifier);
|
567 |
-
foreach(array_diff_key($input, $this->opt) as $setting => $value)
|
568 |
-
{
|
569 |
-
$temp .= '<br />' . $setting;
|
570 |
-
}
|
571 |
-
$this->messages[] = new mtekk_adminKit_message($temp . '<br />' . sprintf(esc_html__('Please include this message in your %sbug report%s.', $this->identifier), '<a title="' . sprintf(esc_attr__('Go to the %s support
|
572 |
-
}
|
573 |
-
add_action('admin_notices', array($this, 'messages'));
|
574 |
-
}
|
575 |
-
/**
|
576 |
-
* Exports a XML options document
|
577 |
-
*/
|
578 |
-
function opts_export()
|
579 |
-
{
|
580 |
-
//Do a nonce check, prevent malicious link/form problems
|
581 |
-
check_admin_referer($this->unique_prefix . '_admin_import_export');
|
582 |
-
//Update our internal settings
|
583 |
-
$this->opt = $this->get_option($this->unique_prefix . '_options');
|
584 |
-
//Create a DOM document
|
585 |
-
$dom = new DOMDocument('1.0', 'UTF-8');
|
586 |
-
//Adds in newlines and tabs to the output
|
587 |
-
$dom->formatOutput = true;
|
588 |
-
//We're not using a DTD therefore we need to specify it as a standalone document
|
589 |
-
$dom->xmlStandalone = true;
|
590 |
-
//Add an element called options
|
591 |
-
$node = $dom->createElement('options');
|
592 |
-
$parnode = $dom->appendChild($node);
|
593 |
-
//Add a child element named plugin
|
594 |
-
$node = $dom->createElement('plugin');
|
595 |
-
$plugnode = $parnode->appendChild($node);
|
596 |
-
//Add some attributes that identify the plugin and version for the options export
|
597 |
-
$plugnode->setAttribute('name', $this->short_name);
|
598 |
-
$plugnode->setAttribute('version', $this::version);
|
599 |
-
//Change our headder to text/xml for direct save
|
600 |
-
header('Cache-Control: public');
|
601 |
-
//The next two will cause good browsers to download instead of displaying the file
|
602 |
-
header('Content-Description: File Transfer');
|
603 |
-
header('Content-disposition: attachemnt; filename=' . $this->unique_prefix . '_settings.xml');
|
604 |
-
header('Content-Type: text/xml');
|
605 |
-
//Loop through the options array
|
606 |
-
foreach($this->opt as $key=>$option)
|
607 |
-
{
|
608 |
-
//Add a option tag under the options tag, store the option value
|
609 |
-
$node = $dom->createElement('option', htmlentities($option, ENT_COMPAT, 'UTF-8'));
|
610 |
-
$newnode = $plugnode->appendChild($node);
|
611 |
-
//Change the tag's name to that of the stored option
|
612 |
-
$newnode->setAttribute('name', $key);
|
613 |
-
}
|
614 |
-
//Prepair the XML for output
|
615 |
-
$output = $dom->saveXML();
|
616 |
-
//Let the browser know how long the file is
|
617 |
-
header('Content-Length: ' . strlen($output)); // binary length
|
618 |
-
//Output the file
|
619 |
-
echo $output;
|
620 |
-
//Prevent WordPress from continuing on
|
621 |
-
die();
|
622 |
-
}
|
623 |
-
/**
|
624 |
-
* Imports a XML options document
|
625 |
-
*/
|
626 |
-
function opts_import()
|
627 |
-
{
|
628 |
-
//Our quick and dirty error supressor
|
629 |
-
function error($errno, $errstr, $eerfile, $errline)
|
630 |
-
{
|
631 |
-
return true;
|
632 |
-
}
|
633 |
-
//Do a nonce check, prevent malicious link/form problems
|
634 |
-
check_admin_referer($this->unique_prefix . '_admin_import_export');
|
635 |
-
//Set the backup options in the DB to the current options
|
636 |
-
$this->opts_backup();
|
637 |
-
//Create a DOM document
|
638 |
-
$dom = new DOMDocument('1.0', 'UTF-8');
|
639 |
-
//We want to catch errors ourselves
|
640 |
-
set_error_handler('error');
|
641 |
-
//Load the user uploaded file, handle failure gracefully
|
642 |
-
if($dom->load($_FILES[$this->unique_prefix . '_admin_import_file']['tmp_name']))
|
643 |
-
{
|
644 |
-
$opts_temp = array();
|
645 |
-
$version = '';
|
646 |
-
//Have to use an xpath query otherwise we run into problems
|
647 |
-
$xpath = new DOMXPath($dom);
|
648 |
-
$option_sets = $xpath->query('plugin');
|
649 |
-
//Loop through all of the xpath query results
|
650 |
-
foreach($option_sets as $options)
|
651 |
-
{
|
652 |
-
//We only want to import options for only this plugin
|
653 |
-
if($options->getAttribute('name') === $this->short_name)
|
654 |
-
{
|
655 |
-
//Grab the file version
|
656 |
-
$version = $options->getAttribute('version');
|
657 |
-
//Loop around all of the options
|
658 |
-
foreach($options->getelementsByTagName('option') as $child)
|
659 |
-
{
|
660 |
-
//Place the option into the option array, DOMDocument decodes html entities for us
|
661 |
-
$opts_temp[$child->getAttribute('name')] = $child->nodeValue;
|
662 |
-
}
|
663 |
-
}
|
664 |
-
}
|
665 |
-
//Make sure we safely import and upgrade settings if needed
|
666 |
-
$this->opts_upgrade($opts_temp, $version);
|
667 |
-
//Commit the loaded options to the database
|
668 |
-
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
669 |
-
//Everything was successful, let the user know
|
670 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully imported from the uploaded file.', $this->identifier)
|
671 |
-
. $this->admin_anchor('undo', __('Undo the options import.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
672 |
-
}
|
673 |
-
else
|
674 |
-
{
|
675 |
-
//Throw an error since we could not load the file for various reasons
|
676 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Importing settings from file failed.', $this->identifier), 'error');
|
677 |
-
}
|
678 |
-
//Reset to the default error handler after we're done
|
679 |
-
restore_error_handler();
|
680 |
-
//Output any messages that there may be
|
681 |
-
add_action('admin_notices', array($this, 'messages'));
|
682 |
-
}
|
683 |
-
/**
|
684 |
-
* Resets the database settings array to the default set in opt
|
685 |
-
*/
|
686 |
-
function opts_reset()
|
687 |
-
{
|
688 |
-
//Do a nonce check, prevent malicious link/form problems
|
689 |
-
check_admin_referer($this->unique_prefix . '_admin_import_export');
|
690 |
-
//Set the backup options in the DB to the current options
|
691 |
-
$this->opts_backup();
|
692 |
-
//Load in the hard coded default option values
|
693 |
-
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
694 |
-
//Reset successful, let the user know
|
695 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully reset to the default values.', $this->identifier)
|
696 |
-
. $this->admin_anchor('undo', __('Undo the options reset.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
697 |
-
add_action('admin_notices', array($this, 'messages'));
|
698 |
-
}
|
699 |
-
/**
|
700 |
-
* Undos the last settings save/reset/import
|
701 |
-
*/
|
702 |
-
function opts_undo()
|
703 |
-
{
|
704 |
-
//Do a nonce check, prevent malicious link/form problems
|
705 |
-
check_admin_referer($this->unique_prefix . '_admin_undo');
|
706 |
-
//Set the options array to the current options
|
707 |
-
$opt = $this->get_option($this->unique_prefix . '_options');
|
708 |
-
//Set the options in the DB to the backup options
|
709 |
-
$this->update_option($this->unique_prefix . '_options', $this->get_option($this->unique_prefix . '_options_bk'));
|
710 |
-
//Set the backup options to the undone options
|
711 |
-
$this->update_option($this->unique_prefix . '_options_bk', $opt);
|
712 |
-
//Send the success/undo message
|
713 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully undid the last operation.', $this->identifier)
|
714 |
-
. $this->admin_anchor('undo', __('Undo the last undo operation.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
715 |
-
add_action('admin_notices', array($this, 'messages'));
|
716 |
-
}
|
717 |
-
/**
|
718 |
-
* Upgrades input options array, sets to $this->opt, designed to be overwritten
|
719 |
-
*
|
720 |
-
* @param array $opts
|
721 |
-
* @param string $version the version of the passed in options
|
722 |
-
*/
|
723 |
-
function opts_upgrade($opts, $version)
|
724 |
-
{
|
725 |
-
//We don't support using newer versioned option files in older releases
|
726 |
-
if(version_compare($this::version, $version, '>='))
|
727 |
-
{
|
728 |
-
$this->opt = $opts;
|
729 |
-
}
|
730 |
-
}
|
731 |
-
/**
|
732 |
-
* Forces a database settings upgrade
|
733 |
-
*/
|
734 |
-
function opts_upgrade_wrapper()
|
735 |
-
{
|
736 |
-
//Do a nonce check, prevent malicious link/form problems
|
737 |
-
check_admin_referer($this->unique_prefix . '_admin_upgrade');
|
738 |
-
//Grab the database options
|
739 |
-
$opts = $this->get_option($this->unique_prefix . '_options');
|
740 |
-
if(is_array($opts))
|
741 |
-
{
|
742 |
-
//Feed the just read options into the upgrade function
|
743 |
-
$this->opts_upgrade($opts, $this->get_option($this->unique_prefix . '_version'));
|
744 |
-
//Always have to update the version
|
745 |
-
$this->update_option($this->unique_prefix . '_version', $this::version);
|
746 |
-
//Store the options
|
747 |
-
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
748 |
-
//Send the success message
|
749 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully migrated.', $this->identifier), 'success');
|
750 |
-
}
|
751 |
-
else
|
752 |
-
{
|
753 |
-
//Run the install script
|
754 |
-
$this->install();
|
755 |
-
//Send the success message
|
756 |
-
$this->messages[] = new mtekk_adminKit_message(esc_html__('Default settings successfully installed.', $this->identifier), 'success');
|
757 |
-
}
|
758 |
-
add_action('admin_notices', array($this, 'messages'));
|
759 |
-
}
|
760 |
-
/**
|
761 |
-
* help action hook function, meant to be overridden
|
762 |
-
*
|
763 |
-
* @return string
|
764 |
-
*
|
765 |
-
*/
|
766 |
-
function help()
|
767 |
-
{
|
768 |
-
$screen = get_current_screen();
|
769 |
-
//Add contextual help on current screen
|
770 |
-
if($screen->id == 'settings_page_' . $this->identifier)
|
771 |
-
{
|
772 |
-
|
773 |
-
}
|
774 |
-
}
|
775 |
-
function dismiss_message()
|
776 |
-
{
|
777 |
-
//Grab the submitted UID
|
778 |
-
$uid = esc_attr($_POST['uid']);
|
779 |
-
//Create a dummy message, with the discovered UID
|
780 |
-
$message = new mtekk_adminKit_message('', '', true, $uid);
|
781 |
-
//Dismiss the message
|
782 |
-
$message->dismiss();
|
783 |
-
wp_die();
|
784 |
-
}
|
785 |
-
/**
|
786 |
-
* Prints to screen all of the messages stored in the message member variable
|
787 |
-
*/
|
788 |
-
function messages()
|
789 |
-
{
|
790 |
-
foreach($this->messages as $message)
|
791 |
-
{
|
792 |
-
$message->render();
|
793 |
-
}
|
794 |
-
//Old deprecated messages
|
795 |
-
if(count($this->message))
|
796 |
-
{
|
797 |
-
_deprecated_function( __FUNCTION__, '2.0.0', __('adminKit::message is deprecated, use new adminkit_messages instead.', $this->identifier) );
|
798 |
-
//Loop through our message classes
|
799 |
-
foreach($this->message as $key => $class)
|
800 |
-
{
|
801 |
-
//Loop through the messages in the current class
|
802 |
-
foreach($class as $message)
|
803 |
-
{
|
804 |
-
printf('<div class="%s"><p>%s</p></div>', esc_attr($key), $message);
|
805 |
-
}
|
806 |
-
}
|
807 |
-
$this->message = array();
|
808 |
-
}
|
809 |
-
$this->messages = array();
|
810 |
-
}
|
811 |
-
/**
|
812 |
-
* Function prototype to prevent errors
|
813 |
-
*/
|
814 |
-
function admin_styles()
|
815 |
-
{
|
816 |
-
|
817 |
-
}
|
818 |
-
/**
|
819 |
-
* Function prototype to prevent errors
|
820 |
-
*/
|
821 |
-
function admin_scripts()
|
822 |
-
{
|
823 |
-
|
824 |
-
}
|
825 |
-
/**
|
826 |
-
* Function prototype to prevent errors
|
827 |
-
*/
|
828 |
-
function admin_head()
|
829 |
-
{
|
830 |
-
|
831 |
-
}
|
832 |
-
/**
|
833 |
-
* Function prototype to prevent errors
|
834 |
-
*/
|
835 |
-
function admin_page()
|
836 |
-
{
|
837 |
-
|
838 |
-
}
|
839 |
-
/**
|
840 |
-
* Function prototype to prevent errors
|
841 |
-
*/
|
842 |
-
protected function _get_help_text()
|
843 |
-
{
|
844 |
-
|
845 |
-
}
|
846 |
-
/**
|
847 |
-
* Returns a valid xHTML element ID
|
848 |
-
*
|
849 |
-
* @param object $option
|
850 |
-
*/
|
851 |
-
static public function get_valid_id($option)
|
852 |
-
{
|
853 |
-
if(is_numeric($option[0]))
|
854 |
-
{
|
855 |
-
return 'p' . $option;
|
856 |
-
}
|
857 |
-
else
|
858 |
-
{
|
859 |
-
return $option;
|
860 |
-
}
|
861 |
-
}
|
862 |
-
function import_form()
|
863 |
-
{
|
864 |
-
$form = '<div id="mtekk_admin_import_export_relocate">';
|
865 |
-
$form .= sprintf('<form action="options-general.php?page=%s" method="post" enctype="multipart/form-data" id="%s_admin_upload">', esc_attr($this->identifier), esc_attr($this->unique_prefix));
|
866 |
-
$form .= wp_nonce_field($this->unique_prefix . '_admin_import_export', '_wpnonce', true, false);
|
867 |
-
$form .= sprintf('<fieldset id="import_export" class="%s_options">', esc_attr($this->unique_prefix));
|
868 |
-
$form .= '<p>' . esc_html__('Import settings from a XML file, export the current settings to a XML file, or reset to the default settings.', $this->identifier) . '</p>';
|
869 |
-
$form .= '<table class="form-table"><tr valign="top"><th scope="row">';
|
870 |
-
$form .= sprintf('<label for="%s_admin_import_file">', esc_attr($this->unique_prefix));
|
871 |
-
$form .= esc_html__('Settings File', $this->identifier);
|
872 |
-
$form .= '</label></th><td>';
|
873 |
-
$form .= sprintf('<input type="file" name="%1$s_admin_import_file" id="%1$s_admin_import_file" size="32" /><p class="description">', esc_attr($this->unique_prefix));
|
874 |
-
$form .= esc_html__('Select a XML settings file to upload and import settings from.', 'breadcrumb_navxt');
|
875 |
-
$form .= '</p></td></tr></table><p class="submit">';
|
876 |
-
$form .= sprintf('<input type="submit" class="button" name="%1$s_admin_import" value="%2$s"/>', $this->unique_prefix, esc_attr__('Import', $this->identifier));
|
877 |
-
$form .= sprintf('<input type="submit" class="button" name="%1$s_admin_export" value="%2$s"/>', $this->unique_prefix, esc_attr__('Export', $this->identifier));
|
878 |
-
$form .= sprintf('<input type="submit" class="button" name="%1$s_admin_reset" value="%2$s"/>', $this->unique_prefix, esc_attr__('Reset', $this->identifier));
|
879 |
-
$form .= '</p></fieldset></form></div>';
|
880 |
-
return $form;
|
881 |
-
}
|
882 |
-
/**
|
883 |
-
* This will output a well formed hidden option
|
884 |
-
*
|
885 |
-
* @param string $option
|
886 |
-
*/
|
887 |
-
function input_hidden($option)
|
888 |
-
{
|
889 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
890 |
-
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
891 |
-
printf('<input type="hidden" name="%1$s" id="%2$s" value="%3$s" />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]));
|
892 |
-
}
|
893 |
-
/**
|
894 |
-
* This will output a well formed option label
|
895 |
-
*
|
896 |
-
* @param string $opt_id
|
897 |
-
* @param string $label
|
898 |
-
*/
|
899 |
-
function label($opt_id, $label)
|
900 |
-
{
|
901 |
-
printf('<label for="%1$s">%2$s</label>', esc_attr($opt_id), $label);
|
902 |
-
}
|
903 |
-
/**
|
904 |
-
* This will output a well formed table row for a text input
|
905 |
-
*
|
906 |
-
* @param string $label
|
907 |
-
* @param string $option
|
908 |
-
* @param string $class (optional)
|
909 |
-
* @param bool $disable (optional)
|
910 |
-
* @param string $description (optional)
|
911 |
-
*/
|
912 |
-
function input_text($label, $option, $class = 'regular-text', $disable = false, $description = '')
|
913 |
-
{
|
914 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
915 |
-
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
916 |
-
if($disable)
|
917 |
-
{
|
918 |
-
$this->input_hidden($option);
|
919 |
-
$class .= ' disabled';
|
920 |
-
}?>
|
921 |
-
<tr valign="top">
|
922 |
-
<th scope="row">
|
923 |
-
<?php $this->label($opt_id, $label);?>
|
924 |
-
</th>
|
925 |
-
<td>
|
926 |
-
<?php printf('<input type="text" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false));?>
|
927 |
-
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
928 |
-
</td>
|
929 |
-
</tr>
|
930 |
-
<?php
|
931 |
-
}
|
932 |
-
/**
|
933 |
-
* This will output a well formed table row for a HTML5 number input
|
934 |
-
*
|
935 |
-
* @param string $label
|
936 |
-
* @param string $option
|
937 |
-
* @param string $class (optional)
|
938 |
-
* @param bool $disable (optional)
|
939 |
-
* @param string $description (optional)
|
940 |
-
* @param int|string $min (optional)
|
941 |
-
* @param int|string $max (optional)
|
942 |
-
* @param int|string $step (optional)
|
943 |
-
*/
|
944 |
-
function input_number($label, $option, $class = 'small-text', $disable = false, $description = '', $min = '', $max = '', $step = '')
|
945 |
-
{
|
946 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
947 |
-
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
948 |
-
$extras = '';
|
949 |
-
if($min !== '')
|
950 |
-
{
|
951 |
-
$extras .= 'min="' . esc_attr($min) . '" ';
|
952 |
-
}
|
953 |
-
if($max !== '')
|
954 |
-
{
|
955 |
-
$extras .= 'max="' . esc_attr($max) . '" ';
|
956 |
-
}
|
957 |
-
if($step !== '')
|
958 |
-
{
|
959 |
-
$extras .= 'step="' . esc_attr($step) . '" ';
|
960 |
-
}
|
961 |
-
if($disable)
|
962 |
-
{
|
963 |
-
$this->input_hidden($option);
|
964 |
-
$class .= ' disabled';
|
965 |
-
}?>
|
966 |
-
<tr valign="top">
|
967 |
-
<th scope="row">
|
968 |
-
<?php $this->label($opt_id, $label);?>
|
969 |
-
</th>
|
970 |
-
<td>
|
971 |
-
<?php printf('<input type="number" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %6$s%5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false), $extras);?>
|
972 |
-
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
973 |
-
</td>
|
974 |
-
</tr>
|
975 |
-
<?php
|
976 |
-
}
|
977 |
-
/**
|
978 |
-
* This will output a well formed textbox
|
979 |
-
*
|
980 |
-
* @param string $label
|
981 |
-
* @param string $option
|
982 |
-
* @param string $rows (optional)
|
983 |
-
* @param bool $disable (optional)
|
984 |
-
* @param string $description (optional)
|
985 |
-
*/
|
986 |
-
function textbox($label, $option, $height = '3', $disable = false, $description = '', $class = '')
|
987 |
-
{
|
988 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
989 |
-
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
990 |
-
$class .= ' large-text';
|
991 |
-
if($disable)
|
992 |
-
{
|
993 |
-
$this->input_hidden($option);
|
994 |
-
$class .= ' disabled';
|
995 |
-
}?>
|
996 |
-
<tr valign="top">
|
997 |
-
<th scope="row">
|
998 |
-
<?php $this->label($opt_id, $label);?>
|
999 |
-
</th>
|
1000 |
-
<td>
|
1001 |
-
<?php printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($this->opt[$option]), esc_attr($class), disabled($disable, true, false), esc_attr($height));?>
|
1002 |
-
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1003 |
-
</td>
|
1004 |
-
</tr>
|
1005 |
-
<?php
|
1006 |
-
}
|
1007 |
-
/**
|
1008 |
-
* This will output a well formed tiny mce ready textbox
|
1009 |
-
*
|
1010 |
-
* @param string $label
|
1011 |
-
* @param string $option
|
1012 |
-
* @param string $rows (optional)
|
1013 |
-
* @param bool $disable (optional)
|
1014 |
-
* @param string $description (optional)
|
1015 |
-
*/
|
1016 |
-
function tinymce($label, $option, $height = '3', $disable = false, $description = '')
|
1017 |
-
{
|
1018 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1019 |
-
$class = 'mtekk_mce';
|
1020 |
-
if($disable)
|
1021 |
-
{
|
1022 |
-
$this->input_hidden($option);
|
1023 |
-
$class .= ' disabled';
|
1024 |
-
}?>
|
1025 |
-
<tr valign="top">
|
1026 |
-
<th scope="row">
|
1027 |
-
<?php $this->label($opt_id, $label);?>
|
1028 |
-
</th>
|
1029 |
-
<td>
|
1030 |
-
<?php printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($this->opt[$option]), esc_attr($class), disabled($disable, true, false), esc_attr($height));?>
|
1031 |
-
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1032 |
-
</td>
|
1033 |
-
</tr>
|
1034 |
-
<?php
|
1035 |
-
}
|
1036 |
-
/**
|
1037 |
-
* This will output a well formed table row for a checkbox input
|
1038 |
-
*
|
1039 |
-
* @param string $label
|
1040 |
-
* @param string $option
|
1041 |
-
* @param string $instruction
|
1042 |
-
* @param bool $disable (optional)
|
1043 |
-
* @param string $description (optional)
|
1044 |
-
* @param string $class (optional)
|
1045 |
-
*/
|
1046 |
-
function input_check($label, $option, $instruction, $disable = false, $description = '', $class = '')
|
1047 |
-
{
|
1048 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1049 |
-
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
1050 |
-
if($disable)
|
1051 |
-
{
|
1052 |
-
$this->input_hidden($option);
|
1053 |
-
$class .= ' disabled';
|
1054 |
-
}?>
|
1055 |
-
<tr valign="top">
|
1056 |
-
<th scope="row">
|
1057 |
-
<?php $this->label($opt_id, $label);?>
|
1058 |
-
</th>
|
1059 |
-
<td>
|
1060 |
-
<label>
|
1061 |
-
<?php printf('<input type="checkbox" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false), checked($this->opt[$option], true, false));?>
|
1062 |
-
<?php echo $instruction; ?>
|
1063 |
-
</label><br />
|
1064 |
-
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1065 |
-
</td>
|
1066 |
-
</tr>
|
1067 |
-
<?php
|
1068 |
-
}
|
1069 |
-
/**
|
1070 |
-
* This will output a singular radio type form input field
|
1071 |
-
*
|
1072 |
-
* @param string $option
|
1073 |
-
* @param string $value
|
1074 |
-
* @param string $instruction
|
1075 |
-
* @param object $disable (optional)
|
1076 |
-
* @param string $class (optional)
|
1077 |
-
*/
|
1078 |
-
function input_radio($option, $value, $instruction, $disable = false, $class = '')
|
1079 |
-
{
|
1080 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1081 |
-
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
1082 |
-
$class .= ' togx';
|
1083 |
-
if($disable)
|
1084 |
-
{
|
1085 |
-
$this->input_hidden($option);
|
1086 |
-
$class .= ' disabled';
|
1087 |
-
}?>
|
1088 |
-
<label>
|
1089 |
-
<?php printf('<input type="radio" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), esc_attr($value), esc_attr($class), disabled($disable, true, false), checked($value, $this->opt[$option], false));?>
|
1090 |
-
<?php echo $instruction; ?>
|
1091 |
-
</label><br/>
|
1092 |
-
<?php
|
1093 |
-
}
|
1094 |
-
/**
|
1095 |
-
* This will output a well formed table row for a select input
|
1096 |
-
*
|
1097 |
-
* @param string $label
|
1098 |
-
* @param string $option
|
1099 |
-
* @param array $values
|
1100 |
-
* @param bool $disable (optional)
|
1101 |
-
* @param string $description (optional)
|
1102 |
-
* @param array $titles (optional) The array of titiles for the options, if they should be different from the values
|
1103 |
-
* @param string $class (optional) Extra class to apply to the elements
|
1104 |
-
*/
|
1105 |
-
function input_select($label, $option, $values, $disable = false, $description = '', $titles = false, $class = '')
|
1106 |
-
{
|
1107 |
-
//If we don't have titles passed in, we'll use option names as values
|
1108 |
-
if(!$titles)
|
1109 |
-
{
|
1110 |
-
$titles = $values;
|
1111 |
-
}
|
1112 |
-
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1113 |
-
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
1114 |
-
if($disable)
|
1115 |
-
{
|
1116 |
-
$this->input_hidden($option);
|
1117 |
-
$class .= ' disabled';
|
1118 |
-
}?>
|
1119 |
-
<tr valign="top">
|
1120 |
-
<th scope="row">
|
1121 |
-
<?php $this->label($opt_id, $label);?>
|
1122 |
-
</th>
|
1123 |
-
<td>
|
1124 |
-
<?php printf('<select name="%1$s" id="%2$s" class="%4$s" %5$s>%3$s</select><br />', esc_attr($opt_name), esc_attr($opt_id), $this->select_options($option, $titles, $values), esc_attr($class), disabled($disable, true, false));?>
|
1125 |
-
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1126 |
-
</td>
|
1127 |
-
</tr>
|
1128 |
-
<?php
|
1129 |
-
}
|
1130 |
-
/**
|
1131 |
-
* Displays wordpress options as <seclect>
|
1132 |
-
*
|
1133 |
-
* @param string $optionname name of wordpress options store
|
1134 |
-
* @param array $options array of names of options that can be selected
|
1135 |
-
* @param array $values array of the values of the options that can be selected
|
1136 |
-
* @param array $exclude(optional) array of names in $options array to be excluded
|
1137 |
-
*
|
1138 |
-
* @return string The assembled HTML for the select options
|
1139 |
-
*/
|
1140 |
-
function select_options($optionname, $options, $values, $exclude = array())
|
1141 |
-
{
|
1142 |
-
$options_html = '';
|
1143 |
-
$value = $this->opt[$optionname];
|
1144 |
-
//Now do the rest
|
1145 |
-
foreach($options as $key => $option)
|
1146 |
-
{
|
1147 |
-
if(!in_array($option, $exclude))
|
1148 |
-
{
|
1149 |
-
$options_html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($values[$key]), selected($value, $values[$key], false), $option);
|
1150 |
-
}
|
1151 |
-
}
|
1152 |
-
return $options_html;
|
1153 |
-
}
|
1154 |
-
/**
|
1155 |
-
* A local pass through for get_option so that we can hook in and pick the correct method if needed
|
1156 |
-
*
|
1157 |
-
* @param string $option The name of the option to retrieve
|
1158 |
-
* @return mixed The value of the option
|
1159 |
-
*/
|
1160 |
-
function get_option($option)
|
1161 |
-
{
|
1162 |
-
return get_option($option);
|
1163 |
-
}
|
1164 |
-
/**
|
1165 |
-
* A local pass through for update_option so that we can hook in and pick the correct method if needed
|
1166 |
-
*
|
1167 |
-
* @param string $option The name of the option to update
|
1168 |
-
* @param mixed $newvalue The new value to set the option to
|
1169 |
-
*/
|
1170 |
-
function update_option($option, $newvalue)
|
1171 |
-
{
|
1172 |
-
return update_option($option, $newvalue);
|
1173 |
-
}
|
1174 |
-
/**
|
1175 |
-
* A local pass through for add_option so that we can hook in and pick the correct method if needed
|
1176 |
-
*
|
1177 |
-
* @param string $option The name of the option to update
|
1178 |
-
* @param mixed $value The new value to set the option to
|
1179 |
-
* @param null $deprecated Deprecated parameter
|
1180 |
-
* @param string $autoload Whether or not to autoload the option, it's a string because WP is special
|
1181 |
-
*/
|
1182 |
-
function add_option($option, $value = '', $deprecated = '', $autoload = 'yes')
|
1183 |
-
{
|
1184 |
-
return add_option($option, $value, null, $autoload);
|
1185 |
-
}
|
1186 |
-
/**
|
1187 |
-
* A local pass through for delete_option so that we can hook in and pick the correct method if needed
|
1188 |
-
*
|
1189 |
-
* @param string $option The name of the option to delete
|
1190 |
-
*/
|
1191 |
-
function delete_option($option)
|
1192 |
-
{
|
1193 |
-
return delete_option($option);
|
1194 |
-
}
|
1195 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
20 |
+
//Include admin base class
|
21 |
+
if(!class_exists('mtekk_adminKit_message'))
|
22 |
+
{
|
23 |
+
require_once(dirname(__FILE__) . '/class.mtekk_adminkit_message.php');
|
24 |
+
}
|
25 |
+
abstract class mtekk_adminKit
|
26 |
+
{
|
27 |
+
const version = '2.0.1';
|
28 |
+
protected $full_name;
|
29 |
+
protected $short_name;
|
30 |
+
protected $plugin_basename;
|
31 |
+
protected $access_level = 'manage_options';
|
32 |
+
protected $identifier;
|
33 |
+
protected $unique_prefix;
|
34 |
+
protected $opt = array();
|
35 |
+
protected $messages;
|
36 |
+
protected $message;
|
37 |
+
protected $support_url;
|
38 |
+
protected $allowed_html;
|
39 |
+
function __construct()
|
40 |
+
{
|
41 |
+
$this->message = array();
|
42 |
+
$this->messages = array();
|
43 |
+
//Admin Init Hook
|
44 |
+
add_action('admin_init', array($this, 'init'));
|
45 |
+
//WordPress Admin interface hook
|
46 |
+
add_action('admin_menu', array($this, 'add_page'));
|
47 |
+
//Installation Script hook
|
48 |
+
add_action('activate_' . $this->plugin_basename, array($this, 'install'));
|
49 |
+
//Initilizes l10n domain
|
50 |
+
$this->local();
|
51 |
+
add_action('wp_loaded', array($this, 'wp_loaded'));
|
52 |
+
//Register Help Output
|
53 |
+
//add_action('add_screen_help_and_options', array($this, 'help'));
|
54 |
+
}
|
55 |
+
function wp_loaded()
|
56 |
+
{
|
57 |
+
//Filter our allowed html tags
|
58 |
+
$this->allowed_html = apply_filters($this->unique_prefix . '_allowed_html', wp_kses_allowed_html('post'));
|
59 |
+
}
|
60 |
+
/**
|
61 |
+
* Returns the internal mtekk_admin_class version
|
62 |
+
*/
|
63 |
+
function get_admin_class_version()
|
64 |
+
{
|
65 |
+
return mtekk_adminKit::version;
|
66 |
+
}
|
67 |
+
/**
|
68 |
+
* Return the URL of the settings page for the plugin
|
69 |
+
*/
|
70 |
+
function admin_url()
|
71 |
+
{
|
72 |
+
return admin_url('options-general.php?page=' . $this->identifier);
|
73 |
+
}
|
74 |
+
/**
|
75 |
+
* A wrapper for nonced_anchor returns a nonced anchor for admin pages
|
76 |
+
*
|
77 |
+
* @param string $mode The nonce "mode", a unique string at the end of the standardized nonce identifier
|
78 |
+
* @param string $title (optional) The text to use in the title portion of the anchor
|
79 |
+
* @param string $text (optional) The text that will be surrounded by the anchor tags
|
80 |
+
* @return string the assembled anchor
|
81 |
+
*/
|
82 |
+
function admin_anchor($mode, $title = '', $text = '')
|
83 |
+
{
|
84 |
+
return $this->nonced_anchor($this->admin_url(), 'admin_' . $mode, 'true', $title, $text);
|
85 |
+
}
|
86 |
+
/**
|
87 |
+
* Returns a properly formed nonced anchor to the specified URI
|
88 |
+
*
|
89 |
+
* @param string $uri The URI that the anchor should be for
|
90 |
+
* @param string $mode The nonce "mode", a unique string at the end of the standardized nonce identifier
|
91 |
+
* @param mixed $value (optional) The value to place in the query string
|
92 |
+
* @param string $title (optional) The text to use in the title portion of the anchor
|
93 |
+
* @param string $text (optional) The text that will be surrounded by the anchor tags
|
94 |
+
* @param string $anchor_extras (optional) This text is placed within the opening anchor tag, good for adding id, classe, rel field
|
95 |
+
* @return string the assembled anchor
|
96 |
+
*/
|
97 |
+
function nonced_anchor($uri, $mode, $value = 'true', $title = '', $text = '', $anchor_extras = '')
|
98 |
+
{
|
99 |
+
//Assemble our url, nonce and all
|
100 |
+
$url = wp_nonce_url(add_query_arg($this->unique_prefix . '_' . $mode, $value, $uri), $this->unique_prefix . '_' . $mode);
|
101 |
+
//Return a valid anchor
|
102 |
+
return ' <a title="' . esc_attr($title) . '" href="' . $url . '" '. $anchor_extras . '>' . esc_html($text) . '</a>';
|
103 |
+
}
|
104 |
+
/**
|
105 |
+
* Abstracts the check_admin_referer so that all the end user has to supply is the mode
|
106 |
+
*
|
107 |
+
* @param string $mode The specific nonce "mode" (see nonced_anchor) that is being checked
|
108 |
+
*/
|
109 |
+
function check_nonce($mode)
|
110 |
+
{
|
111 |
+
check_admin_referer($this->unique_prefix . '_' . $mode);
|
112 |
+
}
|
113 |
+
/**
|
114 |
+
* Makes sure the current user can manage options to proceed
|
115 |
+
*/
|
116 |
+
function security()
|
117 |
+
{
|
118 |
+
//If the user can not manage options we will die on them
|
119 |
+
if(!current_user_can($this->access_level))
|
120 |
+
{
|
121 |
+
wp_die(__('Insufficient privileges to proceed.', $this->identifier));
|
122 |
+
}
|
123 |
+
}
|
124 |
+
function init()
|
125 |
+
{
|
126 |
+
//Admin Options reset hook
|
127 |
+
if(isset($_POST[$this->unique_prefix . '_admin_reset']))
|
128 |
+
{
|
129 |
+
//Run the reset function on init if reset form has been submitted
|
130 |
+
$this->opts_reset();
|
131 |
+
}
|
132 |
+
//Admin Options export hook
|
133 |
+
else if(isset($_POST[$this->unique_prefix . '_admin_export']))
|
134 |
+
{
|
135 |
+
//Run the export function on init if export form has been submitted
|
136 |
+
$this->opts_export();
|
137 |
+
}
|
138 |
+
//Admin Options import hook
|
139 |
+
else if(isset($_FILES[$this->unique_prefix . '_admin_import_file']) && !empty($_FILES[$this->unique_prefix . '_admin_import_file']['name']))
|
140 |
+
{
|
141 |
+
//Run the import function on init if import form has been submitted
|
142 |
+
$this->opts_import();
|
143 |
+
}
|
144 |
+
//Admin Options rollback hook
|
145 |
+
else if(isset($_GET[$this->unique_prefix . '_admin_undo']))
|
146 |
+
{
|
147 |
+
//Run the rollback function on init if undo button has been pressed
|
148 |
+
$this->opts_undo();
|
149 |
+
}
|
150 |
+
//Admin Options upgrade hook
|
151 |
+
else if(isset($_GET[$this->unique_prefix . '_admin_upgrade']))
|
152 |
+
{
|
153 |
+
//Run the upgrade function on init if upgrade button has been pressed
|
154 |
+
$this->opts_upgrade_wrapper();
|
155 |
+
}
|
156 |
+
//Admin Options fix hook
|
157 |
+
else if(isset($_GET[$this->unique_prefix . '_admin_fix']))
|
158 |
+
{
|
159 |
+
//Run the options fix function on init if fix button has been pressed
|
160 |
+
$this->opts_upgrade_wrapper();
|
161 |
+
}
|
162 |
+
//Admin Options update hook
|
163 |
+
else if(isset($_POST[$this->unique_prefix . '_admin_options']))
|
164 |
+
{
|
165 |
+
//Temporarily add update function on init if form has been submitted
|
166 |
+
$this->opts_update();
|
167 |
+
}
|
168 |
+
//Add in the nice "settings" link to the plugins page
|
169 |
+
add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
|
170 |
+
if(defined('SCRIPT_DEBUG') && SCRIPT_DEBUG)
|
171 |
+
{
|
172 |
+
$suffix = '';
|
173 |
+
}
|
174 |
+
else
|
175 |
+
{
|
176 |
+
$suffix = '.min';
|
177 |
+
}
|
178 |
+
//Register JS for more permanently dismissing messages
|
179 |
+
wp_register_script('mtekk_adminkit_messages', plugins_url('/mtekk_adminkit_messages' . $suffix . '.js', dirname(__FILE__) . '/mtekk_adminkit_messages' . $suffix . '.js'), array('jquery'), self::version, true);
|
180 |
+
//Register JS for enable/disable settings groups
|
181 |
+
wp_register_script('mtekk_adminkit_engroups', plugins_url('/mtekk_adminkit_engroups' . $suffix . '.js', dirname(__FILE__) . '/mtekk_adminkit_engroups' . $suffix . '.js'), array('jquery'), self::version, true);
|
182 |
+
//Register JS for tabs
|
183 |
+
wp_register_script('mtekk_adminkit_tabs', plugins_url('/mtekk_adminkit_tabs' . $suffix . '.js', dirname(__FILE__) . '/mtekk_adminkit_tabs' . $suffix . '.js'), array('jquery-ui-tabs'), self::version, true);
|
184 |
+
//Register CSS for tabs
|
185 |
+
wp_register_style('mtekk_adminkit_tabs', plugins_url('/mtekk_adminkit_tabs' . $suffix . '.css', dirname(__FILE__) . '/mtekk_adminkit_tabs' . $suffix . '.css'));
|
186 |
+
//Register options
|
187 |
+
register_setting($this->unique_prefix . '_options', $this->unique_prefix . '_options', '');
|
188 |
+
//Synchronize up our settings with the database as we're done modifying them now
|
189 |
+
$this->opt = $this::parse_args($this->get_option($this->unique_prefix . '_options'), $this->opt);
|
190 |
+
//Run the opts fix filter
|
191 |
+
$this->opts_fix($this->opt);
|
192 |
+
add_action('wp_ajax_mtekk_admin_message_dismiss', array($this, 'dismiss_message'));
|
193 |
+
}
|
194 |
+
/**
|
195 |
+
* Adds the adminpage the menu and the nice little settings link
|
196 |
+
* TODO: make this more generic for easier extension
|
197 |
+
*/
|
198 |
+
function add_page()
|
199 |
+
{
|
200 |
+
//Add the submenu page to "settings" menu
|
201 |
+
$hookname = add_submenu_page('options-general.php', $this->full_name, $this->short_name, $this->access_level, $this->identifier, array($this, 'admin_page'));
|
202 |
+
// check capability of user to manage options (access control)
|
203 |
+
if(current_user_can($this->access_level))
|
204 |
+
{
|
205 |
+
//Register admin_head-$hookname callback
|
206 |
+
add_action('admin_head-' . $hookname, array($this, 'admin_head'));
|
207 |
+
//Register admin_print_styles-$hookname callback
|
208 |
+
add_action('admin_print_styles-' . $hookname, array($this, 'admin_styles'));
|
209 |
+
//Register admin_print_scripts-$hookname callback
|
210 |
+
add_action('admin_print_scripts-' . $hookname, array($this, 'admin_scripts'));
|
211 |
+
//Register Help Output
|
212 |
+
add_action('load-' . $hookname, array($this, 'help'));
|
213 |
+
}
|
214 |
+
}
|
215 |
+
/**
|
216 |
+
* Initilizes localization textdomain for translations (if applicable)
|
217 |
+
*
|
218 |
+
* Will conditionally load the textdomain for translations. This is here for
|
219 |
+
* plugins that span multiple files and have localization in more than one file
|
220 |
+
*
|
221 |
+
* @return void
|
222 |
+
*/
|
223 |
+
function local()
|
224 |
+
{
|
225 |
+
global $l10n;
|
226 |
+
// the global and the check might become obsolete in
|
227 |
+
// further wordpress versions
|
228 |
+
// @see https://core.trac.wordpress.org/ticket/10527
|
229 |
+
if(!isset($l10n[$this->identifier]))
|
230 |
+
{
|
231 |
+
load_plugin_textdomain($this->identifier, false, $this->identifier . '/languages');
|
232 |
+
}
|
233 |
+
}
|
234 |
+
/**
|
235 |
+
* Places in a link to the settings page in the plugins listing entry
|
236 |
+
*
|
237 |
+
* @param array $links An array of links that are output in the listing
|
238 |
+
* @param string $file The file that is currently in processing
|
239 |
+
* @return array Array of links that are output in the listing.
|
240 |
+
*/
|
241 |
+
function filter_plugin_actions($links, $file)
|
242 |
+
{
|
243 |
+
//Make sure we are adding only for the current plugin
|
244 |
+
if($file == $this->plugin_basename)
|
245 |
+
{
|
246 |
+
//Add our link to the end of the array to better integrate into the WP 2.8 plugins page
|
247 |
+
$links[] = '<a href="' . $this->admin_url() . '">' . esc_html__('Settings') . '</a>';
|
248 |
+
}
|
249 |
+
return $links;
|
250 |
+
}
|
251 |
+
/**
|
252 |
+
* Checks to see if the plugin has been fully installed
|
253 |
+
*
|
254 |
+
* @return bool whether or not the plugin has been installed
|
255 |
+
*/
|
256 |
+
function is_installed()
|
257 |
+
{
|
258 |
+
|
259 |
+
}
|
260 |
+
/**
|
261 |
+
* This sets up and upgrades the database settings, runs on every activation
|
262 |
+
*/
|
263 |
+
function install()
|
264 |
+
{
|
265 |
+
//Call our little security function
|
266 |
+
$this->security();
|
267 |
+
//Try retrieving the options from the database
|
268 |
+
$opts = $this->get_option($this->unique_prefix . '_options');
|
269 |
+
//If there are no settings, copy over the default settings
|
270 |
+
if(!is_array($opts))
|
271 |
+
{
|
272 |
+
//Grab defaults from the object
|
273 |
+
$opts = $this->opt;
|
274 |
+
//Add the options
|
275 |
+
$this->add_option($this->unique_prefix . '_options', $opts);
|
276 |
+
$this->add_option($this->unique_prefix . '_options_bk', $opts, '', 'no');
|
277 |
+
//Add the version, no need to autoload the db version
|
278 |
+
$this->add_option($this->unique_prefix . '_version', $this::version, '', 'no');
|
279 |
+
}
|
280 |
+
else
|
281 |
+
{
|
282 |
+
//Retrieve the database version
|
283 |
+
$db_version = $this->get_option($this->unique_prefix . '_version');
|
284 |
+
if($this::version !== $db_version)
|
285 |
+
{
|
286 |
+
//Run the settings update script
|
287 |
+
$this->opts_upgrade($opts, $db_version);
|
288 |
+
//Always have to update the version
|
289 |
+
$this->update_option($this->unique_prefix . '_version', $this::version);
|
290 |
+
//Store the options
|
291 |
+
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
292 |
+
}
|
293 |
+
}
|
294 |
+
}
|
295 |
+
/**
|
296 |
+
* This removes database settings upon deletion of the plugin from WordPress
|
297 |
+
*/
|
298 |
+
function uninstall()
|
299 |
+
{
|
300 |
+
//Remove the option array setting
|
301 |
+
$this->delete_option($this->unique_prefix . '_options');
|
302 |
+
//Remove the option backup array setting
|
303 |
+
$this->delete_option($this->unique_prefix . '_options_bk');
|
304 |
+
//Remove the version setting
|
305 |
+
$this->delete_option($this->unique_prefix . '_version');
|
306 |
+
}
|
307 |
+
/**
|
308 |
+
* Compares the supplided version with the internal version, places an upgrade warning if there is a missmatch
|
309 |
+
* TODO: change this to being auto called in admin_init action
|
310 |
+
*/
|
311 |
+
function version_check($version)
|
312 |
+
{
|
313 |
+
//If we didn't get a version, setup
|
314 |
+
if($version === false)
|
315 |
+
{
|
316 |
+
//Add the version, no need to autoload the db version
|
317 |
+
$this->add_option($this->unique_prefix . '_version', $this::version, '', 'no');
|
318 |
+
}
|
319 |
+
//Do a quick version check
|
320 |
+
if($version && version_compare($version, $this::version, '<') && is_array($this->opt))
|
321 |
+
{
|
322 |
+
//Throw an error since the DB version is out of date
|
323 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Your settings are for an older version of this plugin and need to be migrated.', $this->identifier)
|
324 |
+
. $this->admin_anchor('upgrade', __('Migrate the settings now.', $this->identifier), __('Migrate now.', $this->identifier)), 'warning');
|
325 |
+
//Output any messages that there may be
|
326 |
+
$this->messages();
|
327 |
+
return false;
|
328 |
+
}
|
329 |
+
//Do a quick version check
|
330 |
+
else if($version && version_compare($version, $this::version, '>') && is_array($this->opt))
|
331 |
+
{
|
332 |
+
//Let the user know that their settings are for a newer version
|
333 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Your settings are for a newer version of this plugin.', $this->identifier)
|
334 |
+
. $this->admin_anchor('upgrade', __('Migrate the settings now.', $this->identifier), __('Attempt back migration now.', $this->identifier)), 'warning');
|
335 |
+
//Output any messages that there may be
|
336 |
+
$this->messages();
|
337 |
+
return true;
|
338 |
+
}
|
339 |
+
else if(!is_array($this->opt))
|
340 |
+
{
|
341 |
+
//Throw an error since it appears the options were never registered
|
342 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Your plugin install is incomplete.', $this->identifier)
|
343 |
+
. $this->admin_anchor('upgrade', __('Load default settings now.', $this->identifier), __('Complete now.', $this->identifier)), 'error');
|
344 |
+
//Output any messages that there may be
|
345 |
+
$this->messages();
|
346 |
+
return false;
|
347 |
+
}
|
348 |
+
else if(!$this->opts_validate($this->opt))
|
349 |
+
{
|
350 |
+
//Throw an error since it appears the options contain invalid data
|
351 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('One or more of your plugin settings are invalid.', $this->identifier)
|
352 |
+
. $this->admin_anchor('fix', __('Attempt to fix settings now.', $this->identifier), __('Fix now.', $this->identifier)), 'error');
|
353 |
+
//Output any messages that there may be
|
354 |
+
$this->messages();
|
355 |
+
return false;
|
356 |
+
}
|
357 |
+
return true;
|
358 |
+
}
|
359 |
+
/**
|
360 |
+
* A prototype function. End user should override if they need this feature.
|
361 |
+
*/
|
362 |
+
function opts_validate(&$opts)
|
363 |
+
{
|
364 |
+
return true;
|
365 |
+
}
|
366 |
+
/**
|
367 |
+
* A prototype function. End user should override if they need this feature.
|
368 |
+
*
|
369 |
+
* @param array $opts
|
370 |
+
*/
|
371 |
+
function opts_fix(&$opts)
|
372 |
+
{
|
373 |
+
}
|
374 |
+
/**
|
375 |
+
* Synchronizes the backup options entry with the current options entry
|
376 |
+
*/
|
377 |
+
function opts_backup()
|
378 |
+
{
|
379 |
+
//Set the backup options in the DB to the current options
|
380 |
+
$this->update_option($this->unique_prefix . '_options_bk', $this->get_option($this->unique_prefix . '_options'));
|
381 |
+
}
|
382 |
+
/**
|
383 |
+
* Runs recursivly through the opts array, sanitizing and merging in updates from the $input array
|
384 |
+
*
|
385 |
+
* @param array $opts good, clean array
|
386 |
+
* @param array $input unsanitzed input array, not trusted at all
|
387 |
+
* @todo This function should probably get a filter thrown within it to be more extensible
|
388 |
+
*/
|
389 |
+
protected function opts_update_loop(&$opts, $input)
|
390 |
+
{
|
391 |
+
//Loop through all of the existing options (avoids random setting injection)
|
392 |
+
foreach($opts as $option => $value)
|
393 |
+
{
|
394 |
+
//If we have an array, dive into another recursive loop
|
395 |
+
if(isset($input[$option]) && is_array($value))
|
396 |
+
{
|
397 |
+
$this->opts_update_loop($opts[$option], $input[$option]);
|
398 |
+
}
|
399 |
+
//We must check for unset settings, but booleans are ok to be unset
|
400 |
+
else if(isset($input[$option]) || $option[0] == 'b')
|
401 |
+
{
|
402 |
+
switch($option[0])
|
403 |
+
{
|
404 |
+
//Handle the boolean options
|
405 |
+
case 'b':
|
406 |
+
$opts[$option] = isset($input[$option]);
|
407 |
+
break;
|
408 |
+
//Handle the integer options
|
409 |
+
case 'i':
|
410 |
+
$opts[$option] = (int) $input[$option];
|
411 |
+
break;
|
412 |
+
//Handle the absolute integer options
|
413 |
+
case 'a':
|
414 |
+
$opts[$option] = (int) abs($input[$option]);
|
415 |
+
break;
|
416 |
+
//Handle the floating point options
|
417 |
+
case 'f':
|
418 |
+
$opts[$option] = (float) $input[$option];
|
419 |
+
break;
|
420 |
+
//Handle the HTML options
|
421 |
+
case 'h':
|
422 |
+
$opts[$option] = wp_kses(stripslashes($input[$option]), $this->allowed_html);
|
423 |
+
break;
|
424 |
+
//Handle the HTML options that must not be null
|
425 |
+
case 'H':
|
426 |
+
if(isset($input[$option]))
|
427 |
+
{
|
428 |
+
$opts[$option] = wp_kses(stripslashes($input[$option]), $this->allowed_html);
|
429 |
+
}
|
430 |
+
break;
|
431 |
+
//Handle the text options that must not be null
|
432 |
+
case 'S':
|
433 |
+
if(isset($input[$option]))
|
434 |
+
{
|
435 |
+
$opts[$option] = esc_html($input[$option]);
|
436 |
+
}
|
437 |
+
break;
|
438 |
+
//Deal with strings that can be null
|
439 |
+
case 's':
|
440 |
+
$opts[$option] = esc_html($input[$option]);
|
441 |
+
break;
|
442 |
+
//Deal with enumerated types
|
443 |
+
case 'E':
|
444 |
+
$opts[$option] = $this->opts_sanitize_enum($input[$option], $option);
|
445 |
+
break;
|
446 |
+
//By default we have nothing to do, allows for internal settings
|
447 |
+
default:
|
448 |
+
break;
|
449 |
+
}
|
450 |
+
}
|
451 |
+
}
|
452 |
+
}
|
453 |
+
/**
|
454 |
+
* Simple sanitization function for enumerated types, end users should overload this
|
455 |
+
* with something more usefull
|
456 |
+
*
|
457 |
+
* @param string $value The input value from the form
|
458 |
+
* @param string $option The option name
|
459 |
+
* @return string The sanitized enumerated string
|
460 |
+
*/
|
461 |
+
private function opts_sanitize_enum($value, $option)
|
462 |
+
{
|
463 |
+
return esc_html($value);
|
464 |
+
}
|
465 |
+
/**
|
466 |
+
* A better version of parse_args, will recrusivly follow arrays
|
467 |
+
*
|
468 |
+
* @param mixed $args The arguments to be parsed
|
469 |
+
* @param mixed $defaults (optional) The default values to validate against
|
470 |
+
* @return mixed
|
471 |
+
*/
|
472 |
+
static function parse_args($args, $defaults = '')
|
473 |
+
{
|
474 |
+
if(is_object($args))
|
475 |
+
{
|
476 |
+
$r = get_object_vars($args);
|
477 |
+
}
|
478 |
+
else if(is_array($args))
|
479 |
+
{
|
480 |
+
$r =& $args;
|
481 |
+
}
|
482 |
+
else
|
483 |
+
{
|
484 |
+
wp_parse_str($args, $r);
|
485 |
+
}
|
486 |
+
if(is_array($defaults))
|
487 |
+
{
|
488 |
+
return mtekk_adminKit::array_merge_recursive($defaults, $r);
|
489 |
+
}
|
490 |
+
return $r;
|
491 |
+
}
|
492 |
+
/**
|
493 |
+
* An alternate version of array_merge_recursive, less flexible
|
494 |
+
* still recursive, ~2x faster than the more flexible version
|
495 |
+
*
|
496 |
+
* @param array $arg1 first array
|
497 |
+
* @param array $arg2 second array to merge into $arg1
|
498 |
+
* @return array
|
499 |
+
*/
|
500 |
+
static function array_merge_recursive($arg1, $arg2)
|
501 |
+
{
|
502 |
+
foreach($arg2 as $key => $value)
|
503 |
+
{
|
504 |
+
if(array_key_exists($key, $arg1) && is_array($value))
|
505 |
+
{
|
506 |
+
$arg1[$key] = mtekk_adminKit::array_merge_recursive($arg1[$key], $value);
|
507 |
+
}
|
508 |
+
else
|
509 |
+
{
|
510 |
+
$arg1[$key] = $value;
|
511 |
+
}
|
512 |
+
}
|
513 |
+
return $arg1;
|
514 |
+
}
|
515 |
+
/**
|
516 |
+
* An action that fires just before the options backup, use to add in dynamically detected options
|
517 |
+
*
|
518 |
+
* @param array $opts the options array, passed in by reference
|
519 |
+
* @return null
|
520 |
+
*/
|
521 |
+
function opts_update_prebk(&$opts)
|
522 |
+
{
|
523 |
+
//Just a prototype function
|
524 |
+
}
|
525 |
+
/**
|
526 |
+
* Updates the database settings from the webform
|
527 |
+
*/
|
528 |
+
function opts_update()
|
529 |
+
{
|
530 |
+
//Do some security related thigns as we are not using the normal WP settings API
|
531 |
+
$this->security();
|
532 |
+
//Do a nonce check, prevent malicious link/form problems
|
533 |
+
check_admin_referer($this->unique_prefix . '_options-options');
|
534 |
+
//Update local options from database
|
535 |
+
$this->opt = $this::parse_args($this->get_option($this->unique_prefix . '_options'), $this->opt);
|
536 |
+
$this->opts_update_prebk($this->opt);
|
537 |
+
//Update our backup options
|
538 |
+
$this->update_option($this->unique_prefix . '_options_bk', $this->opt);
|
539 |
+
$opt_prev = $this->opt;
|
540 |
+
//Grab our incomming array (the data is dirty)
|
541 |
+
$input = $_POST[$this->unique_prefix . '_options'];
|
542 |
+
//Run the update loop
|
543 |
+
$this->opts_update_loop($this->opt, $input);
|
544 |
+
//Commit the option changes
|
545 |
+
$updated = $this->update_option($this->unique_prefix . '_options', $this->opt);
|
546 |
+
//Check if known settings match attempted save
|
547 |
+
if($updated && count(array_diff_key($input, $this->opt)) == 0)
|
548 |
+
{
|
549 |
+
//Let the user know everything went ok
|
550 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully saved.', $this->identifier)
|
551 |
+
. $this->admin_anchor('undo', __('Undo the options save.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
552 |
+
}
|
553 |
+
else if(!$updated && count(array_diff_key($opt_prev, $this->opt)) == 0)
|
554 |
+
{
|
555 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings did not change, nothing to save.', $this->identifier), 'info');
|
556 |
+
}
|
557 |
+
else if(!$updated)
|
558 |
+
{
|
559 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings were not saved.', $this->identifier), 'error');
|
560 |
+
}
|
561 |
+
else
|
562 |
+
{
|
563 |
+
//Let the user know the following were not saved
|
564 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Some settings were not saved.', $this->identifier)
|
565 |
+
. $this->admin_anchor('undo', __('Undo the options save.', $this->identifier), __('Undo', $this->identifier)), 'warning');
|
566 |
+
$temp = esc_html__('The following settings were not saved:', $this->identifier);
|
567 |
+
foreach(array_diff_key($input, $this->opt) as $setting => $value)
|
568 |
+
{
|
569 |
+
$temp .= '<br />' . $setting;
|
570 |
+
}
|
571 |
+
$this->messages[] = new mtekk_adminKit_message($temp . '<br />' . sprintf(esc_html__('Please include this message in your %sbug report%s.', $this->identifier), '<a title="' . sprintf(esc_attr__('Go to the %s support forum.', $this->identifier), $this->short_name) . '" href="' . $this->support_url . '">', '</a>'), 'info');
|
572 |
+
}
|
573 |
+
add_action('admin_notices', array($this, 'messages'));
|
574 |
+
}
|
575 |
+
/**
|
576 |
+
* Exports a XML options document
|
577 |
+
*/
|
578 |
+
function opts_export()
|
579 |
+
{
|
580 |
+
//Do a nonce check, prevent malicious link/form problems
|
581 |
+
check_admin_referer($this->unique_prefix . '_admin_import_export');
|
582 |
+
//Update our internal settings
|
583 |
+
$this->opt = $this->get_option($this->unique_prefix . '_options');
|
584 |
+
//Create a DOM document
|
585 |
+
$dom = new DOMDocument('1.0', 'UTF-8');
|
586 |
+
//Adds in newlines and tabs to the output
|
587 |
+
$dom->formatOutput = true;
|
588 |
+
//We're not using a DTD therefore we need to specify it as a standalone document
|
589 |
+
$dom->xmlStandalone = true;
|
590 |
+
//Add an element called options
|
591 |
+
$node = $dom->createElement('options');
|
592 |
+
$parnode = $dom->appendChild($node);
|
593 |
+
//Add a child element named plugin
|
594 |
+
$node = $dom->createElement('plugin');
|
595 |
+
$plugnode = $parnode->appendChild($node);
|
596 |
+
//Add some attributes that identify the plugin and version for the options export
|
597 |
+
$plugnode->setAttribute('name', $this->short_name);
|
598 |
+
$plugnode->setAttribute('version', $this::version);
|
599 |
+
//Change our headder to text/xml for direct save
|
600 |
+
header('Cache-Control: public');
|
601 |
+
//The next two will cause good browsers to download instead of displaying the file
|
602 |
+
header('Content-Description: File Transfer');
|
603 |
+
header('Content-disposition: attachemnt; filename=' . $this->unique_prefix . '_settings.xml');
|
604 |
+
header('Content-Type: text/xml');
|
605 |
+
//Loop through the options array
|
606 |
+
foreach($this->opt as $key=>$option)
|
607 |
+
{
|
608 |
+
//Add a option tag under the options tag, store the option value
|
609 |
+
$node = $dom->createElement('option', htmlentities($option, ENT_COMPAT, 'UTF-8'));
|
610 |
+
$newnode = $plugnode->appendChild($node);
|
611 |
+
//Change the tag's name to that of the stored option
|
612 |
+
$newnode->setAttribute('name', $key);
|
613 |
+
}
|
614 |
+
//Prepair the XML for output
|
615 |
+
$output = $dom->saveXML();
|
616 |
+
//Let the browser know how long the file is
|
617 |
+
header('Content-Length: ' . strlen($output)); // binary length
|
618 |
+
//Output the file
|
619 |
+
echo $output;
|
620 |
+
//Prevent WordPress from continuing on
|
621 |
+
die();
|
622 |
+
}
|
623 |
+
/**
|
624 |
+
* Imports a XML options document
|
625 |
+
*/
|
626 |
+
function opts_import()
|
627 |
+
{
|
628 |
+
//Our quick and dirty error supressor
|
629 |
+
function error($errno, $errstr, $eerfile, $errline)
|
630 |
+
{
|
631 |
+
return true;
|
632 |
+
}
|
633 |
+
//Do a nonce check, prevent malicious link/form problems
|
634 |
+
check_admin_referer($this->unique_prefix . '_admin_import_export');
|
635 |
+
//Set the backup options in the DB to the current options
|
636 |
+
$this->opts_backup();
|
637 |
+
//Create a DOM document
|
638 |
+
$dom = new DOMDocument('1.0', 'UTF-8');
|
639 |
+
//We want to catch errors ourselves
|
640 |
+
set_error_handler('error');
|
641 |
+
//Load the user uploaded file, handle failure gracefully
|
642 |
+
if($dom->load($_FILES[$this->unique_prefix . '_admin_import_file']['tmp_name']))
|
643 |
+
{
|
644 |
+
$opts_temp = array();
|
645 |
+
$version = '';
|
646 |
+
//Have to use an xpath query otherwise we run into problems
|
647 |
+
$xpath = new DOMXPath($dom);
|
648 |
+
$option_sets = $xpath->query('plugin');
|
649 |
+
//Loop through all of the xpath query results
|
650 |
+
foreach($option_sets as $options)
|
651 |
+
{
|
652 |
+
//We only want to import options for only this plugin
|
653 |
+
if($options->getAttribute('name') === $this->short_name)
|
654 |
+
{
|
655 |
+
//Grab the file version
|
656 |
+
$version = $options->getAttribute('version');
|
657 |
+
//Loop around all of the options
|
658 |
+
foreach($options->getelementsByTagName('option') as $child)
|
659 |
+
{
|
660 |
+
//Place the option into the option array, DOMDocument decodes html entities for us
|
661 |
+
$opts_temp[$child->getAttribute('name')] = $child->nodeValue;
|
662 |
+
}
|
663 |
+
}
|
664 |
+
}
|
665 |
+
//Make sure we safely import and upgrade settings if needed
|
666 |
+
$this->opts_upgrade($opts_temp, $version);
|
667 |
+
//Commit the loaded options to the database
|
668 |
+
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
669 |
+
//Everything was successful, let the user know
|
670 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully imported from the uploaded file.', $this->identifier)
|
671 |
+
. $this->admin_anchor('undo', __('Undo the options import.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
672 |
+
}
|
673 |
+
else
|
674 |
+
{
|
675 |
+
//Throw an error since we could not load the file for various reasons
|
676 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Importing settings from file failed.', $this->identifier), 'error');
|
677 |
+
}
|
678 |
+
//Reset to the default error handler after we're done
|
679 |
+
restore_error_handler();
|
680 |
+
//Output any messages that there may be
|
681 |
+
add_action('admin_notices', array($this, 'messages'));
|
682 |
+
}
|
683 |
+
/**
|
684 |
+
* Resets the database settings array to the default set in opt
|
685 |
+
*/
|
686 |
+
function opts_reset()
|
687 |
+
{
|
688 |
+
//Do a nonce check, prevent malicious link/form problems
|
689 |
+
check_admin_referer($this->unique_prefix . '_admin_import_export');
|
690 |
+
//Set the backup options in the DB to the current options
|
691 |
+
$this->opts_backup();
|
692 |
+
//Load in the hard coded default option values
|
693 |
+
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
694 |
+
//Reset successful, let the user know
|
695 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully reset to the default values.', $this->identifier)
|
696 |
+
. $this->admin_anchor('undo', __('Undo the options reset.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
697 |
+
add_action('admin_notices', array($this, 'messages'));
|
698 |
+
}
|
699 |
+
/**
|
700 |
+
* Undos the last settings save/reset/import
|
701 |
+
*/
|
702 |
+
function opts_undo()
|
703 |
+
{
|
704 |
+
//Do a nonce check, prevent malicious link/form problems
|
705 |
+
check_admin_referer($this->unique_prefix . '_admin_undo');
|
706 |
+
//Set the options array to the current options
|
707 |
+
$opt = $this->get_option($this->unique_prefix . '_options');
|
708 |
+
//Set the options in the DB to the backup options
|
709 |
+
$this->update_option($this->unique_prefix . '_options', $this->get_option($this->unique_prefix . '_options_bk'));
|
710 |
+
//Set the backup options to the undone options
|
711 |
+
$this->update_option($this->unique_prefix . '_options_bk', $opt);
|
712 |
+
//Send the success/undo message
|
713 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully undid the last operation.', $this->identifier)
|
714 |
+
. $this->admin_anchor('undo', __('Undo the last undo operation.', $this->identifier), __('Undo', $this->identifier)), 'success');
|
715 |
+
add_action('admin_notices', array($this, 'messages'));
|
716 |
+
}
|
717 |
+
/**
|
718 |
+
* Upgrades input options array, sets to $this->opt, designed to be overwritten
|
719 |
+
*
|
720 |
+
* @param array $opts
|
721 |
+
* @param string $version the version of the passed in options
|
722 |
+
*/
|
723 |
+
function opts_upgrade($opts, $version)
|
724 |
+
{
|
725 |
+
//We don't support using newer versioned option files in older releases
|
726 |
+
if(version_compare($this::version, $version, '>='))
|
727 |
+
{
|
728 |
+
$this->opt = $opts;
|
729 |
+
}
|
730 |
+
}
|
731 |
+
/**
|
732 |
+
* Forces a database settings upgrade
|
733 |
+
*/
|
734 |
+
function opts_upgrade_wrapper()
|
735 |
+
{
|
736 |
+
//Do a nonce check, prevent malicious link/form problems
|
737 |
+
check_admin_referer($this->unique_prefix . '_admin_upgrade');
|
738 |
+
//Grab the database options
|
739 |
+
$opts = $this->get_option($this->unique_prefix . '_options');
|
740 |
+
if(is_array($opts))
|
741 |
+
{
|
742 |
+
//Feed the just read options into the upgrade function
|
743 |
+
$this->opts_upgrade($opts, $this->get_option($this->unique_prefix . '_version'));
|
744 |
+
//Always have to update the version
|
745 |
+
$this->update_option($this->unique_prefix . '_version', $this::version);
|
746 |
+
//Store the options
|
747 |
+
$this->update_option($this->unique_prefix . '_options', $this->opt);
|
748 |
+
//Send the success message
|
749 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Settings successfully migrated.', $this->identifier), 'success');
|
750 |
+
}
|
751 |
+
else
|
752 |
+
{
|
753 |
+
//Run the install script
|
754 |
+
$this->install();
|
755 |
+
//Send the success message
|
756 |
+
$this->messages[] = new mtekk_adminKit_message(esc_html__('Default settings successfully installed.', $this->identifier), 'success');
|
757 |
+
}
|
758 |
+
add_action('admin_notices', array($this, 'messages'));
|
759 |
+
}
|
760 |
+
/**
|
761 |
+
* help action hook function, meant to be overridden
|
762 |
+
*
|
763 |
+
* @return string
|
764 |
+
*
|
765 |
+
*/
|
766 |
+
function help()
|
767 |
+
{
|
768 |
+
$screen = get_current_screen();
|
769 |
+
//Add contextual help on current screen
|
770 |
+
if($screen->id == 'settings_page_' . $this->identifier)
|
771 |
+
{
|
772 |
+
|
773 |
+
}
|
774 |
+
}
|
775 |
+
function dismiss_message()
|
776 |
+
{
|
777 |
+
//Grab the submitted UID
|
778 |
+
$uid = esc_attr($_POST['uid']);
|
779 |
+
//Create a dummy message, with the discovered UID
|
780 |
+
$message = new mtekk_adminKit_message('', '', true, $uid);
|
781 |
+
//Dismiss the message
|
782 |
+
$message->dismiss();
|
783 |
+
wp_die();
|
784 |
+
}
|
785 |
+
/**
|
786 |
+
* Prints to screen all of the messages stored in the message member variable
|
787 |
+
*/
|
788 |
+
function messages()
|
789 |
+
{
|
790 |
+
foreach($this->messages as $message)
|
791 |
+
{
|
792 |
+
$message->render();
|
793 |
+
}
|
794 |
+
//Old deprecated messages
|
795 |
+
if(count($this->message))
|
796 |
+
{
|
797 |
+
_deprecated_function( __FUNCTION__, '2.0.0', __('adminKit::message is deprecated, use new adminkit_messages instead.', $this->identifier) );
|
798 |
+
//Loop through our message classes
|
799 |
+
foreach($this->message as $key => $class)
|
800 |
+
{
|
801 |
+
//Loop through the messages in the current class
|
802 |
+
foreach($class as $message)
|
803 |
+
{
|
804 |
+
printf('<div class="%s"><p>%s</p></div>', esc_attr($key), $message);
|
805 |
+
}
|
806 |
+
}
|
807 |
+
$this->message = array();
|
808 |
+
}
|
809 |
+
$this->messages = array();
|
810 |
+
}
|
811 |
+
/**
|
812 |
+
* Function prototype to prevent errors
|
813 |
+
*/
|
814 |
+
function admin_styles()
|
815 |
+
{
|
816 |
+
|
817 |
+
}
|
818 |
+
/**
|
819 |
+
* Function prototype to prevent errors
|
820 |
+
*/
|
821 |
+
function admin_scripts()
|
822 |
+
{
|
823 |
+
|
824 |
+
}
|
825 |
+
/**
|
826 |
+
* Function prototype to prevent errors
|
827 |
+
*/
|
828 |
+
function admin_head()
|
829 |
+
{
|
830 |
+
|
831 |
+
}
|
832 |
+
/**
|
833 |
+
* Function prototype to prevent errors
|
834 |
+
*/
|
835 |
+
function admin_page()
|
836 |
+
{
|
837 |
+
|
838 |
+
}
|
839 |
+
/**
|
840 |
+
* Function prototype to prevent errors
|
841 |
+
*/
|
842 |
+
protected function _get_help_text()
|
843 |
+
{
|
844 |
+
|
845 |
+
}
|
846 |
+
/**
|
847 |
+
* Returns a valid xHTML element ID
|
848 |
+
*
|
849 |
+
* @param object $option
|
850 |
+
*/
|
851 |
+
static public function get_valid_id($option)
|
852 |
+
{
|
853 |
+
if(is_numeric($option[0]))
|
854 |
+
{
|
855 |
+
return 'p' . $option;
|
856 |
+
}
|
857 |
+
else
|
858 |
+
{
|
859 |
+
return $option;
|
860 |
+
}
|
861 |
+
}
|
862 |
+
function import_form()
|
863 |
+
{
|
864 |
+
$form = '<div id="mtekk_admin_import_export_relocate">';
|
865 |
+
$form .= sprintf('<form action="options-general.php?page=%s" method="post" enctype="multipart/form-data" id="%s_admin_upload">', esc_attr($this->identifier), esc_attr($this->unique_prefix));
|
866 |
+
$form .= wp_nonce_field($this->unique_prefix . '_admin_import_export', '_wpnonce', true, false);
|
867 |
+
$form .= sprintf('<fieldset id="import_export" class="%s_options">', esc_attr($this->unique_prefix));
|
868 |
+
$form .= '<p>' . esc_html__('Import settings from a XML file, export the current settings to a XML file, or reset to the default settings.', $this->identifier) . '</p>';
|
869 |
+
$form .= '<table class="form-table"><tr valign="top"><th scope="row">';
|
870 |
+
$form .= sprintf('<label for="%s_admin_import_file">', esc_attr($this->unique_prefix));
|
871 |
+
$form .= esc_html__('Settings File', $this->identifier);
|
872 |
+
$form .= '</label></th><td>';
|
873 |
+
$form .= sprintf('<input type="file" name="%1$s_admin_import_file" id="%1$s_admin_import_file" size="32" /><p class="description">', esc_attr($this->unique_prefix));
|
874 |
+
$form .= esc_html__('Select a XML settings file to upload and import settings from.', 'breadcrumb_navxt');
|
875 |
+
$form .= '</p></td></tr></table><p class="submit">';
|
876 |
+
$form .= sprintf('<input type="submit" class="button" name="%1$s_admin_import" value="%2$s"/>', $this->unique_prefix, esc_attr__('Import', $this->identifier));
|
877 |
+
$form .= sprintf('<input type="submit" class="button" name="%1$s_admin_export" value="%2$s"/>', $this->unique_prefix, esc_attr__('Export', $this->identifier));
|
878 |
+
$form .= sprintf('<input type="submit" class="button" name="%1$s_admin_reset" value="%2$s"/>', $this->unique_prefix, esc_attr__('Reset', $this->identifier));
|
879 |
+
$form .= '</p></fieldset></form></div>';
|
880 |
+
return $form;
|
881 |
+
}
|
882 |
+
/**
|
883 |
+
* This will output a well formed hidden option
|
884 |
+
*
|
885 |
+
* @param string $option
|
886 |
+
*/
|
887 |
+
function input_hidden($option)
|
888 |
+
{
|
889 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
890 |
+
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
891 |
+
printf('<input type="hidden" name="%1$s" id="%2$s" value="%3$s" />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]));
|
892 |
+
}
|
893 |
+
/**
|
894 |
+
* This will output a well formed option label
|
895 |
+
*
|
896 |
+
* @param string $opt_id
|
897 |
+
* @param string $label
|
898 |
+
*/
|
899 |
+
function label($opt_id, $label)
|
900 |
+
{
|
901 |
+
printf('<label for="%1$s">%2$s</label>', esc_attr($opt_id), $label);
|
902 |
+
}
|
903 |
+
/**
|
904 |
+
* This will output a well formed table row for a text input
|
905 |
+
*
|
906 |
+
* @param string $label
|
907 |
+
* @param string $option
|
908 |
+
* @param string $class (optional)
|
909 |
+
* @param bool $disable (optional)
|
910 |
+
* @param string $description (optional)
|
911 |
+
*/
|
912 |
+
function input_text($label, $option, $class = 'regular-text', $disable = false, $description = '')
|
913 |
+
{
|
914 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
915 |
+
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
916 |
+
if($disable)
|
917 |
+
{
|
918 |
+
$this->input_hidden($option);
|
919 |
+
$class .= ' disabled';
|
920 |
+
}?>
|
921 |
+
<tr valign="top">
|
922 |
+
<th scope="row">
|
923 |
+
<?php $this->label($opt_id, $label);?>
|
924 |
+
</th>
|
925 |
+
<td>
|
926 |
+
<?php printf('<input type="text" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false));?>
|
927 |
+
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
928 |
+
</td>
|
929 |
+
</tr>
|
930 |
+
<?php
|
931 |
+
}
|
932 |
+
/**
|
933 |
+
* This will output a well formed table row for a HTML5 number input
|
934 |
+
*
|
935 |
+
* @param string $label
|
936 |
+
* @param string $option
|
937 |
+
* @param string $class (optional)
|
938 |
+
* @param bool $disable (optional)
|
939 |
+
* @param string $description (optional)
|
940 |
+
* @param int|string $min (optional)
|
941 |
+
* @param int|string $max (optional)
|
942 |
+
* @param int|string $step (optional)
|
943 |
+
*/
|
944 |
+
function input_number($label, $option, $class = 'small-text', $disable = false, $description = '', $min = '', $max = '', $step = '')
|
945 |
+
{
|
946 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
947 |
+
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
948 |
+
$extras = '';
|
949 |
+
if($min !== '')
|
950 |
+
{
|
951 |
+
$extras .= 'min="' . esc_attr($min) . '" ';
|
952 |
+
}
|
953 |
+
if($max !== '')
|
954 |
+
{
|
955 |
+
$extras .= 'max="' . esc_attr($max) . '" ';
|
956 |
+
}
|
957 |
+
if($step !== '')
|
958 |
+
{
|
959 |
+
$extras .= 'step="' . esc_attr($step) . '" ';
|
960 |
+
}
|
961 |
+
if($disable)
|
962 |
+
{
|
963 |
+
$this->input_hidden($option);
|
964 |
+
$class .= ' disabled';
|
965 |
+
}?>
|
966 |
+
<tr valign="top">
|
967 |
+
<th scope="row">
|
968 |
+
<?php $this->label($opt_id, $label);?>
|
969 |
+
</th>
|
970 |
+
<td>
|
971 |
+
<?php printf('<input type="number" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %6$s%5$s/><br />', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false), $extras);?>
|
972 |
+
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
973 |
+
</td>
|
974 |
+
</tr>
|
975 |
+
<?php
|
976 |
+
}
|
977 |
+
/**
|
978 |
+
* This will output a well formed textbox
|
979 |
+
*
|
980 |
+
* @param string $label
|
981 |
+
* @param string $option
|
982 |
+
* @param string $rows (optional)
|
983 |
+
* @param bool $disable (optional)
|
984 |
+
* @param string $description (optional)
|
985 |
+
*/
|
986 |
+
function textbox($label, $option, $height = '3', $disable = false, $description = '', $class = '')
|
987 |
+
{
|
988 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
989 |
+
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
990 |
+
$class .= ' large-text';
|
991 |
+
if($disable)
|
992 |
+
{
|
993 |
+
$this->input_hidden($option);
|
994 |
+
$class .= ' disabled';
|
995 |
+
}?>
|
996 |
+
<tr valign="top">
|
997 |
+
<th scope="row">
|
998 |
+
<?php $this->label($opt_id, $label);?>
|
999 |
+
</th>
|
1000 |
+
<td>
|
1001 |
+
<?php printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($this->opt[$option]), esc_attr($class), disabled($disable, true, false), esc_attr($height));?>
|
1002 |
+
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1003 |
+
</td>
|
1004 |
+
</tr>
|
1005 |
+
<?php
|
1006 |
+
}
|
1007 |
+
/**
|
1008 |
+
* This will output a well formed tiny mce ready textbox
|
1009 |
+
*
|
1010 |
+
* @param string $label
|
1011 |
+
* @param string $option
|
1012 |
+
* @param string $rows (optional)
|
1013 |
+
* @param bool $disable (optional)
|
1014 |
+
* @param string $description (optional)
|
1015 |
+
*/
|
1016 |
+
function tinymce($label, $option, $height = '3', $disable = false, $description = '')
|
1017 |
+
{
|
1018 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1019 |
+
$class = 'mtekk_mce';
|
1020 |
+
if($disable)
|
1021 |
+
{
|
1022 |
+
$this->input_hidden($option);
|
1023 |
+
$class .= ' disabled';
|
1024 |
+
}?>
|
1025 |
+
<tr valign="top">
|
1026 |
+
<th scope="row">
|
1027 |
+
<?php $this->label($opt_id, $label);?>
|
1028 |
+
</th>
|
1029 |
+
<td>
|
1030 |
+
<?php printf('<textarea rows="%6$s" name="%1$s" id="%2$s" class="%4$s" %5$s/>%3$s</textarea><br />', esc_attr($opt_name), esc_attr($opt_id), esc_textarea($this->opt[$option]), esc_attr($class), disabled($disable, true, false), esc_attr($height));?>
|
1031 |
+
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1032 |
+
</td>
|
1033 |
+
</tr>
|
1034 |
+
<?php
|
1035 |
+
}
|
1036 |
+
/**
|
1037 |
+
* This will output a well formed table row for a checkbox input
|
1038 |
+
*
|
1039 |
+
* @param string $label
|
1040 |
+
* @param string $option
|
1041 |
+
* @param string $instruction
|
1042 |
+
* @param bool $disable (optional)
|
1043 |
+
* @param string $description (optional)
|
1044 |
+
* @param string $class (optional)
|
1045 |
+
*/
|
1046 |
+
function input_check($label, $option, $instruction, $disable = false, $description = '', $class = '')
|
1047 |
+
{
|
1048 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1049 |
+
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
1050 |
+
if($disable)
|
1051 |
+
{
|
1052 |
+
$this->input_hidden($option);
|
1053 |
+
$class .= ' disabled';
|
1054 |
+
}?>
|
1055 |
+
<tr valign="top">
|
1056 |
+
<th scope="row">
|
1057 |
+
<?php $this->label($opt_id, $label);?>
|
1058 |
+
</th>
|
1059 |
+
<td>
|
1060 |
+
<label>
|
1061 |
+
<?php printf('<input type="checkbox" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), esc_attr($this->opt[$option]), esc_attr($class), disabled($disable, true, false), checked($this->opt[$option], true, false));?>
|
1062 |
+
<?php echo $instruction; ?>
|
1063 |
+
</label><br />
|
1064 |
+
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1065 |
+
</td>
|
1066 |
+
</tr>
|
1067 |
+
<?php
|
1068 |
+
}
|
1069 |
+
/**
|
1070 |
+
* This will output a singular radio type form input field
|
1071 |
+
*
|
1072 |
+
* @param string $option
|
1073 |
+
* @param string $value
|
1074 |
+
* @param string $instruction
|
1075 |
+
* @param object $disable (optional)
|
1076 |
+
* @param string $class (optional)
|
1077 |
+
*/
|
1078 |
+
function input_radio($option, $value, $instruction, $disable = false, $class = '')
|
1079 |
+
{
|
1080 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1081 |
+
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
1082 |
+
$class .= ' togx';
|
1083 |
+
if($disable)
|
1084 |
+
{
|
1085 |
+
$this->input_hidden($option);
|
1086 |
+
$class .= ' disabled';
|
1087 |
+
}?>
|
1088 |
+
<label>
|
1089 |
+
<?php printf('<input type="radio" name="%1$s" id="%2$s" value="%3$s" class="%4$s" %5$s %6$s/>', esc_attr($opt_name), esc_attr($opt_id), esc_attr($value), esc_attr($class), disabled($disable, true, false), checked($value, $this->opt[$option], false));?>
|
1090 |
+
<?php echo $instruction; ?>
|
1091 |
+
</label><br/>
|
1092 |
+
<?php
|
1093 |
+
}
|
1094 |
+
/**
|
1095 |
+
* This will output a well formed table row for a select input
|
1096 |
+
*
|
1097 |
+
* @param string $label
|
1098 |
+
* @param string $option
|
1099 |
+
* @param array $values
|
1100 |
+
* @param bool $disable (optional)
|
1101 |
+
* @param string $description (optional)
|
1102 |
+
* @param array $titles (optional) The array of titiles for the options, if they should be different from the values
|
1103 |
+
* @param string $class (optional) Extra class to apply to the elements
|
1104 |
+
*/
|
1105 |
+
function input_select($label, $option, $values, $disable = false, $description = '', $titles = false, $class = '')
|
1106 |
+
{
|
1107 |
+
//If we don't have titles passed in, we'll use option names as values
|
1108 |
+
if(!$titles)
|
1109 |
+
{
|
1110 |
+
$titles = $values;
|
1111 |
+
}
|
1112 |
+
$opt_id = mtekk_adminKit::get_valid_id($option);
|
1113 |
+
$opt_name = $this->unique_prefix . '_options[' . $option . ']';
|
1114 |
+
if($disable)
|
1115 |
+
{
|
1116 |
+
$this->input_hidden($option);
|
1117 |
+
$class .= ' disabled';
|
1118 |
+
}?>
|
1119 |
+
<tr valign="top">
|
1120 |
+
<th scope="row">
|
1121 |
+
<?php $this->label($opt_id, $label);?>
|
1122 |
+
</th>
|
1123 |
+
<td>
|
1124 |
+
<?php printf('<select name="%1$s" id="%2$s" class="%4$s" %5$s>%3$s</select><br />', esc_attr($opt_name), esc_attr($opt_id), $this->select_options($option, $titles, $values), esc_attr($class), disabled($disable, true, false));?>
|
1125 |
+
<?php if($description !== ''){?><p class="description"><?php echo $description;?></p><?php }?>
|
1126 |
+
</td>
|
1127 |
+
</tr>
|
1128 |
+
<?php
|
1129 |
+
}
|
1130 |
+
/**
|
1131 |
+
* Displays wordpress options as <seclect>
|
1132 |
+
*
|
1133 |
+
* @param string $optionname name of wordpress options store
|
1134 |
+
* @param array $options array of names of options that can be selected
|
1135 |
+
* @param array $values array of the values of the options that can be selected
|
1136 |
+
* @param array $exclude(optional) array of names in $options array to be excluded
|
1137 |
+
*
|
1138 |
+
* @return string The assembled HTML for the select options
|
1139 |
+
*/
|
1140 |
+
function select_options($optionname, $options, $values, $exclude = array())
|
1141 |
+
{
|
1142 |
+
$options_html = '';
|
1143 |
+
$value = $this->opt[$optionname];
|
1144 |
+
//Now do the rest
|
1145 |
+
foreach($options as $key => $option)
|
1146 |
+
{
|
1147 |
+
if(!in_array($option, $exclude))
|
1148 |
+
{
|
1149 |
+
$options_html .= sprintf('<option value="%1$s" %2$s>%3$s</option>', esc_attr($values[$key]), selected($value, $values[$key], false), $option);
|
1150 |
+
}
|
1151 |
+
}
|
1152 |
+
return $options_html;
|
1153 |
+
}
|
1154 |
+
/**
|
1155 |
+
* A local pass through for get_option so that we can hook in and pick the correct method if needed
|
1156 |
+
*
|
1157 |
+
* @param string $option The name of the option to retrieve
|
1158 |
+
* @return mixed The value of the option
|
1159 |
+
*/
|
1160 |
+
function get_option($option)
|
1161 |
+
{
|
1162 |
+
return get_option($option);
|
1163 |
+
}
|
1164 |
+
/**
|
1165 |
+
* A local pass through for update_option so that we can hook in and pick the correct method if needed
|
1166 |
+
*
|
1167 |
+
* @param string $option The name of the option to update
|
1168 |
+
* @param mixed $newvalue The new value to set the option to
|
1169 |
+
*/
|
1170 |
+
function update_option($option, $newvalue)
|
1171 |
+
{
|
1172 |
+
return update_option($option, $newvalue);
|
1173 |
+
}
|
1174 |
+
/**
|
1175 |
+
* A local pass through for add_option so that we can hook in and pick the correct method if needed
|
1176 |
+
*
|
1177 |
+
* @param string $option The name of the option to update
|
1178 |
+
* @param mixed $value The new value to set the option to
|
1179 |
+
* @param null $deprecated Deprecated parameter
|
1180 |
+
* @param string $autoload Whether or not to autoload the option, it's a string because WP is special
|
1181 |
+
*/
|
1182 |
+
function add_option($option, $value = '', $deprecated = '', $autoload = 'yes')
|
1183 |
+
{
|
1184 |
+
return add_option($option, $value, null, $autoload);
|
1185 |
+
}
|
1186 |
+
/**
|
1187 |
+
* A local pass through for delete_option so that we can hook in and pick the correct method if needed
|
1188 |
+
*
|
1189 |
+
* @param string $option The name of the option to delete
|
1190 |
+
*/
|
1191 |
+
function delete_option($option)
|
1192 |
+
{
|
1193 |
+
return delete_option($option);
|
1194 |
+
}
|
1195 |
}
|
includes/class.mtekk_adminkit_message.php
CHANGED
@@ -1,99 +1,99 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
20 |
-
class mtekk_adminKit_message
|
21 |
-
{
|
22 |
-
const version = '1.0.0';
|
23 |
-
protected $type = '';
|
24 |
-
protected $contents = '';
|
25 |
-
protected $dismissed = false;
|
26 |
-
protected $dismissible = false;
|
27 |
-
protected $uid;
|
28 |
-
/**
|
29 |
-
* Default constructor function
|
30 |
-
*
|
31 |
-
* @param string $contents The string to display in the message
|
32 |
-
* @param string $type The message type, 'error', 'warning', 'success', or 'info'
|
33 |
-
* @param bool $dismissible Whether or not the message is dismissable
|
34 |
-
* @param string $uid The message unique ID, only necessary if the message is dismissable
|
35 |
-
*/
|
36 |
-
public function __construct($contents, $type = 'info', $dismissible = false, $uid = '')
|
37 |
-
{
|
38 |
-
$uid = sanitize_html_class($uid);
|
39 |
-
//If the message is dismissable, the UID better not be null/empty
|
40 |
-
if($dismissible === true && $uid === '')
|
41 |
-
{
|
42 |
-
//Let the user know they're doing it wrong
|
43 |
-
_doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('$uid must not be null if message is dismissible', 'mtekk_adminKit'), '1.0.0');
|
44 |
-
//Treat the message as non-dismissible
|
45 |
-
$dismissible = false;
|
46 |
-
}
|
47 |
-
$this->contents = $contents;
|
48 |
-
$this->type = $type;
|
49 |
-
$this->dismissible = $dismissible;
|
50 |
-
$this->uid = $uid;
|
51 |
-
if($this->dismissible)
|
52 |
-
{
|
53 |
-
$this->dismissed = $this->was_dismissed();
|
54 |
-
}
|
55 |
-
}
|
56 |
-
/**
|
57 |
-
* Attempts to retrieve the dismissal transient for this message
|
58 |
-
*
|
59 |
-
* @return bool Whether or not the message has been dismissed
|
60 |
-
*/
|
61 |
-
public function was_dismissed()
|
62 |
-
{
|
63 |
-
$this->dismissed = get_transient($this->uid);
|
64 |
-
return $this->dismissed;
|
65 |
-
}
|
66 |
-
/**
|
67 |
-
* Dismisses the message, preventing it from being rendered
|
68 |
-
*/
|
69 |
-
public function dismiss()
|
70 |
-
{
|
71 |
-
if($this->dismissible && isset($_POST['uid']) && esc_attr($_POST['uid']) === $this->uid)
|
72 |
-
{
|
73 |
-
check_ajax_referer($this->uid . '_dismiss', 'nonce');
|
74 |
-
$this->dismissed = true;
|
75 |
-
//If the message was dismissed, update the transient for 30 days
|
76 |
-
$result = set_transient($this->uid, $this->dismissed, 2592000);
|
77 |
-
}
|
78 |
-
}
|
79 |
-
/**
|
80 |
-
* Function that prints out the message if not already dismissed
|
81 |
-
*/
|
82 |
-
public function render()
|
83 |
-
{
|
84 |
-
if($this->dismissible)
|
85 |
-
{
|
86 |
-
//Don't render dismissed messages
|
87 |
-
if($this->was_dismissed())
|
88 |
-
{
|
89 |
-
return;
|
90 |
-
}
|
91 |
-
wp_enqueue_script('mtekk_adminkit_messages');
|
92 |
-
printf('<div class="notice notice-%1$s is-dismissible"><p>%2$s</p><meta property="uid" content="%3$s"><meta property="nonce" content="%4$s"></div>', esc_attr($this->type), $this->contents, esc_attr($this->uid), wp_create_nonce($this->uid . '_dismiss'));
|
93 |
-
}
|
94 |
-
else
|
95 |
-
{
|
96 |
-
printf('<div class="notice notice-%1$s"><p>%2$s</p></div>', esc_attr($this->type), $this->contents);
|
97 |
-
}
|
98 |
-
}
|
99 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
20 |
+
class mtekk_adminKit_message
|
21 |
+
{
|
22 |
+
const version = '1.0.0';
|
23 |
+
protected $type = '';
|
24 |
+
protected $contents = '';
|
25 |
+
protected $dismissed = false;
|
26 |
+
protected $dismissible = false;
|
27 |
+
protected $uid;
|
28 |
+
/**
|
29 |
+
* Default constructor function
|
30 |
+
*
|
31 |
+
* @param string $contents The string to display in the message
|
32 |
+
* @param string $type The message type, 'error', 'warning', 'success', or 'info'
|
33 |
+
* @param bool $dismissible Whether or not the message is dismissable
|
34 |
+
* @param string $uid The message unique ID, only necessary if the message is dismissable
|
35 |
+
*/
|
36 |
+
public function __construct($contents, $type = 'info', $dismissible = false, $uid = '')
|
37 |
+
{
|
38 |
+
$uid = sanitize_html_class($uid);
|
39 |
+
//If the message is dismissable, the UID better not be null/empty
|
40 |
+
if($dismissible === true && $uid === '')
|
41 |
+
{
|
42 |
+
//Let the user know they're doing it wrong
|
43 |
+
_doing_it_wrong(__CLASS__ . '::' . __FUNCTION__, __('$uid must not be null if message is dismissible', 'mtekk_adminKit'), '1.0.0');
|
44 |
+
//Treat the message as non-dismissible
|
45 |
+
$dismissible = false;
|
46 |
+
}
|
47 |
+
$this->contents = $contents;
|
48 |
+
$this->type = $type;
|
49 |
+
$this->dismissible = $dismissible;
|
50 |
+
$this->uid = $uid;
|
51 |
+
if($this->dismissible)
|
52 |
+
{
|
53 |
+
$this->dismissed = $this->was_dismissed();
|
54 |
+
}
|
55 |
+
}
|
56 |
+
/**
|
57 |
+
* Attempts to retrieve the dismissal transient for this message
|
58 |
+
*
|
59 |
+
* @return bool Whether or not the message has been dismissed
|
60 |
+
*/
|
61 |
+
public function was_dismissed()
|
62 |
+
{
|
63 |
+
$this->dismissed = get_transient($this->uid);
|
64 |
+
return $this->dismissed;
|
65 |
+
}
|
66 |
+
/**
|
67 |
+
* Dismisses the message, preventing it from being rendered
|
68 |
+
*/
|
69 |
+
public function dismiss()
|
70 |
+
{
|
71 |
+
if($this->dismissible && isset($_POST['uid']) && esc_attr($_POST['uid']) === $this->uid)
|
72 |
+
{
|
73 |
+
check_ajax_referer($this->uid . '_dismiss', 'nonce');
|
74 |
+
$this->dismissed = true;
|
75 |
+
//If the message was dismissed, update the transient for 30 days
|
76 |
+
$result = set_transient($this->uid, $this->dismissed, 2592000);
|
77 |
+
}
|
78 |
+
}
|
79 |
+
/**
|
80 |
+
* Function that prints out the message if not already dismissed
|
81 |
+
*/
|
82 |
+
public function render()
|
83 |
+
{
|
84 |
+
if($this->dismissible)
|
85 |
+
{
|
86 |
+
//Don't render dismissed messages
|
87 |
+
if($this->was_dismissed())
|
88 |
+
{
|
89 |
+
return;
|
90 |
+
}
|
91 |
+
wp_enqueue_script('mtekk_adminkit_messages');
|
92 |
+
printf('<div class="notice notice-%1$s is-dismissible"><p>%2$s</p><meta property="uid" content="%3$s"><meta property="nonce" content="%4$s"></div>', esc_attr($this->type), $this->contents, esc_attr($this->uid), wp_create_nonce($this->uid . '_dismiss'));
|
93 |
+
}
|
94 |
+
else
|
95 |
+
{
|
96 |
+
printf('<div class="notice notice-%1$s"><p>%2$s</p></div>', esc_attr($this->type), $this->contents);
|
97 |
+
}
|
98 |
+
}
|
99 |
}
|
includes/class.mtekk_adminkit_uninstaller.php
CHANGED
@@ -1,70 +1,70 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
-
|
5 |
-
This program is free software; you can redistribute it and/or modify
|
6 |
-
it under the terms of the GNU General Public License as published by
|
7 |
-
the Free Software Foundation; either version 2 of the License, or
|
8 |
-
(at your option) any later version.
|
9 |
-
|
10 |
-
This program is distributed in the hope that it will be useful,
|
11 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
-
GNU General Public License for more details.
|
14 |
-
|
15 |
-
You should have received a copy of the GNU General Public License
|
16 |
-
along with this program; if not, write to the Free Software
|
17 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
-
*/
|
19 |
-
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
20 |
-
/**
|
21 |
-
* Breadcrumb NavXT abstract plugin uninstaller class
|
22 |
-
*
|
23 |
-
* @author Tom Klingenberg
|
24 |
-
*/
|
25 |
-
abstract class mtekk_adminKit_uninstaller
|
26 |
-
{
|
27 |
-
protected $unique_prefix = '';
|
28 |
-
protected $plugin_basename = null;
|
29 |
-
protected $_uninstall_result = false;
|
30 |
-
/**
|
31 |
-
* get plugin path
|
32 |
-
*
|
33 |
-
* @return string full path to plugin file
|
34 |
-
*/
|
35 |
-
protected function _get_plugin_path()
|
36 |
-
{
|
37 |
-
return sprintf('%s/%s', dirname(dirname(__FILE__)), $this->plugin_basename);
|
38 |
-
}
|
39 |
-
|
40 |
-
/**
|
41 |
-
* constructor
|
42 |
-
*
|
43 |
-
* @param array $options class options
|
44 |
-
* plugin =>
|
45 |
-
*/
|
46 |
-
public function __construct()
|
47 |
-
{
|
48 |
-
$this->_uninstall_result = $this->uninstall();
|
49 |
-
}
|
50 |
-
|
51 |
-
/**
|
52 |
-
* Result Getter
|
53 |
-
*
|
54 |
-
* @return bool wether or not uninstall did run successfull.
|
55 |
-
*/
|
56 |
-
public function get_result()
|
57 |
-
{
|
58 |
-
return $this->_uninstall_result;
|
59 |
-
}
|
60 |
-
|
61 |
-
public function is_installed()
|
62 |
-
{
|
63 |
-
return ((get_option($this->unique_prefix . '_options') !== false)
|
64 |
-
&& (get_option($this->unique_prefix . '_options_bk') !== false)
|
65 |
-
&& (get_option($this->unique_prefix . '_version') !== false)
|
66 |
-
&& (get_site_option($this->unique_prefix . '_options') !== false)
|
67 |
-
&& (get_site_option($this->unique_prefix . '_options_bk') !== false)
|
68 |
-
&& (get_site_option($this->unique_prefix . '_version') !== false));
|
69 |
-
}
|
70 |
} /// class bcn_uninstaller_abstract
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Copyright 2015-2018 John Havlik (email : john.havlik@mtekk.us)
|
4 |
+
|
5 |
+
This program is free software; you can redistribute it and/or modify
|
6 |
+
it under the terms of the GNU General Public License as published by
|
7 |
+
the Free Software Foundation; either version 2 of the License, or
|
8 |
+
(at your option) any later version.
|
9 |
+
|
10 |
+
This program is distributed in the hope that it will be useful,
|
11 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
+
GNU General Public License for more details.
|
14 |
+
|
15 |
+
You should have received a copy of the GNU General Public License
|
16 |
+
along with this program; if not, write to the Free Software
|
17 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
+
*/
|
19 |
+
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
20 |
+
/**
|
21 |
+
* Breadcrumb NavXT abstract plugin uninstaller class
|
22 |
+
*
|
23 |
+
* @author Tom Klingenberg
|
24 |
+
*/
|
25 |
+
abstract class mtekk_adminKit_uninstaller
|
26 |
+
{
|
27 |
+
protected $unique_prefix = '';
|
28 |
+
protected $plugin_basename = null;
|
29 |
+
protected $_uninstall_result = false;
|
30 |
+
/**
|
31 |
+
* get plugin path
|
32 |
+
*
|
33 |
+
* @return string full path to plugin file
|
34 |
+
*/
|
35 |
+
protected function _get_plugin_path()
|
36 |
+
{
|
37 |
+
return sprintf('%s/%s', dirname(dirname(__FILE__)), $this->plugin_basename);
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* constructor
|
42 |
+
*
|
43 |
+
* @param array $options class options
|
44 |
+
* plugin =>
|
45 |
+
*/
|
46 |
+
public function __construct()
|
47 |
+
{
|
48 |
+
$this->_uninstall_result = $this->uninstall();
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Result Getter
|
53 |
+
*
|
54 |
+
* @return bool wether or not uninstall did run successfull.
|
55 |
+
*/
|
56 |
+
public function get_result()
|
57 |
+
{
|
58 |
+
return $this->_uninstall_result;
|
59 |
+
}
|
60 |
+
|
61 |
+
public function is_installed()
|
62 |
+
{
|
63 |
+
return ((get_option($this->unique_prefix . '_options') !== false)
|
64 |
+
&& (get_option($this->unique_prefix . '_options_bk') !== false)
|
65 |
+
&& (get_option($this->unique_prefix . '_version') !== false)
|
66 |
+
&& (get_site_option($this->unique_prefix . '_options') !== false)
|
67 |
+
&& (get_site_option($this->unique_prefix . '_options_bk') !== false)
|
68 |
+
&& (get_site_option($this->unique_prefix . '_version') !== false));
|
69 |
+
}
|
70 |
} /// class bcn_uninstaller_abstract
|
includes/mtekk_adminkit_engroups.js
CHANGED
@@ -1,37 +1,37 @@
|
|
1 |
-
jQuery(function()
|
2 |
-
{
|
3 |
-
jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_group);
|
4 |
-
jQuery("input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_set);
|
5 |
-
});
|
6 |
-
function mtekk_admin_enable_group(){
|
7 |
-
var setting = this;
|
8 |
-
jQuery(this).parents(".adminkit-engroup").find("input, textarea").each(function(){
|
9 |
-
if(this != setting){
|
10 |
-
if(jQuery(setting).prop("checked")){
|
11 |
-
jQuery(this).prop("disabled", false);
|
12 |
-
jQuery(this).removeClass("disabled");
|
13 |
-
}
|
14 |
-
else{
|
15 |
-
jQuery(this).prop("disabled", true);
|
16 |
-
jQuery(this).addClass("disabled");
|
17 |
-
}
|
18 |
-
}
|
19 |
-
});
|
20 |
-
}
|
21 |
-
function mtekk_admin_enable_set(){
|
22 |
-
var setting = this;
|
23 |
-
jQuery(this).parents(".adminkit-enset-top").find("input.adminkit-enset, textarea.adminkit-enset").each(function(){
|
24 |
-
if(this != setting){
|
25 |
-
if(jQuery(setting).prop("checked")){
|
26 |
-
jQuery(this).prop("disabled", false);
|
27 |
-
jQuery(this).removeClass("disabled");
|
28 |
-
}
|
29 |
-
else{
|
30 |
-
jQuery(this).prop("disabled", true);
|
31 |
-
jQuery(this).addClass("disabled");
|
32 |
-
}
|
33 |
-
}
|
34 |
-
});
|
35 |
-
}
|
36 |
-
jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_group);
|
37 |
jQuery("input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_set);
|
1 |
+
jQuery(function()
|
2 |
+
{
|
3 |
+
jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_group);
|
4 |
+
jQuery("input:checkbox.adminkit-enset-ctrl").each(mtekk_admin_enable_set);
|
5 |
+
});
|
6 |
+
function mtekk_admin_enable_group(){
|
7 |
+
var setting = this;
|
8 |
+
jQuery(this).parents(".adminkit-engroup").find("input, textarea").each(function(){
|
9 |
+
if(this != setting){
|
10 |
+
if(jQuery(setting).prop("checked")){
|
11 |
+
jQuery(this).prop("disabled", false);
|
12 |
+
jQuery(this).removeClass("disabled");
|
13 |
+
}
|
14 |
+
else{
|
15 |
+
jQuery(this).prop("disabled", true);
|
16 |
+
jQuery(this).addClass("disabled");
|
17 |
+
}
|
18 |
+
}
|
19 |
+
});
|
20 |
+
}
|
21 |
+
function mtekk_admin_enable_set(){
|
22 |
+
var setting = this;
|
23 |
+
jQuery(this).parents(".adminkit-enset-top").find("input.adminkit-enset, textarea.adminkit-enset").each(function(){
|
24 |
+
if(this != setting){
|
25 |
+
if(jQuery(setting).prop("checked")){
|
26 |
+
jQuery(this).prop("disabled", false);
|
27 |
+
jQuery(this).removeClass("disabled");
|
28 |
+
}
|
29 |
+
else{
|
30 |
+
jQuery(this).prop("disabled", true);
|
31 |
+
jQuery(this).addClass("disabled");
|
32 |
+
}
|
33 |
+
}
|
34 |
+
});
|
35 |
+
}
|
36 |
+
jQuery(".adminkit-engroup input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_group);
|
37 |
jQuery("input:checkbox.adminkit-enset-ctrl").change(mtekk_admin_enable_set);
|
includes/mtekk_adminkit_messages.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
jQuery(function()
|
2 |
-
{
|
3 |
-
jQuery("div.notice button.notice-dismiss").click(function (event){
|
4 |
-
data = {
|
5 |
-
'action': 'mtekk_admin_message_dismiss',
|
6 |
-
'uid': jQuery(this).parent().children("meta[property='uid']").attr("content"),
|
7 |
-
'nonce': jQuery(this).parent().children("meta[property='nonce']").attr("content")
|
8 |
-
};
|
9 |
-
jQuery.post(ajaxurl, data);
|
10 |
-
});
|
11 |
});
|
1 |
+
jQuery(function()
|
2 |
+
{
|
3 |
+
jQuery("div.notice button.notice-dismiss").click(function (event){
|
4 |
+
data = {
|
5 |
+
'action': 'mtekk_admin_message_dismiss',
|
6 |
+
'uid': jQuery(this).parent().children("meta[property='uid']").attr("content"),
|
7 |
+
'nonce': jQuery(this).parent().children("meta[property='nonce']").attr("content")
|
8 |
+
};
|
9 |
+
jQuery.post(ajaxurl, data);
|
10 |
+
});
|
11 |
});
|
includes/mtekk_adminkit_messages.min.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
jQuery(function()
|
2 |
-
{
|
3 |
-
jQuery("div.notice button.notice-dismiss").click(function (event){
|
4 |
-
data = {
|
5 |
-
'action': 'mtekk_admin_message_dismiss',
|
6 |
-
'uid': jQuery(this).parent().children("meta[property='uid']").attr("content"),
|
7 |
-
'nonce': jQuery(this).parent().children("meta[property='nonce']").attr("content")
|
8 |
-
};
|
9 |
-
jQuery.post(ajaxurl, data);
|
10 |
-
});
|
11 |
});
|
1 |
+
jQuery(function()
|
2 |
+
{
|
3 |
+
jQuery("div.notice button.notice-dismiss").click(function (event){
|
4 |
+
data = {
|
5 |
+
'action': 'mtekk_admin_message_dismiss',
|
6 |
+
'uid': jQuery(this).parent().children("meta[property='uid']").attr("content"),
|
7 |
+
'nonce': jQuery(this).parent().children("meta[property='nonce']").attr("content")
|
8 |
+
};
|
9 |
+
jQuery.post(ajaxurl, data);
|
10 |
+
});
|
11 |
});
|
includes/mtekk_adminkit_tabs.css
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
#hasadmintabs ul.ui-tabs-nav{float: left; width: 100%; border-bottom:1px solid #ccc; font-size:12px; height:27px; list-style-image:none; list-style-position:outside; list-style-type:none; margin:14px 0 0; overflow:visible;padding:0 0 0 6px;}
|
2 |
-
#hasadmintabs ul.ui-tabs-nav li{display:block; float:left; line-height:200%; list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:0; position:relative; text-align:center; white-space:nowrap; width:auto;}
|
3 |
-
#hasadmintabs ul.ui-tabs-nav li a{border-bottom:1px solid #ccc; display:block; color:#464646; float:left; line-height:25px; padding:1px 13px 0; position:relative; text-decoration:none;margin:0 4px 0 0;}
|
4 |
-
#hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a{background:none;border:1px solid #ccc; border-bottom-color:#f1f1f1; height: 25px; color:#464646; font-weight:normal; padding:1px 13px 0;color:#000;}
|
5 |
-
#hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a:hover, #hasadmintabs ul.ui-tabs-nav a:hover{outline-color:-moz-use-text-color; outline-style:none; outline-width:medium;}
|
6 |
-
#hasadmintabs ul.ui-tabs-nav li a:focus, #hasadmintabs ul.ui-tabs-nav li a:active{outline: none;}
|
7 |
-
#hasadmintabs ul.ui-tabs-nav span{font-size: 12px; font-weight: bolder;}
|
8 |
#screen-options-wrap p.submit {margin:0; padding:0;}
|
1 |
+
#hasadmintabs ul.ui-tabs-nav{float: left; width: 100%; border-bottom:1px solid #ccc; font-size:12px; height:27px; list-style-image:none; list-style-position:outside; list-style-type:none; margin:14px 0 0; overflow:visible;padding:0 0 0 6px;}
|
2 |
+
#hasadmintabs ul.ui-tabs-nav li{display:block; float:left; line-height:200%; list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:0; position:relative; text-align:center; white-space:nowrap; width:auto;}
|
3 |
+
#hasadmintabs ul.ui-tabs-nav li a{border-bottom:1px solid #ccc; display:block; color:#464646; float:left; line-height:25px; padding:1px 13px 0; position:relative; text-decoration:none;margin:0 4px 0 0;}
|
4 |
+
#hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a{background:none;border:1px solid #ccc; border-bottom-color:#f1f1f1; height: 25px; color:#464646; font-weight:normal; padding:1px 13px 0;color:#000;}
|
5 |
+
#hasadmintabs ul.ui-tabs-nav li.ui-tabs-active a:hover, #hasadmintabs ul.ui-tabs-nav a:hover{outline-color:-moz-use-text-color; outline-style:none; outline-width:medium;}
|
6 |
+
#hasadmintabs ul.ui-tabs-nav li a:focus, #hasadmintabs ul.ui-tabs-nav li a:active{outline: none;}
|
7 |
+
#hasadmintabs ul.ui-tabs-nav span{font-size: 12px; font-weight: bolder;}
|
8 |
#screen-options-wrap p.submit {margin:0; padding:0;}
|
includes/mtekk_adminkit_tabs.js
CHANGED
@@ -1,40 +1,40 @@
|
|
1 |
-
jQuery(function()
|
2 |
-
{
|
3 |
-
mtekk_admin_tabulator_init();
|
4 |
-
});
|
5 |
-
/**
|
6 |
-
* Tabulator Bootup
|
7 |
-
*/
|
8 |
-
function mtekk_admin_tabulator_init(){
|
9 |
-
if(!jQuery("#hasadmintabs").length) return;
|
10 |
-
/* init markup for tabs */
|
11 |
-
jQuery('#hasadmintabs').prepend('<ul class="nav-tab-wrapper"><\/ul>');
|
12 |
-
jQuery('#hasadmintabs > fieldset').each(function(i){
|
13 |
-
id = jQuery(this).attr('id');
|
14 |
-
cssc = jQuery(this).attr('class');
|
15 |
-
title = jQuery(this).find('h3.tab-title').attr('title');
|
16 |
-
caption = jQuery(this).find('h3.tab-title').text();
|
17 |
-
jQuery('#hasadmintabs > ul').append('<li><a href="#'+id+'" class="nav-tab '+cssc+'" title="'+title+'"><span>'+caption+"<\/span><\/a><\/li>");
|
18 |
-
jQuery(this).find('h3.tab-title').hide();
|
19 |
-
});
|
20 |
-
var form = jQuery('#'+objectL10n.mtad_uid+'-options');
|
21 |
-
/* init the tabs plugin */
|
22 |
-
var tabs = jQuery("#hasadmintabs").tabs({
|
23 |
-
beforeActivate: function(event, ui){
|
24 |
-
form.find('input').each(function(){
|
25 |
-
if(!this.checkValidity()){
|
26 |
-
form.find(':submit').click();
|
27 |
-
event.preventDefault();
|
28 |
-
}
|
29 |
-
});
|
30 |
-
/* Update form action for reload on tab traversal*/
|
31 |
-
var action = form.attr("action").split('#', 1) + '#' + ui.newPanel[0].id;
|
32 |
-
form.get(0).setAttribute("action", action);
|
33 |
-
},
|
34 |
-
create: function(event, ui){
|
35 |
-
/* Update form action for reload of current tab on page load */
|
36 |
-
var action = form.attr("action").split('#', 1) + '#' + ui.panel[0].id;
|
37 |
-
form.get(0).setAttribute("action", action);
|
38 |
-
}
|
39 |
-
});
|
40 |
}
|
1 |
+
jQuery(function()
|
2 |
+
{
|
3 |
+
mtekk_admin_tabulator_init();
|
4 |
+
});
|
5 |
+
/**
|
6 |
+
* Tabulator Bootup
|
7 |
+
*/
|
8 |
+
function mtekk_admin_tabulator_init(){
|
9 |
+
if(!jQuery("#hasadmintabs").length) return;
|
10 |
+
/* init markup for tabs */
|
11 |
+
jQuery('#hasadmintabs').prepend('<ul class="nav-tab-wrapper"><\/ul>');
|
12 |
+
jQuery('#hasadmintabs > fieldset').each(function(i){
|
13 |
+
id = jQuery(this).attr('id');
|
14 |
+
cssc = jQuery(this).attr('class');
|
15 |
+
title = jQuery(this).find('h3.tab-title').attr('title');
|
16 |
+
caption = jQuery(this).find('h3.tab-title').text();
|
17 |
+
jQuery('#hasadmintabs > ul').append('<li><a href="#'+id+'" class="nav-tab '+cssc+'" title="'+title+'"><span>'+caption+"<\/span><\/a><\/li>");
|
18 |
+
jQuery(this).find('h3.tab-title').hide();
|
19 |
+
});
|
20 |
+
var form = jQuery('#'+objectL10n.mtad_uid+'-options');
|
21 |
+
/* init the tabs plugin */
|
22 |
+
var tabs = jQuery("#hasadmintabs").tabs({
|
23 |
+
beforeActivate: function(event, ui){
|
24 |
+
form.find('input').each(function(){
|
25 |
+
if(!this.checkValidity()){
|
26 |
+
form.find(':submit').click();
|
27 |
+
event.preventDefault();
|
28 |
+
}
|
29 |
+
});
|
30 |
+
/* Update form action for reload on tab traversal*/
|
31 |
+
var action = form.attr("action").split('#', 1) + '#' + ui.newPanel[0].id;
|
32 |
+
form.get(0).setAttribute("action", action);
|
33 |
+
},
|
34 |
+
create: function(event, ui){
|
35 |
+
/* Update form action for reload of current tab on page load */
|
36 |
+
var action = form.attr("action").split('#', 1) + '#' + ui.panel[0].id;
|
37 |
+
form.get(0).setAttribute("action", action);
|
38 |
+
}
|
39 |
+
});
|
40 |
}
|
includes/multibyte_supplicant.php
CHANGED
@@ -1,111 +1,111 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
A small library that adds in fallbacks for some of the PHP multibyte string
|
4 |
-
functions. Mainly inteneded to be used with Breadcrumb NavXT
|
5 |
-
|
6 |
-
Copyright 2009-2018 John Havlik (email : john.havlik@mtekk.us)
|
7 |
-
|
8 |
-
This program is free software; you can redistribute it and/or modify
|
9 |
-
it under the terms of the GNU General Public License as published by
|
10 |
-
the Free Software Foundation; either version 2 of the License, or
|
11 |
-
(at your option) any later version.
|
12 |
-
|
13 |
-
This program is distributed in the hope that it will be useful,
|
14 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
-
GNU General Public License for more details.
|
17 |
-
|
18 |
-
You should have received a copy of the GNU General Public License
|
19 |
-
along with this program; if not, write to the Free Software
|
20 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21 |
-
*/
|
22 |
-
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
23 |
-
if(!function_exists('mb_strlen'))
|
24 |
-
{
|
25 |
-
/**
|
26 |
-
* Fallback for mb_strlen for users without multibyte support
|
27 |
-
*
|
28 |
-
* @param string $string the string to determine the lenght of
|
29 |
-
* @return int the number of characters in the string
|
30 |
-
*/
|
31 |
-
function mb_strlen($string)
|
32 |
-
{
|
33 |
-
return strlen($string);
|
34 |
-
}
|
35 |
-
}
|
36 |
-
if(!function_exists('mb_strpos'))
|
37 |
-
{
|
38 |
-
/**
|
39 |
-
* Fallback for mb_strpos for users without multibyte support
|
40 |
-
*
|
41 |
-
* @param string $haystack the string to search within
|
42 |
-
* @param string $needle the string to search for
|
43 |
-
* @return mixed position of the first instances of needle, or false if needle not found
|
44 |
-
*/
|
45 |
-
function mb_strpos($haystack, $needle, $offset = 0)
|
46 |
-
{
|
47 |
-
return strpos($haystack, $needle, $offset);
|
48 |
-
}
|
49 |
-
}
|
50 |
-
if(!function_exists('mb_substr'))
|
51 |
-
{
|
52 |
-
/**
|
53 |
-
* Fallback for mb_substr for users without multibyte support
|
54 |
-
*
|
55 |
-
* @param string $string the input string
|
56 |
-
* @param int $start the start
|
57 |
-
* @param int length the length of the substring
|
58 |
-
* @return string the substring of specified length
|
59 |
-
*/
|
60 |
-
function mb_substr($string, $start, $length = 'a')
|
61 |
-
{
|
62 |
-
//This happens to be the easiest way to preserve the behavior of substr
|
63 |
-
if($length = 'a')
|
64 |
-
{
|
65 |
-
return substr($string, $start);
|
66 |
-
}
|
67 |
-
else
|
68 |
-
{
|
69 |
-
return substr($string, $start, $length);
|
70 |
-
}
|
71 |
-
}
|
72 |
-
}
|
73 |
-
if(!function_exists('mb_strtolower'))
|
74 |
-
{
|
75 |
-
/**
|
76 |
-
* Fallback for mb_strtolower for users without multibyte support
|
77 |
-
*
|
78 |
-
* @param string $str the string to change to lowercase
|
79 |
-
* @param string $encoding the encoding of the string
|
80 |
-
* @return string the lowercase string
|
81 |
-
*/
|
82 |
-
function mb_strtolower($str, $encoding = 'UTF-8')
|
83 |
-
{
|
84 |
-
return strtolower($str);
|
85 |
-
}
|
86 |
-
}
|
87 |
-
//We need this constant to be defined, otherwise things will break
|
88 |
-
if(!defined('MB_CASE_TITLE'))
|
89 |
-
{
|
90 |
-
define('MB_CASE_TITLE', '1');
|
91 |
-
}
|
92 |
-
if(!function_exists('mb_convert_case'))
|
93 |
-
{
|
94 |
-
/**
|
95 |
-
* A very hacky fallback for mb_convert_case for users without multibyte support
|
96 |
-
*
|
97 |
-
* @param string $str the string to change the case on
|
98 |
-
* @param int $mode the mode of case convert to use
|
99 |
-
* @param string $encoding the encoding of the string
|
100 |
-
* @return string the case converted string
|
101 |
-
*/
|
102 |
-
function mb_convert_case($str, $mode = MB_CASE_TITLE, $encoding = 'UTF-8')
|
103 |
-
{
|
104 |
-
//Only implementing MB_CASE_TITLE
|
105 |
-
if($mode = MB_CASE_TITLE)
|
106 |
-
{
|
107 |
-
return ucwords($str);
|
108 |
-
}
|
109 |
-
return $str;
|
110 |
-
}
|
111 |
}
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
A small library that adds in fallbacks for some of the PHP multibyte string
|
4 |
+
functions. Mainly inteneded to be used with Breadcrumb NavXT
|
5 |
+
|
6 |
+
Copyright 2009-2018 John Havlik (email : john.havlik@mtekk.us)
|
7 |
+
|
8 |
+
This program is free software; you can redistribute it and/or modify
|
9 |
+
it under the terms of the GNU General Public License as published by
|
10 |
+
the Free Software Foundation; either version 2 of the License, or
|
11 |
+
(at your option) any later version.
|
12 |
+
|
13 |
+
This program is distributed in the hope that it will be useful,
|
14 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
+
GNU General Public License for more details.
|
17 |
+
|
18 |
+
You should have received a copy of the GNU General Public License
|
19 |
+
along with this program; if not, write to the Free Software
|
20 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21 |
+
*/
|
22 |
+
require_once(dirname(__FILE__) . '/block_direct_access.php');
|
23 |
+
if(!function_exists('mb_strlen'))
|
24 |
+
{
|
25 |
+
/**
|
26 |
+
* Fallback for mb_strlen for users without multibyte support
|
27 |
+
*
|
28 |
+
* @param string $string the string to determine the lenght of
|
29 |
+
* @return int the number of characters in the string
|
30 |
+
*/
|
31 |
+
function mb_strlen($string)
|
32 |
+
{
|
33 |
+
return strlen($string);
|
34 |
+
}
|
35 |
+
}
|
36 |
+
if(!function_exists('mb_strpos'))
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Fallback for mb_strpos for users without multibyte support
|
40 |
+
*
|
41 |
+
* @param string $haystack the string to search within
|
42 |
+
* @param string $needle the string to search for
|
43 |
+
* @return mixed position of the first instances of needle, or false if needle not found
|
44 |
+
*/
|
45 |
+
function mb_strpos($haystack, $needle, $offset = 0)
|
46 |
+
{
|
47 |
+
return strpos($haystack, $needle, $offset);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
if(!function_exists('mb_substr'))
|
51 |
+
{
|
52 |
+
/**
|
53 |
+
* Fallback for mb_substr for users without multibyte support
|
54 |
+
*
|
55 |
+
* @param string $string the input string
|
56 |
+
* @param int $start the start
|
57 |
+
* @param int length the length of the substring
|
58 |
+
* @return string the substring of specified length
|
59 |
+
*/
|
60 |
+
function mb_substr($string, $start, $length = 'a')
|
61 |
+
{
|
62 |
+
//This happens to be the easiest way to preserve the behavior of substr
|
63 |
+
if($length = 'a')
|
64 |
+
{
|
65 |
+
return substr($string, $start);
|
66 |
+
}
|
67 |
+
else
|
68 |
+
{
|
69 |
+
return substr($string, $start, $length);
|
70 |
+
}
|
71 |
+
}
|
72 |
+
}
|
73 |
+
if(!function_exists('mb_strtolower'))
|
74 |
+
{
|
75 |
+
/**
|
76 |
+
* Fallback for mb_strtolower for users without multibyte support
|
77 |
+
*
|
78 |
+
* @param string $str the string to change to lowercase
|
79 |
+
* @param string $encoding the encoding of the string
|
80 |
+
* @return string the lowercase string
|
81 |
+
*/
|
82 |
+
function mb_strtolower($str, $encoding = 'UTF-8')
|
83 |
+
{
|
84 |
+
return strtolower($str);
|
85 |
+
}
|
86 |
+
}
|
87 |
+
//We need this constant to be defined, otherwise things will break
|
88 |
+
if(!defined('MB_CASE_TITLE'))
|
89 |
+
{
|
90 |
+
define('MB_CASE_TITLE', '1');
|
91 |
+
}
|
92 |
+
if(!function_exists('mb_convert_case'))
|
93 |
+
{
|
94 |
+
/**
|
95 |
+
* A very hacky fallback for mb_convert_case for users without multibyte support
|
96 |
+
*
|
97 |
+
* @param string $str the string to change the case on
|
98 |
+
* @param int $mode the mode of case convert to use
|
99 |
+
* @param string $encoding the encoding of the string
|
100 |
+
* @return string the case converted string
|
101 |
+
*/
|
102 |
+
function mb_convert_case($str, $mode = MB_CASE_TITLE, $encoding = 'UTF-8')
|
103 |
+
{
|
104 |
+
//Only implementing MB_CASE_TITLE
|
105 |
+
if($mode = MB_CASE_TITLE)
|
106 |
+
{
|
107 |
+
return ucwords($str);
|
108 |
+
}
|
109 |
+
return $str;
|
110 |
+
}
|
111 |
}
|
readme.txt
CHANGED
@@ -1,270 +1,280 @@
|
|
1 |
-
=== Breadcrumb NavXT ===
|
2 |
-
Contributors: mtekk, hakre
|
3 |
-
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=FD5XEU783BR8U&lc=US&item_name=Breadcrumb%20NavXT%20Donation¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
-
Tags: breadcrumb, breadcrumbs, trail, navigation, menu, widget
|
5 |
-
Requires at least: 4.7
|
6 |
-
Tested up to: 4.9
|
7 |
-
Stable tag: 6.0
|
8 |
-
Requires PHP: 5.3
|
9 |
-
License: GPLv2 or later
|
10 |
-
Adds breadcrumb navigation showing the visitor's path to their current location.
|
11 |
-
|
12 |
-
== Description ==
|
13 |
-
|
14 |
-
Breadcrumb NavXT, the successor to the popular WordPress plugin Breadcrumb Navigation XT, was written from the ground up to be better than its ancestor. This plugin generates locational breadcrumb trails for your WordPress powered blog or website. These breadcrumb trails are highly customizable to suit the needs of just about any website running WordPress. The Administrative interface makes setting options easy, while a direct class access is available for theme developers and more adventurous users.
|
15 |
-
|
16 |
-
= PHP Requirements =
|
17 |
-
Breadcrumb NavXT 5.2 and newer require PHP5.3
|
18 |
-
Breadcrumb NavXT 5.1.1 and older require PHP5.2
|
19 |
-
|
20 |
-
= Features (non-exhaustive) =
|
21 |
-
* RDFa format Schema.org BreadcrumbList compatible breadcrumb generation.
|
22 |
-
* Extensive breadcrumb customization control via a settings page with appropriate default values for most use cases.
|
23 |
-
* Network admin settings page for managing breadcrumb settings for all subsites with [configurable global priority](http://mtekk.us/archives/guides/controlling-breadcrumb-navxt-settings-from-the-network-settings-page/ "Go to the article on configuring the network settings priority.").
|
24 |
-
* Built in WordPress Widget.
|
25 |
-
* Extensible via OOP and provided [actions](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/2/#action_reference "Go to the Breadcrumb NavXT Documentation's action reference.") and [filters](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/2/#filter_reference "Go to the Breadcrumb NavXT Documentation's filter reference.").
|
26 |
-
* WPML compatible (enhanced compatibility with WPML extensions plugin).
|
27 |
-
* Polylang compatible (enhanced compatibility with Polylang extensions plugin).
|
28 |
-
* bbPress compatible (enhanced compatibility with bbPress extensions plugin).
|
29 |
-
* BuddyPress compatible (enhanced compatibility with BuddyPress extensions plugin).
|
30 |
-
|
31 |
-
= Translations =
|
32 |
-
|
33 |
-
Breadcrumb NavXT now supports WordPress.org language packs. Want to translate Breadcrumb NavXT? Visit [Breadcrumb NavXT's WordPress.org translation project](https://translate.wordpress.org/projects/wp-plugins/breadcrumb-navxt/).
|
34 |
-
|
35 |
-
== Installation ==
|
36 |
-
Breadcrumb NavXT can be installed from within WordPress’ administration panel. After installing and activating the plugin, to get breadcrumb trails to display either use the included widget, or call the breadcrumb trail in your theme (or child theme). See the [Calling the Breadcrumb Trail](http://mtekk.us/archives/guides/calling-the-breadcrumb-trail "Read more on calling the breadcrumb trail") article for more information on calling the breadcrumb trail.
|
37 |
-
|
38 |
-
To customize the breadcrumb trail you may edit the default values for the options in the administrative interface. This is located in your administration panel under Settings > Breadcrumb NavXT.
|
39 |
-
|
40 |
-
Please visit [Breadcrumb NavXT's Documentation](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/ "Go to Breadcrumb NavXT's Documentation.") page for more information.
|
41 |
-
|
42 |
-
== Screenshots ==
|
43 |
-
1. This screenshot shows 5 different examples of breadcrumbs generated by Breadcrumb NavXT
|
44 |
-
2. A screenshot of the General tab of the settings page
|
45 |
-
3. A screenshot of the Post Types tab of the settings page
|
46 |
-
4. A screenshot of the Taxonomies tab of the settings page
|
47 |
-
5. A screenshot of the Miscellaneous tab of the settings page
|
48 |
-
6. A screenshot of the Settings Import/Export/Reset form under the Help menu
|
49 |
-
|
50 |
-
== Changelog ==
|
51 |
-
|
52 |
-
= 6.0
|
53 |
-
Release date:
|
54 |
-
|
55 |
-
* Behavior change:
|
56 |
-
*
|
57 |
-
*
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
* Bug fix: Fixed issue where
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
*
|
79 |
-
* Bug fix:
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
* Behavior change:
|
88 |
-
*
|
89 |
-
*
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
*
|
95 |
-
*
|
96 |
-
*
|
97 |
-
*
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
*
|
103 |
-
*
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
*
|
119 |
-
* Bug fix: Fixed issue where the
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
* Bug fix: Fixed issue
|
130 |
-
|
131 |
-
= 5.5.
|
132 |
-
Release date:
|
133 |
-
|
134 |
-
*
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
*
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
*
|
148 |
-
* New feature: Added `
|
149 |
-
* New feature: Added `
|
150 |
-
* New feature: Added `
|
151 |
-
* Bug fix: Fixed
|
152 |
-
* Bug fix:
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
*
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
* Bug fix:
|
163 |
-
* Bug fix: Fixed
|
164 |
-
* Bug fix:
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
*
|
173 |
-
*
|
174 |
-
*
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
*
|
180 |
-
*
|
181 |
-
*
|
182 |
-
*
|
183 |
-
*
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
*
|
189 |
-
*
|
190 |
-
*
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
* Bug fix: Fixed issue where
|
199 |
-
* Bug fix:
|
200 |
-
* Bug fix: Fixed issue where
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
*
|
207 |
-
*
|
208 |
-
*
|
209 |
-
*
|
210 |
-
*
|
211 |
-
*
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
*
|
220 |
-
*
|
221 |
-
*
|
222 |
-
* Bug fix:
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
*
|
230 |
-
*
|
231 |
-
* Bug fix:
|
232 |
-
* Bug fix:
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
*
|
238 |
-
*
|
239 |
-
*
|
240 |
-
*
|
241 |
-
* Bug fix:
|
242 |
-
* Bug fix:
|
243 |
-
* Bug fix:
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
*
|
249 |
-
* Bug fix:
|
250 |
-
* Bug fix: Fixed issue where `
|
251 |
-
* Bug fix: Fixed
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
*
|
259 |
-
*
|
260 |
-
*
|
261 |
-
*
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
This version requires PHP5.3 or newer. This version introduces a new 4th optional parameter to `bcn_display()` and `bcn_display_list()` that bypasses the internal caching mechanism.
|
1 |
+
=== Breadcrumb NavXT ===
|
2 |
+
Contributors: mtekk, hakre
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=FD5XEU783BR8U&lc=US&item_name=Breadcrumb%20NavXT%20Donation¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
|
4 |
+
Tags: breadcrumb, breadcrumbs, trail, navigation, menu, widget
|
5 |
+
Requires at least: 4.7
|
6 |
+
Tested up to: 4.9
|
7 |
+
Stable tag: 6.1.0
|
8 |
+
Requires PHP: 5.3
|
9 |
+
License: GPLv2 or later
|
10 |
+
Adds breadcrumb navigation showing the visitor's path to their current location.
|
11 |
+
|
12 |
+
== Description ==
|
13 |
+
|
14 |
+
Breadcrumb NavXT, the successor to the popular WordPress plugin Breadcrumb Navigation XT, was written from the ground up to be better than its ancestor. This plugin generates locational breadcrumb trails for your WordPress powered blog or website. These breadcrumb trails are highly customizable to suit the needs of just about any website running WordPress. The Administrative interface makes setting options easy, while a direct class access is available for theme developers and more adventurous users.
|
15 |
+
|
16 |
+
= PHP Requirements =
|
17 |
+
Breadcrumb NavXT 5.2 and newer require PHP5.3
|
18 |
+
Breadcrumb NavXT 5.1.1 and older require PHP5.2
|
19 |
+
|
20 |
+
= Features (non-exhaustive) =
|
21 |
+
* RDFa format Schema.org BreadcrumbList compatible breadcrumb generation.
|
22 |
+
* Extensive breadcrumb customization control via a settings page with appropriate default values for most use cases.
|
23 |
+
* Network admin settings page for managing breadcrumb settings for all subsites with [configurable global priority](http://mtekk.us/archives/guides/controlling-breadcrumb-navxt-settings-from-the-network-settings-page/ "Go to the article on configuring the network settings priority.").
|
24 |
+
* Built in WordPress Widget.
|
25 |
+
* Extensible via OOP and provided [actions](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/2/#action_reference "Go to the Breadcrumb NavXT Documentation's action reference.") and [filters](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/2/#filter_reference "Go to the Breadcrumb NavXT Documentation's filter reference.").
|
26 |
+
* WPML compatible (enhanced compatibility with WPML extensions plugin).
|
27 |
+
* Polylang compatible (enhanced compatibility with Polylang extensions plugin).
|
28 |
+
* bbPress compatible (enhanced compatibility with bbPress extensions plugin).
|
29 |
+
* BuddyPress compatible (enhanced compatibility with BuddyPress extensions plugin).
|
30 |
+
|
31 |
+
= Translations =
|
32 |
+
|
33 |
+
Breadcrumb NavXT now supports WordPress.org language packs. Want to translate Breadcrumb NavXT? Visit [Breadcrumb NavXT's WordPress.org translation project](https://translate.wordpress.org/projects/wp-plugins/breadcrumb-navxt/).
|
34 |
+
|
35 |
+
== Installation ==
|
36 |
+
Breadcrumb NavXT can be installed from within WordPress’ administration panel. After installing and activating the plugin, to get breadcrumb trails to display either use the included widget, or call the breadcrumb trail in your theme (or child theme). See the [Calling the Breadcrumb Trail](http://mtekk.us/archives/guides/calling-the-breadcrumb-trail "Read more on calling the breadcrumb trail") article for more information on calling the breadcrumb trail.
|
37 |
+
|
38 |
+
To customize the breadcrumb trail you may edit the default values for the options in the administrative interface. This is located in your administration panel under Settings > Breadcrumb NavXT.
|
39 |
+
|
40 |
+
Please visit [Breadcrumb NavXT's Documentation](http://mtekk.us/code/breadcrumb-navxt/breadcrumb-navxt-doc/ "Go to Breadcrumb NavXT's Documentation.") page for more information.
|
41 |
+
|
42 |
+
== Screenshots ==
|
43 |
+
1. This screenshot shows 5 different examples of breadcrumbs generated by Breadcrumb NavXT
|
44 |
+
2. A screenshot of the General tab of the settings page
|
45 |
+
3. A screenshot of the Post Types tab of the settings page
|
46 |
+
4. A screenshot of the Taxonomies tab of the settings page
|
47 |
+
5. A screenshot of the Miscellaneous tab of the settings page
|
48 |
+
6. A screenshot of the Settings Import/Export/Reset form under the Help menu
|
49 |
+
|
50 |
+
== Changelog ==
|
51 |
+
|
52 |
+
= 6.1.0 =
|
53 |
+
Release date: June, 1st 2018
|
54 |
+
|
55 |
+
* Behavior change: Links to generate support requests migrated to the WordPress.org forums.
|
56 |
+
* New feature: Added support for Schema.org BreadcrumbList (microdata format) in the included widget.
|
57 |
+
* New feature: Added new Root Page support for author archives.
|
58 |
+
* New feature: Added REST API endpoint for posts, terms, and author archives.
|
59 |
+
* Bug fix: Corrected label for the Schema.org BreadcrumbList (RDFa format) option in the included widget.
|
60 |
+
* Bug fix: Fixed issue where a PHP warning would be thrown due to `get_term()` returning something other than an instance of `WP_Term`.
|
61 |
+
|
62 |
+
= 6.0.4 =
|
63 |
+
Release date: January, 26th 2018
|
64 |
+
|
65 |
+
* Behavior change: Added auto migration of post type hierarchy settings to `bcn_display*()` functions.
|
66 |
+
* Bug fix: Fixed issue where a PHP notice would be generated on the page for posts when the blog breadcrumb display option is set to false.
|
67 |
+
* Bug fix: Fixed issue where a PHP notice would be generated on archive pages where attachments were included in the `wp_query` results.
|
68 |
+
|
69 |
+
= 6.0.3 =
|
70 |
+
Release date: January, 1st 2018
|
71 |
+
|
72 |
+
* Bug fix: Fixed issue where an improper breadcrumb would be generated in the trail for pages under some circumstances.
|
73 |
+
* Bug fix: Fixed issue where the post and page roots were not updating to track user changes in Settings > Reading.
|
74 |
+
|
75 |
+
= 6.0.2 =
|
76 |
+
Release date: December, 30th 2017
|
77 |
+
|
78 |
+
* Behavior change: Added warning alerting that `bcn_breadcrumb::type` must be an array.
|
79 |
+
* Bug fix: Changed Breadcrumb Separator and Paged Template from an input field to a textbox to reduce confusion caused by HTML entities.
|
80 |
+
* Bug fix: Fixed issue where the parents of a page may not show up in the breadcrumb trail.
|
81 |
+
* Bug fix: Fixed issue where the `$reverse` parameter for `bcn_display` and `bcn_display_list` did not work properly.
|
82 |
+
* Bug fix: Fixed issue where the `bcn_display_list` function did not include the `li` elements.
|
83 |
+
|
84 |
+
= 6.0.1 =
|
85 |
+
Release date: December, 28th 2017
|
86 |
+
|
87 |
+
* Behavior change: Removed unused Blog Template and Blog Template (Unlinked) from settings page.
|
88 |
+
* Bug fix: Fixed issue where changes to the hierarchy type for any post type would not save.
|
89 |
+
* Bug fix: Fixed issue where the blog display setting was ignored.
|
90 |
+
|
91 |
+
= 6.0.0 =
|
92 |
+
Release date: December, 26th 2017
|
93 |
+
|
94 |
+
* Behavior change: `bcn_breadcrumb_trail::display_list()` deprecated in favor of using the `$template` parameter in `bcn_breadcrumb_trail::display()`.
|
95 |
+
* Behavior change: `bcn_breadcrumb_trail::do_attachment()` deprecated in favor of calling `bcn_breadcrumb_trail::do_post()`.
|
96 |
+
* Behavior change: `bcn_breadcrumb_trail::do_front_page()` deprecated in favor of calling `bcn_breadcrumb_trail::do_home()`.
|
97 |
+
* Behavior change: `bcn_li_attributes` filter was deprecated in favor of `bcn_display_attributes`.
|
98 |
+
* Behavior change: `bcn_breadcrumb_trail::do_archive_by_date()` deprecated in favor of calling bcn_breadcrumb_trail::do_day()`, `bcn_breadcrumb_trail::do_month()`, and/or `bcn_breadcrumb_trail::do_year()`.
|
99 |
+
* Behavior change: `bcn_breadcrumb_trail::find_type()` deprecated and removed from bcn_breadcrumb_trail.
|
100 |
+
* Behavior change: Breadcrumb for 404 error pages changed to be a child of the front page.
|
101 |
+
* New feature: Added support for various HTML tags in the widget's pretext field.
|
102 |
+
* New feature: Added `bcn_default_hierarchy_display` filter.
|
103 |
+
* New feature: Added `bcn_default_hierarchy_type` filter.
|
104 |
+
* New feature: Added `$posttype_name` as the third parameter to `bcn_show_tax_private`.
|
105 |
+
* Bug fix: Fixed UI/UX issue in the settings screen where enabling/disabling settings groups for the Home, Blog, and Mainsite breadcrumb settings did not work.
|
106 |
+
* Bug fix: Fixed UI/UX issue in the settings screen where not including the paged breadcrumb still allowed the paged breadcrumb template to be edited.
|
107 |
+
* Bug fix: Removed use of `create_function` in registering the widget as it was deprecated in PHP 7.2.
|
108 |
+
|
109 |
+
= 5.7.1 =
|
110 |
+
Release date: June 30th, 2017
|
111 |
+
|
112 |
+
* Bug fix: Fixed erroneous use of `$linked` that caused a PHP warning in `bcn_display_json_ld()`.
|
113 |
+
* Bug fix: Fixed issue where removing a breadcrumb from the trail could cause one or more breadcrumb separators to inappropriately disappear.
|
114 |
+
|
115 |
+
= 5.7.0 =
|
116 |
+
Release date: April 21st, 2017
|
117 |
+
|
118 |
+
* New feature: Added `bcn_display_json_ld(`) function for producing Schema.org BreadcrumbList compliant JSON-LD markup.
|
119 |
+
* Bug fix: Fixed issue where the uninstaller caused PHP Errors when ran from WP CLI.
|
120 |
+
* Bug fix: Fixed issue where `bcn_breadcrumb_trail::find_type()` caused a PHP Warnings in certain circumstances.
|
121 |
+
* Bug fix: Fixed typo in the administrative interface.
|
122 |
+
|
123 |
+
= 5.6.0 =
|
124 |
+
Release date: December 23rd, 2016
|
125 |
+
|
126 |
+
* New feature: Added fourth parameter, `$force`, to `bcn_display()`, and `bcn_display_list()` allowing the internal caching mechanism to be bypassed.
|
127 |
+
* New feature: Moved to multiple line text boxes rather than regular single line text inputs for the breadcrumb templates in the settings page to enhance visibility.
|
128 |
+
* Bug fix: Fixed issue where general searches had the blog breadcrumb in the breadcrumb trail.
|
129 |
+
* Bug fix: Fixed issue where the blog breadcrumb options were erroneously made available when a Posts Page was not set.
|
130 |
+
|
131 |
+
= 5.5.2 =
|
132 |
+
Release date: September 30th, 2016
|
133 |
+
|
134 |
+
* Bug fix: Fixed issue where the “blog breadcrumb” setting does not affect the inclusion of the blog breadcrumb in the breadcrumb trail.
|
135 |
+
|
136 |
+
= 5.5.1 =
|
137 |
+
Release date: August 13th, 2016
|
138 |
+
|
139 |
+
* Bug fix: Fixed issue in `bcn_breadcrumb_trail::find_type()` that identified pages as posts, causing the erroneous inclusion of the post root in the breadcrumb trail for pages.
|
140 |
+
|
141 |
+
= 5.5.0 =
|
142 |
+
Release date: August 12th, 2016
|
143 |
+
|
144 |
+
* Behavior change: Internal mechanics to handle post parents as the hierarchy for a post (of any post type) has changed to use 'BCN_POST_PARENT' rather than 'page' for the taxonomy_type.
|
145 |
+
* Behavior change: Internal mechanics to handle dates as the hierarchy for a post (of any post type) has changed to use 'BCN_DATE' rather than 'date' for the taxonomy_type.
|
146 |
+
* Behavior change: Taxonomy term hierarchy selection logic in `bcn_breadcrumb_trail::pick_post_term()` has changed to picking the deepest known child of the first hierarchy found in the list of terms returned by `get_the_terms()` rather than the first term with a child.
|
147 |
+
* New feature: Added support for referer influenced taxonomy selection for a post's (any post type) breadcrumb trail.
|
148 |
+
* New feature: Added `translate` and `lang` as valid attributes for tags within breadcrumb templates.
|
149 |
+
* New feature: Added `srcset` and `sizes` as valid attributes for `img` tags within breadcrumb templates.
|
150 |
+
* New feature: Added `itemprop` as a valid attribute for the `meta` tags within breadcrumb templates.
|
151 |
+
* Bug fix: Fixed various issues caused by other plugins/themes modifying the `$post` global.
|
152 |
+
* Bug fix: Fixed issue where WPML Extensions would cause a CPT without a set root page to use the Post post type's root page.
|
153 |
+
|
154 |
+
= 5.4.0 =
|
155 |
+
Release date: March 15th, 2016
|
156 |
+
|
157 |
+
* Behavior change: Migrated to new adminKit version, some functions previously in the admin classes are now handled upstream.
|
158 |
+
* New feature: Added `bcn_post_terms` filter to `bcn_breadcrumb_trail::post_terms()` to control the terms included in a non-hierarchical term breadcrumb for a post.
|
159 |
+
* New feature: Added `bcn_add_post_type_arg` filter to `bcn_breadcrumb_trail::maybe_add_post_type_arg()` to control when the post_type argument is added to URLs for archives.
|
160 |
+
* New feature: Added `bcn_pick_post_term` filter to `bcn_breadcrumb_trail::post_hierarchy()` to allow overriding Breadcrumb NavXT’s default term selection behavior.
|
161 |
+
* Bug fix: Fixed issue with untranslatable title on the settings page.
|
162 |
+
* Bug fix: Cleanup of several trivial differences between `bcn_admin` and `bcn_network_admin`.
|
163 |
+
* Bug fix: Fixed improper display of “Your settings are out of date. Migrate now.” message on fresh installs.
|
164 |
+
* Bug fix: Clarified verbiage in regards to the paged breadcrumb.
|
165 |
+
* Bug fix: Added translation wrappers for date format strings in `bcn_breadcrumb_trail::do_archive_by_date()`.
|
166 |
+
* Bug fix: Fixed issue where `bcn_breadcrumb_trail::is_builtin()` would cause PHP warnings when the passed in post type was not an actual post type.
|
167 |
+
* Bug fix: Fixed issue that would cause a PHP error if `WP_Widget` is unavailable.
|
168 |
+
|
169 |
+
= 5.3.1 =
|
170 |
+
Release date: December 14th, 2015
|
171 |
+
|
172 |
+
* Bug fix: Fixed alignment issue of the main content of the settings page on WordPress 4.4.
|
173 |
+
* Bug fix: Fixed error caused by options upgrading not re-establishing new settings.
|
174 |
+
* Bug fix: Fixed PHP error caused by `bcn_breadcrumb_trail::get_type_string_query_var()` returning an array when the post_type query variable is an array.
|
175 |
+
|
176 |
+
= 5.3.0 =
|
177 |
+
Release date: November 12th, 2015
|
178 |
+
|
179 |
+
* Behavior change: Breadcrumb NavXT will no longer default to setting the root page for CPTs.
|
180 |
+
* Behavior change: Breadcrumb NavXT will no longer inject a breadcrumb for a CPT archive page if a root page is set for that CPT.
|
181 |
+
* Behavior change: Breadcrumb NavXT now defaults to `BCN_SETTINGS_USE_LOCAL` rather than `BCN_SETTINGS_USE_NETWORK` if all of the `BCN_SETTINGS_*` globals are not defined.
|
182 |
+
* Behavior change: The included widget now supports RDFA style, Schema.org BreadcrumbList format rather than the deprecated Google Breadcrumbs format.
|
183 |
+
* Behavior change: Default settings for breadcrumb templates now conform to RDFA style, Schema.org BreadcrumbList format rather than the deprecated Google Breadcrumbs format.
|
184 |
+
* New feature: Added `bcn_widget_display_trail` action to enhance the included widget’s extensibility.
|
185 |
+
* New feature: Added `bcn_widget_display_types` action to enhance the included widget’s extensibility.
|
186 |
+
* New feature: The plugin uninstaller has been re-factored, includes support for uninstalling in PHP5.2.
|
187 |
+
* New feature: Unit tests added for all non-deprecated features in bcn_breadcrumb.
|
188 |
+
* New feature: Unit tests added for the uninstaller.
|
189 |
+
* New feature: Date based hierarchies are now available for CPTs.
|
190 |
+
* New feature: Date archives restricted by CPT are now supported.
|
191 |
+
* New feature: Taxonomy archives restricted by CPT are now supported.
|
192 |
+
* Bug fix: Fixed issue where the multibyte supplicant functions were not always being included due to WordPress shipping with its own subset of theses functions.
|
193 |
+
* Bug fix: Fixed issue where on an archive for a post type the archive breadcrumb would appear twice.
|
194 |
+
|
195 |
+
= 5.2.2 =
|
196 |
+
Release date: June 1st, 2015
|
197 |
+
|
198 |
+
* Bug fix: Fixed issue where the current item would use a built in default template rather than the breadcrumb template in the settings.
|
199 |
+
* Bug fix: Updated currently distributed translations set and list to match the current set of translations that achieve the 90% completeness threshold for inclusion.
|
200 |
+
* Bug fix: Fixed issue where a PHP warning would be displayed when BCN_SETTINGS_USE_NETWORK is defined.
|
201 |
+
|
202 |
+
= 5.2.1 =
|
203 |
+
Release date: May 25th, 2015
|
204 |
+
|
205 |
+
* Bug fix: Added additional checks for empty URLs and templates within `bcn_breadcrumb` to prevent various bugs when empty URLs and/or templates are passed in.
|
206 |
+
* Bug fix: Move away from building URLs for search breadcrumbs and instead using `get_search_link()` to fix support for pretty permalinks.
|
207 |
+
* Bug fix: Fixed issue where media items (attachments) that have not been attached to a post yet would cause an incorrect breadcrumb trail to be generated.
|
208 |
+
* Bug fix: Fixed issue where attachments of the front page would cause PHP Warnings.
|
209 |
+
* Bug fix: Fixed issue where attachments of the front page would have duplicate breadcrumbs for the home page.
|
210 |
+
* Bug fix: Fixed issue where attachments of pages would have an extraneous breadcrumb relating to the page for posts.
|
211 |
+
* Bug fix: Fixed issue with the text domain/domain path in the plugin header.
|
212 |
+
|
213 |
+
= 5.2.0 =
|
214 |
+
Release date: January 9th, 2015
|
215 |
+
|
216 |
+
* Deprecated: The Max Breadcrumb Length setting has been deprecated in favor of [using CSS styling to perform the length limiting](http://mtekk.us/archives/guides/trimming-breadcrumb-title-lengths-with-css/ "Go to the article presenting how to shorten the breadcrumb title length using CSS").
|
217 |
+
* Behavior change: The archive page for a post type is now generated for the top ancestor post rather than for the current page when "post parent" is used as the post's hierarchy.
|
218 |
+
* Behavior change: Now requires PHP5.3 or newer.
|
219 |
+
* New feature: Added `bcn_type_archive_post_type` filter.
|
220 |
+
* New feature: Settings depending on another setting to be enabled are disabled when the dependency setting is disabled.
|
221 |
+
* New feature: More descriptive messages on settings saving (notify user on success, failure, and no changes to save).
|
222 |
+
* Bug fix: Fixed awkward wording in the settings page for post hierarchy settings.
|
223 |
+
* Bug fix: Fixed missed default templates for post formats when all taxonomy settings had the tax_ prefix added in 5.1.
|
224 |
+
* Bug fix: Fixed bulk of compatibility issues with bbPress.
|
225 |
+
|
226 |
+
= 5.1.1 =
|
227 |
+
Release date: July 29th, 2014
|
228 |
+
|
229 |
+
* Bug fix: Fixed issue where attachments and their parents have the same link when 'link current item' is enabled.
|
230 |
+
* Bug fix: Pass the same parameters into the widget title and (pre) text filters as the default WordPress widgets.
|
231 |
+
* Bug fix: Fixed issue where PHP warnings would be thrown on author pages for authors that do not have any posts.
|
232 |
+
* Bug fix: Reduced severity of `$post` global not being of type `WP_Post`, will silently exit on non-WP_DEBUG enabled sites.
|
233 |
+
|
234 |
+
= 5.1.0 =
|
235 |
+
Release date: June 9th, 2014
|
236 |
+
|
237 |
+
* Behavior change: `bcn_breadcrumb_trail::do_post()` now expects to be passed in a valid WP_Post object.
|
238 |
+
* Behavior change: `breadcrumb_navxt::version` changed to a constant to allow uninstantiated access of the plugin version.
|
239 |
+
* New feature: Support Google's RDFa Breadcrumbs microformat by default.
|
240 |
+
* New feature: Added `bcn_opts_update_prebk` filter.
|
241 |
+
* Bug fix: Validate HTML5 options on tab traversal.
|
242 |
+
* Bug fix: Fixed issue where the settings importer parsed the version string incorrectly.
|
243 |
+
* Bug fix: Added 'typeof' to list of valid HTML tag attributes.
|
244 |
+
* Bug fix: Prefixed all taxonomies with 'tax_' to prevent name collisions.
|
245 |
+
* Bug fix: Added ID to Post and Taxonomy Term Elements in `bcn_breadcrumb_trail::do_root()` as is done everywhere else.
|
246 |
+
* Bug fix: Fixed issue with `bcn_breadcrumb_trail::do_author()` returning the incorrect user under some circumstances.
|
247 |
+
* Bug fix: Fixed issue where saving twice on a tab in the settings page would cause the next page load to open the general tab rather than the current tab.
|
248 |
+
* Bug fix: Added bcn_breadcrumb_template filter back into `bcn_breadcrumb::set_template()`, was a regression in 5.0 from 4.4.
|
249 |
+
* Bug fix: Fixed issue where the included widget did not check against default settings, causing PHP Warnings to show up on the frontend under some circumstances.
|
250 |
+
* Bug fix: Fixed issue where we didn't handle `WP_POST::has_archive` correctly when it was a string, causing issues with CPTs generated by some plugins.
|
251 |
+
* Bug fix: Fixed issue where the default taxonomy selected for a CPT could be a non-public taxonomy.
|
252 |
+
* Bug fix: Attachments get their own title within the settings page now.
|
253 |
+
* Bug fix: Filter the title and pre text in the widget.
|
254 |
+
|
255 |
+
= 5.0.1 =
|
256 |
+
Release date: December 31st, 2013
|
257 |
+
|
258 |
+
* Behavior Change: Notify multisite users when settings may be overridden by the network settings and vice versa.
|
259 |
+
* Bug fix: Updated tab style to match WordPress 3.8 look and feel.
|
260 |
+
* Bug fix: Fixed issue where `bcn_breadcrumb_trail::display_list()` would produce multiple instances of the class attribute.
|
261 |
+
* Bug fix: Fixed several issues with the uninstaller.
|
262 |
+
|
263 |
+
= 5.0.0 =
|
264 |
+
Release date: November 20th, 2013
|
265 |
+
|
266 |
+
* Behavior Change: Moved `bcn_breadcrumb_trail::trail` to `bcn_breadcrumb_trail::breadcrumbs`
|
267 |
+
* Behavior Change: When WordPress is in multisite/network mode, the settings set in the network settings page take priority over subsite settings.
|
268 |
+
* New feature: Added `bcn_breadcrumb_trail_object` filter.
|
269 |
+
* New feature: Added `bcn_li_attributes` filter.
|
270 |
+
* New feature: Added `bcn_breadcrumb_types` filter.
|
271 |
+
* New feature: Added Network Admin Settings page.
|
272 |
+
* New feature: Added `xmlns:v` and `property` to the valid tag attributes.
|
273 |
+
* Bug fix: The current_item breadcrumb for search results should result in a valid HTTPS link when appropriate.
|
274 |
+
|
275 |
+
== Upgrade Notice ==
|
276 |
+
= 6.0.0 =
|
277 |
+
This version requires PHP5.3 or newer. This version introduces three new filters and deprecates a filter.
|
278 |
+
|
279 |
+
= 5.6.0 =
|
280 |
This version requires PHP5.3 or newer. This version introduces a new 4th optional parameter to `bcn_display()` and `bcn_display_list()` that bypasses the internal caching mechanism.
|
uninstall.php
CHANGED
@@ -1,124 +1,124 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Breadcrumb NavXT - uninstall script
|
4 |
-
*
|
5 |
-
* uninstall script based on WordPress Uninstall Plugin API
|
6 |
-
*
|
7 |
-
*
|
8 |
-
* Because bcn_admin->uninstall() does not work with WPMU,
|
9 |
-
* an uninstaller class has been written, that encapsulates
|
10 |
-
* the uninstall logic and calls bcn_admin->uninstall()
|
11 |
-
* when applicable.
|
12 |
-
*
|
13 |
-
* @see http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7#Uninstall_Plugin_API
|
14 |
-
* @see http://trac.mu.wordpress.org/ticket/967
|
15 |
-
*
|
16 |
-
* this uninstall.php file was executed multiple times because
|
17 |
-
* breadcrumb navxt (until 3.3) constsisted of two plugins:
|
18 |
-
*
|
19 |
-
* 1.) breadcrumb_navxt_class.php / Core
|
20 |
-
* 2.) breadcrumb_navxt_admin.php / Adminstration Interface
|
21 |
-
*
|
22 |
-
* @author Tom Klingenberg
|
23 |
-
*/
|
24 |
-
/*
|
25 |
-
Copyright 2010-2018 John Havlik (email : john.havlik@mtekk.us)
|
26 |
-
|
27 |
-
This program is free software; you can redistribute it and/or modify
|
28 |
-
it under the terms of the GNU General Public License as published by
|
29 |
-
the Free Software Foundation; either version 2 of the License, or
|
30 |
-
(at your option) any later version.
|
31 |
-
|
32 |
-
This program is distributed in the hope that it will be useful,
|
33 |
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
34 |
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
35 |
-
GNU General Public License for more details.
|
36 |
-
|
37 |
-
You should have received a copy of the GNU General Public License
|
38 |
-
along with this program; if not, write to the Free Software
|
39 |
-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
40 |
-
*/
|
41 |
-
//Ensure the uninstall.php file was only called by WordPress and not directly
|
42 |
-
if(!defined('WP_UNINSTALL_PLUGIN'))
|
43 |
-
{
|
44 |
-
//First catches the Apache users
|
45 |
-
header("HTTP/1.0 404 Not Found");
|
46 |
-
//This should catch FastCGI users
|
47 |
-
header("Status: 404 Not Found");
|
48 |
-
die();
|
49 |
-
}
|
50 |
-
require_once(dirname(__FILE__) . '/includes/class.mtekk_adminkit_uninstaller.php');
|
51 |
-
|
52 |
-
/**
|
53 |
-
* Breadcrumb NavXT uninstaller class
|
54 |
-
*
|
55 |
-
* @author Tom Klingenberg
|
56 |
-
*/
|
57 |
-
class bcn_uninstaller extends mtekk_adminKit_uninstaller
|
58 |
-
{
|
59 |
-
protected $unique_prefix = 'bcn';
|
60 |
-
protected $plugin_basename = null;
|
61 |
-
|
62 |
-
public function __construct()
|
63 |
-
{
|
64 |
-
$this->plugin_basename = plugin_basename('/breadcrumb-navxt.php');
|
65 |
-
parent::__construct();
|
66 |
-
}
|
67 |
-
/**
|
68 |
-
* Options uninstallation function for legacy
|
69 |
-
*/
|
70 |
-
private function uninstall_legacy()
|
71 |
-
{
|
72 |
-
delete_option($this->unique_prefix . '_options');
|
73 |
-
delete_option($this->unique_prefix . '_options_bk');
|
74 |
-
delete_option($this->unique_prefix . '_version');
|
75 |
-
delete_site_option($this->unique_prefix . '_options');
|
76 |
-
delete_site_option($this->unique_prefix . '_options_bk');
|
77 |
-
delete_site_option($this->unique_prefix . '_version');
|
78 |
-
}
|
79 |
-
/**
|
80 |
-
* uninstall breadcrumb navxt admin plugin
|
81 |
-
*
|
82 |
-
* @return bool
|
83 |
-
*/
|
84 |
-
private function uninstall_options()
|
85 |
-
{
|
86 |
-
if(version_compare(phpversion(), '5.3.0', '<'))
|
87 |
-
{
|
88 |
-
return $this->uninstall_legacy();
|
89 |
-
}
|
90 |
-
//Grab our global breadcrumb_navxt object
|
91 |
-
global $breadcrumb_navxt;
|
92 |
-
//Load dependencies if applicable
|
93 |
-
if(!class_exists('breadcrumb_navxt'))
|
94 |
-
{
|
95 |
-
require_once($this->_get_plugin_path());
|
96 |
-
}
|
97 |
-
//Initalize $breadcrumb_navxt so we can use it
|
98 |
-
$bcn_breadcrumb_trail = new bcn_breadcrumb_trail();
|
99 |
-
//Let's make an instance of our object takes care of everything
|
100 |
-
$breadcrumb_navxt = new breadcrumb_navxt($bcn_breadcrumb_trail);
|
101 |
-
//Uninstall
|
102 |
-
return $breadcrumb_navxt->uninstall();
|
103 |
-
}
|
104 |
-
|
105 |
-
/**
|
106 |
-
* uninstall method
|
107 |
-
*
|
108 |
-
* @return bool wether or not uninstall did run successfull.
|
109 |
-
*/
|
110 |
-
public function uninstall()
|
111 |
-
{
|
112 |
-
//Only bother to do things if we have something in the database
|
113 |
-
if($this->is_installed())
|
114 |
-
{
|
115 |
-
return $this->uninstall_options();
|
116 |
-
}
|
117 |
-
}
|
118 |
-
|
119 |
-
} /// class bcn_uninstaller
|
120 |
-
|
121 |
-
/*
|
122 |
-
* main
|
123 |
-
*/
|
124 |
new bcn_uninstaller();
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Breadcrumb NavXT - uninstall script
|
4 |
+
*
|
5 |
+
* uninstall script based on WordPress Uninstall Plugin API
|
6 |
+
*
|
7 |
+
*
|
8 |
+
* Because bcn_admin->uninstall() does not work with WPMU,
|
9 |
+
* an uninstaller class has been written, that encapsulates
|
10 |
+
* the uninstall logic and calls bcn_admin->uninstall()
|
11 |
+
* when applicable.
|
12 |
+
*
|
13 |
+
* @see http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.7#Uninstall_Plugin_API
|
14 |
+
* @see http://trac.mu.wordpress.org/ticket/967
|
15 |
+
*
|
16 |
+
* this uninstall.php file was executed multiple times because
|
17 |
+
* breadcrumb navxt (until 3.3) constsisted of two plugins:
|
18 |
+
*
|
19 |
+
* 1.) breadcrumb_navxt_class.php / Core
|
20 |
+
* 2.) breadcrumb_navxt_admin.php / Adminstration Interface
|
21 |
+
*
|
22 |
+
* @author Tom Klingenberg
|
23 |
+
*/
|
24 |
+
/*
|
25 |
+
Copyright 2010-2018 John Havlik (email : john.havlik@mtekk.us)
|
26 |
+
|
27 |
+
This program is free software; you can redistribute it and/or modify
|
28 |
+
it under the terms of the GNU General Public License as published by
|
29 |
+
the Free Software Foundation; either version 2 of the License, or
|
30 |
+
(at your option) any later version.
|
31 |
+
|
32 |
+
This program is distributed in the hope that it will be useful,
|
33 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
34 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
35 |
+
GNU General Public License for more details.
|
36 |
+
|
37 |
+
You should have received a copy of the GNU General Public License
|
38 |
+
along with this program; if not, write to the Free Software
|
39 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
40 |
+
*/
|
41 |
+
//Ensure the uninstall.php file was only called by WordPress and not directly
|
42 |
+
if(!defined('WP_UNINSTALL_PLUGIN'))
|
43 |
+
{
|
44 |
+
//First catches the Apache users
|
45 |
+
header("HTTP/1.0 404 Not Found");
|
46 |
+
//This should catch FastCGI users
|
47 |
+
header("Status: 404 Not Found");
|
48 |
+
die();
|
49 |
+
}
|
50 |
+
require_once(dirname(__FILE__) . '/includes/class.mtekk_adminkit_uninstaller.php');
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Breadcrumb NavXT uninstaller class
|
54 |
+
*
|
55 |
+
* @author Tom Klingenberg
|
56 |
+
*/
|
57 |
+
class bcn_uninstaller extends mtekk_adminKit_uninstaller
|
58 |
+
{
|
59 |
+
protected $unique_prefix = 'bcn';
|
60 |
+
protected $plugin_basename = null;
|
61 |
+
|
62 |
+
public function __construct()
|
63 |
+
{
|
64 |
+
$this->plugin_basename = plugin_basename('/breadcrumb-navxt.php');
|
65 |
+
parent::__construct();
|
66 |
+
}
|
67 |
+
/**
|
68 |
+
* Options uninstallation function for legacy
|
69 |
+
*/
|
70 |
+
private function uninstall_legacy()
|
71 |
+
{
|
72 |
+
delete_option($this->unique_prefix . '_options');
|
73 |
+
delete_option($this->unique_prefix . '_options_bk');
|
74 |
+
delete_option($this->unique_prefix . '_version');
|
75 |
+
delete_site_option($this->unique_prefix . '_options');
|
76 |
+
delete_site_option($this->unique_prefix . '_options_bk');
|
77 |
+
delete_site_option($this->unique_prefix . '_version');
|
78 |
+
}
|
79 |
+
/**
|
80 |
+
* uninstall breadcrumb navxt admin plugin
|
81 |
+
*
|
82 |
+
* @return bool
|
83 |
+
*/
|
84 |
+
private function uninstall_options()
|
85 |
+
{
|
86 |
+
if(version_compare(phpversion(), '5.3.0', '<'))
|
87 |
+
{
|
88 |
+
return $this->uninstall_legacy();
|
89 |
+
}
|
90 |
+
//Grab our global breadcrumb_navxt object
|
91 |
+
global $breadcrumb_navxt;
|
92 |
+
//Load dependencies if applicable
|
93 |
+
if(!class_exists('breadcrumb_navxt'))
|
94 |
+
{
|
95 |
+
require_once($this->_get_plugin_path());
|
96 |
+
}
|
97 |
+
//Initalize $breadcrumb_navxt so we can use it
|
98 |
+
$bcn_breadcrumb_trail = new bcn_breadcrumb_trail();
|
99 |
+
//Let's make an instance of our object takes care of everything
|
100 |
+
$breadcrumb_navxt = new breadcrumb_navxt($bcn_breadcrumb_trail);
|
101 |
+
//Uninstall
|
102 |
+
return $breadcrumb_navxt->uninstall();
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* uninstall method
|
107 |
+
*
|
108 |
+
* @return bool wether or not uninstall did run successfull.
|
109 |
+
*/
|
110 |
+
public function uninstall()
|
111 |
+
{
|
112 |
+
//Only bother to do things if we have something in the database
|
113 |
+
if($this->is_installed())
|
114 |
+
{
|
115 |
+
return $this->uninstall_options();
|
116 |
+
}
|
117 |
+
}
|
118 |
+
|
119 |
+
} /// class bcn_uninstaller
|
120 |
+
|
121 |
+
/*
|
122 |
+
* main
|
123 |
+
*/
|
124 |
new bcn_uninstaller();
|