template-tags.php ➔ bp_nouveau_pagination()   F
last analyzed

Complexity

Conditions 18
Paths 704

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 114
Code Lines 74

Importance

Changes 0
Metric Value
cc 18
eloc 74
nc 704
nop 1
dl 0
loc 114
rs 2.3577
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Common template tags
4
 *
5
 * @since 3.0.0
6
 * @version 3.1.0
7
 */
8
9
// Exit if accessed directly.
10
defined( 'ABSPATH' ) || exit;
11
12
/**
13
 * Fire specific hooks at various places of templates
14
 *
15
 * @since 3.0.0
16
 *
17
 * @param array $pieces The list of terms of the hook to join.
18
 */
19
function bp_nouveau_hook( $pieces = array() ) {
20
	if ( ! $pieces ) {
0 ignored issues
show
Bug Best Practice introduced by Hugo Ashmore
The expression $pieces of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
21
		return;
22
	}
23
24
	$bp_prefix = reset( $pieces );
25
	if ( 'bp' !== $bp_prefix ) {
26
		array_unshift( $pieces, 'bp' );
27
	}
28
29
	$hook = join( '_', $pieces );
30
31
	/**
32
	 * Fires inside the `bp_nouveau_hook()` function.
33
	 *
34
	 * @since 3.0.0
35
	 */
36
	do_action( $hook );
37
}
38
39
/**
40
 * Fire plugin hooks in the plugins.php template (Groups and Members single items)
41
 *
42
 * @since 3.0.0
43
 *
44
 * @param string The suffix of the hook.
45
 */
46
function bp_nouveau_plugin_hook( $suffix = '' ) {
47
	if ( ! $suffix ) {
48
		return;
49
	}
50
51
	bp_nouveau_hook(
52
		array(
53
			'bp',
54
			'template',
55
			$suffix,
56
		)
57
	);
58
}
59
60
/**
61
 * Fire friend hooks
62
 *
63
 * @todo Move this into bp-nouveau/includes/friends/template-tags.php
64
 *       once we'll need other friends template tags.
65
 *
66
 * @since 3.0.0
67
 *
68
 * @param string The suffix of the hook.
69
 */
70
function bp_nouveau_friend_hook( $suffix = '' ) {
71
	if ( ! $suffix ) {
72
		return;
73
	}
74
75
	bp_nouveau_hook(
76
		array(
77
			'bp',
78
			'friend',
79
			$suffix,
80
		)
81
	);
82
}
83
84
/**
85
 * Add classes to style the template notice/feedback message
86
 *
87
 * @since 3.0.0
88
 */
89
function bp_nouveau_template_message_classes() {
90
	$classes = array( 'bp-feedback', 'bp-messages' );
91
92
	if ( ! empty( bp_nouveau()->template_message['message'] ) ) {
93
		$classes[] = 'bp-template-notice';
94
	}
95
96
	$classes[] = bp_nouveau_get_template_message_type();
97
	echo join( ' ', array_map( 'sanitize_html_class', $classes ) );
98
}
99
100
	/**
101
	 * Get the template notice/feedback message type
102
	 *
103
	 * @since 3.0.0
104
	 *
105
	 * @return string The type of the notice. Defaults to error.
106
	 */
107
	function bp_nouveau_get_template_message_type() {
108
		$bp_nouveau = bp_nouveau();
109
		$type       = 'error';
110
111
		if ( ! empty( $bp_nouveau->template_message['type'] ) ) {
112
			$type = $bp_nouveau->template_message['type'];
113
		} elseif ( ! empty( $bp_nouveau->user_feedback['type'] ) ) {
114
			$type = $bp_nouveau->user_feedback['type'];
115
		}
116
117
		return $type;
118
	}
119
120
/**
121
 * Checks if a template notice/feedback message is set
122
 *
123
 * @since 3.0.0
124
 *
125
 * @return bool True if a template notice is set. False otherwise.
126
 */
