Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
Tz Tools
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
2ea55b3d
authored
2010-10-21 21:45:19 +0000
by
Chris Boden
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Added some wp function and Menu component
1 parent
2c940cfa
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
0 deletions
com/Menu/Menu.php
wp_functions.php
com/Menu/Menu.php
0 → 100644
View file @
2ea55b3
<?php
namespace
Tz\WordPress\Tools\Menu
;
use
Exception
,
Countable
,
Iterator
;
function
get_nav_menu
(
$location
)
{
$locations
=
get_nav_menu_locations
();
if
(
!
isset
(
$locations
[
$location
]))
{
throw
new
Exception
(
"
{
$location
}
is not a defined menu location"
);
}
$menu_location
=
_get_nav_menu_object
(
$locations
[
$location
])
->
slug
;
$menu
=
_get_nav_menu_items
(
$menu_location
);
_wp_menu_item_classes_by_context
(
$menu
);
return
$menu
;
}
class
HierarchicalMenu
implements
Countable
,
Iterator
{
private
$contents
=
Array
();
private
$current
=
0
;
private
$id_lookup
=
Array
();
private
$target_lookup
=
Array
();
public
function
__construct
(
Array
$menu
,
$parent
=
0
)
{
$i
=
0
;
$last_id
=
-
1
;
foreach
(
$menu
as
$key
=>
$item
)
{
$item
->
_children
=
false
;
if
(
$item
->
menu_item_parent
==
$parent
)
{
$this
->
contents
[
$i
]
=
$item
;
$this
->
id_lookup
[
$item
->
ID
]
=
$i
;
$this
->
target_lookup
[
$item
->
object_id
]
=
$i
;
$i
++
;
$last_id
=
$item
->
ID
;
}
elseif
(
$item
->
menu_item_parent
==
$last_id
)
{
$this
->
contents
[
$this
->
id_lookup
[
$last_id
]]
->
_children
=
true
;
}
}
foreach
(
$this
->
contents
as
$key
=>
$item
)
{
if
(
true
===
$item
->
_children
)
{
$item
->
HierarchicalMenu
=
new
HierarchicalMenu
(
$menu
,
$item
->
ID
);
}
unset
(
$this
->
contents
[
$key
]
->
_children
);
}
}
public
function
count
()
{
return
count
(
$this
->
contents
);
}
public
function
current
()
{
return
$this
->
contents
[
$this
->
current
];
}
public
function
key
()
{
return
$this
->
current
;
}
public
function
next
()
{
$this
->
current
++
;
}
public
function
rewind
()
{
$this
->
rewind
=
0
;
}
public
function
valid
()
{
return
(
isset
(
$this
->
contents
[
$this
->
current
])
?
true
:
false
);
}
public
function
getItemByID
(
$id
)
{
return
$this
->
id_lookup
[
$id
]
?:
false
;
}
public
function
getItemByTarget
(
$id
)
{
return
$this
->
target_lookup
[
$id
]
?:
false
;
}
}
?>
\ No newline at end of file
wp_functions.php
View file @
2ea55b3
...
...
@@ -180,4 +180,19 @@ function _nav_menu() {
$params
=
func_get_args
();
return
call_user_func_array
(
'wp'
.
__FUNCTION__
,
$params
);
}
function
_get_nav_menu_object
()
{
$params
=
func_get_args
();
return
call_user_func_array
(
'wp'
.
__FUNCTION__
,
$params
);
}
function
_get_nav_menu_items
()
{
$params
=
func_get_args
();
return
call_user_func_array
(
'wp'
.
__FUNCTION__
,
$params
);
}
function
_reset_postdata
()
{
$params
=
func_get_args
();
return
call_user_func_array
(
'wp'
.
__FUNCTION__
,
$params
);
}
?>
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment