[buddypress-trac] [BuddyPress Trac] #6752: Provide the group object to the groups template filters
buddypress-trac
noreply at wordpress.org
Thu Nov 26 00:18:24 UTC 2015
#6752: Provide the group object to the groups template filters
--------------------------------+-----------------------------
Reporter: garrett-eclipse | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Component - Groups | Version: 2.4.0
Severity: normal | Keywords:
--------------------------------+-----------------------------
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
<?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
<?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
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6752>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list