127
function bp_nouveau_has_template_message() {
128
	$bp_nouveau = bp_nouveau();
129
130
	if ( empty( $bp_nouveau->template_message['message'] ) && empty( $bp_nouveau->user_feedback ) ) {
0 ignored issues
show
Unused Code introduced by Hugo Ashmore
This if statement, and the following return statement can be replaced with return !(empty($bp_nouve...uveau->user_feedback));.
Loading history...
131
		return false;
132
	}
133
134
	return true;
135
}
136
137
/**
138
 * Checks if the template notice/feedback message needs a dismiss button
139
 *
140
 * @todo Dismiss button re-worked to try and prevent buttons on general
141
 *       BP template notices - Nouveau user_feedback key needs review.
142
 *
143
 * @since 3.0.0
144
 *
145
 * @return bool True if a template notice needs a dismiss button. False otherwise.
146
 */
147
function bp_nouveau_has_dismiss_button() {
148
	$bp_nouveau = bp_nouveau();
149
150
	// BP template notices - set 'dismiss' true for a type in `bp_nouveau_template_notices()`
151
	if ( ! empty( $bp_nouveau->template_message['message'] ) && true === $bp_nouveau->template_message['dismiss'] ) {
152
		return true;
153
	}
154
155
	// Test for isset as value can be falsey.
156
	if ( isset( $bp_nouveau->user_feedback['dismiss'] ) ) {
0 ignored issues
show
Unused Code introduced by Hugo Ashmore
This if statement, and the following return statement can be replaced with return isset($bp_nouveau...r_feedback['dismiss']);.
Loading history...
157
		return true;
158
	}
159
160
	return false;
161
}
162
163
/**
164
 * Ouptut the dismiss type.
165
 *
166
 * $type is used to set the data-attr for the button.
167
 * 'clear' is tested for & used to remove cookies, if set, in buddypress-nouveau.js.
168
 * Currently template_notices(BP) will take $type = 'clear' if button set to true.
169
 *
170
 * @since 3.0.0
171
 */
172
function bp_nouveau_dismiss_button_type() {
173
	$bp_nouveau = bp_nouveau();
174
	$type       = 'clear';
175
176
	if ( ! empty( $bp_nouveau->user_feedback['dismiss'] ) ) {
177
		$type = $bp_nouveau->user_feedback['dismiss'];
178
	}
179
180
	echo esc_attr( $type );
181
}
182
183
/**
184
 * Displays a template notice/feedback message.
185
 *
186
 * @since 3.0.0
187
 */
188
function bp_nouveau_template_message() {
189
	echo bp_nouveau_get_template_message();
190
}
191
192
	/**
193
	 * Get the template notice/feedback message and make sure core filter is applied.
194
	 *
195
	 * @since 3.0.0
196
	 *
197
	 * @return string HTML Output.
198
	 */
199
	function bp_nouveau_get_template_message() {
200
		$bp_nouveau = bp_nouveau();
201
202
		if ( ! empty( $bp_nouveau->user_feedback['message'] ) ) {
203
			$user_feedback = $bp_nouveau->user_feedback['message'];
204
205
			// @TODO: why is this treated differently?
206
			foreach ( array( 'wp_kses_data', 'wp_unslash', 'wptexturize', 'convert_smilies', 'convert_chars' ) as $filter ) {
207
				$user_feedback = call_user_func( $filter, $user_feedback );
208
			}
209
210
			return '<p>' . $user_feedback . '</p>';
211
212
		} elseif ( ! empty( $bp_nouveau->template_message['message'] ) ) {
213
			/**
214
			 * Filters the 'template_notices' feedback message content.
215
			 *
216
			 * @since 1.5.5
217
			 *
218
			 * @param string $template_message Feedback message content.
219
			 * @param string $type             The type of message being displayed.
220
			 *                                 Either 'updated' or 'error'.
221
			 */
222
			return apply_filters( 'bp_core_render_message_content', $bp_nouveau->template_message['message'], bp_nouveau_get_template_message_type() );
223
		}
224
	}
225
226
/**
227
 * Template tag to display feedback notices to users, if there are to display
228
 *
229
 * @since 3.0.0
230
 */
