bp_nouveau_get_loop_classes()

Get the component’s loop classes


Return Return

(string) space separated value of classes.


Source 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
		$is_directory = bp_is_directory();

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

		/*
		 * For the groups component, we need to take in account the
		 * Groups directory can list Groups according to a Group Type.
		 */
		if ( 'groups' === $component ) {
			$is_directory = bp_is_groups_directory();
		}

		$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';
		}

		$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 ] ) && ( $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 )
			);

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

				if ( isset( $grid_classes[ $layout_prefs ] ) ) {
					$classes = array_merge( $classes, array(
						'grid',
						$grid_classes[ $layout_prefs ],
					) );
				}

				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 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 ) );
	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.