-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSocial_Walker_Nav_Menu.php
73 lines (59 loc) · 1.95 KB
/
Social_Walker_Nav_Menu.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
<?php
class Social_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
$item_output = '<a'
. $this->build_link_class( $item, $args )
. $this->build_link_attributes( $item )
. '><i class="fa fa-fw fa-'
. $this->build_social_icon_name( $item )
. '"></i><span'
. $this->build_text_class( $item, $args )
. '>'
. apply_filters( 'the_title', $item->title, $item->ID );
$output .= apply_filters(
'walker_nav_menu_start_el',
$item_output,
$item,
$depth,
$args
);
}
private function build_link_class( $item, $args ) {
if ( ! empty ( $args->social_link_class ) ) {
return ' class="' . esc_attr( $args->social_link_class ) . '"';
}
return "";
}
private function build_link_attributes( $item ) {
$attributes = '';
! empty( $item->target )
and $attributes .= ' target="' . esc_attr( $item->target ) .'"';
! empty( $item->url )
and $attributes .= ' href="' . esc_attr( $item->url ) .'"';
return $attributes;
}
private function build_social_icon_name( $item ) {
$matches = [];
preg_match(
'#\/\/[\w\d\.]*?([\w\d]+)\.[\w\d]+\/#',
$item->url,
$matches
);
return strtolower( $matches[1] );
}
private function build_text_class( $item, $args ) {
if ( ! empty ( $args->social_text_class ) ) {
return ' class="' . esc_attr( $args->social_text_class ) . '"';
}
return "";
}
function end_el( &$output, $item, $depth = 0, $args = array() ) {
$output .= apply_filters(
'walker_nav_menu_end_el',
'</span></a>',
$item,
$depth,
$args
);
}
}