231
function bp_nouveau_template_notices() {
232
	$bp         = buddypress();
233
	$bp_nouveau = bp_nouveau();
234
235
	if ( ! empty( $bp->template_message ) ) {
236
		// Clone BuddyPress template message to avoid altering it.
237
		$template_message = array( 'message' => $bp->template_message );
238
239
		if ( ! empty( $bp->template_message_type ) ) {
240
			$template_message['type'] = $bp->template_message_type;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property template_message_type does not exist on object<BuddyPress>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
241
		}
242
243
		// Adds a 'dimiss' (button) key to array - set true/false.
244
		$template_message['dismiss'] = false;
245
246
		// Set dismiss button true for sitewide notices
247
		if ( 'bp-sitewide-notice' == $template_message['type'] ) {
248
			$template_message['dismiss'] = true;
249
		}
250
251
		$bp_nouveau->template_message = $template_message;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property template_message does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
252
		bp_get_template_part( 'common/notices/template-notices' );
253
254
		// Reset just after rendering it.
255
		$bp_nouveau->template_message = array();
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property template_message does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
256
257
		/**
258
		 * Fires after the display of any template_notices feedback messages.
259
		 *
260
		 * @since 3.0.0
261
		 */
262
		do_action( 'bp_core_render_message' );
263
	}
264
265
	/**
266
	 * Fires towards the top of template pages for notice display.
267
	 *
268
	 * @since 3.0.0
269
	 */
270
	do_action( 'template_notices' );
271
}
272
273
/**
274
 * Displays a feedback message to the user.
275
 *
276
 * @since 3.0.0
277
 *
278
 * @param string $feedback_id The ID of the message to display
279
 */
280
function bp_nouveau_user_feedback( $feedback_id = '' ) {
281
	if ( ! isset( $feedback_id ) ) {
282
		return;
283
	}
284
285
	$bp_nouveau = bp_nouveau();
286
	$feedback   = bp_nouveau_get_user_feedback( $feedback_id );
287
288
	if ( ! $feedback ) {
0 ignored issues
show
Bug Best Practice introduced by Hugo Ashmore
The expression $feedback of type string|false is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
289
		return;
290
	}
291
292
	if ( ! empty( $feedback['before'] ) ) {
293
294
		/**
295
		 * Fires before display of a feedback message to the user.
296
		 *
297
		 * This is a dynamic filter that is dependent on the "before" value provided by bp_nouveau_get_user_feedback().
298
		 *
299
		 * @since 3.0.0
300
		 */
301
		do_action( $feedback['before'] );
302
	}
303
304
	$bp_nouveau->user_feedback = $feedback;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property user_feedback does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
305
306
	bp_get_template_part(
307
308
		/**
309
		 * Filter here if you wish to use a different templates than the notice one.
310
		 *
311
		 * @since 3.0.0
312
		 *
313
		 * @param string path to your template part.
314
		 */
315
		apply_filters( 'bp_nouveau_user_feedback_template', 'common/notices/template-notices' )
316
	);
317
318
	if ( ! empty( $feedback['after'] ) ) {
319
320
		/**
321
		 * Fires before display of a feedback message to the user.
322
		 *
323
		 * This is a dynamic filter that is dependent on the "after" value provided by bp_nouveau_get_user_feedback().
324
		 *
325
		 * @since 3.0.0
326
		 */
327
		do_action( $feedback['after'] );
328
	}
329
330
	// Reset the feedback message.
331
	$bp_nouveau->user_feedback = array();
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property user_feedback does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
332
}
333
334
/**
335
 * Template tag to wrap the before component loop
336
 *
337
 * @since 3.0.0
338
 */
339 View Code Duplication
function bp_nouveau_before_loop() {
340
	$component = bp_current_component();
341
342
	if ( bp_is_group() ) {
343
		$component = bp_current_action();
344
	}
345
346
	/**
347
	 * Fires before the start of the component loop.
348
	 *
349
	 * This is a variable hook that is dependent on the current component.
350
	 *
351
	 * @since 1.2.0
352
	 */
353
	do_action( "bp_before_{$component}_loop" );
354
}
355
356
/**
357
 * Template tag to wrap the after component loop
358
 *
359
 * @since 3.0.0
360
 */
