bp_nouveau_get_loop_classes()

Get the component’s loop classes

Description

Return

(string) space separated value of classes.

Source

File: bp-templates/bp-nouveau/includes/template-tags.php

	function bp_nouveau_get_loop_classes() {
		$bp_nouveau = bp_nouveau();

		// @todo: this function could do with passing args so we can pass simple strings in or array of strings

		// The $component is faked if it's the single group member loop
		if ( ! bp_is_directory() && ( bp_is_group() && 'members' === bp_current_action() ) ) {
			$component = 'members_group';
		} elseif ( ! bp_is_directory() && ( bp_is_user() && ( 'my-friends' === bp_current_action() || 'mutual' === bp_current_action() ) ) ) {
			$component = 'members_friends';
		} else {
			$component = sanitize_key( bp_current_component() );
		}

		$classes = array(
			'item-list',
			sprintf( '%s-list', str_replace( '_', '-', $component ) ),
			'bp-list',
		);

		if ( bp_is_user() && 'my-friends' === bp_current_action() ) {
			$classes[] = 'members-list';
		}

		if ( bp_is_user() && 'requests' === bp_current_action() ) {
			$classes[] = 'friends-request-list';
		}

		if ( bp_is_user() && 'mutual' === bp_current_action() ) {
			$classes[] = 'friends-mutual-list';
		}

		$available_components = array(
			'members' => true,
			'groups'  => true,
			'blogs'   => true,

			/*
			 * Technically not a component but allows us to check the single group members loop as a seperate loop.
			 */
			'members_group'   => true,
			'members_friends' => true,
		);

		// Only the available components supports custom layouts.
		if ( ! empty( $available_components[ $component ] ) && ( bp_is_directory() || bp_is_group() || bp_is_user() ) ) {
			$customizer_option = sprintf( '%s_layout', $component );
			$layout_prefs      = bp_nouveau_get_temporary_setting(
				$customizer_option,
				bp_nouveau_get_appearance_settings( $customizer_option )
			);

			// check for layout options in browsers storage
			$list = false;
			if ( isset( $_POST['extras'] ) && ! empty( $_POST['extras']['layout'] ) && 'list' == $_POST['extras']['layout'] ) {
				$list = true;
            }

			if ( $layout_prefs && (int) $layout_prefs > 1 ) {
				$grid_classes = bp_nouveau_customizer_grid_choices( 'classes' );

				if ( isset( $grid_classes[ $layout_prefs ] ) && ! $list ) {
					$classes = array_merge( $classes, array(
						'grid',
                        'four',/*Remove customizer number of columns in grid view*/
						//$grid_classes[ $layout_prefs ],/*Remove customizer number of columns in grid view*/
					) );
				} else {
					$classes = array_merge( $classes, array(
                        'four',/*Remove customizer number of columns in grid view*/
						//$grid_classes[ $layout_prefs ],/*Remove customizer number of columns in grid view*/
					) );
                }

				if ( ! isset( $bp_nouveau->{$component} ) ) {
				    $bp_nouveau->{$component} = new stdClass;
				}

				// Set the global for a later use.
				$bp_nouveau->{$component}->loop_layout = $layout_prefs;
			}
		}

		/**
		 * Filter to edit/add classes.
		 *
		 * NB: you can also directly add classes into the template parts.
		 *
		 * @since BuddyPress 3.0.0
		 *
		 * @param array  $classes   The list of classes.
		 * @param string $component The current component's loop.
		 */
		$class_list = (array) apply_filters( 'bp_nouveau_get_loop_classes', $classes, $component );

		return join( ' ', array_map( 'sanitize_html_class', $class_list ) );
	}

Changelog

Changelog
Version Description
BuddyPress 3.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.