Skip to:
Content

BuddyPress.org

Changeset 8083


Ignore:
Timestamp:
03/08/2014 12:39:35 PM (11 years ago)
Author:
boonebgorges
Message:

Coding standards and documentation improvements in bp_get_member_profile_data()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-members/bp-members-template.php

    r8082 r8083  
    655655    }
    656656
     657/**
     658 * Output a piece of user profile data.
     659 *
     660 * @see bp_get_member_profile_data() for a description of params.
     661 *
     662 * @param array $args See {@link bp_get_member_profile_data()}.
     663 */
    657664function bp_member_profile_data( $args = '' ) {
    658665    echo bp_get_member_profile_data( $args );
    659666}
     667    /**
     668     * Get a piece of user profile data.
     669     *
     670     * When used in a bp_has_members() loop, this function will attempt
     671     * to fetch profile data cached in the template global. It is also safe
     672     * to use outside of the loop.
     673     *
     674     * @param array $args {
     675     *     Array of config paramaters.
     676     *     @type string $field Name of the profile field.
     677     *     @type int $user_id ID of the user whose data is being fetched.
     678     *           Defaults to the current member in the loop, or if not
     679     *           present, to the currently displayed user.
     680     * }
     681     * @return string|bool Profile data if found, otherwise false.
     682     */
    660683    function bp_get_member_profile_data( $args = '' ) {
    661684        global $members_template;
    662685
    663         if ( !bp_is_active( 'xprofile' ) )
     686        if ( ! bp_is_active( 'xprofile' ) ) {
    664687            return false;
     688        }
    665689
    666690        // Declare local variables
     
    669693        // Guess at default $user_id
    670694        $default_user_id = 0;
    671         if ( !empty( $members_template->member->id ) )
     695        if ( ! empty( $members_template->member->id ) ) {
    672696            $default_user_id = $members_template->member->id;
    673         elseif ( bp_displayed_user_id() )
     697        } elseif ( bp_displayed_user_id() ) {
    674698            $default_user_id = bp_displayed_user_id();
     699        }
    675700
    676701        $defaults = array(
     
    680705
    681706        $r = wp_parse_args( $args, $defaults );
    682         extract( $r, EXTR_SKIP );
    683707
    684708        // If we're in a members loop, get the data from the global
     
    689713        // Otherwise query for the data
    690714        if ( empty( $profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) {
    691             $profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
     715            $profile_data = BP_XProfile_ProfileData::get_all_for_user( $r['user_id'] );
    692716        }
    693717
     
    698722        }
    699723
    700         // Get the field data if there is data to get
    701         if ( ! empty( $profile_data ) && ! empty( $profile_data[ $field ]['field_type'] ) && ! empty( $profile_data[ $field ]['field_data'] ) )
    702             $data = xprofile_format_profile_field( $profile_data[ $field ]['field_type'], $profile_data[ $field ]['field_data'] );
     724        // Get the data for the specific field requested
     725        if ( ! empty( $profile_data ) && ! empty( $profile_data[ $r['field'] ]['field_type'] ) && ! empty( $profile_data[ $r['field'] ]['field_data'] ) ) {
     726            $data = xprofile_format_profile_field( $profile_data[ $r['field'] ]['field_type'], $profile_data[ $r['field'] ]['field_data'] );
     727        }
    703728
    704729        return apply_filters( 'bp_get_member_profile_data', $data );
Note: See TracChangeset for help on using the changeset viewer.