BP_XProfile_Data_Template::__construct( array|string $args = '' )

Get activity items, as specified by parameters.


Description Description

See also See also


Top ↑

Parameters Parameters

$args

(array|string) (Optional) An array of arguments. All items are optional.

  • 'user_id'
    (int) Fetch field data for this user ID.
  • 'member_type'
    (string|array) Limit results to those matching member type(s).
  • 'profile_group_id'
    (int) Field group to fetch fields & data for.
  • 'hide_empty_groups'
    (int|bool) Should empty field groups be skipped.
  • 'fetch_fields'
    (int|bool) Fetch fields for field group.
  • 'fetch_field_data'
    (int|bool) Fetch field data for fields in group.
  • 'exclude_groups'
    (array) Exclude these field groups.
  • 'exclude_fields'
    (array) Exclude these fields.
  • 'hide_empty_fields'
    (int|bool) Should empty fields be skipped.
  • 'fetch_visibility_level'
    (int|bool) Fetch visibility levels.
  • 'hide_field_types'
    (string[]) List of field types to hide form loop. Default: empty array.
  • 'signup_fields_only'
    (bool) Whether to only return signup fields. Default: false.
  • 'update_meta_cache'
    (int|bool) Should metadata cache be updated.

Default value: ''


Top ↑

Source Source

File: bp-xprofile/classes/class-bp-xprofile-data-template.php

	public function __construct( $args = '' ) {
		$function_args = func_get_args();

		// Backward compatibility with old method of passing arguments.
		if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
			_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );

			$old_args_keys = array(
				0 => 'user_id',
				1 => 'profile_group_id',
				2 => 'hide_empty_groups',
				3 => 'fetch_fields',
				4 => 'fetch_field_data',
				5 => 'exclude_groups',
				6 => 'exclude_fields',
				7 => 'hide_empty_fields',
				8 => 'fetch_visibility_level',
				9 => 'update_meta_cache'
			);

			$args = bp_core_parse_args_array( $old_args_keys, $function_args );
		}

		$r = wp_parse_args( $args, array(
			'profile_group_id'       => false,
			'user_id'                => false,
			'member_type'            => 'any',
			'hide_empty_groups'      => false,
			'hide_empty_fields'      => false,
			'fetch_fields'           => false,
			'fetch_field_data'       => false,
			'fetch_visibility_level' => false,
			'exclude_groups'         => false,
			'exclude_fields'         => false,
			'hide_field_types'       => array(),
			'signup_fields_only'     => false,
			'update_meta_cache'      => true
		) );

		$groups = bp_xprofile_get_groups( $r );

		if ( true === $r['signup_fields_only'] ) {
			$signup_fields_order       = bp_xprofile_get_signup_field_ids();
			$signup_group              = new BP_XProfile_Group();
			$signup_group->id          = 0;
			$signup_group->name        = __( 'Signup Fields', 'buddypress' );
			$signup_group->description = '';
			$signup_group->can_delete  = 0;
			$signup_group->group_order = 0;
			$fields                    = array();
			$signup_group->fields      = array();

			// Get all group fields.
			foreach ( $groups as $group ) {
				if ( ! $group->fields ) {
					continue;
				}

				// Populate fields using the field ID as key.
				foreach ( $group->fields as $signup_field ) {
					$fields[ $signup_field->id ] = $signup_field;
				}
			}

			if ( $fields ) {
				// Reorder signup fields.
				foreach ( $signup_fields_order as $ordered_signup_field_id ) {
					if ( ! isset( $fields[ $ordered_signup_field_id ] ) ) {
						continue;
					}

					$signup_group->fields[] = $fields[ $ordered_signup_field_id ];
				}
			}

			// Override groups with the signup one.
			$groups = array( $signup_group );
		}

		$this->groups      = $groups;
		$this->group_count = count( $this->groups );
		$this->user_id     = $r['user_id'];
	}


Top ↑

Changelog Changelog

Changelog
Version Description
8.0.0 Introduced $hide_field_types & $signup_fields_only arguments.
2.4.0 Introduced $member_type argument.
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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