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
|
|
|
preg_quote( '<p class="field-move hide-if-no-js description description-wide">' ), |
35
|
|
|
preg_quote( '<fieldset class="field-move hide-if-no-js description description-wide">' ), |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
// Build the regex |
39
|
|
|
$regex = sprintf( |
40
|
|
|
'~(?<!%s)(%s)~', |
41
|
|
|
preg_quote( $flag, '~' ), |
42
|
|
|
implode( '|', $markers) |
|
|
|
|
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
// Injects the HTML |
46
|
|
|
$output = preg_replace( $regex, $fields . "$1", $output ); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
} |
50
|
|
|
|