Skip to:
Content

BuddyPress.org

Changeset 13085


Ignore:
Timestamp:
08/22/2021 12:38:43 AM (5 years ago)
Author:
espellcaste
Message:

We are introducing in this commit two new helper functions to get a group: bp_get_group_by and bp_get_group. The former allows for getting a group by id/ID or slug.
And the latter allows for getting a group by id/ID, group object, slug. And when used in the context of a Group loop built by the BP_Groups_Template class, it defaults to the Group being iterated on.

  • The new helper functions were applied to several functions in the Group component.
  • bp_group_is_visible was updated to check against a specific user ID. Previously, only the current logged in user was verified.
  • bp_get_group_avatar was updated to use the new functions and new arguments that are passed to bp_core_fetch_avatar were added.
  • PHPDoc were updated to reflect those changes.

Props imath, boonebgorges and DJPaul

Fixes #6749 (trunk)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-functions.php

    r12991 r13085  
    6868         */
    6969        return apply_filters( 'groups_get_group', $group );
     70}
     71
     72/**
     73 * Retrieve group by a given field.
     74 *
     75 * @since 10.0.0
     76 *
     77 * @param string     $field (Required) The field to use to retrieve the group.
     78 *                          Possible values are `'id'` or `'slug'`.
     79 * @param string|int $value (Required) A value for the $field. A Group ID or slug.
     80 * @return BP_Groups_Group|false The Group object if found, false otherwise.
     81 */
     82function bp_get_group_by( $field, $value ) {
     83        $group_id = $value;
     84
     85        if ( 'slug' === $field && is_string( $value ) ) {
     86                $group_id = groups_get_id( $value );
     87        }
     88
     89        $group = groups_get_group( array( 'group_id' => (int) $group_id ) );
     90
     91        if ( empty( $group->id ) ) {
     92                return false;
     93        }
     94
     95        return $group;
     96}
     97
     98/**
     99 * Retrieve a Group.
     100 *
     101 * When used into the context of a Groups loop built by the `BP_Groups_Template` class, it defaults to the
     102 * Group being iterated on.
     103 *
     104 * @since 10.0.0
     105 *
     106 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     107 *                                                Default: false.
     108 * @return BP_Groups_Group|false                  The Group object if found, false otherwise.
     109 */
     110function bp_get_group( $group = false ) {
     111        global $groups_template;
     112
     113        $group_obj = false;
     114
     115        if ( $group instanceof BP_Groups_Group ) {
     116                $group_obj = $group;
     117        } elseif ( is_string( $group ) ) {
     118                $group_obj = bp_get_group_by( 'slug', $group );
     119        } elseif ( is_numeric( $group ) ) {
     120                $group_obj = bp_get_group_by( 'id', $group );
     121        } elseif ( isset( $groups_template->group ) && is_object( $groups_template->group ) ) {
     122                $group_obj = $groups_template->group;
     123        }
     124
     125        return $group_obj;
    70126}
    71127
  • trunk/src/bp-groups/bp-groups-template.php

    r12930 r13085  
    9090                 * @since 2.7.0
    9191                 *
    92                  * @param string $base
     92                 * @param string $base Base slug of the group type.
    9393                 */
    9494                return apply_filters( 'bp_groups_group_type_base', _x( 'type', 'group type URL base', 'buddypress' ) );
     
    542542 * @since 1.0.0
    543543 *
    544  * @return object
     544 * @return BP_Groups_Group
    545545 */
    546546function bp_the_group() {
     
    550550
    551551/**
    552  * Is the group accessible to the currently logged-in user?
     552 * Is the group accessible to a user?
    553553 * Despite the name of the function, it has historically checked
    554554 * whether a user has access to a group.
     
    559559 *
    560560 * @since 1.0.0
    561  *
    562  * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
    563  * @return bool
    564  */
    565 function bp_group_is_visible( $group = null ) {
    566         global $groups_template;
    567 
    568         if ( bp_current_user_can( 'bp_moderate' ) ) {
    569                 return true;
    570         }
    571 
    572         if ( empty( $group ) ) {
    573                 $group =& $groups_template->group;
    574         }
    575 
    576         return bp_current_user_can( 'groups_access_group', array( 'group_id' => $group->id ) );
    577 }
    578 
    579 /**
    580  * Output the ID of the current group in the loop.
    581  *
    582  * @since 1.0.0
    583  *
    584  * @param object|bool $group Optional. Group object. Default: current group in loop.
     561 * @since 10.0.0 Updated to use `bp_get_group` and added the `$user_id` parameter.
     562 *
     563 * @param false|int|string|BP_Groups_Group $group   (Optional) The Group ID, the Group Slug or the Group object.
     564 *                                                  Default: false.
     565 * @param int                              $user_id ID of the User.
     566 *                                                  Default: current logged in user ID.
     567 * @return bool                                     True if the Group is accessible to the user. False otherwise.
     568 */
     569function bp_group_is_visible( $group = false, $user_id = 0 ) {
     570        $group = bp_get_group( $group );
     571
     572        if ( empty( $group->id ) ) {
     573                return false;
     574        }
     575
     576        if ( empty( $user_id ) ) {
     577                $user_id = bp_loggedin_user_id();
     578        }
     579
     580        return (bool) ( bp_current_user_can( 'bp_moderate' ) || bp_user_can( $user_id, 'groups_access_group', array( 'group_id' => $group->id ) ) );
     581}
     582
     583/**
     584 * Output the ID of the group.
     585 *
     586 * @since 1.0.0
     587 *
     588 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     589 *                                                 Default: false.
    585590 */
    586591function bp_group_id( $group = false ) {
     
    588593}
    589594        /**
    590          * Get the ID of the current group in the loop.
     595         * Get the ID of the group.
    591596         *
    592597         * @since 1.0.0
    593          *
    594          * @param object|bool $group Optional. Group object.
    595          *                           Default: current group in loop.
     598         * @since 10.0.0 Updated to use `bp_get_group`.
     599         *
     600         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     601         *                                   Default: false.
    596602         * @return int
    597603         */
    598604        function bp_get_group_id( $group = false ) {
    599                 global $groups_template;
    600 
    601                 if ( empty( $group ) ) {
    602                         $group =& $groups_template->group;
    603                 }
    604 
    605                 /**
    606                  * Filters the ID of the current group in the loop.
     605                $group = bp_get_group( $group );
     606
     607                if ( empty( $group->id ) ) {
     608                        return 0;
     609                }
     610
     611                /**
     612                 * Filters the ID of the group.
    607613                 *
    608614                 * @since 1.0.0
    609615                 * @since 2.5.0 Added the `$group` parameter.
    610616                 *
    611                  * @param int    $id    ID of the current group in the loop.
    612                  * @param object $group Group object.
     617                 * @param int             $id    ID of the group.
     618                 * @param BP_Groups_Group $group The group object.
    613619                 */
    614620                return apply_filters( 'bp_get_group_id', $group->id, $group );
     
    697703
    698704/**
    699  * Output the name of the current group in the loop.
    700  *
    701  * @since 1.0.0
    702  *
    703  * @param object|bool $group Optional. Group object.
    704  *                           Default: current group in loop.
     705 * Output the name of the group.
     706 *
     707 * @since 1.0.0
     708 *
     709 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     710 *                                                Default: false.
    705711 */
    706712function bp_group_name( $group = false ) {
     
    708714}
    709715        /**
    710          * Get the name of the current group in the loop.
     716         * Get the name of the group.
    711717         *
    712718         * @since 1.0.0
    713          *
    714          * @param object|bool $group Optional. Group object.
    715          *                           Default: current group in loop.
     719         * @since 10.0.0 Updated to use `bp_get_group`.
     720         *
     721         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     722         *                                                Default: current group in loop.
    716723         * @return string
    717          */
     724         */
    718725        function bp_get_group_name( $group = false ) {
    719                 global $groups_template;
    720 
    721                 if ( empty( $group ) ) {
    722                         $group =& $groups_template->group;
    723                 }
    724 
    725                 /**
    726                  * Filters the name of the current group in the loop.
     726                $group = bp_get_group( $group );
     727
     728                if ( empty( $group->id ) ) {
     729                        return '';
     730                }
     731
     732                /**
     733                 * Filters the name of the group.
    727734                 *
    728735                 * @since 1.0.0
    729736                 * @since 2.5.0 Added the `$group` parameter.
    730737                 *
    731                  * @param string $name  Name of the current group in the loop.
    732                  * @param object $group Group object.
     738                 * @param string          $name  Name of the group.
     739                 * @param BP_Groups_Group $group The group object.
    733740                 */
    734741                return apply_filters( 'bp_get_group_name', $group->name, $group );
     
    736743
    737744/**
    738  * Output the type of the current group in the loop.
    739  *
    740  * @since 1.0.0
    741  *
    742  * @param object|bool $group Optional. Group object.
    743  *                           Default: current group in loop.
     745 * Output the type of the group.
     746 *
     747 * @since 1.0.0
     748 *
     749 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     750 *                                                Default: false.
    744751 */
    745752function bp_group_type( $group = false ) {
    746753        echo bp_get_group_type( $group );
    747754}
    748 
    749 /**
    750  * Get the type of the current group in the loop.
    751  *
    752  * @since 1.0.0
    753  *
    754  * @param object|bool $group Optional. Group object.
    755  *                           Default: current group in loop.
    756  * @return string
    757  */
    758 function bp_get_group_type( $group = false ) {
    759         global $groups_template;
    760 
    761         if ( empty( $group ) ) {
    762                 $group =& $groups_template->group;
    763         }
    764 
    765         if ( 'public' == $group->status ) {
    766                 $type = __( "Public Group", 'buddypress' );
    767         } elseif ( 'hidden' == $group->status ) {
    768                 $type = __( "Hidden Group", 'buddypress' );
    769         } elseif ( 'private' == $group->status ) {
    770                 $type = __( "Private Group", 'buddypress' );
    771         } else {
    772                 $type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' );
    773         }
    774 
    775         /**
    776          * Filters the type for the current group in the loop.
     755        /**
     756         * Get the type of the group.
    777757         *
    778758         * @since 1.0.0
    779          * @since 2.5.0 Added the `$group` parameter.
    780          *
    781          * @param string $type  Type for the current group in the loop.
    782          * @param object $group Group object.
    783          */
    784         return apply_filters( 'bp_get_group_type', $type, $group );
    785 }
    786 /**
    787  * Output the status of the current group in the loop.
     759         * @since 10.0.0 Updated to use `bp_get_group`.
     760         *
     761         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     762     *                                                Default: false.
     763         * @return string
     764         */
     765        function bp_get_group_type( $group = false ) {
     766                $group = bp_get_group( $group );
     767
     768                if ( empty( $group->id ) ) {
     769                        return '';
     770                }
     771
     772                if ( 'public' === $group->status ) {
     773                        $type = __( "Public Group", 'buddypress' );
     774                } elseif ( 'hidden' === $group->status ) {
     775                        $type = __( "Hidden Group", 'buddypress' );
     776                } elseif ( 'private' === $group->status ) {
     777                        $type = __( "Private Group", 'buddypress' );
     778                } else {
     779                        $type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' );
     780                }
     781
     782                /**
     783                 * Filters the type for the group.
     784                 *
     785                 * @since 1.0.0
     786                 * @since 2.5.0 Added the `$group` parameter.
     787                 *
     788                 * @param string          $type  Type for the group.
     789                 * @param BP_Groups_Group $group The group object.
     790                 */
     791                return apply_filters( 'bp_get_group_type', $type, $group );
     792        }
     793
     794/**
     795 * Output the status of the group.
    788796 *
    789797 * @since 1.1.0
    790798 *
    791  * @param object|bool $group Optional. Group object.
    792  *                           Default: current group in loop.
     799 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     800 *                                                 Default: false.
    793801 */
    794802function bp_group_status( $group = false ) {
     
    796804}
    797805        /**
    798          * Get the status of the current group in the loop.
     806         * Get the status of the group.
    799807         *
    800808         * @since 1.1.0
    801          *
    802          * @param object|bool $group Optional. Group object.
    803          *                           Default: current group in loop.
     809         * @since 10.0.0 Updated to use `bp_get_group`.
     810         *
     811         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     812     *                                                Default: false.
    804813         * @return string
    805814         */
    806815        function bp_get_group_status( $group = false ) {
    807                 global $groups_template;
    808 
    809                 if ( empty( $group ) ) {
    810                         $group =& $groups_template->group;
    811                 }
    812 
    813                 /**
    814                  * Filters the status of the current group in the loop.
     816                $group  = bp_get_group( $group );
     817
     818                if ( empty( $group->id ) ) {
     819                        return '';
     820                }
     821
     822                /**
     823                 * Filters the status of the group.
    815824                 *
    816825                 * @since 1.0.0
    817826                 * @since 2.5.0 Added the `$group` parameter.
    818827                 *
    819                  * @param string $status Status of the current group in the loop.
    820                  * @param object $group  Group object.
     828                 * @param string          $status Status of the group.
     829                 * @param BP_Groups_Group $group  The group object.
    821830                 */
    822831                return apply_filters( 'bp_get_group_status', $group->status, $group );
     
    824833
    825834/**
    826  * Output the group avatar while in the groups loop.
    827  *
    828  * @since 1.0.0
     835 * Output the group avatar.
     836 *
     837 * @since 1.0.0
     838 * @since 10.0.0 Added the `$group` parameter.
    829839 *
    830840 * @param array|string $args {
    831841 *      See {@link bp_get_group_avatar()} for description of arguments.
    832842 * }
    833  */
    834 function bp_group_avatar( $args = '' ) {
    835         echo bp_get_group_avatar( $args );
     843 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     844 *                                                Default: false.
     845 */
     846function bp_group_avatar( $args = '', $group = false ) {
     847        echo bp_get_group_avatar( $args, $group );
    836848}
    837849        /**
     
    839851         *
    840852         * @since 1.0.0
     853         * @since 10.0.0 Added the `$group` parameter.
    841854         *
    842855         * @see bp_core_fetch_avatar() For a description of arguments and return values.
    843856         *
    844          * @param array|string $args {
     857         * @param array|string                     $args {
    845858         *     Arguments are listed here with an explanation of their defaults.
    846859         *     For more information about the arguments, see {@link bp_core_fetch_avatar()}.
    847860         *
    848          *     @type string   $alt     Default: 'Group logo of [group name]'.
    849          *     @type string   $class   Default: 'avatar'.
    850          *     @type string   $type    Default: 'full'.
    851          *     @type int|bool $width   Default: false.
    852          *     @type int|bool $height  Default: false.
    853          *     @type bool     $id      Passed to `$css_id` parameter.
     861         *     @type string       $type    Default: 'full'.
     862         *     @type int|bool     $width   Default: false.
     863         *     @type int|bool     $height  Default: false.
     864         *     @type string       $class   Default: 'avatar'.
     865         *     @type bool         $no_grav Default: false.
     866         *     @type bool         $html    Default: true.
     867         *     @type string|bool  $id      Passed to `$css_id` parameter. Default: false.
     868         *     @type string       $alt     Default: 'Group logo of [group name]'.
    854869         * }
    855          * @return string Group avatar string.
    856          */
    857         function bp_get_group_avatar( $args = '' ) {
    858                 global $groups_template;
     870         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     871     *                                                Default: false.
     872         * @return string|bool                            HTML output for the Group Avatar. or false if avatar uploads is disabled.
     873         */
     874        function bp_get_group_avatar( $args = '', $group = false ) {
     875                $group = bp_get_group( $group );
     876
     877                if ( empty( $group->id ) ) {
     878                        return '';
     879                }
    859880
    860881                // Bail if avatars are turned off.
     
    864885
    865886                // Parse the arguments.
    866                 $r = bp_parse_args( $args, array(
    867                         'type'   => 'full',
    868                         'width'  => false,
    869                         'height' => false,
    870                         'class'  => 'avatar',
    871                         'id'     => false,
    872                         'alt'    => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name )
    873                 ) );
     887                $r = bp_parse_args(
     888                        $args,
     889                        array(
     890                                'type'    => 'full',
     891                                'width'   => false,
     892                                'height'  => false,
     893                                'class'   => 'avatar',
     894                                'no_grav' => false,
     895                                'html'    => true,
     896                                'id'      => false,
     897                                // translators: %1$s is the name of the group.
     898                                'alt'     => sprintf( __( 'Group logo of %1$s', 'buddypress' ), $group->name ),
     899                        )
     900                );
    874901
    875902                // Fetch the avatar from the folder.
    876                 $avatar = bp_core_fetch_avatar( array(
    877                         'item_id'    => $groups_template->group->id,
    878                         'avatar_dir' => 'group-avatars',
    879                         'object'     => 'group',
    880                         'type'       => $r['type'],
    881                         'alt'        => $r['alt'],
    882                         'css_id'     => $r['id'],
    883                         'class'      => $r['class'],
    884                         'width'      => $r['width'],
    885                         'height'     => $r['height'],
    886                 ) );
    887 
    888                 // If No avatar found, provide some backwards compatibility.
     903                $avatar = bp_core_fetch_avatar(
     904                        array(
     905                                'item_id'    => $group->id,
     906                                'avatar_dir' => 'group-avatars',
     907                                'object'     => 'group',
     908                                'type'       => $r['type'],
     909                                'html'       => $r['html'],
     910                                'alt'        => $r['alt'],
     911                                'no_grav'    => $r['no_grav'],
     912                                'css_id'     => $r['id'],
     913                                'class'      => $r['class'],
     914                                'width'      => $r['width'],
     915                                'height'     => $r['height'],
     916                        )
     917                );
     918
     919                // If no avatar is found, provide some backwards compatibility.
    889920                if ( empty( $avatar ) ) {
    890                         $avatar = '<img src="' . esc_url( $groups_template->group->avatar_thumb ) . '" class="avatar" alt="' . esc_attr( $groups_template->group->name ) . '" />';
    891                 }
    892 
    893                 /**
    894                  * Filters the group avatar while in the groups loop.
     921                        $avatar = sprintf(
     922                                '<img src"%1$s" class="avatar" alt="%2$s" />',
     923                                esc_url( bp_get_group_avatar_thumb( $group ) ),
     924                                esc_attr( $group->name )
     925                        );
     926                }
     927
     928                /**
     929                 * Filters the group avatar.
    895930                 *
    896931                 * @since 1.0.0
    897                  *
    898                  * @param string $avatar HTML image element holding the group avatar.
    899                  * @param array  $r      Array of parsed arguments for the group avatar.
    900                  */
    901                 return apply_filters( 'bp_get_group_avatar', $avatar, $r );
    902         }
    903 
    904 /**
    905  * Output the group avatar thumbnail while in the groups loop.
    906  *
    907  * @since 1.0.0
    908  *
    909  * @param object|bool $group Optional. Group object.
    910  *                           Default: current group in loop.
     932                 * @since 10.0.0 Added the `$group` paremeter.
     933                 *
     934                 * @param string          $avatar HTML image element holding the group avatar.
     935                 * @param array           $r      Array of parsed arguments for the group avatar.
     936                 * @param BP_Groups_Group $group  The group object.
     937                 */
     938                return apply_filters( 'bp_get_group_avatar', $avatar, $r, $group );
     939        }
     940
     941/**
     942 * Output the group avatar thumbnail.
     943 *
     944 * @since 1.0.0
     945 *
     946 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     947 *                                                Default: false.
    911948 */
    912949function bp_group_avatar_thumb( $group = false ) {
     
    914951}
    915952        /**
    916          * Return the group avatar thumbnail while in the groups loop.
     953         * Return the group avatar thumbnail.
    917954         *
    918955         * @since 1.0.0
    919956         *
    920          * @param object|bool $group Optional. Group object.
    921          *                           Default: current group in loop.
    922          * @return string
     957         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     958         *                                                Default: false.
     959         * @return string                                 HTML output for the Group Avatar.
    923960         */
    924961        function bp_get_group_avatar_thumb( $group = false ) {
    925                 return bp_get_group_avatar( array(
    926                         'type' => 'thumb',
    927                         'id'   => ! empty( $group->id ) ? $group->id : false
    928                 ) );
    929         }
    930 
    931 /**
    932  * Output the miniature group avatar thumbnail while in the groups loop.
    933  *
    934  * @since 1.0.0
    935  *
    936  * @param object|bool $group Optional. Group object.
    937  *                           Default: current group in loop.
     962                return bp_get_group_avatar(
     963                        array(
     964                                'type' => 'thumb',
     965                                'id'   => ! empty( $group->id ) ? $group->id : false,
     966                        ),
     967                        $group
     968                );
     969        }
     970
     971/**
     972 * Output the miniature group avatar thumbnail.
     973 *
     974 * @since 1.0.0
     975 *
     976 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     977 *                                                Default: false.
    938978 */
    939979function bp_group_avatar_mini( $group = false ) {
     
    941981}
    942982        /**
    943          * Return the miniature group avatar thumbnail while in the groups loop.
     983         * Return the miniature group avatar thumbnail.
    944984         *
    945985         * @since 1.0.0
    946986         *
    947          * @param object|bool $group Optional. Group object.
    948          *                           Default: current group in loop.
     987         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     988         *                                                Default: false.
     989         * @return string                                 HTML output for the Group Avatar.
     990         */
     991        function bp_get_group_avatar_mini( $group = false ) {
     992                return bp_get_group_avatar(
     993                        array(
     994                                'type'   => 'thumb',
     995                                'width'  => 30,
     996                                'height' => 30,
     997                                'id'     => ! empty( $group->id ) ? $group->id : false,
     998                        ),
     999                        $group
     1000                );
     1001        }
     1002
     1003/**
     1004 * Output the group avatar URL.
     1005 *
     1006 * @since 10.0.0
     1007 *
     1008 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1009 *                                                Default: false.
     1010 * @param string                           $type  Optional. The type of the avatar ('full' or 'thumb').
     1011 *                                                Default 'full'.
     1012 */
     1013function bp_group_avatar_url( $group = false, $type = 'full' ) {
     1014        echo bp_get_group_avatar_url( $group, $type );
     1015}
     1016        /**
     1017         * Returns the group avatar URL.
     1018         *
     1019         * @since 5.0.0
     1020         * @since 10.0.0 Updated to use `bp_get_group_avatar`
     1021         *
     1022         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1023         *                                                Default: false.
     1024         * @param string                                  $type  Optional. The type of the avatar ('full' or 'thumb').
     1025         *                                                Default 'full'.
    9491026         * @return string
    9501027         */
    951         function bp_get_group_avatar_mini( $group = false ) {
    952                 return bp_get_group_avatar( array(
    953                         'type'   => 'thumb',
    954                         'width'  => 30,
    955                         'height' => 30,
    956                         'id'     => ! empty( $group->id ) ? $group->id : false
    957                 ) );
    958         }
    959 
    960 /**
    961  * Returns the group avatar URL.
    962  *
    963  * @since 5.0.0
    964  *
    965  * @param object|bool $group Optional. Group object. Default current group in loop.
    966  * @param string      $type  Optional. The type of the avatar ('full' or 'thumb'). Default 'full'.
    967  * @return string The avatar URL.
    968  */
    969 function bp_get_group_avatar_url( $group = false, $type = 'full' ) {
    970         $group_id = bp_get_group_id( $group );
    971 
    972         if ( ! $group_id ) {
    973                 return '';
    974         }
    975 
    976         return bp_core_fetch_avatar(
    977                 array(
    978                         'type'    => $type,
    979                         'object'  => 'group',
    980                         'item_id' => $group_id,
    981                         'html'    => false,
    982                 )
    983         );
    984 }
     1028        function bp_get_group_avatar_url( $group = false, $type = 'full' ) {
     1029                return bp_get_group_avatar( array( 'type' => $type ), $group );
     1030        }
    9851031
    9861032/** Group cover image *********************************************************/
    9871033
    9881034/**
    989  * Should we use the group's cover image header.
     1035 * Check if the group's cover image header enabled/active.
    9901036 *
    9911037 * @since 2.4.0
    9921038 *
    993  * @return bool True if the displayed user has a cover image,
    994  *              False otherwise
     1039 * @return bool True if the cover image header is enabled, false otherwise.
    9951040 */
    9961041function bp_group_use_cover_image_header() {
     
    10021047 *
    10031048 * @since 5.0.0
    1004  *
    1005  * @param object|bool $group Optional. Group object. Default current group in loop.
    1006  * @return string The cover image URL or empty string if not found.
     1049 * @since 10.0.0 Updated to use `bp_get_group`.
     1050 *
     1051 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1052 *                                                Default: false.
     1053 * @return string                                 The cover image URL or empty string if not found.
    10071054 */
    10081055function bp_get_group_cover_url( $group = false ) {
    1009         $group_id = bp_get_group_id( $group );
    1010 
    1011         if ( ! $group_id ) {
     1056        $group = bp_get_group( $group );
     1057
     1058        if ( empty( $group->id ) ) {
    10121059                return '';
    10131060        }
     
    10171064                array(
    10181065                        'object_dir' => 'groups',
    1019                         'item_id'    => $group_id,
     1066                        'item_id'    => $group->id,
    10201067                )
    10211068        );
     
    10291076
    10301077/**
    1031  * Output the 'last active' string for the current group in the loop.
    1032  *
    1033  * @since 1.0.0
    1034  * @since 2.7.0 Added $args as a parameter.
    1035  *
    1036  * @param object|bool  $group Optional. Group object. Default: current group in loop.
    1037  * @param array|string $args Optional. {@see bp_get_group_last_active()}.
     1078 * Output the 'last active' string for the group.
     1079 *
     1080 * @since 1.0.0
     1081 * @since 2.7.0 Added `$args` as a parameter.
     1082 *
     1083 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1084 *                                                Default: false.
     1085 * @param array|string                     $args  Optional. {@see bp_get_group_last_active()}.
    10381086 */
    10391087function bp_group_last_active( $group = false, $args = array() ) {
     
    10411089}
    10421090        /**
    1043          * Return the 'last active' string for the current group in the loop.
     1091         * Return the 'last active' string for the group.
    10441092         *
    10451093         * @since 1.0.0
    1046          * @since 2.7.0 Added $args as a parameter.
    1047          *
    1048          * @param object|bool  $group Optional. Group object. Default: current group in loop.
     1094         * @since 2.7.0  Added `$args` as a parameter.
     1095         * @since 10.0.0 Updated to use `bp_get_group`.
     1096         *
     1097         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1098     *                                                Default: false.
    10491099         * @param array|string $args {
    10501100         *     Array of optional parameters.
     
    10561106         */
    10571107        function bp_get_group_last_active( $group = false, $args = array() ) {
    1058                 global $groups_template;
    1059 
    1060                 if ( empty( $group ) ) {
    1061                         $group =& $groups_template->group;
     1108                $group = bp_get_group( $group );
     1109
     1110                if ( empty( $group->id ) ) {
     1111                        return '';
    10621112                }
    10631113
     
    10871137                         * @since 2.5.0 Added the `$group` parameter.
    10881138                         *
    1089                          * @param string $value Determined last active value for the current group.
    1090                          * @param object $group Group object.
     1139                         * @param string               $value Determined last active value for the current group.
     1140                         * @param BP_Groups_Group|null $group The group object.
    10911141                         */
    10921142                        return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group );
     
    10951145
    10961146/**
    1097  * Output the permalink for the current group in the loop.
    1098  *
    1099  * @since 1.0.0
    1100  *
    1101  * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
    1102  */
    1103 function bp_group_permalink( $group = null ) {
     1147 * Output the permalink for the group.
     1148 *
     1149 * @since 1.0.0
     1150 *
     1151 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1152 *                                                Default: false.
     1153 */
     1154function bp_group_permalink( $group = false ) {
    11041155        echo bp_get_group_permalink( $group );
    11051156}
    11061157        /**
    1107          * Return the permalink for the current group in the loop.
     1158         * Return the permalink for the group.
    11081159         *
    11091160         * @since 1.0.0
    1110          *
    1111          * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
     1161         * @since 10.0.0 Updated to use `bp_get_group`.
     1162         *
     1163         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1164     *                                                Default: false.
    11121165         * @return string
    11131166         */
    1114         function bp_get_group_permalink( $group = null ) {
    1115                 global $groups_template;
    1116 
    1117                 if ( empty( $group ) ) {
    1118                         $group =& $groups_template->group;
    1119                 }
    1120 
    1121                 /**
    1122                  * Filters the permalink for the current group in the loop.
     1167        function bp_get_group_permalink( $group = false ) {
     1168                $group = bp_get_group( $group );
     1169
     1170                if ( empty( $group->id ) ) {
     1171                        return '';
     1172                }
     1173
     1174                /**
     1175                 * Filters the permalink for the group.
    11231176                 *
    11241177                 * @since 1.0.0
    11251178                 * @since 2.5.0 Added the `$group` parameter.
    11261179                 *
    1127                  * @param string $value Permalink for the current group in the loop.
    1128                  * @param object $group Group object.
     1180                 * @param string          $permalink Permalink for the group.
     1181                 * @param BP_Groups_Group $group     The group object.
    11291182                 */
    11301183                return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_group_slug( $group ) . '/' ), $group );
     
    11321185
    11331186/**
    1134  * Output an HTML-formatted link for the current group in the loop.
     1187 * Output an HTML-formatted link for the group.
    11351188 *
    11361189 * @since 2.9.0
    11371190 *
    1138  * @param BP_Groups_Group|null $group Optional. Group object.
    1139  *                                    Default: current group in loop.
    1140  */
    1141 function bp_group_link( $group = null ) {
     1191 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1192 *                                                Default: false.
     1193 */
     1194function bp_group_link( $group = false ) {
    11421195        echo bp_get_group_link( $group );
    11431196}
    11441197        /**
    1145          * Return an HTML-formatted link for the current group in the loop.
     1198         * Return an HTML-formatted link for the group.
    11461199         *
    11471200         * @since 2.9.0
    1148          *
    1149          * @param BP_Groups_Group|null $group Optional. Group object.
    1150          *                                    Default: current group in loop.
     1201         * @since 10.0.0 Updated to use `bp_get_group`.
     1202         *
     1203         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1204     *                                                Default: false.
    11511205         * @return string
    11521206         */
    1153         function bp_get_group_link( $group = null ) {
    1154                 global $groups_template;
    1155 
    1156                 if ( empty( $group ) ) {
    1157                         $group =& $groups_template->group;
     1207        function bp_get_group_link( $group = false ) {
     1208                $group = bp_get_group( $group );
     1209
     1210                if ( empty( $group->id ) ) {
     1211                        return '';
    11581212                }
    11591213
     
    11661220
    11671221                /**
    1168                  * Filters the HTML-formatted link for the current group in the loop.
     1222                 * Filters the HTML-formatted link for the group.
    11691223                 *
    11701224                 * @since 2.9.0
    11711225                 *
    1172                  * @param string          $value HTML-formatted link for the
    1173                  *                               current group in the loop.
    1174                  * @param BP_Groups_Group $group The current group object.
     1226                 * @param string          $link  HTML-formatted link for the group.
     1227                 * @param BP_Groups_Group $group The group object.
    11751228                 */
    11761229                return apply_filters( 'bp_get_group_link', $link, $group );
     
    11781231
    11791232/**
    1180  * Output the permalink for the admin section of the current group in the loop.
    1181  *
    1182  * @since 1.0.0
    1183  *
    1184  * @param object|bool $group Optional. Group object.
    1185  *                           Default: current group in loop.
     1233 * Output the permalink for the admin section of the group.
     1234 *
     1235 * @since 1.0.0
     1236 *
     1237 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1238 *                                                Default: false.
    11861239 */
    11871240function bp_group_admin_permalink( $group = false ) {
     
    11891242}
    11901243        /**
    1191          * Return the permalink for the admin section of the current group in the loop.
     1244         * Return the permalink for the admin section of the group.
    11921245         *
    11931246         * @since 1.0.0
    1194          *
    1195          * @param object|bool $group Optional. Group object.
    1196          *                           Default: current group in loop.
     1247         * @since 10.0.0 Updated to use `bp_get_group`.
     1248         *
     1249         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1250     *                                                Default: false.
    11971251         * @return string
    11981252         */
    11991253        function bp_get_group_admin_permalink( $group = false ) {
    1200                 global $groups_template;
    1201 
    1202                 if ( empty( $group ) ) {
    1203                         $group =& $groups_template->group;
    1204                 }
    1205 
    1206                 /**
    1207                  * Filters the permalink for the admin section of the current group in the loop.
     1254                $group = bp_get_group( $group );
     1255
     1256                if ( empty( $group->id ) ) {
     1257                        return '';
     1258                }
     1259
     1260                /**
     1261                 * Filters the permalink for the admin section of the group.
    12081262                 *
    12091263                 * @since 1.0.0
    12101264                 * @since 2.5.0 Added the `$group` parameter.
    12111265                 *
    1212                  * @param string $value Permalink for the admin section of the current group in the loop.
    1213                  * @param object $group Group object.
     1266                 * @param string          $permalink Permalink for the admin section of the group.
     1267                 * @param BP_Groups_Group $group     The group object.
    12141268                 */
    12151269                return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ), $group );
     
    12171271
    12181272/**
    1219  * Return the slug for the current group in the loop.
    1220  *
    1221  * @since 1.0.0
    1222  *
    1223  * @param object|bool $group Optional. Group object.
    1224  *                           Default: current group in loop.
     1273 * Output the slug for the group.
     1274 *
     1275 * @since 1.0.0
     1276 *
     1277 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1278 *                                                Default: false.
    12251279 */
    12261280function bp_group_slug( $group = false ) {
     
    12281282}
    12291283        /**
    1230          * Return the slug for the current group in the loop.
     1284         * Return the slug for the group.
    12311285         *
    12321286         * @since 1.0.0
    1233          *
    1234          * @param object|bool $group Optional. Group object.
    1235          *                           Default: current group in loop.
     1287         * @since 10.0.0 Updated to use `bp_get_group`.
     1288         *
     1289         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1290     *                                                Default: false.
    12361291         * @return string
    12371292         */
    12381293        function bp_get_group_slug( $group = false ) {
    1239                 global $groups_template;
    1240 
    1241                 if ( empty( $group ) ) {
    1242                         $group =& $groups_template->group;
    1243                 }
    1244 
    1245                 /**
    1246                  * Filters the slug for the current group in the loop.
     1294                $group = bp_get_group( $group );
     1295
     1296                if ( empty( $group->id ) ) {
     1297                        return '';
     1298                }
     1299
     1300                /**
     1301                 * Filters the slug for the group.
    12471302                 *
    12481303                 * @since 1.0.0
    12491304                 * @since 2.5.0 Added the `$group` parameter.
    12501305                 *
    1251                  * @param string $slug  Slug for the current group in the loop.
    1252                  * @param object $group Group object.
     1306                 * @param string          $slug  Slug for the group.
     1307                 * @param BP_Groups_Group $group The group object.
    12531308                 */
    12541309                return apply_filters( 'bp_get_group_slug', $group->slug, $group );
     
    12561311
    12571312/**
    1258  * Output the description for the current group in the loop.
    1259  *
    1260  * @since 1.0.0
    1261  *
    1262  * @param object|bool $group Optional. Group object.
    1263  *                           Default: current group in loop.
     1313 * Output the description for the group.
     1314 *
     1315 * @since 1.0.0
     1316 *
     1317 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1318 *                                                Default: false.
    12641319 */
    12651320function bp_group_description( $group = false ) {
     
    12671322}
    12681323        /**
    1269          * Return the description for the current group in the loop.
     1324         * Return the description for the group.
    12701325         *
    12711326         * @since 1.0.0
    1272          *
    1273          * @param object|bool $group Optional. Group object.
    1274          *                           Default: current group in loop.
     1327         * @since 10.0.0 Updated to use `bp_get_group`.
     1328         *
     1329         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1330     *                                                Default: false.
    12751331         * @return string
    12761332         */
    12771333        function bp_get_group_description( $group = false ) {
    1278                 global $groups_template;
    1279 
    1280                 if ( empty( $group ) ) {
    1281                         $group =& $groups_template->group;
    1282                 }
    1283 
    1284                 /**
    1285                  * Filters the description for the current group in the loop.
     1334                $group = bp_get_group( $group );
     1335
     1336                if ( empty( $group->id ) ) {
     1337                        return '';
     1338                }
     1339
     1340                /**
     1341                 * Filters the description for the group.
    12861342                 *
    12871343                 * @since 1.0.0
    12881344                 * @since 2.5.0 Added the `$group` parameter.
    12891345                 *
    1290                  * @param string $value Description for the current group.
    1291                  * @param object $group Group object.
     1346                 * @param string          $description Description for the group.
     1347                 * @param BP_Groups_Group $group       The group object.
    12921348                 */
    12931349                return apply_filters( 'bp_get_group_description', stripslashes( $group->description ), $group );
     
    12951351
    12961352/**
    1297  * Output the description for the current group in the loop, for use in a textarea.
    1298  *
    1299  * @since 1.0.0
    1300  *
    1301  * @param object|bool $group Optional. Group object.
    1302  *                           Default: current group in loop.
     1353 * Output the description for the group, for use in a textarea.
     1354 *
     1355 * @since 1.0.0
     1356 *
     1357 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1358 *                                                Default: false.
    13031359 */
    13041360function bp_group_description_editable( $group = false ) {
     
    13061362}
    13071363        /**
    1308          * Return the permalink for the current group in the loop, for use in a textarea.
     1364         * Return the permalink for the group, for use in a textarea.
    13091365         *
    13101366         * 'bp_get_group_description_editable' does not have the formatting
     
    13131369         *
    13141370         * @since 1.0.0
    1315          *
    1316          * @param object|bool $group Optional. Group object.
    1317          *                           Default: current group in loop.
     1371         * @since 10.0.0 Updated to use `bp_get_group`.
     1372         *
     1373         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1374     *                                                Default: false.
    13181375         * @return string
    13191376         */
    13201377        function bp_get_group_description_editable( $group = false ) {
    1321                 global $groups_template;
    1322 
    1323                 if ( empty( $group ) ) {
    1324                         $group =& $groups_template->group;
    1325                 }
    1326 
    1327                 /**
    1328                  * Filters the permalink for the current group in the loop, for use in a textarea.
     1378                $group = bp_get_group( $group );
     1379
     1380                if ( empty( $group->id ) ) {
     1381                        return '';
     1382                }
     1383
     1384                /**
     1385                 * Filters the permalink for the group, for use in a textarea.
    13291386                 *
    13301387                 * 'bp_get_group_description_editable' does not have the formatting filters that
     
    13341391                 * @since 2.5.0 Added the `$group` parameter.
    13351392                 *
    1336                  * @param string $description Description for the current group in the loop.
    1337                  * @param object $group       Group object.
     1393                 * @param string          $description Description for the group.
     1394                 * @param BP_Groups_Group $group       The group object.
    13381395                 */
    13391396                return apply_filters( 'bp_get_group_description_editable', $group->description, $group );
     
    13451402 * @since 1.0.0
    13461403 *
    1347  * @param object|bool $group  Optional. The group being referenced.
    1348  *                            Defaults to the group currently being
    1349  *                            iterated on in the groups loop.
    1350  * @param int         $length Optional. Length of returned string, including ellipsis.
    1351  *                            Default: 225.
     1404 * @param false|int|string|BP_Groups_Group $group  (Optional) The Group ID, the Group Slug or the Group object.
     1405 *                                                 Default:false.
     1406 * @param int                              $length (Optional) Length of returned string, including ellipsis.
     1407 *                                                 Default: 225.
    13521408 */
    13531409function bp_group_description_excerpt( $group = false, $length = 225 ) {
     
    13581414         *
    13591415         * @since 1.0.0
    1360          *
    1361          * @param object|bool $group  Optional. The group being referenced.
    1362          *                            Defaults to the group currently being
    1363          *                            iterated on in the groups loop.
    1364          * @param int         $length Optional. Length of returned string, including ellipsis.
    1365          *                            Default: 225.
    1366          * @return string Excerpt.
     1416         * @since 10.0.0 Updated to use `bp_get_group`.
     1417         *
     1418         * @param false|int|string|BP_Groups_Group $group  (Optional) The Group ID, the Group Slug or the Group object.
     1419     *                                                 Default: false.
     1420         * @param int                              $length (Optional) Length of returned string, including ellipsis.
     1421         *                                                 Default: 225.
     1422         * @return string
    13671423         */
    13681424        function bp_get_group_description_excerpt( $group = false, $length = 225 ) {
    1369                 global $groups_template;
    1370 
    1371                 if ( empty( $group ) ) {
    1372                         $group =& $groups_template->group;
     1425                $group = bp_get_group( $group );
     1426
     1427                if ( empty( $group->id ) ) {
     1428                        return '';
    13731429                }
    13741430
     
    13781434                 * @since 1.0.0
    13791435                 *
    1380                  * @param string $value Excerpt of a group description.
    1381                  * @param object $group Object for group whose description is made into an excerpt.
     1436                 * @param string          $description Excerpt of a group description.
     1437                 * @param BP_Groups_Group $group       The group object.
    13821438                 */
    13831439                return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description, $length ), $group );
     
    13851441
    13861442/**
    1387  * Output the created date of the current group in the loop.
    1388  *
    1389  * @since 1.0.0
    1390  * @since 2.7.0 Added $args as a parameter.
    1391  *
    1392  * @param object|bool  $group Optional. Group object. Default: current group in loop.
    1393  * @param array|string $args  {@see bp_get_group_date_created()}.
     1443 * Output the created date of the group.
     1444 *
     1445 * @since 1.0.0
     1446 * @since 2.7.0 Added `$args` as a parameter.
     1447 *
     1448 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1449 *                                                Default: false.
     1450 * @param array|string                     $args  {@see bp_get_group_date_created()}.
    13941451 */
    13951452function bp_group_date_created( $group = false, $args = array() ) {
     
    13971454}
    13981455        /**
    1399          * Return the created date of the current group in the loop.
     1456         * Return the created date of the group.
    14001457         *
    14011458         * @since 1.0.0
    1402          * @since 2.7.0 Added $args as a parameter.
    1403          *
    1404          * @param object|bool  $group Optional. Group object. Default: current group in loop.
    1405          * @param array|string $args {
     1459         * @since 2.7.0  Added `$args` as a parameter.
     1460         * @since 10.0.0 Updated to use `bp_get_group`.
     1461         *
     1462         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1463     *                                                Default: false.
     1464         * @param array|string                     $args {
    14061465         *     Array of optional parameters.
    14071466         *
     
    14121471         */
    14131472        function bp_get_group_date_created( $group = false, $args = array() ) {
    1414                 global $groups_template;
    1415 
    1416                 $r = bp_parse_args( $args, array(
    1417                         'relative' => true,
    1418                 ), 'group_date_created' );
    1419 
    1420                 if ( empty( $group ) ) {
    1421                         $group =& $groups_template->group;
    1422                 }
     1473                $group = bp_get_group( $group );
     1474
     1475                if ( empty( $group->id ) ) {
     1476                        return '';
     1477                }
     1478
     1479                $r = bp_parse_args(
     1480                        $args,
     1481                        array( 'relative' => true ),
     1482                        'group_date_created'
     1483                );
    14231484
    14241485                // We do not want relative time, so return now.
     
    14291490
    14301491                /**
    1431                  * Filters the created date of the current group in the loop.
     1492                 * Filters the created date of the group.
    14321493                 *
    14331494                 * @since 1.0.0
    14341495                 * @since 2.5.0 Added the `$group` parameter.
    14351496                 *
    1436                  * @param string $value Created date for the current group.
    1437                  * @param object $group Group object.
     1497                 * @param string          $date  Created date for the group.
     1498                 * @param BP_Groups_Group $group The group object.
    14381499                 */
    14391500                return apply_filters( 'bp_get_group_date_created', bp_core_time_since( $group->date_created ), $group );
     
    14411502
    14421503/**
    1443  * Output the username of the creator of the current group in the loop.
     1504 * Output the username of the creator of the group.
    14441505 *
    14451506 * @since 1.7.0
    14461507 *
    1447  * @param object|bool $group Optional. Group object.
    1448  *                           Default: current group in loop.
     1508 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1509 *                                                Default: false.
    14491510 */
    14501511function bp_group_creator_username( $group = false ) {
     
    14521513}
    14531514        /**
    1454          * Return the username of the creator of the current group in the loop.
     1515         * Return the username of the creator of the group.
    14551516         *
    14561517         * @since 1.7.0
    1457          *
    1458          * @param object|bool $group Optional. Group object.
    1459          *                           Default: current group in loop.
     1518         * @since 10.0.0 Updated to use `bp_get_group`.
     1519         *
     1520         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1521     *                                                Default: false.
    14601522         * @return string
    14611523         */
    14621524        function bp_get_group_creator_username( $group = false ) {
    1463                 global $groups_template;
    1464 
    1465                 if ( empty( $group ) ) {
    1466                         $group =& $groups_template->group;
    1467                 }
    1468 
    1469                 /**
    1470                  * Filters the username of the creator of the current group in the loop.
     1525                $group = bp_get_group( $group );
     1526
     1527                if ( empty( $group->id ) ) {
     1528                        return '';
     1529                }
     1530
     1531                /**
     1532                 * Filters the username of the creator of the group.
    14711533                 *
    14721534                 * @since 1.7.0
    14731535                 * @since 2.5.0 Added the `$group` parameter.
    14741536                 *
    1475                  * @param string $value Username of the group creator.
    1476                  * @param object $group Group object.
     1537                 * @param string          $creator_id Username of the group creator.
     1538                 * @param BP_Groups_Group $group      The group object.
    14771539                 */
    14781540                return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ), $group );
     
    14801542
    14811543/**
    1482  * Output the user ID of the creator of the current group in the loop.
     1544 * Output the user ID of the creator of the group.
    14831545 *
    14841546 * @since 1.7.0
    14851547 *
    1486  * @param object|bool $group Optional. Group object.
    1487  *                           Default: current group in loop.
     1548 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1549 *                                                Default: false.
    14881550 */
    14891551function bp_group_creator_id( $group = false ) {
     
    14911553}
    14921554        /**
    1493          * Return the user ID of the creator of the current group in the loop.
     1555         * Return the user ID of the creator of the group.
    14941556         *
    14951557         * @since 1.7.0
    1496          *
    1497          * @param object|bool $group Optional. Group object.
    1498          *                           Default: current group in loop.
     1558         * @since 10.0.0 Updated to use `bp_get_group`.
     1559         *
     1560         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1561     *                                                Default: false.
    14991562         * @return int
    15001563         */
    15011564        function bp_get_group_creator_id( $group = false ) {
    1502                 global $groups_template;
    1503 
    1504                 if ( empty( $group ) ) {
    1505                         $group =& $groups_template->group;
    1506                 }
    1507 
    1508                 /**
    1509                  * Filters the user ID of the creator of the current group in the loop.
     1565                $group = bp_get_group( $group );
     1566
     1567                if ( empty( $group->id ) ) {
     1568                        return 0;
     1569                }
     1570
     1571                /**
     1572                 * Filters the user ID of the creator of the group.
    15101573                 *
    15111574                 * @since 1.7.0
    15121575                 * @since 2.5.0 Added the `$group` parameter.
    15131576                 *
    1514                  * @param int $creator_id User ID of the group creator.
    1515                  * @param object $group Group object.
     1577                 * @param int             $creator_id User ID of the group creator.
     1578                 * @param BP_Groups_Group $group      The group object.
    15161579                 */
    15171580                return apply_filters( 'bp_get_group_creator_id', $group->creator_id, $group );
     
    15191582
    15201583/**
    1521  * Output the permalink of the creator of the current group in the loop.
     1584 * Output the permalink of the creator of the group.
    15221585 *
    15231586 * @since 1.7.0
    15241587 *
    1525  * @param object|bool $group Optional. Group object.
    1526  *                           Default: current group in loop.
     1588 * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1589 *                                                Default: false.
    15271590 */
    15281591function bp_group_creator_permalink( $group = false ) {
     
    15301593}
    15311594        /**
    1532          * Return the permalink of the creator of the current group in the loop.
     1595         * Return the permalink of the creator of the group.
    15331596         *
    15341597         * @since 1.7.0
    1535          *
    1536          * @param object|bool $group Optional. Group object.
    1537          *                           Default: current group in loop.
     1598         * @since 10.0.0 Updated to use `bp_get_group`.
     1599         *
     1600         * @param false|int|string|BP_Groups_Group $group (Optional) The Group ID, the Group Slug or the Group object.
     1601     *                                                Default: false.
    15381602         * @return string
    15391603         */
    15401604        function bp_get_group_creator_permalink( $group = false ) {
    1541                 global $groups_template;
    1542 
    1543                 if ( empty( $group ) ) {
    1544                         $group =& $groups_template->group;
    1545                 }
    1546 
    1547                 /**
    1548                  * Filters the permalink of the creator of the current group in the loop.
     1605                $group = bp_get_group( $group );
     1606
     1607                if ( empty( $group->id ) ) {
     1608                        return '';
     1609                }
     1610
     1611                /**
     1612                 * Filters the permalink of the creator of the group.
    15491613                 *
    15501614                 * @since 1.7.0
    15511615                 * @since 2.5.0 Added the `$group` parameter.
    15521616                 *
    1553                  * @param string $value Permalink of the group creator.
    1554                  * @param object $group Group object.
     1617                 * @param string          $permalink Permalink of the group creator.
     1618                 * @param BP_Groups_Group $group     The group object.
    15551619                 */
    15561620                return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ), $group );
     
    15581622
    15591623/**
    1560  * Determine whether a user is the creator of the current group in the loop.
     1624 * Determine whether a user is the creator of the group.
    15611625 *
    15621626 * @since 1.7.0
    1563  *
    1564  * @param BP_Groups_Group|null $group   Optional. Group object. Default: current group in loop.
    1565  * @param int                  $user_id ID of the user.
     1627 * @since 10.0.0 Updated to use `bp_get_group`.
     1628 *
     1629 * @param false|int|string|BP_Groups_Group $group   (Optional) The Group ID, the Group Slug or the Group object.
     1630 *                                                  Default: false.
     1631 * @param int                              $user_id ID of the user.
     1632 *                                                  Default: current logged in user.
    15661633 * @return bool
    15671634 */
    1568 function bp_is_group_creator( $group = null, $user_id = 0 ) {
    1569         global $groups_template;
    1570 
    1571         if ( empty( $group ) ) {
    1572                 $group =& $groups_template->group;
     1635function bp_is_group_creator( $group = false, $user_id = 0 ) {
     1636        $group = bp_get_group( $group );
     1637
     1638        if ( empty( $group->id ) ) {
     1639                return false;
    15731640        }
    15741641
     
    15771644        }
    15781645
    1579         return (bool) ( $group->creator_id == $user_id );
     1646        return (bool) ( $group->creator_id === $user_id );
    15801647}
    15811648
     
    54325499 *
    54335500 * @since 1.1.0
     5501 * @since 10.0.0 Updated to use `bp_get_group_avatar`
    54345502 *
    54355503 * @param int|bool $group_id Group ID to check.
    5436  * @return boolean
     5504 * @return bool
    54375505 */
    54385506function bp_get_group_has_avatar( $group_id = false ) {
    54395507
    5440         if ( false === $group_id ) {
     5508        if ( empty( $group_id ) ) {
    54415509                $group_id = bp_get_current_group_id();
    54425510        }
    54435511
    54445512        $avatar_args = array(
    5445                 'item_id' => $group_id,
    5446                 'object'  => 'group',
    54475513                'no_grav' => true,
    54485514                'html'    => false,
     
    54505516        );
    54515517
    5452         $group_avatar = bp_core_fetch_avatar( $avatar_args );
    5453 
    5454         if ( bp_core_avatar_default( 'local', $avatar_args ) === $group_avatar ) {
    5455                 return false;
    5456         }
    5457 
    5458         return true;
     5518        $group_avatar = bp_get_group_avatar( $avatar_args, $group_id );
     5519        $avatar_args  = array_merge(
     5520                $avatar_args,
     5521                array(
     5522                        'item_id' => $group_id,
     5523                        'object'  => 'group',
     5524                )
     5525        );
     5526
     5527        return ( bp_core_avatar_default( 'local', $avatar_args ) !== $group_avatar );
    54595528}
    54605529
  • trunk/tests/phpunit/testcases/groups/template/bpGroupStatusMessage.php

    r12433 r13085  
    33/**
    44 * @group groups
     5 * @group template
    56 */
    6 class BP_Tests_Groups_Template_BpGroupStatusMessage extends BP_UnitTestCase {
     7class BP_Tests_Groups_Template_Status_Message extends BP_UnitTestCase {
    78        private $current_user;
    89        private $groups_template = null;
Note: See TracChangeset for help on using the changeset viewer.