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

Check display setting permission from platform.

Description

Parameters

$retval

(Required) Return value should be boolean or WP_Error.

$field_id

(Required) xProfile Field ID to check permission.

Return

(WP_Error|Boolean)

Source

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

1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
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.