-
Notifications
You must be signed in to change notification settings - Fork 3
/
bp-event-organiser-walker.php
156 lines (109 loc) · 4.06 KB
/
bp-event-organiser-walker.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php /*
--------------------------------------------------------------------------------
Walker Classes
Kudos to the fantastic Group Organiser plugin for the code framework
--------------------------------------------------------------------------------
*/
/**
* Amend Walker to include parent field
*/
class Walker_BPEO extends Walker {
// update db fields
var $db_fields = array(
'parent' => 'parent_id',
'id' => 'id'
);
}
/**
* Create HTML list of items with checkboxes.
*/
class Walker_BPEO_Group extends Walker_BPEO {
/**
* @see Walker_Nav_Menu::start_lvl()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
function start_lvl( &$output, $depth = 0, $args = array() ) {}
/**
* @see Walker_Nav_Menu::end_lvl()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
function end_lvl( &$output, $depth = 0, $args = array() ) {
}
/**
* @see Walker::start_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param WP_Post $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
* @param int $id Current item ID.
*/
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
// if the user is not an admin
if ( !is_super_admin() OR !current_user_can( 'manage_options' ) ) {
// if not a public group
if ( isset( $item->status ) AND 'public' != $item->status ) {
// kick out if not member
if ( !bp_group_is_member( $item ) ) return;
}
}
// allow plugins to reject an item by returning boolean true
$override = apply_filters( 'bp_event_organiser_reject_item', false, $item );
// did we get a response?
if ( $override ) return;
// start buffer
ob_start();
// sanitise ID
$item_id = esc_attr( $item->id );
// define classes
$classes = array(
'menu-item menu-item-depth-' . $depth
);
// get title
$title = $item->name;
// update title based on ststus
if ( isset( $item->status ) && 'private' == $item->status ) {
$classes[] = 'status-private';
/* translators: %s: title of private group */
$title = sprintf( __( '%s (Private)', 'bp-event-organizer' ), $title );
} elseif ( isset( $item->status ) && 'hidden' == $item->status ) {
$classes[] = 'status-hidden';
/* translators: %s: title of hidden group */
$title = sprintf( __('%s (Hidden)', 'bp-event-organizer' ), $title );
}
// init checked
$checked = '';
// access array of group IDs for this event
$groups_for_this_event = bp_event_organiser_get_group_ids();
//print_r( $groups_for_this_event ); die();
// is this item checked?
if ( in_array( $item->id, $groups_for_this_event ) ) {
// override checked
$checked = ' checked="checked"';
}
// create markup
?>
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>">
<span class="item-title"><input type="checkbox" value="<?php echo $item_id ?>" id="bp-group-organizer-group-<?php echo $item_id ?>" name="bp_group_organizer_groups[]"<?php echo $checked; ?> /> <label for="bp-group-organizer-group-<?php echo $item_id ?>"><?php echo esc_html( stripslashes( $title ) ); ?></label></span>
<?php
// collapse buffer into output
$output .= ob_get_clean();
}
} // class ends
/**
* @description: a modified clone of the walk_group_tree function from Group Organiser
*/
function bp_event_organiser_walk_group_tree( $items, $depth, $r ) {
$walker = ( empty($r->walker) ) ? new Walker_BPEO : $r->walker;
$args = array( $items, $depth, $r );
return call_user_func_array( array(&$walker, 'walk'), $args );
}