Skip to:
Content

BuddyPress.org

Ticket #6749: 6749-1.diff

File 6749-1.diff, 54.6 KB (added by espellcaste, 4 years ago)
  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index 9ecddaad7..76292afc3 100644
    function groups_get_group( $group_id ) { 
    6969        return apply_filters( 'groups_get_group', $group );
    7070}
    7171
     72/**
     73 * Get a group from its identifier (ID, slug, BP_Groups_Group, defaults to: BP_Groups_Template).
     74 *
     75 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     76 *                                          Default: current group in loop.
     77 * @return BP_Groups_Group|null
     78 */
     79function bp_get_group_from_param( $group = false ) {
     80        global $groups_template;
     81
     82        $group_obj = null;
     83
     84        // Get group ID from its slug.
     85        if ( is_string( $group ) ) {
     86                $group = groups_get_id( $group );
     87        }
     88
     89        if ( $group instanceof BP_Groups_Group ) {
     90                $group_obj = $group;
     91        } elseif ( is_numeric( $group ) ) {
     92                $group_obj = groups_get_group( array( 'group_id' => $group ) );
     93        } elseif ( isset( $groups_template->group ) && is_object( $groups_template->group ) ) {
     94                $group_obj = $groups_template->group;
     95        }
     96
     97        if ( empty( $group_obj->id ) ) {
     98                return null;
     99        }
     100
     101        return $group_obj;
     102}
     103
    72104/** Group Creation, Editing & Deletion ****************************************/
    73105
    74106/**
  • src/bp-groups/bp-groups-template.php

    diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php
    index 91df7d46e..3ca705f97 100644
    function bp_groups_group_type_base() { 
    8989                 *
    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' ) );
    9595        }
    function bp_groups() { 
    541541 *
    542542 * @since 1.0.0
    543543 *
    544  * @return object
     544 * @return BP_Groups_Group
    545545 */
    546546function bp_the_group() {
    547547        global $groups_template;
    function bp_the_group() { 
    549549}
    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.
    555555 * In BP 2.9, a property was added to the BP_Groups_Group class,
    function bp_the_group() { 
    558558 * bp_current_user_can( 'groups_see_group' ).
    559559 *
    560560 * @since 1.0.0
     561 * @since 10.0.0 Updated to use `bp_get_group_from_param` and added the `$user_id` parameter.
    561562 *
    562  * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
     563 * @param int|string|BP_Groups_Group $group   Optional. Group identifier.
     564 *                                   Default: current group in loop.
     565 * @param int                        $user_id ID of the User.
     566 *                                   Default: current logged in user.
    563567 * @return bool
    564568 */
    565 function bp_group_is_visible( $group = null ) {
    566         global $groups_template;
     569function bp_group_is_visible( $group = false, $user_id = 0 ) {
     570        $group = bp_get_group_from_param( $group );
    567571
    568         if ( bp_current_user_can( 'bp_moderate' ) ) {
    569                 return true;
     572        if ( empty( $group->id ) ) {
     573                return false;
    570574        }
    571575
    572         if ( empty( $group ) ) {
    573                 $group =& $groups_template->group;
     576        if ( empty( $user_id ) ) {
     577                $user_id = bp_loggedin_user_id();
    574578        }
    575579
    576         return bp_current_user_can( 'groups_access_group', array( 'group_id' => $group->id ) );
     580        return (bool) ( bp_current_user_can( 'bp_moderate' ) || bp_user_can( $user_id, 'groups_access_group', array( 'group_id' => $group->id ) ) );
    577581}
    578582
    579583/**
    580  * Output the ID of the current group in the loop.
     584 * Output the ID of the group.
    581585 *
    582586 * @since 1.0.0
    583587 *
    584  * @param object|bool $group Optional. Group object. Default: current group in loop.
     588 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     589 *                                   Default: current group in loop.
    585590 */
    586591function bp_group_id( $group = false ) {
    587592        echo bp_get_group_id( $group );
    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
     598         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    593599         *
    594          * @param object|bool $group Optional. Group object.
    595          *                           Default: current group in loop.
     600         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     601         *                                   Default: current group in loop.
    596602         * @return int
    597603         */
    598604        function bp_get_group_id( $group = false ) {
    599                 global $groups_template;
     605                $group = bp_get_group_from_param( $group );
    600606
    601                 if ( empty( $group ) ) {
    602                         $group =& $groups_template->group;
     607                if ( empty( $group->id ) ) {
     608                        return 0;
    603609                }
    604610
    605611                /**
    606                  * Filters the ID of the current group in the loop.
     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 );
    615621        }
    function bp_group_class( $classes = array() ) { 
    696702        }
    697703
    698704/**
    699  * Output the name of the current group in the loop.
     705 * Output the name of the group.
    700706 *
    701707 * @since 1.0.0
    702708 *
    703  * @param object|bool $group Optional. Group object.
    704  *                           Default: current group in loop.
     709 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     710 *                                   Default: current group in loop.
    705711 */
    706712function bp_group_name( $group = false ) {
    707713        echo bp_get_group_name( $group );
    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
     719         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    713720         *
    714          * @param object|bool $group Optional. Group object.
    715          *                           Default: current group in loop.
     721         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     722         *                                   Default: current group in loop.
    716723         * @return string
    717          */
     724         */
    718725        function bp_get_group_name( $group = false ) {
    719                 global $groups_template;
     726                $group = bp_get_group_from_param( $group );
    720727
    721                 if ( empty( $group ) ) {
    722                         $group =& $groups_template->group;
     728                if ( empty( $group->id ) ) {
     729                        return '';
    723730                }
    724731
    725732                /**
    726                  * Filters the name of the current group in the loop.
     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 );
    735742        }
    736743
    737744/**
    738  * Output the type of the current group in the loop.
     745 * Output the type of the group.
    739746 *
    740747 * @since 1.0.0
    741748 *
    742  * @param object|bool $group Optional. Group object.
    743  *                           Default: current group in loop.
     749 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     750 *                                   Default: current group in loop.
    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 
    775755        /**
    776          * Filters the type for the current group in the loop.
     756         * Get the type of the group.
    777757         *
    778758         * @since 1.0.0
    779          * @since 2.5.0 Added the `$group` parameter.
     759         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    780760         *
    781          * @param string $type  Type for the current group in the loop.
    782          * @param object $group Group object.
     761         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     762     *                                          Default: current group in loop.
     763         * @return string
    783764         */
    784         return apply_filters( 'bp_get_group_type', $type, $group );
    785 }
     765        function bp_get_group_type( $group = false ) {
     766                $group = bp_get_group_from_param( $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
    786794/**
    787  * Output the status of the current group in the loop.
     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 int|string|BP_Groups_Group $group Optional. Group identifier.
     800 *                                          Default: current group in loop.
    793801 */
    794802function bp_group_status( $group = false ) {
    795803        echo bp_get_group_status( $group );
    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
     809         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    801810         *
    802          * @param object|bool $group Optional. Group object.
    803          *                           Default: current group in loop.
     811         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     812     *                                          Default: current group in loop.
    804813         * @return string
    805814         */
    806815        function bp_get_group_status( $group = false ) {
    807                 global $groups_template;
     816                $group  = bp_get_group_from_param( $group );
    808817
    809                 if ( empty( $group ) ) {
    810                         $group =& $groups_template->group;
     818                if ( empty( $group->id ) ) {
     819                        return '';
    811820                }
    812821
    813822                /**
    814                  * Filters the status of the current group in the loop.
     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 );
    823832        }
    824833
    825834/**
    826  * Output the group avatar while in the groups loop.
     835 * Output the group avatar.
    827836 *
    828837 * @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 * }
     843 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     844 *                                          Default: current group in loop.
    833845 */
    834 function bp_group_avatar( $args = '' ) {
    835         echo bp_get_group_avatar( $args );
     846function bp_group_avatar( $args = '', $group = false ) {
     847        echo bp_get_group_avatar( $args, $group );
    836848}
    837849        /**
    838850         * Get a group's avatar.
    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         *
    function bp_group_avatar( $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: false.
     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.
     870         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     871     *                                          Default: current group in loop.
     872         * @return string|bool Group avatar string or false if avatar uploads is disabled.
    856873         */
    857         function bp_get_group_avatar( $args = '' ) {
    858                 global $groups_template;
     874        function bp_get_group_avatar( $args = '', $group = false ) {
     875                $group = bp_get_group_from_param( $group );
     876
     877                if ( empty( $group->id ) ) {
     878                        return '';
     879                }
    859880
    860881                // Bail if avatars are turned off.
    861882                if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) {
    function bp_group_avatar( $args = '' ) { 
    863884                }
    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'    => false,
     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                 ) );
     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                );
    887918
    888                 // If No avatar found, provide some backwards compatibility.
     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 ) . '" />';
     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                        );
    891926                }
    892927
    893928                /**
    894                  * Filters the group avatar while in the groups loop.
     929                 * Filters the group avatar.
    895930                 *
    896931                 * @since 1.0.0
     932                 * @since 10.0.0 Added the `$group` paremeter.
    897933                 *
    898                  * @param string $avatar HTML image element holding the group avatar.
    899                  * @param array  $r      Array of parsed arguments for the group avatar.
     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.
    900937                 */
    901                 return apply_filters( 'bp_get_group_avatar', $avatar, $r );
     938                return apply_filters( 'bp_get_group_avatar', $avatar, $r, $group );
    902939        }
    903940
    904941/**
    905  * Output the group avatar thumbnail while in the groups loop.
     942 * Output the group avatar thumbnail.
    906943 *
    907944 * @since 1.0.0
    908945 *
    909  * @param object|bool $group Optional. Group object.
    910  *                           Default: current group in loop.
     946 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     947 *                                          Default: current group in loop.
    911948 */
    912949function bp_group_avatar_thumb( $group = false ) {
    913950        echo bp_get_group_avatar_thumb( $group );
    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.
     957         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     958         *                                          Default: current group in loop.
    922959         * @return string
    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                 ) );
     962                return bp_get_group_avatar(
     963                        array(
     964                                'type' => 'thumb',
     965                                'id'   => ! empty( $group->id ) ? $group->id : false,
     966                        ),
     967                        $group
     968                );
    929969        }
    930970
    931971/**
    932  * Output the miniature group avatar thumbnail while in the groups loop.
     972 * Output the miniature group avatar thumbnail.
    933973 *
    934974 * @since 1.0.0
    935975 *
    936  * @param object|bool $group Optional. Group object.
    937  *                           Default: current group in loop.
     976 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     977 *                                          Default: current group in loop.
    938978 */
    939979function bp_group_avatar_mini( $group = false ) {
    940980        echo bp_get_group_avatar_mini( $group );
    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 int|string|BP_Groups_Group $group Optional. Group identifier.
     988         *                                          Default: current group in loop.
    949989         * @return string
    950990         */
    951991        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                 ) );
     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                );
    9581001        }
    9591002
    9601003/**
    961  * Returns the group avatar URL.
     1004 * Output the group avatar URL.
    9621005 *
    963  * @since 5.0.0
     1006 * @since 10.0.0
    9641007 *
    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.
     1008 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1009 *                                   Default: current group in loop.
     1010 * @param string                     $type  Optional. The type of the avatar ('full' or 'thumb').
     1011 *                                   Default 'full'.
    9681012 */
    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         );
     1013function bp_group_avatar_url( $group = false, $type = 'full' ) {
     1014        echo bp_get_group_avatar_url( $group, $type );
    9841015}
     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 int|string|BP_Groups_Group $group Optional. Group identifier.
     1023         *                                   Default: current group in loop.
     1024         * @param string                     $type  Optional. The type of the avatar ('full' or 'thumb').
     1025         *                                   Default 'full'.
     1026         * @return string
     1027         */
     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
    function bp_get_group_avatar_url( $group = false, $type = 'full' ) { 
    9911037 * @since 2.4.0
    9921038 *
    9931039 * @return bool True if the displayed user has a cover image,
    994  *              False otherwise
     1040 *              False otherwise.
    9951041 */
    9961042function bp_group_use_cover_image_header() {
    9971043        return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads();
    function bp_group_use_cover_image_header() { 
    10011047 * Returns the group cover image URL.
    10021048 *
    10031049 * @since 5.0.0
     1050 * @since 10.0.0 Updated to use `bp_get_group_from_param`
    10041051 *
    1005  * @param object|bool $group Optional. Group object. Default current group in loop.
     1052 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1053 *                                          Default: current group in loop.
    10061054 * @return string The cover image URL or empty string if not found.
    10071055 */
    10081056function bp_get_group_cover_url( $group = false ) {
    1009         $group_id = bp_get_group_id( $group );
     1057        $group = bp_get_group_from_param( $group );
    10101058
    1011         if ( ! $group_id ) {
     1059        if ( empty( $group->id ) ) {
    10121060                return '';
    10131061        }
    10141062
    function bp_get_group_cover_url( $group = false ) { 
    10161064                'url',
    10171065                array(
    10181066                        'object_dir' => 'groups',
    1019                         'item_id'    => $group_id,
     1067                        'item_id'    => $group->id,
    10201068                )
    10211069        );
    10221070
    function bp_get_group_cover_url( $group = false ) { 
    10281076}
    10291077
    10301078/**
    1031  * Output the 'last active' string for the current group in the loop.
     1079 * Output the 'last active' string for the group.
    10321080 *
    10331081 * @since 1.0.0
    1034  * @since 2.7.0 Added $args as a parameter.
     1082 * @since 2.7.0 Added `$args` as a parameter.
    10351083 *
    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()}.
     1084 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1085 *                                          Default: current group in loop.
     1086 * @param array|string               $args  Optional. {@see bp_get_group_last_active()}.
    10381087 */
    10391088function bp_group_last_active( $group = false, $args = array() ) {
    10401089        echo bp_get_group_last_active( $group, $args );
    10411090}
    10421091        /**
    1043          * Return the 'last active' string for the current group in the loop.
     1092         * Return the 'last active' string for the group.
    10441093         *
    10451094         * @since 1.0.0
    1046          * @since 2.7.0 Added $args as a parameter.
     1095         * @since 2.7.0  Added `$args` as a parameter.
     1096         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    10471097         *
    1048          * @param object|bool  $group Optional. Group object. Default: current group in loop.
     1098         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1099     *                                          Default: current group in loop.
    10491100         * @param array|string $args {
    10501101         *     Array of optional parameters.
    10511102         *
    function bp_group_last_active( $group = false, $args = array() ) { 
    10551106         * @return string
    10561107         */
    10571108        function bp_get_group_last_active( $group = false, $args = array() ) {
    1058                 global $groups_template;
     1109                $group = bp_get_group_from_param( $group );
    10591110
    1060                 if ( empty( $group ) ) {
    1061                         $group =& $groups_template->group;
     1111                if ( empty( $group->id ) ) {
     1112                        return '';
    10621113                }
    10631114
    10641115                $r = bp_parse_args( $args, array(
    function bp_group_last_active( $group = false, $args = array() ) { 
    10861137                         * @since 1.0.0
    10871138                         * @since 2.5.0 Added the `$group` parameter.
    10881139                         *
    1089                          * @param string $value Determined last active value for the current group.
    1090                          * @param object $group Group object.
     1140                         * @param string               $value Determined last active value for the current group.
     1141                         * @param BP_Groups_Group|null $group The group object.
    10911142                         */
    10921143                        return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group );
    10931144                }
    10941145        }
    10951146
    10961147/**
    1097  * Output the permalink for the current group in the loop.
     1148 * Output the permalink for the group.
    10981149 *
    10991150 * @since 1.0.0
    11001151 *
    1101  * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
     1152 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1153 *                                   Default: current group in loop.
    11021154 */
    1103 function bp_group_permalink( $group = null ) {
     1155function bp_group_permalink( $group = false ) {
    11041156        echo bp_get_group_permalink( $group );
    11051157}
    11061158        /**
    1107          * Return the permalink for the current group in the loop.
     1159         * Return the permalink for the group.
    11081160         *
    11091161         * @since 1.0.0
     1162         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    11101163         *
    1111          * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
     1164         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1165     *                                   Default: current group in loop.
    11121166         * @return string
    11131167         */
    1114         function bp_get_group_permalink( $group = null ) {
    1115                 global $groups_template;
     1168        function bp_get_group_permalink( $group = false ) {
     1169                $group = bp_get_group_from_param( $group );
    11161170
    1117                 if ( empty( $group ) ) {
    1118                         $group =& $groups_template->group;
     1171                if ( empty( $group->id ) ) {
     1172                        return '';
    11191173                }
    11201174
    11211175                /**
    1122                  * Filters the permalink for the current group in the loop.
     1176                 * Filters the permalink for the group.
    11231177                 *
    11241178                 * @since 1.0.0
    11251179                 * @since 2.5.0 Added the `$group` parameter.
    11261180                 *
    1127                  * @param string $value Permalink for the current group in the loop.
    1128                  * @param object $group Group object.
     1181                 * @param string          $permalink Permalink for the group.
     1182                 * @param BP_Groups_Group $group     The group object.
    11291183                 */
    11301184                return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_group_slug( $group ) . '/' ), $group );
    11311185        }
    11321186
    11331187/**
    1134  * Output an HTML-formatted link for the current group in the loop.
     1188 * Output an HTML-formatted link for the group.
    11351189 *
    11361190 * @since 2.9.0
    11371191 *
    1138  * @param BP_Groups_Group|null $group Optional. Group object.
    1139  *                                    Default: current group in loop.
     1192 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1193 *                                   Default: current group in loop.
    11401194 */
    1141 function bp_group_link( $group = null ) {
     1195function bp_group_link( $group = false ) {
    11421196        echo bp_get_group_link( $group );
    11431197}
    11441198        /**
    1145          * Return an HTML-formatted link for the current group in the loop.
     1199         * Return an HTML-formatted link for the group.
    11461200         *
    11471201         * @since 2.9.0
     1202         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    11481203         *
    1149          * @param BP_Groups_Group|null $group Optional. Group object.
    1150          *                                    Default: current group in loop.
     1204         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1205     *                                   Default: current group in loop.
    11511206         * @return string
    11521207         */
    1153         function bp_get_group_link( $group = null ) {
    1154                 global $groups_template;
     1208        function bp_get_group_link( $group = false ) {
     1209                $group = bp_get_group_from_param( $group );
    11551210
    1156                 if ( empty( $group ) ) {
    1157                         $group =& $groups_template->group;
     1211                if ( empty( $group->id ) ) {
     1212                        return '';
    11581213                }
    11591214
    11601215                $link = sprintf(
    function bp_group_link( $group = null ) { 
    11651220                );
    11661221
    11671222                /**
    1168                  * Filters the HTML-formatted link for the current group in the loop.
     1223                 * Filters the HTML-formatted link for the group.
    11691224                 *
    11701225                 * @since 2.9.0
    11711226                 *
    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.
     1227                 * @param string          $link  HTML-formatted link for the group.
     1228                 * @param BP_Groups_Group $group The group object.
    11751229                 */
    11761230                return apply_filters( 'bp_get_group_link', $link, $group );
    11771231        }
    11781232
    11791233/**
    1180  * Output the permalink for the admin section of the current group in the loop.
     1234 * Output the permalink for the admin section of the group.
    11811235 *
    11821236 * @since 1.0.0
    11831237 *
    1184  * @param object|bool $group Optional. Group object.
    1185  *                           Default: current group in loop.
     1238 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1239 *                                   Default: current group in loop.
    11861240 */
    11871241function bp_group_admin_permalink( $group = false ) {
    11881242        echo bp_get_group_admin_permalink( $group );
    11891243}
    11901244        /**
    1191          * Return the permalink for the admin section of the current group in the loop.
     1245         * Return the permalink for the admin section of the group.
    11921246         *
    11931247         * @since 1.0.0
     1248         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    11941249         *
    1195          * @param object|bool $group Optional. Group object.
    1196          *                           Default: current group in loop.
     1250         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1251     *                                   Default: current group in loop.
    11971252         * @return string
    11981253         */
    11991254        function bp_get_group_admin_permalink( $group = false ) {
    1200                 global $groups_template;
     1255                $group = bp_get_group_from_param( $group );
    12011256
    1202                 if ( empty( $group ) ) {
    1203                         $group =& $groups_template->group;
     1257                if ( empty( $group->id ) ) {
     1258                        return '';
    12041259                }
    12051260
    12061261                /**
    1207                  * Filters the permalink for the admin section of the current group in the loop.
     1262                 * Filters the permalink for the admin section of the group.
    12081263                 *
    12091264                 * @since 1.0.0
    12101265                 * @since 2.5.0 Added the `$group` parameter.
    12111266                 *
    1212                  * @param string $value Permalink for the admin section of the current group in the loop.
    1213                  * @param object $group Group object.
     1267                 * @param string          $permalink Permalink for the admin section of the group.
     1268                 * @param BP_Groups_Group $group     The group object.
    12141269                 */
    12151270                return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ), $group );
    12161271        }
    12171272
    12181273/**
    1219  * Return the slug for the current group in the loop.
     1274 * Output the slug for the group.
    12201275 *
    12211276 * @since 1.0.0
    12221277 *
    1223  * @param object|bool $group Optional. Group object.
    1224  *                           Default: current group in loop.
     1278 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1279 *                                   Default: current group in loop.
    12251280 */
    12261281function bp_group_slug( $group = false ) {
    12271282        echo bp_get_group_slug( $group );
    12281283}
    12291284        /**
    1230          * Return the slug for the current group in the loop.
     1285         * Return the slug for the group.
    12311286         *
    12321287         * @since 1.0.0
     1288         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    12331289         *
    1234          * @param object|bool $group Optional. Group object.
    1235          *                           Default: current group in loop.
     1290         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1291     *                                   Default: current group in loop.
    12361292         * @return string
    12371293         */
    12381294        function bp_get_group_slug( $group = false ) {
    1239                 global $groups_template;
     1295                $group = bp_get_group_from_param( $group );
    12401296
    1241                 if ( empty( $group ) ) {
    1242                         $group =& $groups_template->group;
     1297                if ( empty( $group->id ) ) {
     1298                        return '';
    12431299                }
    12441300
    12451301                /**
    1246                  * Filters the slug for the current group in the loop.
     1302                 * Filters the slug for the group.
    12471303                 *
    12481304                 * @since 1.0.0
    12491305                 * @since 2.5.0 Added the `$group` parameter.
    12501306                 *
    1251                  * @param string $slug  Slug for the current group in the loop.
    1252                  * @param object $group Group object.
     1307                 * @param string          $slug  Slug for the group.
     1308                 * @param BP_Groups_Group $group The group object.
    12531309                 */
    12541310                return apply_filters( 'bp_get_group_slug', $group->slug, $group );
    12551311        }
    12561312
    12571313/**
    1258  * Output the description for the current group in the loop.
     1314 * Output the description for the group.
    12591315 *
    12601316 * @since 1.0.0
    12611317 *
    1262  * @param object|bool $group Optional. Group object.
    1263  *                           Default: current group in loop.
     1318 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1319 *                                   Default: current group in loop.
    12641320 */
    12651321function bp_group_description( $group = false ) {
    12661322        echo bp_get_group_description( $group );
    12671323}
    12681324        /**
    1269          * Return the description for the current group in the loop.
     1325         * Return the description for the group.
    12701326         *
    12711327         * @since 1.0.0
     1328         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    12721329         *
    1273          * @param object|bool $group Optional. Group object.
    1274          *                           Default: current group in loop.
     1330         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1331     *                                   Default: current group in loop.
    12751332         * @return string
    12761333         */
    12771334        function bp_get_group_description( $group = false ) {
    1278                 global $groups_template;
     1335                $group = bp_get_group_from_param( $group );
    12791336
    1280                 if ( empty( $group ) ) {
    1281                         $group =& $groups_template->group;
     1337                if ( empty( $group->id ) ) {
     1338                        return '';
    12821339                }
    12831340
    12841341                /**
    1285                  * Filters the description for the current group in the loop.
     1342                 * Filters the description for the group.
    12861343                 *
    12871344                 * @since 1.0.0
    12881345                 * @since 2.5.0 Added the `$group` parameter.
    12891346                 *
    1290                  * @param string $value Description for the current group.
    1291                  * @param object $group Group object.
     1347                 * @param string          $description Description for the group.
     1348                 * @param BP_Groups_Group $group       The group object.
    12921349                 */
    12931350                return apply_filters( 'bp_get_group_description', stripslashes( $group->description ), $group );
    12941351        }
    12951352
    12961353/**
    1297  * Output the description for the current group in the loop, for use in a textarea.
     1354 * Output the description for the group, for use in a textarea.
    12981355 *
    12991356 * @since 1.0.0
    13001357 *
    1301  * @param object|bool $group Optional. Group object.
    1302  *                           Default: current group in loop.
     1358 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1359 *                                          Default: current group in loop.
    13031360 */
    13041361function bp_group_description_editable( $group = false ) {
    13051362        echo bp_get_group_description_editable( $group );
    13061363}
    13071364        /**
    1308          * Return the permalink for the current group in the loop, for use in a textarea.
     1365         * Return the permalink for the group, for use in a textarea.
    13091366         *
    13101367         * 'bp_get_group_description_editable' does not have the formatting
    13111368         * filters that 'bp_get_group_description' has, which makes it
    13121369         * appropriate for "raw" editing.
    13131370         *
    13141371         * @since 1.0.0
     1372         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    13151373         *
    1316          * @param object|bool $group Optional. Group object.
    1317          *                           Default: current group in loop.
     1374         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1375     *                                   Default: current group in loop.
    13181376         * @return string
    13191377         */
    13201378        function bp_get_group_description_editable( $group = false ) {
    1321                 global $groups_template;
     1379                $group = bp_get_group_from_param( $group );
    13221380
    1323                 if ( empty( $group ) ) {
    1324                         $group =& $groups_template->group;
     1381                if ( empty( $group->id ) ) {
     1382                        return '';
    13251383                }
    13261384
    13271385                /**
    1328                  * Filters the permalink for the current group in the loop, for use in a textarea.
     1386                 * Filters the permalink for the group, for use in a textarea.
    13291387                 *
    13301388                 * 'bp_get_group_description_editable' does not have the formatting filters that
    13311389                 * 'bp_get_group_description' has, which makes it appropriate for "raw" editing.
    function bp_group_description_editable( $group = false ) { 
    13331391                 * @since 1.0.0
    13341392                 * @since 2.5.0 Added the `$group` parameter.
    13351393                 *
    1336                  * @param string $description Description for the current group in the loop.
    1337                  * @param object $group       Group object.
     1394                 * @param string          $description Description for the group.
     1395                 * @param BP_Groups_Group $group       The group object.
    13381396                 */
    13391397                return apply_filters( 'bp_get_group_description_editable', $group->description, $group );
    13401398        }
    function bp_group_description_editable( $group = false ) { 
    13441402 *
    13451403 * @since 1.0.0
    13461404 *
    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.
     1405 * @param int|string|BP_Groups_Group $group  Optional. Group identifier.
     1406 *                                           Default: current group in loop.
     1407 * @param int                        $length Optional. Length of returned string, including ellipsis.
     1408 *                                           Default: 225.
    13521409 */
    13531410function bp_group_description_excerpt( $group = false, $length = 225 ) {
    13541411        echo bp_get_group_description_excerpt( $group, $length );
    function bp_group_description_excerpt( $group = false, $length = 225 ) { 
    13571414         * Get an excerpt of a group description.
    13581415         *
    13591416         * @since 1.0.0
     1417         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    13601418         *
    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.
     1419         * @param int|string|BP_Groups_Group $group  Optional. Group identifier.
     1420     *                                   Default: current group in loop.
     1421         * @param int                        $length Optional. Length of returned string, including ellipsis.
     1422         *                                   Default: 225.
     1423         * @return string
    13671424         */
    13681425        function bp_get_group_description_excerpt( $group = false, $length = 225 ) {
    1369                 global $groups_template;
     1426                $group = bp_get_group_from_param( $group );
    13701427
    1371                 if ( empty( $group ) ) {
    1372                         $group =& $groups_template->group;
     1428                if ( empty( $group->id ) ) {
     1429                        return '';
    13731430                }
    13741431
    13751432                /**
    function bp_group_description_excerpt( $group = false, $length = 225 ) { 
    13771434                 *
    13781435                 * @since 1.0.0
    13791436                 *
    1380                  * @param string $value Excerpt of a group description.
    1381                  * @param object $group Object for group whose description is made into an excerpt.
     1437                 * @param string          $description Excerpt of a group description.
     1438                 * @param BP_Groups_Group $group       The group object.
    13821439                 */
    13831440                return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description, $length ), $group );
    13841441        }
    13851442
    13861443/**
    1387  * Output the created date of the current group in the loop.
     1444 * Output the created date of the group.
    13881445 *
    13891446 * @since 1.0.0
    1390  * @since 2.7.0 Added $args as a parameter.
     1447 * @since 2.7.0 Added `$args` as a parameter.
    13911448 *
    1392  * @param object|bool  $group Optional. Group object. Default: current group in loop.
    1393  * @param array|string $args  {@see bp_get_group_date_created()}.
     1449 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1450 *                                          Default: current group in loop.
     1451 * @param array|string               $args  {@see bp_get_group_date_created()}.
    13941452 */
    13951453function bp_group_date_created( $group = false, $args = array() ) {
    13961454        echo bp_get_group_date_created( $group, $args );
    13971455}
    13981456        /**
    1399          * Return the created date of the current group in the loop.
     1457         * Return the created date of the group.
    14001458         *
    14011459         * @since 1.0.0
    1402          * @since 2.7.0 Added $args as a parameter.
     1460         * @since 2.7.0  Added `$args` as a parameter.
     1461         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    14031462         *
    1404          * @param object|bool  $group Optional. Group object. Default: current group in loop.
    1405          * @param array|string $args {
     1463         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1464     *                                   Default: current group in loop.
     1465         * @param array|string               $args {
    14061466         *     Array of optional parameters.
    14071467         *
    14081468         *     @type bool $relative Optional. If true, returns relative created date. eg. active 5 months ago.
    function bp_group_date_created( $group = false, $args = array() ) { 
    14111471         * @return string
    14121472         */
    14131473        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' );
     1474                $group = bp_get_group_from_param( $group );
    14191475
    1420                 if ( empty( $group ) ) {
    1421                         $group =& $groups_template->group;
     1476                if ( empty( $group->id ) ) {
     1477                        return '';
    14221478                }
    14231479
     1480                $r = bp_parse_args(
     1481                        $args,
     1482                        array( 'relative' => true ),
     1483                        'group_date_created'
     1484                );
     1485
    14241486                // We do not want relative time, so return now.
    14251487                // @todo Should the 'bp_get_group_date_created' filter be applied here?
    14261488                if ( ! $r['relative'] ) {
    function bp_group_date_created( $group = false, $args = array() ) { 
    14281490                }
    14291491
    14301492                /**
    1431                  * Filters the created date of the current group in the loop.
     1493                 * Filters the created date of the group.
    14321494                 *
    14331495                 * @since 1.0.0
    14341496                 * @since 2.5.0 Added the `$group` parameter.
    14351497                 *
    1436                  * @param string $value Created date for the current group.
    1437                  * @param object $group Group object.
     1498                 * @param string          $date  Created date for the group.
     1499                 * @param BP_Groups_Group $group The group object.
    14381500                 */
    14391501                return apply_filters( 'bp_get_group_date_created', bp_core_time_since( $group->date_created ), $group );
    14401502        }
    14411503
    14421504/**
    1443  * Output the username of the creator of the current group in the loop.
     1505 * Output the username of the creator of the group.
    14441506 *
    14451507 * @since 1.7.0
    14461508 *
    1447  * @param object|bool $group Optional. Group object.
    1448  *                           Default: current group in loop.
     1509 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1510 *                                          Default: current group in loop.
    14491511 */
    14501512function bp_group_creator_username( $group = false ) {
    14511513        echo bp_get_group_creator_username( $group );
    14521514}
    14531515        /**
    1454          * Return the username of the creator of the current group in the loop.
     1516         * Return the username of the creator of the group.
    14551517         *
    14561518         * @since 1.7.0
     1519         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    14571520         *
    1458          * @param object|bool $group Optional. Group object.
    1459          *                           Default: current group in loop.
     1521         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1522     *                                   Default: current group in loop.
    14601523         * @return string
    14611524         */
    14621525        function bp_get_group_creator_username( $group = false ) {
    1463                 global $groups_template;
     1526                $group = bp_get_group_from_param( $group );
    14641527
    1465                 if ( empty( $group ) ) {
    1466                         $group =& $groups_template->group;
     1528                if ( empty( $group->id ) ) {
     1529                        return '';
    14671530                }
    14681531
    14691532                /**
    1470                  * Filters the username of the creator of the current group in the loop.
     1533                 * Filters the username of the creator of the group.
    14711534                 *
    14721535                 * @since 1.7.0
    14731536                 * @since 2.5.0 Added the `$group` parameter.
    14741537                 *
    1475                  * @param string $value Username of the group creator.
    1476                  * @param object $group Group object.
     1538                 * @param string          $creator_id Username of the group creator.
     1539                 * @param BP_Groups_Group $group      The group object.
    14771540                 */
    14781541                return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ), $group );
    14791542        }
    14801543
    14811544/**
    1482  * Output the user ID of the creator of the current group in the loop.
     1545 * Output the user ID of the creator of the group.
    14831546 *
    14841547 * @since 1.7.0
    14851548 *
    1486  * @param object|bool $group Optional. Group object.
    1487  *                           Default: current group in loop.
     1549 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1550 *                                          Default: current group in loop.
    14881551 */
    14891552function bp_group_creator_id( $group = false ) {
    14901553        echo bp_get_group_creator_id( $group );
    14911554}
    14921555        /**
    1493          * Return the user ID of the creator of the current group in the loop.
     1556         * Return the user ID of the creator of the group.
    14941557         *
    14951558         * @since 1.7.0
     1559         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    14961560         *
    1497          * @param object|bool $group Optional. Group object.
    1498          *                           Default: current group in loop.
     1561         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1562     *                                   Default: current group in loop.
    14991563         * @return int
    15001564         */
    15011565        function bp_get_group_creator_id( $group = false ) {
    1502                 global $groups_template;
     1566                $group = bp_get_group_from_param( $group );
    15031567
    1504                 if ( empty( $group ) ) {
    1505                         $group =& $groups_template->group;
     1568                if ( empty( $group->id ) ) {
     1569                        return 0;
    15061570                }
    15071571
    15081572                /**
    1509                  * Filters the user ID of the creator of the current group in the loop.
     1573                 * Filters the user ID of the creator of the group.
    15101574                 *
    15111575                 * @since 1.7.0
    15121576                 * @since 2.5.0 Added the `$group` parameter.
    15131577                 *
    1514                  * @param int $creator_id User ID of the group creator.
    1515                  * @param object $group Group object.
     1578                 * @param int             $creator_id User ID of the group creator.
     1579                 * @param BP_Groups_Group $group      The group object.
    15161580                 */
    15171581                return apply_filters( 'bp_get_group_creator_id', $group->creator_id, $group );
    15181582        }
    15191583
    15201584/**
    1521  * Output the permalink of the creator of the current group in the loop.
     1585 * Output the permalink of the creator of the group.
    15221586 *
    15231587 * @since 1.7.0
    15241588 *
    1525  * @param object|bool $group Optional. Group object.
    1526  *                           Default: current group in loop.
     1589 * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1590 *                                          Default: current group in loop.
    15271591 */
    15281592function bp_group_creator_permalink( $group = false ) {
    15291593        echo bp_get_group_creator_permalink( $group );
    15301594}
    15311595        /**
    1532          * Return the permalink of the creator of the current group in the loop.
     1596         * Return the permalink of the creator of the group.
    15331597         *
    15341598         * @since 1.7.0
     1599         * @since 10.0.0 Updated to use `bp_get_group_from_param`
    15351600         *
    1536          * @param object|bool $group Optional. Group object.
    1537          *                           Default: current group in loop.
     1601         * @param int|string|BP_Groups_Group $group Optional. Group identifier.
     1602     *                                   Default: current group in loop.
    15381603         * @return string
    15391604         */
    15401605        function bp_get_group_creator_permalink( $group = false ) {
    1541                 global $groups_template;
     1606                $group = bp_get_group_from_param( $group );
    15421607
    1543                 if ( empty( $group ) ) {
    1544                         $group =& $groups_template->group;
     1608                if ( empty( $group->id ) ) {
     1609                        return '';
    15451610                }
    15461611
    15471612                /**
    1548                  * Filters the permalink of the creator of the current group in the loop.
     1613                 * Filters the permalink of the creator of the group.
    15491614                 *
    15501615                 * @since 1.7.0
    15511616                 * @since 2.5.0 Added the `$group` parameter.
    15521617                 *
    1553                  * @param string $value Permalink of the group creator.
    1554                  * @param object $group Group object.
     1618                 * @param string          $permalink Permalink of the group creator.
     1619                 * @param BP_Groups_Group $group     The group object.
    15551620                 */
    15561621                return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ), $group );
    15571622        }
    15581623
    15591624/**
    1560  * Determine whether a user is the creator of the current group in the loop.
     1625 * Determine whether a user is the creator of the group.
    15611626 *
    15621627 * @since 1.7.0
     1628 * @since 10.0.0 Updated to use `bp_get_group_from_param`
    15631629 *
    1564  * @param BP_Groups_Group|null $group   Optional. Group object. Default: current group in loop.
    1565  * @param int                  $user_id ID of the user.
     1630 * @param int|string|BP_Groups_Group $group   Optional. Group identifier.
     1631 *                                            Default: current group in loop.
     1632 * @param int                        $user_id ID of the user.
     1633 *                                            Default: current logged in user.
    15661634 * @return bool
    15671635 */
    1568 function bp_is_group_creator( $group = null, $user_id = 0 ) {
    1569         global $groups_template;
     1636function bp_is_group_creator( $group = false, $user_id = 0 ) {
     1637        $group = bp_get_group_from_param( $group );
    15701638
    1571         if ( empty( $group ) ) {
    1572                 $group =& $groups_template->group;
     1639        if ( empty( $group->id ) ) {
     1640                return false;
    15731641        }
    15741642
    15751643        if ( empty( $user_id ) ) {
    15761644                $user_id = bp_loggedin_user_id();
    15771645        }
    15781646
    1579         return (bool) ( $group->creator_id == $user_id );
     1647        return (bool) ( $group->creator_id === $user_id );
    15801648}
    15811649
    15821650/**
    function bp_group_current_avatar( $type = 'thumb' ) { 
    54315499 * Return whether a group has an avatar.
    54325500 *
    54335501 * @since 1.1.0
     5502 * @since 10.0.0 Updated to use `bp_get_group_avatar`
    54345503 *
    54355504 * @param int|bool $group_id Group ID to check.
    5436  * @return boolean
     5505 * @return bool
    54375506 */
    54385507function bp_get_group_has_avatar( $group_id = false ) {
    54395508
    5440         if ( false === $group_id ) {
     5509        if ( empty( $group_id ) ) {
    54415510                $group_id = bp_get_current_group_id();
    54425511        }
    54435512
    54445513        $avatar_args = array(
    5445                 'item_id' => $group_id,
    5446                 'object'  => 'group',
    54475514                'no_grav' => true,
    54485515                'html'    => false,
    54495516                'type'    => 'thumb',
    54505517        );
    54515518
    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         }
     5519        $group_avatar = bp_get_group_avatar( $avatar_args, $group_id );
     5520        $avatar_args  = array_merge(
     5521                $avatar_args,
     5522                array(
     5523                        'item_id' => $group_id,
     5524                        'object'  => 'group',
     5525                )
     5526        );
    54575527
    5458         return true;
     5528        return ( bp_core_avatar_default( 'local', $avatar_args ) !== $group_avatar );
    54595529}
    54605530
    54615531/**
  • new file tests/phpunit/testcases/groups/functions/get-group-param.php

    diff --git tests/phpunit/testcases/groups/functions/get-group-param.php tests/phpunit/testcases/groups/functions/get-group-param.php
    new file mode 100644
    index 000000000..84a8cd923
    - +  
     1<?php
     2
     3/**
     4 * @group groups
     5 * @group functions
     6 */
     7class BP_Tests_Get_Groups_Param extends BP_UnitTestCase {
     8
     9        public function setUp() {
     10                parent::setUp();
     11
     12                if ( isset( $GLOBALS['groups_template'] ) ) {
     13                        $this->groups_template = $GLOBALS['groups_template'];
     14                }
     15        }
     16
     17        public function tearDown() {
     18                if ( $this->groups_template ) {
     19                        $GLOBALS['groups_template'] = $this->groups_template;
     20                }
     21
     22                parent::tearDown();
     23        }
     24
     25        public function test_bp_get_group_with_no_group() {
     26                $this->assertNull( bp_get_group_from_param() );
     27        }
     28
     29        public function test_bp_get_group_with_id() {
     30                $g = $this->factory->group->create();
     31
     32                $this->assertSame( $g, bp_get_group_from_param( $g )->id );
     33        }
     34
     35        public function test_bp_get_group_with_slug() {
     36                $slug  = 'test-group';
     37                $g     = $this->factory->group->create( array( 'slug' => $slug ) );
     38                $group = bp_get_group_from_param( $slug );
     39
     40                $this->assertSame( $g, $group->id );
     41                $this->assertSame( $slug, $group->slug );
     42        }
     43
     44        public function test_bp_get_group_with_object() {
     45                $g = $this->factory->group->create_and_get();
     46
     47                $this->assertSame( $g->id, bp_get_group_from_param( $g )->id );
     48        }
     49
     50        public function test_bp_get_group_from_groups_template() {
     51                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     52
     53                // Fake the current group.
     54                $GLOBALS['groups_template'] = new stdClass;
     55                $GLOBALS['groups_template']->group = groups_get_group( $g );
     56
     57                $this->assertSame( $g, bp_get_group_from_param()->id );
     58        }
     59}
  • new file tests/phpunit/testcases/groups/template/group-is-visible.php

    diff --git tests/phpunit/testcases/groups/template/group-is-visible.php tests/phpunit/testcases/groups/template/group-is-visible.php
    new file mode 100644
    index 000000000..c1f78148b
    - +  
     1<?php
     2
     3/**
     4 * @group groups
     5 * @group template
     6 */
     7class BP_Tests_Groups_Template_Is_Visible extends BP_UnitTestCase {
     8
     9        public function setUp() {
     10                parent::setUp();
     11
     12                if ( isset( $GLOBALS['groups_template'] ) ) {
     13                        $this->groups_template = $GLOBALS['groups_template'];
     14                }
     15        }
     16
     17        public function tearDown() {
     18                if ( $this->groups_template ) {
     19                        $GLOBALS['groups_template'] = $this->groups_template;
     20                }
     21
     22                parent::tearDown();
     23        }
     24
     25        public function test_bp_group_is_visible_no_member() {
     26                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     27
     28                $this->assertFalse( bp_group_is_visible( $g ) );
     29        }
     30
     31        public function test_bp_group_is_visible_regular_member() {
     32                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     33                $u = $this->factory->user->create();
     34
     35                $this->set_current_user( $u );
     36
     37                $this->assertFalse( bp_group_is_visible( $g ) );
     38        }
     39
     40        public function test_bp_group_is_visible_regular_member_from_group() {
     41                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     42                $u = $this->factory->user->create();
     43
     44                $this->set_current_user( $u );
     45
     46                $this->add_user_to_group( $u, $g );
     47
     48                $this->assertTrue( bp_group_is_visible( $g ) );
     49        }
     50
     51        public function test_bp_group_is_visible_invalid_group() {
     52                $u = $this->factory->user->create();
     53
     54                // Empty the current group.
     55                $GLOBALS['groups_template'] = new stdClass;
     56                $GLOBALS['groups_template']->group = null;
     57
     58                $this->set_current_user( $u );
     59
     60                $this->assertFalse( bp_group_is_visible() );
     61        }
     62
     63        public function test_bp_group_is_visible_admin() {
     64                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     65                $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
     66
     67                $this->set_current_user( $u );
     68
     69                $this->assertTrue( bp_group_is_visible( $g ) );
     70        }
     71
     72        public function test_bp_group_is_visible_using_user_id() {
     73                $g = $this->factory->group->create( array( 'status' => 'hidden' ) );
     74                $u = $this->factory->user->create();
     75
     76                $this->add_user_to_group( $u, $g );
     77
     78                $this->assertTrue( bp_group_is_visible( $g, $u ) );
     79        }
     80
     81        public function test_bp_group_is_not_visible_using_user_id() {
     82                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     83                $u = $this->factory->user->create();
     84
     85                $this->assertFalse( bp_group_is_visible( $g, $u ) );
     86        }
     87
     88        public function test_bp_group_is_visible_with_group_slug() {
     89                $slug = 'test-group';
     90
     91                $this->factory->group->create(
     92                        array(
     93                                'status' => 'private',
     94                                'slug'   => $slug,
     95                        )
     96                );
     97
     98                $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
     99
     100                $this->set_current_user( $u );
     101
     102                $this->assertTrue( bp_group_is_visible( $slug ) );
     103        }
     104
     105        public function test_bp_group_is_visible_from_current_group() {
     106                $g = $this->factory->group->create( array( 'status' => 'private' ) );
     107                $u = $this->factory->user->create( array( 'role' => 'administrator' ) );
     108
     109                // Fake the current group.
     110                $GLOBALS['groups_template'] = new stdClass;
     111                $GLOBALS['groups_template']->group = groups_get_group( $g );
     112
     113                $this->set_current_user( $u );
     114
     115                $this->assertTrue( bp_group_is_visible() );
     116        }
     117}
  • tests/phpunit/testcases/groups/template/

    diff --git tests/phpunit/testcases/groups/template/bpGroupStatusMessage.php tests/phpunit/testcases/groups/template/status-message.php
    similarity index 97%
    rename from tests/phpunit/testcases/groups/template/bpGroupStatusMessage.php
    rename to tests/phpunit/testcases/groups/template/status-message.php
    index bcc1ff3eb..c4fd836f7 100644
    old new  
    22
    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;
    910