361 View Code Duplication
function bp_nouveau_after_loop() {
362
	$component = bp_current_component();
363
364
	if ( bp_is_group() ) {
365
		$component = bp_current_action();
366
	}
367
368
	/**
369
	 * Fires after the finish of the component loop.
370
	 *
371
	 * This is a variable hook that is dependent on the current component.
372
	 *
373
	 * @since 1.2.0
374
	 */
375
	do_action( "bp_after_{$component}_loop" );
376
}
377
378
/**
379
 * Pagination for loops
380
 *
381
 * @param string $position
382
 *
383
 * @since 3.0.0
384
 */
385
function bp_nouveau_pagination( $position ) {
386
	$screen          = 'dir';
387
	$pagination_type = bp_current_component();
388
389
	if ( bp_is_user() ) {
390
		$screen = 'user';
391
392
	} elseif ( bp_is_group() ) {
393
		$screen          = 'group';
394
		$pagination_type = bp_current_action();
395
396
		if ( bp_is_group_admin_page() ) {
397
			$pagination_type = bp_action_variable( 0 );
398
		}
399
	}
400
401
	switch ( $pagination_type ) {
402
		case 'blogs':
403
			$pag_count   = bp_get_blogs_pagination_count();
404
			$pag_links   = bp_get_blogs_pagination_links();
405
			$top_hook    = 'bp_before_directory_blogs_list';
406
			$bottom_hook = 'bp_after_directory_blogs_list';
407
			$page_arg    = $GLOBALS['blogs_template']->pag_arg;
408
			break;
409
410
		case 'members':
411
		case 'friends':
412
		case 'manage-members':
413
			$pag_count = bp_get_members_pagination_count();
414
			$pag_links = bp_get_members_pagination_links();
415
416
			// Groups single items are not using these hooks
417
			if ( ! bp_is_group() ) {
418
				$top_hook    = 'bp_before_directory_members_list';
419
				$bottom_hook = 'bp_after_directory_members_list';
420
			}
421
422
			$page_arg = $GLOBALS['members_template']->pag_arg;
423
			break;
424
425
		case 'groups':
426
			$pag_count   = bp_get_groups_pagination_count();
427
			$pag_links   = bp_get_groups_pagination_links();
428
			$top_hook    = 'bp_before_directory_groups_list';
429
			$bottom_hook = 'bp_after_directory_groups_list';
430
			$page_arg    = $GLOBALS['groups_template']->pag_arg;
431
			break;
432
433
		case 'notifications':
434
			$pag_count   = bp_get_notifications_pagination_count();
435
			$pag_links   = bp_get_notifications_pagination_links();
436
			$top_hook    = '';
437
			$bottom_hook = '';
438
			$page_arg    = buddypress()->notifications->query_loop->pag_arg;
439
			break;
440
441
		case 'membership-requests':
442
			$pag_count   = bp_get_group_requests_pagination_count();
443
			$pag_links   = bp_get_group_requests_pagination_links();
444
			$top_hook    = '';
445
			$bottom_hook = '';
446
			$page_arg    = $GLOBALS['requests_template']->pag_arg;
447
			break;
448
	}
449
450
	$count_class = sprintf( '%1$s-%2$s-count-%3$s', $pagination_type, $screen, $position );
451
	$links_class = sprintf( '%1$s-%2$s-links-%3$s', $pagination_type, $screen, $position );
452
	?>
453
454
	<?php
455
	if ( 'bottom' === $position && isset( $bottom_hook ) ) {
456
		/**
457
		 * Fires after the component directory list.
458
		 *
459
		 * @since 3.0.0
460
		 */
461
		do_action( $bottom_hook );
462
	};
463
	?>
464
465
	<div class="<?php echo esc_attr( 'bp-pagination ' . sanitize_html_class( $position ) ); ?>" data-bp-pagination="<?php echo esc_attr( $page_arg ); ?>">
466
467
		<?php if ( $pag_count ) : ?>
468
			<div class="<?php echo esc_attr( 'pag-count ' . sanitize_html_class( $position ) ); ?>">
469
470
				<p class="pag-data">
471
					<?php echo esc_html( $pag_count ); ?>
472
				</p>
473
474
			</div>
475
		<?php endif; ?>
476
477
		<?php if ( $pag_links ) : ?>
478
			<div class="<?php echo esc_attr( 'bp-pagination-links ' . sanitize_html_class( $position ) ); ?>">
479
480
				<p class="pag-data">
481
					<?php echo wp_kses_post( $pag_links ); ?>
482
				</p>
483
484
			</div>
485
		<?php endif; ?>
486
487
	</div>
488
489
	<?php
490
	if ( 'top' === $position && isset( $top_hook ) ) {
491
		/**
492
		 * Fires before the component directory list.
493
		 *
494
		 * @since 3.0.0
495
		 */
496
		do_action( $top_hook );
497
	};
498
}
499
500
/**
501
 * Display the component's loop classes
502
 *
503
 * @since 3.0.0
504
 *
505
 * @return string CSS class attributes (escaped).
0 ignored issues
show
Documentation introduced by Hugo Ashmore
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
506
 */
