BP_Media_Album_Template::__construct( array $args )

Constructor method.

Description

The arguments passed to this class constructor are of the same format as BP_Media_Album::get().

See also

Parameters

$args

(array) (Required) Array of arguments. Supports all arguments from BP_Media_Album::get(), as well as 'page_arg' and 'include'. Default values for 'per_page' differ from the originating function, and are described below.

  • 'page_arg'
    (string) The string used as a query parameter in pagination links. Default: 'acpage'.
  • 'include'
    (array|bool) Pass an array of activity IDs to retrieve only those items, or false to noop the 'include' parameter. 'include' differs from 'in' in that 'in' forms an IN clause that works in conjunction with other filters passed to the function, while 'include' is interpreted as an exact list of items to retrieve, which skips all other filter-related parameters. Default: false.
  • 'per_page'
    (int|bool) Default: 20.

Source

File: bp-media/classes/class-bp-media-album-template.php

	public function __construct( $args ) {

		$defaults = array(
			'page'              => 1,
			'per_page'          => 20,
			'page_arg'          => 'acpage',
			'max'               => false,
			'user_id'           => false,
			'fields'            => 'all',
			'count_total'       => false,
			'sort'              => false,
			'include'           => false,
			'exclude'           => false,
			'privacy'           => false,
			'search_terms'      => false,
		);
		$r = wp_parse_args( $args, $defaults );
		extract( $r );

		$this->pag_arg  = sanitize_key( $r['page_arg'] );
		$this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
		$this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );

		// Get an array of the logged in user's favorite album.
		$this->my_favs = bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_album', true );

		// Fetch specific album items based on ID's.
		if ( !empty( $include ) ) {
			$this->albums = bp_album_get_specific( array(
				'album_ids'         => explode( ',', $include ),
				'max'               => $max,
				'count_total'       => $count_total,
				'page'              => $this->pag_page,
				'per_page'          => $this->pag_num,
				'sort'              => $sort,
				'user_id'           => $user_id,
			) );

			// Fetch all albums.
		} else {
			$this->albums = bp_album_get( array(
				'max'               => $max,
				'count_total'       => $count_total,
				'per_page'          => $this->pag_num,
				'page'              => $this->pag_page,
				'sort'              => $sort,
				'search_terms'      => $search_terms,
				'user_id'           => $user_id,
				'group_id'          => $group_id,
				'exclude'           => $exclude,
				'privacy'           => $privacy,
			) );
		}

		// The total_album_count property will be set only if a
		// 'count_total' query has taken place.
		if ( ! is_null( $this->albums['total'] ) ) {
			if ( ! $max || $max >= (int) $this->albums['total'] ) {
				$this->total_album_count = (int) $this->albums['total'];
			} else {
				$this->total_album_count = (int) $max;
			}
		}

		$this->has_more_items = $this->albums['has_more_items'];

		$this->albums = $this->albums['albums'];

		if ( $max ) {
			if ( $max >= count($this->albums) ) {
				$this->album_count = count( $this->albums );
			} else {
				$this->album_count = (int) $max;
			}
		} else {
			$this->album_count = count( $this->albums );
		}

		if ( (int) $this->total_album_count && (int) $this->pag_num ) {
			$this->pag_links = paginate_links( array(
				'base'      => add_query_arg( $this->pag_arg, '%#%' ),
				'format'    => '',
				'total'     => ceil( (int) $this->total_album_count / (int) $this->pag_num ),
				'current'   => (int) $this->pag_page,
				'prev_text' => __( '←', 'buddyboss' ),
				'next_text' => __( '→', 'buddyboss' ),
				'mid_size'  => 1,
				'add_args'  => array(),
			) );
		}
	}

Changelog

Changelog
Version Description
BuddyBoss 1.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.