Completed
Pull Request — master (#151)
by
unknown
02:10
created

Nav_Menu_Edit_Walker   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 40
rs 10
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B start_el() 0 27 1
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;
1 ignored issue
show
introduced by
Expected next thing to be a escaping function, not '$flag'
Loading history...
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)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
43
		);
44
45
		// Injects the HTML
46
		$output = preg_replace( $regex, $fields . "$1", $output );
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal $1 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
47
	}
48
49
}
50