xprofile_filter_field_edit_name( string $field_name )

Conditionally filters ‘bp_get_the_profile_field_name’ to return alternate name if available.

Description

Filter is only applied if:

  1. we are on profile > edit screens
  2. we are on registration page

Parameters

$field_name

(Required)

Return

(string)

Source

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

function xprofile_filter_field_edit_name ( $field_name ) {
    $is_field_edit_mode = false;

    $current_field = false;

    if ( bp_is_profile_component() && 'edit' == bp_current_action() ) {
        //we are on profile > edit screens, we should display alternate name, if available, instead of main name.
        $is_field_edit_mode = true;

        //we can use global $field variable here
        global $field;
        $current_field = $field;
    }

    if ( !$is_field_edit_mode && bp_is_register_page() ) {
        //We are on registration page/form. We should display alternate name, if available, instead of main name.
        $is_field_edit_mode = true;

        //we can use global $field variable here
        global $field;
        $current_field = $field;
    }

    //@todo : Should we do it if an admin is editing user profiles in backend ( wp-admin/edit-user.php... ) ?

    if ( $is_field_edit_mode ) {
        $alternate_name = bp_get_the_profile_field_alternate_name( $current_field );

        if ( !empty( $alternate_name ) ) {
            $field_name = $alternate_name;
        }
    }

    return $field_name;
}

Changelog

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