BP_REST_XProfile_Fields_Endpoint::get_xprofile_field_display_permission( boolean $retval, int $field_id )

Check display setting permission from platform.

Description

Parameters

$retval

(boolean) (Required) Return value should be boolean or WP_Error.

$field_id

(int) (Required) xProfile Field ID to check permission.

Return

(WP_Error|Boolean)

Source

File: bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php

	public function get_xprofile_field_display_permission( $retval, $field_id = 0 ) {

		if ( empty( $field_id ) ) {
			return $retval;
		}

		/**
		 * Added support for display name format support from platform.
		 */
		// Get the current display settings from BuddyBoss > Settings > Profiles > Display Name Format.
		$current_value = bp_get_option( 'bp-display-name-format' );
		if (
			// If First Name selected then do not add last name field.
			(
				'first_name' === $current_value
				&& function_exists( 'bp_xprofile_lastname_field_id' )
				&& bp_xprofile_lastname_field_id() === $field_id
				&& function_exists( 'bp_hide_last_name' )
				&& false === bp_hide_last_name()
			)
			// If Nick Name selected then do not add first & last name field.
			|| (
				'nickname' === $current_value
				&& function_exists( 'bp_xprofile_lastname_field_id' )
				&& bp_xprofile_lastname_field_id() === $field_id
				&& function_exists( 'bp_hide_nickname_last_name' )
				&& false === bp_hide_nickname_last_name()
			)
			|| (
				'nickname' === $current_value
				&& function_exists( 'bp_xprofile_firstname_field_id' )
				&& bp_xprofile_firstname_field_id() === $field_id
				&& function_exists( 'bp_hide_nickname_first_name' )
				&& false === bp_hide_nickname_first_name()
			)
			|| (
				function_exists( 'bp_member_type_enable_disable' )
				&& false === bp_member_type_enable_disable()
				&& function_exists( 'bp_get_xprofile_member_type_field_id' )
				&& bp_get_xprofile_member_type_field_id() === $field_id
			)
		) {
			$retval = new WP_Error(
				'bp_rest_invalid_id',
				__( 'Invalid field ID.', 'buddyboss' ),
				array(
					'status' => 404,
				)
			);
		}

		return $retval;
	}

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.