507
function bp_nouveau_loop_classes() {
508
	echo esc_attr( bp_nouveau_get_loop_classes() );
509
}
510
511
	/**
512
	 * Get the component's loop classes
513
	 *
514
	 * @since 3.0.0
515
	 *
516
	 * @return string space separated value of classes.
517
	 */
518
	function bp_nouveau_get_loop_classes() {
519
		$bp_nouveau = bp_nouveau();
520
521
		// @todo: this function could do with passing args so we can pass simple strings in or array of strings
522
523
		// The $component is faked if it's the single group member loop
524
		if ( ! bp_is_directory() && ( bp_is_group() && 'members' === bp_current_action() ) ) {
525
			$component = 'members_group';
526
		} elseif ( ! bp_is_directory() && ( bp_is_user() && 'my-friends' === bp_current_action() ) ) {
527
			$component = 'members_friends';
528
		} else {
529
			$component = sanitize_key( bp_current_component() );
530
		}
531
532
		$classes = array(
533
			'item-list',
534
			sprintf( '%s-list', str_replace( '_', '-', $component ) ),
535
			'bp-list',
536
		);
537
538
		if ( bp_is_user() && 'my-friends' === bp_current_action() ) {
539
			$classes[] = 'members-list';
540
		}
541
542
		if ( bp_is_user() && 'requests' === bp_current_action() ) {
543
			$classes[] = 'friends-request-list';
544
		}
545
546
		$available_components = array(
547
			'members' => true,
548
			'groups'  => true,
549
			'blogs'   => true,
550
551
			/*
552
			 * Technically not a component but allows us to check the single group members loop as a seperate loop.
553
			 */
554
			'members_group'   => true,
555
			'members_friends' => true,
556
		);
557
558
		// Only the available components supports custom layouts.
559
		if ( ! empty( $available_components[ $component ] ) && ( bp_is_directory() || bp_is_group() || bp_is_user() ) ) {
560
			$customizer_option = sprintf( '%s_layout', $component );
561
			$layout_prefs      = bp_nouveau_get_temporary_setting(
562
				$customizer_option,
563
				bp_nouveau_get_appearance_settings( $customizer_option )
564
			);
565
566
			if ( $layout_prefs && (int) $layout_prefs > 1 ) {
567
				$grid_classes = bp_nouveau_customizer_grid_choices( 'classes' );
568
569
				if ( isset( $grid_classes[ $layout_prefs ] ) ) {
570
					$classes = array_merge( $classes, array(
571
						'grid',
572
						$grid_classes[ $layout_prefs ],
573
					) );
574
				}
575
576
				// Set the global for a later use.
577
				$bp_nouveau->{$component}->loop_layout = $layout_prefs;
578
			}
579
		}
580
581
		/**
582
		 * Filter to edit/add classes.
583
		 *
584
		 * NB: you can also directly add classes into the template parts.
585
		 *
586
		 * @since 3.0.0
587
		 *
588
		 * @param array  $classes   The list of classes.
589
		 * @param string $component The current component's loop.
590
		 */
591
		$class_list = (array) apply_filters( 'bp_nouveau_get_loop_classes', $classes, $component );
592
593
		return join( ' ', array_map( 'sanitize_html_class', $class_list ) );
594
	}
