#6752 closed defect (bug) (fixed)
Provide the group object to the groups template filters
Reported by: | garrett-eclipse | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 2.5 | Priority: | normal |
Severity: | normal | Version: | 2.4.0 |
Component: | Groups | Keywords: | |
Cc: |
Description
Hello,
This is an enhancement request to update the groups template filters such as bp_get_group_name to provide the filter with the group object.
This is beneficial in my case as I have a group meta field for short_name which I want to use to replace the group name on the front-end.
Currently the function in bp-groups/bp-groups-template.php starting line 742:
<?php /** * Output the name of the current group in the loop. * * @param object|bool $group Optional. Group object. * Default: current group in loop. */ function bp_group_name( $group = false ) { echo bp_get_group_name( $group ); } /** * Get the name of the current group in the loop. * * @param object|bool $group Optional. Group object. * Default: current group in loop. * @return string */ function bp_get_group_name( $group = false ) { global $groups_template; if ( empty( $group ) ) { $group =& $groups_template->group; } /** * Filters the name of the current group in the loop. * * @since 1.0.0 * * @param string $name Name of the current group in the loop. */ return apply_filters( 'bp_get_group_name', $group->name ); }
This applies the bp_get_group_name filter supplying the $group->name.
In most cases this will come to play within the groups loop which means we can use the groups_template to retrieve the group object. But in any plugin or custom code which calls bp_group_name or bp_get_group_name while supplying a group object there's no way to retrieve this object within the filter function.
I'd love to see this filter and most others within the bp-groups-template.php file supply the group object.
As an example of how I want to use the filter see below, it expects there's a group meta field called bp_group_short_name:
<?php // Use Short Name for Groups on Front-end function wplms_replace_group_name($name, $group) { if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) return $name; $short_name = groups_get_groupmeta( $group->id, 'bp_group_short_name' ); if ( ! empty( trim( $short_name ) ) ) { $name = $short_name; } return $name; } add_filter('bp_get_group_name', array($this, 'wplms_replace_group_name'), 10, 2);
Let me know if I can clarify or provide any information.
Thank you
Change History (5)
#1
@
9 years ago
- Milestone changed from Awaiting Review to 2.5
- Owner set to boonebgorges
- Status changed from new to assigned
#3
@
8 years ago
Opened new ticket to catch an instance where the $group object isn't being supplied to the bp_get_group_name filter in bp-groups-admin.php;
https://buddypress.trac.wordpress.org/ticket/7069
Yes, this looks correct. Anytime a function like this accepts a
$group
parameter, the$group
should also be passed to the filter. Thanks for the ticket, @garrett-eclipse.