Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/28/2015 03:24:45 AM (8 years ago)
Author:
boonebgorges
Message:

Pass group objects to some group template filters.

A number of group template functions accept a $group parameter, but are
generally used within the group loop, and infer the current group when no
object is explicitly passed to the function. Filter callbacks can generally
assume which group is intended when the filters are invoked within the loop
(by examining the $groups_template global), but this technique doesn't work
when the functions are used outside of the loop, with a $group passed as
a function parameter. In each of these cases, we should be passing the $group
object - whether inferred or explicit.

Props garrett-eclipse.
Fixes #6752.

File:
1 edited

Legend:

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

    r10378 r10383  
    661661         *
    662662         * @since 1.0.0
    663          *
    664          * @param int $id ID of the current group in the loop.
    665          */
    666         return apply_filters( 'bp_get_group_id', $group->id );
     663         * @since 2.5.0 Added the `$group` parameter.
     664         *
     665         * @param int    $id    ID of the current group in the loop.
     666         * @param object $group Group object.
     667         */
     668        return apply_filters( 'bp_get_group_id', $group->id, $group );
    667669    }
    668670
     
    768770         *
    769771         * @since 1.0.0
    770          *
    771          * @param string $name Name of the current group in the loop.
    772          */
    773         return apply_filters( 'bp_get_group_name', $group->name );
     772         * @since 2.5.0 Added the `$group` parameter.
     773         *
     774         * @param string $name  Name of the current group in the loop.
     775         * @param object $group Group object.
     776         */
     777        return apply_filters( 'bp_get_group_name', $group->name, $group );
    774778    }
    775779
     
    812816     *
    813817     * @since 1.0.0
    814      *
    815      * @param string $type Type for the current group in the loop.
    816      */
    817     return apply_filters( 'bp_get_group_type', $type );
     818     * @since 2.5.0 Added the `$group` parameter.
     819     *
     820     * @param string $type  Type for the current group in the loop.
     821     * @param object $group Group object.
     822     */
     823    return apply_filters( 'bp_get_group_type', $type, $group );
    818824}
    819825/**
     
    844850         *
    845851         * @since 1.0.0
     852         * @since 2.5.0 Added the `$group` parameter.
    846853         *
    847854         * @param string $status Status of the current group in the loop.
    848          */
    849         return apply_filters( 'bp_get_group_status', $group->status );
     855         * @param object $group  Group object.
     856         */
     857        return apply_filters( 'bp_get_group_status', $group->status, $group );
    850858    }
    851859
     
    10371045             *
    10381046             * @since 1.0.0
     1047             * @since 2.5.0 Added the `$group` parameter.
    10391048             *
    10401049             * @param string $value Determined last active value for the current group.
     1050             * @param object $group Group object.
    10411051             */
    1042             return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ) );
     1052            return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group );
    10431053        }
    10441054    }
     
    10711081         *
    10721082         * @since 1.0.0
     1083         * @since 2.5.0 Added the `$group` parameter.
    10731084         *
    10741085         * @param string $value Permalink for the current group in the loop.
    1075          */
    1076         return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . $group->slug . '/' ) );
     1086         * @param object $group Group object.
     1087         */
     1088        return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . $group->slug . '/' ), $group );
    10771089    }
    10781090
     
    11041116         *
    11051117         * @since 1.0.0
     1118         * @since 2.5.0 Added the `$group` parameter.
    11061119         *
    11071120         * @param string $value Permalink for the admin section of the current group in the loop.
    1108          */
    1109         return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ) );
     1121         * @param object $group Group object.
     1122         */
     1123        return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ), $group );
    11101124    }
    11111125
     
    11371151         *
    11381152         * @since 1.0.0
    1139          *
    1140          * @param string $slug Slug for the current group in the loop.
    1141          */
    1142         return apply_filters( 'bp_get_group_slug', $group->slug );
     1153         * @since 2.5.0 Added the `$group` parameter.
     1154         *
     1155         * @param string $slug  Slug for the current group in the loop.
     1156         * @param object $group Group object.
     1157         */
     1158        return apply_filters( 'bp_get_group_slug', $group->slug, $group );
    11431159    }
    11441160
     
    11701186         *
    11711187         * @since 1.0.0
     1188         * @since 2.5.0 Added the `$group` parameter.
    11721189         *
    11731190         * @param string $value Description for the current group.
    1174          */
    1175         return apply_filters( 'bp_get_group_description', stripslashes($group->description) );
     1191         * @param object $group Group object.
     1192         */
     1193        return apply_filters( 'bp_get_group_description', stripslashes( $group->description ), $group );
    11761194    }
    11771195
     
    12061224         * Filters the permalink for the current group in the loop, for use in a textarea.
    12071225         *
    1208          * 'bp_get_group_description_editable' does not have the formatting
    1209          * filters that 'bp_get_group_description' has, which makes it
    1210          * appropriate for "raw" editing.
     1226         * 'bp_get_group_description_editable' does not have the formatting filters that
     1227         * 'bp_get_group_description' has, which makes it appropriate for "raw" editing.
    12111228         *
    12121229         * @since 1.0.0
     1230         * @since 2.5.0 Added the `$group` parameter.
    12131231         *
    12141232         * @param string $description Description for the current group in the loop.
    1215          */
    1216         return apply_filters( 'bp_get_group_description_editable', $group->description );
     1233         * @param object $group       Group object.
     1234         */
     1235        return apply_filters( 'bp_get_group_description_editable', $group->description, $group );
    12171236    }
    12181237
     
    13141333        }
    13151334
    1316         return apply_filters( 'bp_get_group_is_public', $group->is_public );
     1335        /**
     1336         * Filters whether the current group in the loop is public.
     1337         *
     1338         * @since 2.5.0 Added the `$group` parameter.
     1339         *
     1340         * @param bool   $public True if the group is public.
     1341         * @param object $group Group object.
     1342         */
     1343        return apply_filters( 'bp_get_group_is_public', $group->is_public, $group );
    13171344    }
    13181345
     
    13441371         *
    13451372         * @since 1.0.0
     1373         * @since 2.5.0 Added the `$group` parameter.
    13461374         *
    13471375         * @param string $value Created date for the current group.
    1348          */
    1349         return apply_filters( 'bp_get_group_date_created', bp_core_time_since( strtotime( $group->date_created ) ) );
     1376         * @param object $group Group object.
     1377         */
     1378        return apply_filters( 'bp_get_group_date_created', bp_core_time_since( strtotime( $group->date_created ) ), $group );
    13501379    }
    13511380
     
    13771406         *
    13781407         * @since 1.7.0
     1408         * @since 2.5.0 Added the `$group` parameter.
    13791409         *
    13801410         * @param string $value Username of the group creator.
    1381          */
    1382         return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ) );
     1411         * @param object $group Group object.
     1412         */
     1413        return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ), $group );
    13831414    }
    13841415
     
    14101441         *
    14111442         * @since 1.7.0
     1443         * @since 2.5.0 Added the `$group` parameter.
    14121444         *
    14131445         * @param int $creator_id User ID of the group creator.
    1414          */
    1415         return apply_filters( 'bp_get_group_creator_id', $group->creator_id );
     1446         * @param object $group Group object.
     1447         */
     1448        return apply_filters( 'bp_get_group_creator_id', $group->creator_id, $group );
    14161449    }
    14171450
     
    14431476         *
    14441477         * @since 1.7.0
     1478         * @since 2.5.0 Added the `$group` parameter.
    14451479         *
    14461480         * @param string $value Permalink of the group creator.
    1447          */
    1448         return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ) );
     1481         * @param object $group Group object.
     1482         */
     1483        return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ), $group );
    14491484    }
    14501485
     
    15271562         *
    15281563         * @since 1.7.0
     1564         * @since 2.5.0 Added the `$group` parameter.
    15291565         *
    15301566         * @param string $avatar Avatar of the group creator.
    1531          */
    1532         return apply_filters( 'bp_get_group_creator_avatar', $avatar );
     1567         * @param object $group  Group object.
     1568         */
     1569        return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group );
    15331570    }
    15341571
     
    16791716     *
    16801717     * @since 1.5.0
     1718     * @since 2.5.0 Added the `$group` parameter.
    16811719     *
    16821720     * @param array|string $admin_ids List of user IDs for a group's admins.
    1683      */
    1684     return apply_filters( 'bp_group_admin_ids', $admin_ids );
     1721     * @param object       $group     Group object.
     1722     */
     1723    return apply_filters( 'bp_group_admin_ids', $admin_ids, $group );
    16851724}
    16861725
     
    17211760     *
    17221761     * @since 1.5.0
     1762     * @since 2.5.0 Added the `$group` parameter.
    17231763     *
    17241764     * @param array|string $admin_ids List of user IDs for a group's moderators.
    1725      */
    1726     return apply_filters( 'bp_group_mod_ids', $mod_ids );
     1765     * @param object       $group     Group object.
     1766     */
     1767    return apply_filters( 'bp_group_mod_ids', $mod_ids, $group );
    17271768}
    17281769
     
    17511792         *
    17521793         * @since 1.0.0
     1794         * @since 2.5.0 Added the `$group` parameter.
    17531795         *
    17541796         * @param string $value Permalink of the Members page for the current group.
    1755          */
    1756         return apply_filters( 'bp_get_group_all_members_permalink', bp_get_group_permalink( $group ) . 'members' );
     1797         * @param object $group Group object.
     1798         */
     1799        return apply_filters( 'bp_get_group_all_members_permalink', bp_get_group_permalink( $group ) . 'members', $group );
    17571800    }
    17581801
     
    19231966         *
    19241967         * @since 1.0.0
    1925          *
    1926          * @param int $total_member_count Total member count for a group.
    1927          */
    1928         return apply_filters( 'bp_get_group_total_members', $group->total_member_count );
     1968         * @since 2.5.0 Added the `$group` parameter.
     1969         *
     1970         * @param int    $total_member_count Total member count for a group.
     1971         * @param object $group              Group object.
     1972         */
     1973        return apply_filters( 'bp_get_group_total_members', $group->total_member_count, $group );
    19291974    }
    19301975
     
    19852030         *
    19862031         * @since 1.0.0
     2032         * @since 2.5.0 Added the `$group` parameter.
    19872033         *
    19882034         * @param string $value URL permalink for the Forum Page.
    1989          */
    1990         return apply_filters( 'bp_get_group_forum_permalink', bp_get_group_permalink( $group ) . 'forum' );
     2035         * @param object $group Group object.
     2036         */
     2037        return apply_filters( 'bp_get_group_forum_permalink', bp_get_group_permalink( $group ) . 'forum', $group );
    19912038    }
    19922039
     
    24852532     *
    24862533     * @since 1.0.0
    2487      *
    2488      * @param array $value Array of user IDs who are a moderator of the provided group.
    2489      */
    2490     return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ) );
     2534     * @since 2.5.0 Added the `$group` parameter.
     2535     *
     2536     * @param array  $value Array of user IDs who are a moderator of the provided group.
     2537     * @param object $group Group object.
     2538     */
     2539    return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ), $group );
    24912540}
    24922541
     
    26072656         *
    26082657         * @since 1.0.0
     2658         * @since 2.5.0 Added the `$group` parameter.
    26092659         *
    26102660         * @param string $value URL to use for demoting a user to member.
    2611          */
    2612         return apply_filters( 'bp_get_group_member_demote_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/demote/' . $user_id, 'groups_demote_member' ) );
     2661         * @param object $group Group object.
     2662         */
     2663        return apply_filters( 'bp_get_group_member_demote_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/demote/' . $user_id, 'groups_demote_member' ), $group );
    26132664    }
    26142665
     
    27312782         *
    27322783         * @since 1.2.6
     2784         * @since 2.5.0 Added the `$group` parameter.
    27332785         *
    27342786         * @param string $value URL to use for removing a member.
    2735          */
    2736         return apply_filters( 'bp_get_group_member_remove_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/remove/' . $user_id, 'groups_remove_member' ) );
     2787         * @param object $group Group object.
     2788         */
     2789        return apply_filters( 'bp_get_group_member_remove_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/remove/' . $user_id, 'groups_remove_member' ), $group );
    27372790    }
    27382791
     
    28442897         *
    28452898         * @since 1.0.0
     2899         * @since 2.5.0 Added the `$group` parameter.
    28462900         *
    28472901         * @param string $value Action attribute for a group form.
    2848          */
    2849         return apply_filters( 'bp_group_form_action', bp_get_group_permalink( $group ) . $page );
     2902         * @param object $group Group object.
     2903         */
     2904        return apply_filters( 'bp_group_form_action', bp_get_group_permalink( $group ) . $page, $group );
    28502905    }
    28512906
     
    28812936         *
    28822937         * @since 1.0.0
     2938         * @since 2.5.0 Added the `$group` parameter.
    28832939         *
    28842940         * @param string $value Action attribute for a group admin form.
    2885          */
    2886         return apply_filters( 'bp_group_admin_form_action', bp_get_group_permalink( $group ) . 'admin/' . $page );
     2941         * @param object $group Group object.
     2942         */
     2943        return apply_filters( 'bp_group_admin_form_action', bp_get_group_permalink( $group ) . 'admin/' . $page, $group );
    28872944    }
    28882945
     
    29332990     *
    29342991     * @since 1.2.4
    2935      *
    2936      * @param bool $is_member If user is a member of group or not.
    2937      */
    2938     return apply_filters( 'bp_group_is_member', !empty( $group->is_member ) );
     2992     * @since 2.5.0 Added the `$group` parameter.
     2993     *
     2994     * @param bool   $is_member If user is a member of group or not.
     2995     * @param object $group     Group object.
     2996     */
     2997    return apply_filters( 'bp_group_is_member', ! empty( $group->is_member ), $group );
    29392998}
    29402999
     
    29573016     *
    29583017     * @since 2.1.0
    2959      *
    2960      * @param bool $is_invited If user has an outstanding group invite.
    2961      */
    2962     return apply_filters( 'bp_group_is_invited', ! empty( $group->is_invited ) );
     3018     * @since 2.5.0 Added the `$group` parameter.
     3019     *
     3020     * @param bool   $is_invited If user has an outstanding group invite.
     3021     * @param object $group      Group object.
     3022     */
     3023    return apply_filters( 'bp_group_is_invited', ! empty( $group->is_invited ), $group );
    29633024}
    29643025
     
    30193080     *
    30203081     * @since 1.5.0
    3021      *
    3022      * @param bool $is_invited If user has been from current group.
    3023      */
    3024     return (bool) apply_filters( 'bp_group_is_user_banned', $retval );
     3082     * @since 2.5.0 Added the `$group` parameter.
     3083     *
     3084     * @param bool   $is_invited If user has been from current group.
     3085     * @param object $group      Group object.
     3086     */
     3087    return (bool) apply_filters( 'bp_group_is_user_banned', $retval, $group );
    30253088}
    30263089
     
    30513114         *
    30523115         * @since 1.0.0
     3116         * @since 2.5.0 Added the `$group` parameter.
    30533117         *
    30543118         * @param string $value URL for accepting an invitation to a group.
    3055          */
    3056         return apply_filters( 'bp_get_group_accept_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/accept/' . $group->id ), 'groups_accept_invite' ) );
     3119         * @param object $group Group object.
     3120         */
     3121        return apply_filters( 'bp_get_group_accept_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/accept/' . $group->id ), 'groups_accept_invite' ), $group );
    30573122    }
    30583123
     
    30833148         *
    30843149         * @since 1.0.0
     3150         * @since 2.5.0 Added the `$group` parameter.
    30853151         *
    30863152         * @param string $value URL for rejecting an invitation to a group.
    3087          */
    3088         return apply_filters( 'bp_get_group_reject_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/reject/' . $group->id ), 'groups_reject_invite' ) );
     3153         * @param object $group Group object.
     3154         */
     3155        return apply_filters( 'bp_get_group_reject_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/reject/' . $group->id ), 'groups_reject_invite' ), $group );
    30893156    }
    30903157
     
    31133180         *
    31143181         * @since 1.0.0
     3182         * @since 2.5.0 Added the `$group` parameter.
    31153183         *
    31163184         * @param string $value URL for confirming a request to leave a group.
    3117          */
    3118         return apply_filters( 'bp_group_leave_confirm_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group/yes', 'groups_leave_group' ) );
     3185         * @param object $group Group object.
     3186         */
     3187        return apply_filters( 'bp_group_leave_confirm_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group/yes', 'groups_leave_group' ), $group );
    31193188    }
    31203189
     
    31433212         *
    31443213         * @since 1.0.0
     3214         * @since 2.5.0 Added the `$group` parameter.
    31453215         *
    31463216         * @param string $value URL for rejecting a request to leave a group.
    3147          */
    3148         return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_permalink( $group ) );
     3217         * @param object $group Group object.
     3218         */
     3219        return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_permalink( $group ), $group );
    31493220    }
    31503221
     
    31733244         *
    31743245         * @since 1.0.0
     3246         * @since 2.5.0 Added the `$group` parameter.
    31753247         *
    31763248         * @param string $value Action attribute for a group send invite form.
    3177          */
    3178         return apply_filters( 'bp_group_send_invite_form_action', bp_get_group_permalink( $group ) . 'send-invites/send' );
     3249         * @param object $group Group object.
     3250         */
     3251        return apply_filters( 'bp_group_send_invite_form_action', bp_get_group_permalink( $group ) . 'send-invites/send', $group );
    31793252    }
    31803253
     
    32533326         *
    32543327         * @since 1.5.0
     3328         * @since 2.5.0 Added the `$group` parameter.
    32553329         *
    32563330         * @param string $button HTML button for a new topic.
    3257          */
    3258         return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button ) );
     3331         * @param object $group  Group object.
     3332         */
     3333        return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button, $group ) );
    32593334    }
    32603335
     
    43384413    }
    43394414
     4415    /**
     4416     * Filters the hierarchy of group front templates corresponding to a specific group.
     4417     *
     4418     * @since 2.4.0
     4419     * @since 2.5.0 Added the `$group` parameter.
     4420     *
     4421     * @param array  $template_names Array of template paths.
     4422     * @param object $group          Group object.
     4423     */
    43404424    $template_names = apply_filters( 'bp_groups_get_front_template', array(
    43414425        'groups/single/front-id-'     . sanitize_file_name( $group->id )     . '.php',
Note: See TracChangeset for help on using the changeset viewer.