595
596
597
/**
598
 * Checks if the layout preferences is set to grid (2 or more columns).
599
 *
600
 * @since 3.0.0
601
 *
602
 * @return bool True if loop is displayed in grid mod. False otherwise.
603
 */
604
function bp_nouveau_loop_is_grid() {
605
	$bp_nouveau = bp_nouveau();
606
	$component  = sanitize_key( bp_current_component() );
607
608
	return ! empty( $bp_nouveau->{$component}->loop_layout ) && $bp_nouveau->{$component}->loop_layout > 1;
609
}
610
611
/**
612
 * Returns the number of columns of the layout preferences.
613
 *
614
 * @since 3.0.0
615
 *
616
 * @return int The number of columns.
617
 */
618
function bp_nouveau_loop_get_grid_columns() {
619
	$bp_nouveau = bp_nouveau();
620
	$component  = sanitize_key( bp_current_component() );
621
622
	$columns = 1;
623
624
	if ( ! empty( $bp_nouveau->{$component}->loop_layout ) ) {
625
		$columns = (int) $bp_nouveau->{$component}->loop_layout;
626
	}
627
628
	/**
629
	 * Filter number of columns for this grid.
630
	 *
631
	 * @since 3.0.0
632
	 *
633
	 * @param int $columns The number of columns.
634
	 */
635
	return (int) apply_filters( 'bp_nouveau_loop_get_grid_columns', $columns );
636
}
637
638
/**
639
 * Return a bool check for component directory layout.
640
 *
641
 * Checks if activity, members, groups, blogs has the vert nav layout selected.
642
 *
643
 * @since 3.0.0
644
 *
645
 * @return bool
646
 */
647
function bp_dir_is_vert_layout() {
648
	$bp_nouveau = bp_nouveau();
649
	$component  = sanitize_key( bp_current_component() );
650
651
	return (bool) $bp_nouveau->{$component}->directory_vertical_layout;
652
}
653
654
/**
655
 * Get the full size avatar args.
656
 *
657
 * @since 3.0.0
658
 *
659
 * @return array The avatar arguments.
660
 */
661
function bp_nouveau_avatar_args() {
662
	/**
663
	 * Filter arguments for full-size avatars.
664
	 *
665
	 * @since 3.0.0
666
	 *
667
	 * @param array $args {
668
	 *     @param string $type   Avatar type.
669
	 *     @param int    $width  Avatar width value.
670
	 *     @param int    $height Avatar height value.
671
	 * }
672
	 */
673
	return apply_filters( 'bp_nouveau_avatar_args', array(
674
		'type'   => 'full',
675
		'width'  => bp_core_avatar_full_width(),
676
		'height' => bp_core_avatar_full_height(),
677
	) );
678
}
679
680
681
/** Template Tags for BuddyPress navigations **********************************/
682
683
/*
684
 * This is the BP Nouveau Navigation Loop.
685
 *
686
 * It can be used by any object using the
687
 * BP_Core_Nav API introduced in BuddyPress 2.6.0.
688
 */
689
690
/**
691
 * Init the Navigation Loop and check it has items.
692
 *
693
 * @since 3.0.0
694
 *
695
 * @param array $args {
696
 *     Array of arguments.
697
 *
698
 *     @type string $type                    The type of Nav to get (primary or secondary)
699
 *                                           Default 'primary'. Required.
700
 *     @type string $object                  The object to get the nav for (eg: 'directory', 'group_manage',
701
 *                                           or any custom object). Default ''. Optional
702
 *     @type bool   $user_has_access         Used by the secondary member's & group's nav. Default true. Optional.
703
 *     @type bool   $show_for_displayed_user Used by the primary member's nav. Default true. Optional.
704
 * }
705
 *
706
 * @return bool True if the Nav contains items. False otherwise.
707
 */
