bp_has_profile( array|string $args = '' )

Query for XProfile groups and fields.

Description

See also

Parameters

$args

(Optional) Array of arguments. See BP_XProfile_Group::get() for full description. Those arguments whose defaults differ from that method are described here:

  • 'user_id'
    (int) Default: ID of the displayed user.
  • 'member_type'
    (string|array) Default: 'any'.
  • 'profile_group_id'
    (int|bool) Default: false.
  • 'hide_empty_groups'
    (bool) Default: true.
  • 'hide_empty_fields'
    (bool) Defaults to true on the Dashboard, on a user's Edit Profile page, or during registration. Otherwise false.
  • 'fetch_fields'
    (bool) Default: true.
  • 'fetch_field_data'
    (bool) Default: true.
  • 'fetch_visibility_level'
    (bool) Defaults to true when an admin is viewing a profile, or when a user is viewing her own profile, or during registration. Otherwise false.
  • 'exclude_groups'
    (int|bool) Default: false.
  • 'exclude_fields'
    (int|bool) Default: false
  • 'include_fields'
    (int|bool) Default: false
  • 'update_meta_cache'
    (bool) Default: true.

Default value: ''

Return

(bool)

Source

File: bp-xprofile/bp-xprofile-template.php

function bp_has_profile( $args = '' ) {
	global $profile_template;

	// Only show empty fields if we're on the Dashboard, or we're on a user's
	// profile edit page, or this is a registration page.
	$hide_empty_fields_default = ( ! is_network_admin() && ! is_admin() && ! bp_is_user_profile_edit() && ! bp_is_register_page() );

	// We only need to fetch visibility levels when viewing your own profile.
	if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) || bp_is_register_page() ) {
		$fetch_visibility_level_default = true;
	} else {
		$fetch_visibility_level_default = false;
	}

	// Parse arguments.
	$r = bp_parse_args( $args, array(
		'user_id'                => bp_displayed_user_id(),
		'member_type'            => 'any',
		'profile_group_id'       => false,
		'hide_empty_groups'      => true,
		'hide_empty_fields'      => $hide_empty_fields_default,
		'fetch_fields'           => true,
		'fetch_field_data'       => true,
		'fetch_visibility_level' => $fetch_visibility_level_default,
		'exclude_groups'         => false, // Comma-separated list of profile field group IDs to exclude.
		'exclude_fields'         => false, // Comma-separated list of profile field IDs to exclude.
		'update_meta_cache'      => true,
	), 'has_profile' );

	// Populate the template loop global.
	$profile_template = new BP_XProfile_Data_Template( $r );

	/**
	 * Filters whether or not a group has a profile to display.
	 *
	 * @since BuddyPress 1.1.0
	 * @since BuddyPress 2.6.0 Added the `$r` parameter.
	 *
	 * @param bool   $has_groups       Whether or not there are group profiles to display.
	 * @param string $profile_template Current profile template being used.
	 * @param array  $r                Array of arguments passed into the BP_XProfile_Data_Template class.
	 */
	return apply_filters( 'bp_has_profile', $profile_template->has_groups(), $profile_template, $r );
}

Changelog

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