Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/11/2021 05:26:17 PM (2 years ago)
Author:
espellcaste
Message:

Making PHPDoc Improvements to the BP Members (component) files.

Also, adding several minor PHP changes.

See #8553

File:
1 edited

Legend:

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

    r12951 r13105  
    66 *
    77 * @package BuddyPress
    8  * @subpackage Members
     8 * @subpackage MembersTemplate
    99 * @since 1.5.0
    1010 */
     
    1717 *
    1818 * @since 2.4.0
    19  *
    2019 */
    2120function bp_profile_slug() {
     
    4544 *
    4645 * @since 1.5.0
    47  *
    4846 */
    4947function bp_members_slug() {
     
    7371 *
    7472 * @since 1.5.0
    75  *
    7673 */
    7774function bp_members_root_slug() {
     
    9289         * @since 1.5.0
    9390         *
    94          * @param string $slug Members component root slug.
     91         * @param string $root_slug Members component root slug.
    9592         */
    9693        return apply_filters( 'bp_get_members_root_slug', buddypress()->members->root_slug );
     
    106103}
    107104    /**
    108      * Get the member type base slug.
     105     * Get the member type URL base.
    109106     *
    110107     * The base slug is the string used as the base prefix when generating member type directory URLs.
     
    117114     */
    118115    function bp_get_members_member_type_base() {
     116
    119117        /**
    120118         * Filters the member type URL base.
     
    122120         * @since 2.3.0
    123121         *
    124          * @param string $base
     122         * @param string $base Base slug for the member type.
    125123         */
    126124        return apply_filters( 'bp_members_member_type_base', _x( 'type', 'member type URL base', 'buddypress' ) );
     
    131129 *
    132130 * @since 1.5.0
    133  *
    134131 */
    135132function bp_members_directory_permalink() {
     
    160157 * @since 2.5.0
    161158 *
    162  * @param string $member_type Optional. Member type.
     159 * @param string $member_type Optional. Member type. Defaults to current member type.
    163160 */
    164161function bp_member_type_directory_permalink( $member_type = '' ) {
     
    205202 *
    206203 * @since 1.5.0
    207  *
    208204 */
    209205function bp_signup_slug() {
     
    215211     * @since 1.5.0
    216212     *
     213     * @global BuddyPress $bp The one true BuddyPress instance.
     214     *
    217215     * @return string
    218216     */
     
    220218        $bp = buddypress();
    221219
    222         if ( !empty( $bp->pages->register->slug ) ) {
     220        if ( ! empty( $bp->pages->register->slug ) ) {
    223221            $slug = $bp->pages->register->slug;
    224222        } elseif ( defined( 'BP_REGISTER_SLUG' ) ) {
     
    242240 *
    243241 * @since 1.5.0
    244  *
    245242 */
    246243function bp_activate_slug() {
     
    252249     * @since 1.5.0
    253250     *
     251     * @global BuddyPress $bp The one true BuddyPress instance.
     252     *
    254253     * @return string
    255254     */
     
    257256        $bp = buddypress();
    258257
    259         if ( !empty( $bp->pages->activate->slug ) ) {
     258        if ( ! empty( $bp->pages->activate->slug ) ) {
    260259            $slug = $bp->pages->activate->slug;
    261260        } elseif ( defined( 'BP_ACTIVATION_SLUG' ) ) {
     
    279278 *
    280279 * @since 8.0.0
    281  *
    282280 */
    283281function bp_members_invitations_slug() {
     
    313311 * @since 7.0.0 Added `xprofile_query` parameter. Added `user_ids` parameter.
    314312 *
    315  * @global object $members_template {@link BP_Members_Template}
     313 * @global BP_Core_Members_Template $members_template
    316314 *
    317315 * @param array|string $args {
     
    440438     * @since 2.6.0 Added the `$r` parameter
    441439     *
    442      * @param bool  $value            Whether or not there are members to iterate over.
    443      * @param array $members_template Populated $members_template global.
    444      * @param array $r                Array of arguments passed into the BP_Core_Members_Template class.
     440     * @param bool                     $value            Whether or not there are members to iterate over.
     441     * @param BP_Core_Members_Template $members_template Populated $members_template global.
     442     * @param array                    $r                Array of arguments passed into the BP_Core_Members_Template class.
    445443     */
    446444    return apply_filters( 'bp_has_members', $members_template->has_members(), $members_template, $r );
     
    451449 *
    452450 * @since 1.2.0
     451 *
     452 * @global BP_Core_Members_Template $members_template
    453453 *
    454454 * @return object
     
    464464 * @since 1.2.0
    465465 *
     466 * @global BP_Core_Members_Template $members_template
     467 *
    466468 * @return bool
    467469 */
     
    484486     * @since 1.5.0
    485487     *
     488     * @global BP_Core_Members_Template $members_template
     489     *
    486490     * @return string
    487491     */
     
    489493        global $members_template;
    490494
    491         if ( empty( $members_template->type ) )
     495        if ( empty( $members_template->type ) ) {
    492496            $members_template->type = '';
     497        }
    493498
    494499        $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
     
    550555     * @since 1.2.0
    551556     *
     557     * @global BP_Core_Members_Template $members_template
     558     *
    552559     * @return string
    553560     */
     
    569576 *
    570577 * @since 1.2.0
    571  *
    572578 */
    573579function bp_member_user_id() {
     
    579585     * @since 1.2.0
    580586     *
    581      * @return string Member ID.
     587     * @global BP_Core_Members_Template $members_template
     588     *
     589     * @return int Member ID.
    582590     */
    583591    function bp_get_member_user_id() {
    584592        global $members_template;
    585         $member_id = isset( $members_template->member->id ) ? (int) $members_template->member->id : false;
     593
     594        $member_id = isset( $members_template->member->id )
     595            ? (int) $members_template->member->id
     596            : 0;
    586597
    587598        /**
     
    592603         * @param int $member_id ID of the member being iterated over.
    593604         */
    594         return apply_filters( 'bp_get_member_user_id', $member_id );
     605        return apply_filters( 'bp_get_member_user_id', (int) $member_id );
    595606    }
    596607
     
    610621     * @since 1.7.0
    611622     *
     623     * @global BP_Core_Members_Template $members_template
     624     *
    612625     * @param array $classes Array of custom classes.
     626     *
    613627     * @return string Row class of the member
    614628     */
     
    679693     * @since 1.2.5
    680694     *
     695     * @global BP_Core_Members_Template $members_template
     696     *
    681697     * @return string Members nicename.
    682698     */
     
    707723     * @since 1.2.5
    708724     *
     725     * @global BP_Core_Members_Template $members_template
     726     *
    709727     * @return string Member's login.
    710728     */
     
    735753     * @since 1.2.5
    736754     *
     755     * @global BP_Core_Members_Template $members_template
     756     *
    737757     * @return string Member's email address.
    738758     */
     
    754774 *
    755775 * @since 1.2.5
     776 * @since 10.0.0 Updated to get member ID from `bp_get_member_user_id`.
    756777 *
    757778 * @return bool
    758779 */
    759780function bp_member_is_loggedin_user() {
    760     global $members_template;
    761781
    762782    /**
     
    767787     * @param bool $value Whether current member in the loop is logged in.
    768788     */
    769     return apply_filters( 'bp_member_is_loggedin_user', bp_loggedin_user_id() == $members_template->member->id ? true : false );
     789    return apply_filters( 'bp_member_is_loggedin_user', ( bp_loggedin_user_id() === bp_get_member_user_id() ) );
    770790}
    771791
     
    796816     *
    797817     * @since 1.2.0
     818     *
     819     * @global BP_Core_Members_Template $members_template
    798820     *
    799821     * @see bp_core_fetch_avatar() For a description of arguments and
     
    809831     *     @type int|bool $width   Default: false.
    810832     *     @type int|bool $height  Default: false.
     833     *     @type bool     $no_grav Default: false.
    811834     *     @type bool     $id      Currently unused.
    812      *     @type bool     $no_grav Default: false.
    813835     * }
    814836     * @return string User avatar string.
     
    817839        global $members_template;
    818840
    819         $fullname = !empty( $members_template->member->fullname ) ? $members_template->member->fullname : $members_template->member->display_name;
    820 
    821         $defaults = array(
    822             'type'   => 'thumb',
    823             'width'  => false,
    824             'height' => false,
    825             'class'  => 'avatar',
    826             'id'     => false,
    827             'alt'    => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname )
     841        $fullname = ! empty( $members_template->member->fullname )
     842            ? $members_template->member->fullname
     843            : $members_template->member->display_name;
     844
     845        $r = wp_parse_args(
     846            $args,
     847            array(
     848                'type'    => 'thumb',
     849                'width'   => false,
     850                'height'  => false,
     851                'class'   => 'avatar',
     852                'id'      => false,
     853                'no_grav' => false,
     854                // translators: %s is the full name of the user.
     855                'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $fullname ),
     856            )
    828857        );
    829858
    830         $r = wp_parse_args( $args, $defaults );
    831         extract( $r, EXTR_SKIP );
    832 
    833         /**
    834          * Filters a members avatar.
     859        $avatar = bp_core_fetch_avatar(
     860            array(
     861                'email'   => bp_get_member_user_email(),
     862                'item_id' => bp_get_member_user_id(),
     863                'type'    => $r['type'],
     864                'alt'     => $r['alt'],
     865                'no_grav' => $r['no_grav'],
     866                'css_id'  => $r['id'],
     867                'class'   => $r['class'],
     868                'width'   => $r['width'],
     869                'height'  => $r['height'],
     870            )
     871        );
     872
     873        /**
     874         * Filters a member's avatar.
    835875         *
    836876         * @since 1.2.0
     
    840880         * @param array  $r     Array of parsed arguments. See {@link bp_get_member_avatar()}.
    841881         */
    842         return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ), $r );
     882        return apply_filters( 'bp_get_member_avatar', $avatar, $r );
    843883    }
    844884
     
    856896     * @since 1.2.0
    857897     *
     898     * @global BP_Core_Members_Template $members_template
     899     *
    858900     * @return string
    859901     */
     
    876918     * @since 1.2.0
    877919     */
    878     function bp_member_link() { echo esc_url( bp_get_member_permalink() ); }
     920    function bp_member_link() {
     921        echo esc_url( bp_get_member_permalink() );
     922    }
    879923
    880924    /**
     
    883927     * @since 1.2.0
    884928     */
    885     function bp_get_member_link() { return bp_get_member_permalink(); }
     929    function bp_get_member_link() {
     930        return bp_get_member_permalink();
     931    }
    886932
    887933/**
     
    910956     *
    911957     * @since 1.2.0
     958     *
     959     * @global BP_Core_Members_Template $members_template
    912960     *
    913961     * @return string The user's fullname for display.
     
    9641012     * @since 2.7.0 Added 'relative' as a parameter to $args.
    9651013     *
     1014     * @global BP_Core_Members_Template $members_template
     1015     *
    9661016     * @param array $args {
    9671017     *     Array of optional arguments.
     
    10321082     * @since 1.2.0
    10331083     *
     1084     * @global BP_Core_Members_Template $members_template
     1085     *
    10341086     * @param array|string $args {
    10351087     *     Array of optional arguments.
     
    11081160     *
    11091161     * @since 1.2.0
     1162     *
     1163     * @global BP_Core_Members_Template $members_template
    11101164     *
    11111165     * @param array|string $args {
     
    11981252 * @since 2.7.0 Added $args as a parameter.
    11991253 *
    1200  * @param array $args Optional. {@see bp_get_member_registered()}
     1254 * @param array $args Optional. {@see bp_get_member_registered()}.
    12011255 */
    12021256function bp_member_registered( $args = array() ) {
     
    12071261     *
    12081262     * @since 1.2.0
    1209      * @since 2.7.0 Added $args as a parameter.
     1263     * @since 2.7.0 Added `$args` as a parameter.
     1264     *
     1265     * @global BP_Core_Members_Template $members_template
    12101266     *
    12111267     * @param array $args {
    12121268     *     Array of optional parameters.
    1213      *
    12141269     *     @type bool $relative Optional. If true, returns relative registered date. eg. registered 5 months ago.
    12151270     *                          If false, returns registered date value from database.
    12161271     * }
    1217      *
    12181272     * @return string
    12191273     */
     
    12401294         *
    12411295         * @param string $registered The 'registered [x days ago]' string.
    1242          */
    1243         return apply_filters( 'bp_member_registered', $registered );
     1296         * @param array  $r          Array of parsed arguments.
     1297         */
     1298        return apply_filters( 'bp_member_registered', $registered, $r );
    12441299    }
    12451300
     
    12481303 *
    12491304 * @since 1.2.0
     1305 * @since 10.0.0 Updated to get member ID using `bp_get_member_user_id`.
    12501306 */
    12511307function bp_member_random_profile_data() {
    1252     global $members_template;
    1253 
    12541308    if ( bp_is_active( 'xprofile' ) ) { ?>
    1255         <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
     1309        <?php $random_data = xprofile_get_random_profile_data( bp_get_member_user_id(), true ); ?>
    12561310            <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
    12571311            <?php echo wp_filter_kses( $random_data[0]->value ) ?>
     
    13231377     * @since 1.2.0
    13241378     *
    1325      * @return int
     1379     * @return string
    13261380     */
    13271381    function bp_get_total_site_member_count() {
     
    13521406 *
    13531407 * @since 1.1.0
     1408 *
     1409 * @global BuddyPress $bp The one true BuddyPress instance.
    13541410 *
    13551411 * @todo Move to a back-compat file?
     
    14421498    }
    14431499
    1444     // Init the hierarchy
     1500    // Init the hierarchy.
    14451501    $template_names = array(
    14461502        'members/single/front-id-' . (int) $displayed_user->id . '.php',
     
    14601516        }
    14611517
    1462         $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type )   . '.php';
    1463     }
    1464 
    1465     // Add The generic template to the end of the hierarchy
     1518        $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type ) . '.php';
     1519    }
     1520
     1521    // Add The generic template to the end of the hierarchy.
    14661522    $template_names[] = 'members/single/front.php';
    14671523
     
    14711527     * @since 2.6.0
    14721528     *
    1473      * @param array  $template_names Array of template paths.
    1474      */
    1475     return bp_locate_template( apply_filters( 'bp_displayed_user_get_front_template', $template_names ), false, true );
     1529     * @param array $template_names Array of template paths.
     1530     */
     1531    $template_names = apply_filters( 'bp_displayed_user_get_front_template', $template_names );
     1532
     1533    return bp_locate_template( $template_names, false, true );
    14761534}
    14771535
     
    14911549 *
    14921550 * @since 1.1.0
     1551 *
     1552 * @global BuddyPress $bp The one true BuddyPress instance.
    14931553 */
    14941554function bp_get_displayed_user_nav() {
     
    16651725     * @since 1.5.0
    16661726     *
     1727     * @global BuddyPress $bp The one true BuddyPress instance.
     1728     *
    16671729     * @return string
    16681730     */
     
    16711733
    16721734        // If displayed user exists, return email address.
    1673         if ( isset( $bp->displayed_user->userdata->user_email ) )
     1735        if ( isset( $bp->displayed_user->userdata->user_email ) ) {
    16741736            $retval = $bp->displayed_user->userdata->user_email;
    1675         else
     1737        } else {
    16761738            $retval = '';
     1739        }
    16771740
    16781741        /**
     
    16961759 */
    16971760function bp_last_activity( $user_id = 0 ) {
    1698 
    1699     /**
    1700      * Filters the 'active [x days ago]' string for a user.
    1701      *
    1702      * @since 1.0.0
    1703      *
    1704      * @param string $value Formatted 'active [x days ago]' string.
    1705      */
    1706     echo apply_filters( 'bp_last_activity', bp_get_last_activity( $user_id ) );
     1761    echo bp_get_last_activity( $user_id );
    17071762}
    17081763    /**
     
    17581813
    17591814        // Try to get displayed user.
    1760         if ( empty( $name ) )
     1815        if ( empty( $name ) ) {
    17611816            $name = bp_get_displayed_user_fullname();
     1817        }
    17621818
    17631819        // Fall back on logged in user.
    1764         if ( empty( $name ) )
     1820        if ( empty( $name ) ) {
    17651821            $name = bp_get_loggedin_user_fullname();
     1822        }
    17661823
    17671824        $fullname = (array) explode( ' ', $name );
     
    18371894     * @deprecated
    18381895     */
    1839     function bp_user_link() { bp_displayed_user_domain(); }
     1896    function bp_user_link() {
     1897        bp_displayed_user_domain();
     1898    }
    18401899
    18411900/**
     
    18441903 * @since 1.0.0
    18451904 */
    1846 function bp_current_user_id() { return bp_displayed_user_id(); }
     1905function bp_current_user_id() {
     1906    return bp_displayed_user_id();
     1907}
    18471908
    18481909/**
     
    18501911 *
    18511912 * @since 1.0.0
     1913 *
     1914 * @global BuddyPress $bp The one true BuddyPress instance.
    18521915 *
    18531916 * @return string
     
    18711934 * @since 1.0.0
    18721935 *
     1936 * @global BuddyPress $bp The one true BuddyPress instance.
     1937 *
    18731938 * @return string
    18741939 */
     
    18991964     * @since 1.2.0
    19001965     *
     1966     * @global BuddyPress $bp The one true BuddyPress instance.
     1967     *
    19011968     * @return string
    19021969     */
     
    19352002     * @since 1.0.0
    19362003     *
     2004     * @global BuddyPress $bp The one true BuddyPress instance.
     2005     *
    19372006     * @return string
    19382007     */
     
    19622031     *
    19632032     * @since 1.2.0
     2033     *
     2034     * @global BuddyPress $bp The one true BuddyPress instance.
    19642035     *
    19652036     * @return string
     
    19962067     *
    19972068     * @since 1.2.0
     2069     *
     2070     * @global BuddyPress $bp The one true BuddyPress instance.
    19982071     *
    19992072     * @return string
     
    20982171 *
    20992172 * @since 7.0.0
    2100  * @see   bp_get_member_type_list() For additional information on default arguments.
     2173 *
     2174 * @see bp_get_member_type_list() For additional information on default arguments.
    21012175 *
    21022176 * @param int   $user_id User ID.
     
    21112185     * @since 7.0.0
    21122186     *
    2113      * @param int $user_id User ID. Defaults to displayed user ID if on a member page.
    2114      * @param array|string $r {
     2187     * @param int          $user_id User ID. Defaults to displayed user ID if on a member page.
     2188     * @param array|string $r       {
    21152189     *     Array of parameters. All items are optional.
    21162190     *     @type string $parent_element     Element to wrap around the list. Defaults to 'p'.
     
    22452319    static $has_page = false;
    22462320
    2247     if ( empty( $has_page ) )
     2321    if ( empty( $has_page ) ) {
    22482322        $has_page = bp_get_signup_slug() && bp_locate_template( array( 'registration/register.php', 'members/register.php', 'register.php' ), false );
     2323    }
    22492324
    22502325    return (bool) $has_page;
     
    25062581     * @since 2.1.0
    25072582     *
     2583     * @global WP_Network $current_site
     2584     *
    25082585     * @return string The base URL - eg, 'example.com' for site_url() example.com or www.example.com.
    25092586     */
     
    26022679     * @since 1.1.0
    26032680     *
     2681     * @global BuddyPress $bp The one true BuddyPress instance.
     2682     *
    26042683     * @return string
    26052684     */
     
    26692748     * @since 1.1.0
    26702749     *
     2750     * @global BuddyPress $bp The one true BuddyPress instance.
     2751     *
    26712752     * @return string
    26722753     */
     
    26912772     *
    26922773     * @since 1.1.0
     2774     *
     2775     * @global BuddyPress $bp The one true BuddyPress instance.
    26932776     *
    26942777     * @see bp_core_fetch_avatar() for description of arguments.
     
    27072790
    27082791        $defaults = array(
    2709             'size' => bp_core_avatar_full_width(),
     2792            'size'  => bp_core_avatar_full_width(),
    27102793            'class' => 'avatar',
    2711             'alt' => __( 'Your Profile Photo', 'buddypress' )
     2794            'alt'   => __( 'Your Profile Photo', 'buddypress' ),
    27122795        );
    27132796
     
    27152798        extract( $r, EXTR_SKIP );
    27162799
     2800        $signup_avatar_dir = bp_get_signup_avatar_dir_value();
     2801
    27172802        // Avatar DIR is found.
    2718         if ( $signup_avatar_dir = bp_get_signup_avatar_dir_value() ) {
     2803        if ( $signup_avatar_dir ) {
    27192804            $gravatar_img = bp_core_fetch_avatar( array(
    27202805                'item_id'    => $signup_avatar_dir,
     
    27252810                'height'     => $size,
    27262811                'alt'        => $alt,
    2727                 'class'      => $class
     2812                'class'      => $class,
    27282813            ) );
    27292814
     
    27322817
    27332818            // Set default gravatar type.
    2734             if ( empty( $bp->grav_default->user ) )
     2819            if ( empty( $bp->grav_default->user ) ) {
    27352820                $default_grav = 'wavatar';
    2736             elseif ( 'mystery' == $bp->grav_default->user )
     2821            } elseif ( 'mystery' === $bp->grav_default->user ) {
    27372822                $default_grav = $bp->plugin_url . 'bp-core/images/mystery-man.jpg';
    2738             else
     2823            } else {
    27392824                $default_grav = $bp->grav_default->user;
     2825            }
    27402826
    27412827            /**
     
    27802866     */
    27812867    function bp_get_signup_allowed() {
     2868
    27822869        /**
    27832870         * Filters whether or not new signups are allowed.
     
    29022989    echo bp_get_avatar_delete_link();
    29032990}
    2904 
    29052991    /**
    29062992     * Return an avatar delete link.
     
    29343020 *
    29353021 * @since 8.0.0
     3022 *
     3023 * @global BuddyPress $bp The one true BuddyPress instance.
    29363024 *
    29373025 * @param array|string $args {
     
    30083096 * @since 8.0.0
    30093097 *
     3098 * @global BuddyPress $bp The one true BuddyPress instance.
     3099 *
    30103100 * @return array List of network invitations.
    30113101 */
     
    30193109 * @since 8.0.0
    30203110 *
     3111 * @global BuddyPress $bp The one true BuddyPress instance.
     3112 *
    30213113 * @return object The current network invitation within the loop.
    30223114 */
     
    30383130     * @since 8.0.0
    30393131     *
     3132     * @global BuddyPress $bp The one true BuddyPress instance.
     3133     *
    30403134     * @return string HTML for the pagination count.
    30413135     */
    30423136    function bp_get_members_invitations_pagination_count() {
    3043         $query_loop = buddypress()->members->invitations->query_loop;
     3137        $bp         = buddypress();
     3138        $query_loop = $bp->members->invitations->query_loop;
    30443139        $start_num  = intval( ( $query_loop->pag_page - 1 ) * $query_loop->pag_num ) + 1;
    30453140        $from_num   = bp_core_number_format( $start_num );
     
    30773172     * @since 8.0.0
    30783173     *
     3174     * @global BuddyPress $bp The one true BuddyPress instance.
     3175     *
    30793176     * @return string HTML for the pagination links.
    30803177     */
    30813178    function bp_get_members_invitations_pagination_links() {
     3179        $bp = buddypress();
    30823180
    30833181        /**
     
    30883186         * @param string $pag_links HTML for the pagination links.
    30893187         */
    3090         return apply_filters( 'bp_get_members_invitations_pagination_links', buddypress()->members->invitations->query_loop->pag_links );
     3188        return apply_filters( 'bp_get_members_invitations_pagination_links', $bp->members->invitations->query_loop->pag_links );
    30913189    }
    30923190
Note: See TracChangeset for help on using the changeset viewer.