708
function bp_nouveau_has_nav( $args = array() ) {
709
	$bp_nouveau = bp_nouveau();
710
711
	$n = bp_parse_args(
712
		$args,
713
		array(
714
			'type'                    => 'primary',
715
			'object'                  => '',
716
			'user_has_access'         => true,
717
			'show_for_displayed_user' => true,
718
		),
719
		'nouveau_has_nav'
720
	);
721
722
	if ( empty( $n['type'] ) ) {
723
		return false;
724
	}
725
726
	$nav                       = array();
727
	$bp_nouveau->displayed_nav = '';
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property displayed_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
728
	$bp_nouveau->object_nav    = $n['object'];
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property object_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
729
730
	if ( bp_is_directory() || 'directory' === $bp_nouveau->object_nav ) {
731
		$bp_nouveau->displayed_nav = 'directory';
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property displayed_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
732
		$nav                       = $bp_nouveau->directory_nav->get_primary();
733
734
	// So far it's only possible to build a Group nav when displaying it.
735
	} elseif ( bp_is_group() ) {
736
		$bp_nouveau->displayed_nav = 'groups';
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property displayed_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
737
		$parent_slug               = bp_get_current_group_slug();
738
		$group_nav                 = buddypress()->groups->nav;
739
740
		if ( 'group_manage' === $bp_nouveau->object_nav && bp_is_group_admin_page() ) {
741
			$parent_slug .= '_manage';
742
743
		/**
744
		 * If it's not the Admin tabs, reorder the Group's nav according to the
745
		 * customizer setting.
746
		 */
747
		} else {
748
			bp_nouveau_set_nav_item_order( $group_nav, bp_nouveau_get_appearance_settings( 'group_nav_order' ), $parent_slug );
749
		}
750
751
		$nav = $group_nav->get_secondary(
752
			array(
753
				'parent_slug'     => $parent_slug,
754
				'user_has_access' => (bool) $n['user_has_access'],
755
			)
756
		);
757
758
	// Build the nav for the displayed user
759
	} elseif ( bp_is_user() ) {
760
		$bp_nouveau->displayed_nav = 'personal';
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property displayed_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
761
		$user_nav                  = buddypress()->members->nav;
762
763
		if ( 'secondary' === $n['type'] ) {
764
			$nav = $user_nav->get_secondary(
765
				array(
766
					'parent_slug'     => bp_current_component(),
767
					'user_has_access' => (bool) $n['user_has_access'],
768
				)
769
			);
770
771
		} else {
772
			$args = array();
0 ignored issues
show
Coding Style introduced by Hugo Ashmore
Consider using a different name than the parameter $args. This often makes code more readable.
Loading history...
773
774
			if ( true === (bool) $n['show_for_displayed_user'] && ! bp_is_my_profile() ) {
775
				$args = array( 'show_for_displayed_user' => true );
0 ignored issues
show
Coding Style introduced by Hugo Ashmore
Consider using a different name than the parameter $args. This often makes code more readable.
Loading history...
776
			}
777
778
			// Reorder the user's primary nav according to the customizer setting.
779
			bp_nouveau_set_nav_item_order( $user_nav, bp_nouveau_get_appearance_settings( 'user_nav_order' ) );
780
781
			$nav = $user_nav->get_primary( $args );
782
		}
783
784
	} elseif ( ! empty( $bp_nouveau->object_nav ) ) {
785
		$bp_nouveau->displayed_nav = $bp_nouveau->object_nav;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property displayed_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by Hugo Ashmore
The property object_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
786
787
		/**
788
		 * Use the filter to use your specific Navigation.
789
		 * Use the $n param to check for your custom object.
790
		 *
791
		 * @since 3.0.0
792
		 *
793
		 * @param array $nav The list of item navigations generated by the BP_Core_Nav API.
794
		 * @param array $n   The arguments of the Navigation loop.
795
		 */
796
		$nav = apply_filters( 'bp_nouveau_get_nav', $nav, $n );
797
798
	}
799
800
	// The navigation can be empty.
801
	if ( $nav === false ) {
802
		$nav = array();
803
	}
804
805
	$bp_nouveau->sorted_nav = array_values( $nav );
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property sorted_nav does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
806
807
	if ( 0 === count( $bp_nouveau->sorted_nav ) || ! $bp_nouveau->displayed_nav ) {
808
		unset( $bp_nouveau->sorted_nav, $bp_nouveau->displayed_nav, $bp_nouveau->object_nav );
809
810
		return false;
811
	}
812
813
	$bp_nouveau->current_nav_index = 0;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property current_nav_index does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
814
	return true;
815
}
816
817
/**
818
 * Checks there are still nav items to display.
819
 *
820
 * @since 3.0.0
821
 *
822
 * @return bool True if there are still items to display. False otherwise.
823
 */
