forked from setola/Wordpress-Theme-Utils-Classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveSpacesWalkerNavMenu.class.php
81 lines (75 loc) · 2.33 KB
/
RemoveSpacesWalkerNavMenu.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
77
78
79
80
81
<?php
/**
* contains RemoveSpacesWalkerNavMenu class definition
*/
/**
* Remove spaces and newlines from the current menu.
* This is very useful if you want to style a menu with:
* <code>display: inline-block;
* text-align: center;</code>
* @author etessore
* @version 1.0.0
* @package classes
*/
class RemoveSpacesWalkerNavMenu extends Walker_Nav_Menu {
/**
* @var array key valuse pair of replacements
*/
public $replacements = array("\n"=>'', "\t"=>'');
/**
* (non-PHPdoc)
* @see Walker_Nav_Menu::start_lvl()
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of page. Used for padding.
*/
public function start_lvl(&$output, $depth){
parent::start_lvl(&$output, $depth);
$this->remove_unwanted_chars(&$output);
}
/**
* (non-PHPdoc)
* @see Walker_Nav_Menu::end_lvl()
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of page. Used for padding.
*/
public function end_lvl(&$output, $depth){
parent::end_lvl(&$output, $depth);
$this->remove_unwanted_chars(&$output);
}
/**
* (non-PHPdoc)
* @see Walker_Nav_Menu::end_el()
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
*/
public function end_el(&$output, $item, $depth){
parent::end_el(&$output, $item, $depth);
$this->remove_unwanted_chars(&$output);
}
/**
* (non-PHPdoc)
* @see Walker_Nav_Menu::start_el()
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param object $args other arguments
*/
public function start_el(&$output, $item, $depth, $args){
parent::start_el(&$output, $item, $depth, $args);
$this->remove_unwanted_chars(&$output);
}
/**
* Removew the unwanted charactes from the given string
* @param string $str the string to be escaped
* @return string the escaped string
*/
private function remove_unwanted_chars(&$str){
$str = str_replace(
array_keys($this->replacements),
array_values($this->replacements),
&$str
);
return $str;
}
}