bp_has_folders( array|string $args = '' )
Initialize the folder loop.
Description
Based on the $args passed, bp_has_folders() populates the $document_folder_template global, enabling the use of BuddyPress templates and template functions to display a list of document folder items.
Parameters
- $args
-
(Optional) Arguments for limiting the contents of the document loop. Most arguments are in the same format as BP_Document_Folder::get(). However, because the format of the arguments accepted here differs in a number of ways, and because bp_has_document() determines some default arguments in a dynamic fashion, we list all accepted arguments here as well. Arguments can be passed as an associative array, or as a URL querystring (eg, 'author_id=4&privacy=public').
- 'page'
(int) Which page of results to fetch. Using page=1 without per_page will result in no pagination. Default: 1. - 'per_page'
(int|bool) Number of results per page. Default: 20. - 'page_arg'
(string) String used as a query parameter in pagination links. Default: 'acpage'. - 'max'
(int|bool) Maximum number of results to return. Default: false (unlimited). - 'fields'
(string) Activity fields to retrieve. 'all' to fetch entire document objects, 'ids' to get only the document IDs. Default 'all'. - 'count_total'
(string|bool) If true, an additional DB query is run to count the total document items for the query. Default: false. - 'sort'
(string) 'ASC' or 'DESC'. Default: 'DESC'. - 'exclude'
(array|bool) Array of document IDs to exclude. Default: false. - 'include'
(array|bool) Array of exact document IDs to query. Providing an 'include' array will override all other filters passed in the argument array. When viewing the permalink page for a single document item, this value defaults to the ID of that item. Otherwise the default is false. - 'search_terms'
(string) Limit results by a search term. Default: false. - 'user_id'
(int|array|bool) The ID(s) of user(s) whose document should be fetched. Pass a single ID or an array of IDs. When viewing a user profile page, 'user_id' defaults to the ID of the displayed user. Otherwise the default is false. - 'group_id'
(int|array|bool) The ID(s) of group(s) whose document should be fetched. Pass a single ID or an array of IDs. When viewing a group page, 'group_id' defaults to the ID of the displayed group. Otherwise the default is false. - 'privacy'
(array) Limit results by a privacy. Default: public | grouponly.
Default value: ''
- 'page'
Return
(bool) Returns true when document found, otherwise false.
Source
File: bp-document/bp-document-template.php
function bp_has_folders( $args = '' ) { global $document_folder_template; /* * Smart Defaults. */ // User filtering. $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : false; $search_terms_default = false; $search_query_arg = bp_core_get_component_search_query_arg( 'folder' ); if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) { $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] ); } $privacy = array( 'public' ); if ( is_user_logged_in() ) { $privacy[] = 'loggedin'; if ( bp_is_active( 'friends' ) ) { // get the login user id. $current_user_id = get_current_user_id(); // check if the login user is friends of the display user. $is_friend = friends_check_friendship( $current_user_id, $user_id ); /** * check if the login user is friends of the display user. * OR check if the login user and the display user is the same */ if ( $is_friend || ! empty( $current_user_id ) && $current_user_id == $user_id ) { $privacy[] = 'friends'; } } if ( bp_is_my_profile() ) { $privacy[] = 'onlyme'; } } $group_id = false; if ( bp_is_group() ) { $group_id = bp_get_current_group_id(); $user_id = false; $privacy = array( 'grouponly' ); } /* * Parse Args. */ // Note: any params used for filtering can be a single value, or multiple // values comma separated. $r = bp_parse_args( $args, array( 'include' => false, // Pass an folder_id or string of IDs comma-separated. 'exclude' => false, // Pass an activity_id or string of IDs comma-separated. 'sort' => 'DESC', // Sort DESC or ASC. 'page' => 1, // Which page to load. 'per_page' => 20, // Number of items per page. 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679. 'max' => false, // Max number to return. 'fields' => 'all', 'count_total' => false, // Filtering. 'user_id' => $user_id, // user_id to filter on. 'group_id' => $group_id, // group_id to filter on. 'privacy' => $privacy, // privacy to filter on - public, onlyme, loggedin, friends, grouponly. // Searching. 'search_terms' => $search_terms_default, ), 'has_folders' ); if ( bp_is_group_single() && bp_is_group_folders() && false === $r['include'] ) { $r['include'] = (int) bp_action_variable( 1 ); } /* * Smart Overrides. */ // Search terms. if ( ! empty( $_REQUEST['s'] ) && empty( $r['search_terms'] ) ) { $r['search_terms'] = $_REQUEST['s']; } // Do not exceed the maximum per page. if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) { $r['per_page'] = $r['max']; } /* * Query */ $document_folder_template = new BP_Document_Folder_Template( $r ); /** * Filters whether or not there are document documents to display. * * @since BuddyBoss 1.4.0 * * @param bool $value Whether or not there are document items to display. * @param string $document_folder_template Current document folder template being used. * @param array $r Array of arguments passed into the BP_Document_Folder_Template class. */ return apply_filters( 'bp_has_folder', $document_folder_template->has_folders(), $document_folder_template, $r ); }
Changelog
Version | Description |
---|---|
BuddyBoss 1.4.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.