824
function bp_nouveau_nav_items() {
825
	$bp_nouveau = bp_nouveau();
826
827
	if ( isset( $bp_nouveau->sorted_nav[ $bp_nouveau->current_nav_index ] ) ) {
828
		return true;
829
	}
830
831
	$bp_nouveau->current_nav_index = 0;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property current_nav_index does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
832
	unset( $bp_nouveau->current_nav_item );
833
834
	return false;
835
}
836
837
/**
838
 * Sets the current nav item and prepare the navigation loop to iterate to next one.
839
 *
840
 * @since 3.0.0
841
 */
842
function bp_nouveau_nav_item() {
843
	$bp_nouveau = bp_nouveau();
844
845
	$bp_nouveau->current_nav_item   = $bp_nouveau->sorted_nav[ $bp_nouveau->current_nav_index ];
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property current_nav_item does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
846
	$bp_nouveau->current_nav_index += 1;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property current_nav_index does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
847
}
848
849
/**
850
 * Displays the nav item ID.
851
 *
852
 * @since 3.0.0
853
 */
854
function bp_nouveau_nav_id() {
855
	echo esc_attr( bp_nouveau_get_nav_id() );
856
}
857
858
	/**
859
	 * Retrieve the ID attribute of the current nav item.
860
	 *
861
	 * @since 3.0.0
862
	 *
863
	 * @return string the ID attribute.
864
	 */
865
	function bp_nouveau_get_nav_id() {
866
		$bp_nouveau = bp_nouveau();
867
		$nav_item   = $bp_nouveau->current_nav_item;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property current_nav_item does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
868
869
		if ( 'directory' === $bp_nouveau->displayed_nav ) {
870
			$id = sprintf( '%1$s-%2$s', $nav_item->component, $nav_item->slug );
871
		} elseif ( 'groups' === $bp_nouveau->displayed_nav || 'personal' ===  $bp_nouveau->displayed_nav ) {
872
			$id = sprintf( '%1$s-%2$s-li', $nav_item->css_id, $bp_nouveau->displayed_nav );
873
		} else {
874
			$id = $nav_item->slug;
875
		}
876
877
		/**
878
		 * Filter to edit the ID attribute of the nav.
879
		 *
880
		 * @since 3.0.0
881
		 *
882
		 * @param string $id       The ID attribute of the nav.
883
		 * @param object $nav_item The current nav item object.
884
		 * @param string $value    The current nav in use (eg: 'directory', 'groups', 'personal', etc..).
885
		 */
886
		return apply_filters( 'bp_nouveau_get_nav_id', $id, $nav_item, $bp_nouveau->displayed_nav );
887
	}
888
889
/**
890
 * Displays the nav item classes.
891
 *
892
 * @since 3.0.0
893
 */
894
function bp_nouveau_nav_classes() {
895
	echo esc_attr( bp_nouveau_get_nav_classes() );
896
}
897
898
	/**
899
	 * Retrieve a space separated list of classes for the current nav item.
900
	 *
901
	 * @since 3.0.0
902
	 *
903
	 * @return string List of classes.
904
	 */
905
	function bp_nouveau_get_nav_classes() {
906
		$bp_nouveau = bp_nouveau();
907
		$nav_item   = $bp_nouveau->current_nav_item;
0 ignored issues
show
Documentation introduced by Hugo Ashmore
The property current_nav_item does not exist on object<BP_Nouveau>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
908
		$classes    = array();
909
910
		if ( 'directory' === $bp_nouveau->displayed_nav && ! empty( $nav_item->li_class ) ) {
911
			$classes = (array) $nav_item->li_class;
912
		} elseif ( 'groups' === $bp_nouveau->displayed_nav || 'personal' === $bp_nouveau->displayed_nav ) {
913
			$classes  = array( 'bp-' . $bp_nouveau->displayed_nav . '-tab' );
914
			$selected = bp_current_action();
915