|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Carbon_Fields\Walker; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Walker for the administration nav menu editing. |
|
7
|
|
|
* |
|
8
|
|
|
* @uses Walker_Nav_Menu_Edit |
|
9
|
|
|
*/ |
|
10
|
|
|
class Nav_Menu_Edit_Walker extends \Walker_Nav_Menu_Edit { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Start the element output. |
|
14
|
|
|
* |
|
15
|
|
|
* @param string $output Passed by reference. Used to append additional content. |
|
16
|
|
|
* @param object $item Menu item data object. |
|
17
|
|
|
* @param int $depth Depth of menu item. Used for padding. |
|
18
|
|
|
* @param array $args An array of arguments. @see wp_nav_menu() |
|
19
|
|
|
* @param int $id Current item ID. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { |
|
22
|
|
|
parent::start_el( $output, $item, $depth, $args, $id ); |
|
23
|
|
|
|
|
24
|
|
|
$flag = '<!--CarbonFields-->'; |
|
25
|
|
|
|
|
26
|
|
|
// Generates the HTML |
|
27
|
|
|
ob_start(); |
|
28
|
|
|
do_action( 'crb_print_carbon_container_nav_menu_fields_html', $item, $output, $depth, $args, $id ); |
|
29
|
|
|
echo $flag; |
|
|
|
|
|
|
30
|
|
|
$fields = ob_get_clean(); |
|
31
|
|
|
|
|
32
|
|
|
// List of possible insertion markers, this may vary between WP Core versions |
|
33
|
|
|
$markers = array( |
|
34
|
|
|
# WordPress < 4.7 |
|
35
|
|
|
preg_quote( '<p class="field-move hide-if-no-js description description-wide">' ), |
|
36
|
|
|
# WordPress 4.7 |
|
37
|
|
|
preg_quote( '<fieldset class="field-move hide-if-no-js description description-wide">' ), |
|
38
|
|
|
); |
|
39
|
|
|
|
|
40
|
|
|
// Build the regex |
|
41
|
|
|
$regex = sprintf( |
|
42
|
|
|
'~(?<!%s)(%s)~', |
|
43
|
|
|
preg_quote( $flag, '~' ), |
|
44
|
|
|
implode( '|', $markers) |
|
|
|
|
|
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
// Injects the HTML |
|
48
|
|
|
$output = preg_replace( $regex, $fields . "$1", $output ); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|