groups->slug );
}
/**
* Output the groups component root slug.
*
* @since 1.5.0
*/
function bp_groups_root_slug() {
echo bp_get_groups_root_slug();
}
/**
* Return the groups component root slug.
*
* @since 1.5.0
*
* @return string
*/
function bp_get_groups_root_slug() {
/**
* Filters the groups component root slug.
*
* @since 1.5.0
*
* @param string $root_slug Groups component root slug.
*/
return apply_filters( 'bp_get_groups_root_slug', buddypress()->groups->root_slug );
}
/**
* Output the group type base slug.
*
* @since 2.7.0
*/
function bp_groups_group_type_base() {
echo esc_url( bp_get_groups_group_type_base() );
}
/**
* Get the group type base slug.
*
* The base slug is the string used as the base prefix when generating group
* type directory URLs. For example, in example.com/groups/type/foo/, 'foo' is
* the group type and 'type' is the base slug.
*
* @since 2.7.0
*
* @return string
*/
function bp_get_groups_group_type_base() {
/**
* Filters the group type URL base.
*
* @since 2.7.0
*
* @param string $base
*/
return apply_filters( 'bp_groups_group_type_base', _x( 'type', 'group type URL base', 'buddypress' ) );
}
/**
* Output group directory permalink.
*
* @since 1.5.0
*/
function bp_groups_directory_permalink() {
echo esc_url( bp_get_groups_directory_permalink() );
}
/**
* Return group directory permalink.
*
* @since 1.5.0
*
* @return string
*/
function bp_get_groups_directory_permalink() {
/**
* Filters the group directory permalink.
*
* @since 1.5.0
*
* @param string $value Permalink for the group directory.
*/
return apply_filters( 'bp_get_groups_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) );
}
/**
* Output group type directory permalink.
*
* @since 2.7.0
*
* @param string $group_type Optional. Group type.
*/
function bp_group_type_directory_permalink( $group_type = '' ) {
echo esc_url( bp_get_group_type_directory_permalink( $group_type ) );
}
/**
* Return group type directory permalink.
*
* @since 2.7.0
*
* @param string $group_type Optional. Group type. Defaults to current group type.
* @return string Group type directory URL on success, an empty string on failure.
*/
function bp_get_group_type_directory_permalink( $group_type = '' ) {
if ( $group_type ) {
$_group_type = $group_type;
} else {
// Fall back on the current group type.
$_group_type = bp_get_current_group_directory_type();
}
$type = bp_groups_get_group_type_object( $_group_type );
// Bail when member type is not found or has no directory.
if ( ! $type || ! $type->has_directory ) {
return '';
}
/**
* Filters the group type directory permalink.
*
* @since 2.7.0
*
* @param string $value Group type directory permalink.
* @param object $type Group type object.
* @param string $member_type Group type name, as passed to the function.
*/
return apply_filters( 'bp_get_group_type_directory_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_groups_group_type_base() . '/' . $type->directory_slug ), $type, $group_type );
}
/**
* Output group type directory link.
*
* @since 2.7.0
*
* @param string $group_type Unique group type identifier as used in bp_groups_register_group_type().
*/
function bp_group_type_directory_link( $group_type = '' ) {
echo bp_get_group_type_directory_link( $group_type );
}
/**
* Return group type directory link.
*
* @since 2.7.0
*
* @param string $group_type Unique group type identifier as used in bp_groups_register_group_type().
* @return string
*/
function bp_get_group_type_directory_link( $group_type = '' ) {
if ( empty( $group_type ) ) {
return '';
}
return sprintf( '%s', esc_url( bp_get_group_type_directory_permalink( $group_type ) ), bp_groups_get_group_type_object( $group_type )->labels['name'] );
}
/**
* Output a comma-delimited list of group types.
*
* @since 2.7.0
* @see bp_get_group_type_list() for parameter documentation.
*/
function bp_group_type_list( $group_id = 0, $r = array() ) {
echo bp_get_group_type_list( $group_id, $r );
}
/**
* Return a comma-delimited list of group types.
*
* @since 2.7.0
*
* @param int $group_id Group ID. Defaults to current group ID if on a group page.
* @param array|string $r {
* Array of parameters. All items are optional.
* @type string $parent_element Element to wrap around the list. Defaults to 'p'.
* @type array $parent_attr Element attributes for parent element. Defaults to
* array( 'class' => 'bp-group-type-list' ).
* @type string $label Label to add before the list. Defaults to 'Group Types:'.
* @type string $label_element Element to wrap around the label. Defaults to 'strong'.
* @type array $label_attr Element attributes for label element. Defaults to array().
* @type bool $show_all Whether to show all registered group types. Defaults to 'false'. If
* 'false', only shows group types with the 'show_in_list' parameter set to
* true. See bp_groups_register_group_type() for more info.
* }
* @return string
*/
function bp_get_group_type_list( $group_id = 0, $r = array() ) {
if ( empty( $group_id ) ) {
$group_id = bp_get_current_group_id();
}
$r = bp_parse_args( $r, array(
'parent_element' => 'p',
'parent_attr' => array(
'class' => 'bp-group-type-list',
),
'label' => __( 'Group Types:', 'buddypress' ),
'label_element' => 'strong',
'label_attr' => array(),
'show_all' => false,
), 'group_type_list' );
$retval = '';
if ( $types = bp_groups_get_group_type( $group_id, false ) ) {
// Make sure we can show the type in the list.
if ( false === $r['show_all'] ) {
$types = array_intersect( bp_groups_get_group_types( array( 'show_in_list' => true ) ), $types );
if ( empty( $types ) ) {
return $retval;
}
}
$before = $after = $label = '';
// Render parent element.
if ( ! empty( $r['parent_element'] ) ) {
$parent_elem = new BP_Core_HTML_Element( array(
'element' => $r['parent_element'],
'attr' => $r['parent_attr']
) );
// Set before and after.
$before = $parent_elem->get( 'open_tag' );
$after = $parent_elem->get( 'close_tag' );
}
// Render label element.
if ( ! empty( $r['label_element'] ) ) {
$label = new BP_Core_HTML_Element( array(
'element' => $r['label_element'],
'attr' => $r['label_attr'],
'inner_html' => esc_html( $r['label'] )
) );
$label = $label->contents() . ' ';
// No element, just the label.
} else {
$label = esc_html( $r['label'] );
}
// Comma-delimit each type into the group type directory link.
$label .= implode( ', ', array_map( 'bp_get_group_type_directory_link', $types ) );
// Retval time!
$retval = $before . $label . $after;
}
return $retval;
}
/**
* Start the Groups Template Loop.
*
* @since 1.0.0
* @since 2.6.0 Added `$group_type`, `$group_type__in`, and `$group_type__not_in` parameters.
* @since 2.7.0 Added `$update_admin_cache` parameter.
*
* @param array|string $args {
* Array of parameters. All items are optional.
* @type string $type Shorthand for certain orderby/order combinations. 'newest', 'active',
* 'popular', 'alphabetical', 'random'. When present, will override
* orderby and order params. Default: null.
* @type string $order Sort order. 'ASC' or 'DESC'. Default: 'DESC'.
* @type string $orderby Property to sort by. 'date_created', 'last_activity',
* 'total_member_count', 'name', 'random'. Default: 'last_activity'.
* @type int $page Page offset of results to return. Default: 1 (first page of results).
* @type int $per_page Number of items to return per page of results. Default: 20.
* @type int $max Does NOT affect query. May change the reported number of total groups
* found, but not the actual number of found groups. Default: false.
* @type bool $show_hidden Whether to include hidden groups in results. Default: false.
* @type string $page_arg Query argument used for pagination. Default: 'grpage'.
* @type int $user_id If provided, results will be limited to groups of which the specified
* user is a member. Default: value of bp_displayed_user_id().
* @type string $slug If provided, only the group with the matching slug will be returned.
* Default: false.
* @type string $search_terms If provided, only groups whose names or descriptions match the search
* terms will be returned. Default: value of `$_REQUEST['groups_search']` or
* `$_REQUEST['s']`, if present. Otherwise false.
* @type array|string $group_type Array or comma-separated list of group types to limit results to.
* @type array|string $group_type__in Array or comma-separated list of group types to limit results to.
* @type array|string $group_type__not_in Array or comma-separated list of group types that will be
* excluded from results.
* @type array $meta_query An array of meta_query conditions.
* See {@link WP_Meta_Query::queries} for description.
* @type array|string $include Array or comma-separated list of group IDs. Results will be limited
* to groups within the list. Default: false.
* @type array|string $exclude Array or comma-separated list of group IDs. Results will exclude
* the listed groups. Default: false.
* @type array|string $parent_id Array or comma-separated list of group IDs. Results will include only
* child groups of the listed groups. Default: null.
* @type bool $update_meta_cache Whether to fetch groupmeta for queried groups. Default: true.
* @type bool $update_admin_cache Whether to pre-fetch group admins for queried groups.
* Defaults to true when on a group directory, where this
* information is needed in the loop. Otherwise false.
* }
* @return bool True if there are groups to display that match the params
*/
function bp_has_groups( $args = '' ) {
global $groups_template;
/*
* Defaults based on the current page & overridden by parsed $args
*/
$slug = false;
$type = '';
$search_terms = false;
// When looking your own groups, check for two action variables.
if ( bp_is_current_action( 'my-groups' ) ) {
if ( bp_is_action_variable( 'most-popular', 0 ) ) {
$type = 'popular';
} elseif ( bp_is_action_variable( 'alphabetically', 0 ) ) {
$type = 'alphabetical';
}
// When looking at invites, set type to invites.
} elseif ( bp_is_current_action( 'invites' ) ) {
$type = 'invites';
// When looking at a single group, set the type and slug.
} elseif ( bp_get_current_group_slug() ) {
$type = 'single-group';
$slug = bp_get_current_group_slug();
}
$group_type = bp_get_current_group_directory_type();
if ( ! $group_type && ! empty( $_GET['group_type'] ) ) {
if ( is_array( $_GET['group_type'] ) ) {
$group_type = $_GET['group_type'];
} else {
// Can be a comma-separated list.
$group_type = explode( ',', $_GET['group_type'] );
}
}
// Default search string (too soon to escape here).
$search_query_arg = bp_core_get_component_search_query_arg( 'groups' );
if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
$search_terms = stripslashes( $_REQUEST[ $search_query_arg ] );
} elseif ( ! empty( $_REQUEST['group-filter-box'] ) ) {
$search_terms = $_REQUEST['group-filter-box'];
} elseif ( !empty( $_REQUEST['s'] ) ) {
$search_terms = $_REQUEST['s'];
}
// Parse defaults and requested arguments.
$r = bp_parse_args( $args, array(
'type' => $type,
'order' => 'DESC',
'orderby' => 'last_activity',
'page' => 1,
'per_page' => 20,
'max' => false,
'show_hidden' => false,
'page_arg' => 'grpage',
'user_id' => bp_displayed_user_id(),
'slug' => $slug,
'search_terms' => $search_terms,
'group_type' => $group_type,
'group_type__in' => '',
'group_type__not_in' => '',
'meta_query' => false,
'include' => false,
'exclude' => false,
'parent_id' => null,
'update_meta_cache' => true,
'update_admin_cache' => bp_is_groups_directory() || bp_is_user_groups(),
), 'has_groups' );
// Setup the Groups template global.
$groups_template = new BP_Groups_Template( array(
'type' => $r['type'],
'order' => $r['order'],
'orderby' => $r['orderby'],
'page' => (int) $r['page'],
'per_page' => (int) $r['per_page'],
'max' => (int) $r['max'],
'show_hidden' => $r['show_hidden'],
'page_arg' => $r['page_arg'],
'user_id' => (int) $r['user_id'],
'slug' => $r['slug'],
'search_terms' => $r['search_terms'],
'group_type' => $r['group_type'],
'group_type__in' => $r['group_type__in'],
'group_type__not_in' => $r['group_type__not_in'],
'meta_query' => $r['meta_query'],
'include' => $r['include'],
'exclude' => $r['exclude'],
'parent_id' => $r['parent_id'],
'update_meta_cache' => (bool) $r['update_meta_cache'],
'update_admin_cache' => (bool) $r['update_admin_cache'],
) );
/**
* Filters whether or not there are groups to iterate over for the groups loop.
*
* @since 1.1.0
*
* @param bool $value Whether or not there are groups to iterate over.
* @param BP_Groups_Template $groups_template BP_Groups_Template object based on parsed arguments.
* @param array $r Array of parsed arguments for the query.
*/
return apply_filters( 'bp_has_groups', $groups_template->has_groups(), $groups_template, $r );
}
/**
* Check whether there are more groups to iterate over.
*
* @since 1.0.0
*
* @return bool
*/
function bp_groups() {
global $groups_template;
return $groups_template->groups();
}
/**
* Set up the current group inside the loop.
*
* @since 1.0.0
*
* @return object
*/
function bp_the_group() {
global $groups_template;
return $groups_template->the_group();
}
/**
* Is the group visible to the currently logged-in user?
*
* @since 1.0.0
*
* @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
* @return bool
*/
function bp_group_is_visible( $group = null ) {
global $groups_template;
if ( bp_current_user_can( 'bp_moderate' ) ) {
return true;
}
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( 'public' == $group->status ) {
return true;
} else {
if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
return true;
}
}
return false;
}
/**
* Output the ID of the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
*/
function bp_group_id( $group = false ) {
echo bp_get_group_id( $group );
}
/**
* Get the ID of the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return int
*/
function bp_get_group_id( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the ID of the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param int $id ID of the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_id', $group->id, $group );
}
/**
* Output the row class of the current group in the loop.
*
* @since 1.7.0
*
* @param array $classes Array of custom classes.
*/
function bp_group_class( $classes = array() ) {
echo bp_get_group_class( $classes );
}
/**
* Get the row class of the current group in the loop.
*
* @since 1.7.0
*
* @param array $classes Array of custom classes.
* @return string Row class of the group.
*/
function bp_get_group_class( $classes = array() ) {
global $groups_template;
// Add even/odd classes, but only if there's more than 1 group.
if ( $groups_template->group_count > 1 ) {
$pos_in_loop = (int) $groups_template->current_group;
$classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
// If we've only one group in the loop, don't bother with odd and even.
} else {
$classes[] = 'bp-single-group';
}
// Group type - public, private, hidden.
$classes[] = sanitize_key( $groups_template->group->status );
// Add current group types.
if ( $group_types = bp_groups_get_group_type( bp_get_group_id(), false ) ) {
foreach ( $group_types as $group_type ) {
$classes[] = sprintf( 'group-type-%s', esc_attr( $group_type ) );
}
}
// User's group role.
if ( bp_is_user_active() ) {
// Admin.
if ( bp_group_is_admin() ) {
$classes[] = 'is-admin';
}
// Moderator.
if ( bp_group_is_mod() ) {
$classes[] = 'is-mod';
}
// Member.
if ( bp_group_is_member() ) {
$classes[] = 'is-member';
}
}
// Whether a group avatar will appear.
if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) {
$classes[] = 'group-no-avatar';
} else {
$classes[] = 'group-has-avatar';
}
/**
* Filters classes that will be applied to row class of the current group in the loop.
*
* @since 1.7.0
*
* @param array $classes Array of determined classes for the row.
*/
$classes = apply_filters( 'bp_get_group_class', $classes );
$classes = array_merge( $classes, array() );
$retval = 'class="' . join( ' ', $classes ) . '"';
return $retval;
}
/**
* Output the name of the current group in the loop.
*
* @since 1.0.0
*
* @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.
*
* @since 1.0.0
*
* @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
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $name Name of the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_name', $group->name, $group );
}
/**
* Output the type of the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_type( $group = false ) {
echo bp_get_group_type( $group );
}
/**
* Get the type of the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_type( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( 'public' == $group->status ) {
$type = __( "Public Group", 'buddypress' );
} elseif ( 'hidden' == $group->status ) {
$type = __( "Hidden Group", 'buddypress' );
} elseif ( 'private' == $group->status ) {
$type = __( "Private Group", 'buddypress' );
} else {
$type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' );
}
/**
* Filters the type for the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $type Type for the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_type', $type, $group );
}
/**
* Output the status of the current group in the loop.
*
* @since 1.1.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_status( $group = false ) {
echo bp_get_group_status( $group );
}
/**
* Get the status of the current group in the loop.
*
* @since 1.1.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_status( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the status of the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $status Status of the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_status', $group->status, $group );
}
/**
* Output the group avatar while in the groups loop.
*
* @since 1.0.0
*
* @param array|string $args {
* See {@link bp_get_group_avatar()} for description of arguments.
* }
*/
function bp_group_avatar( $args = '' ) {
echo bp_get_group_avatar( $args );
}
/**
* Get a group's avatar.
*
* @since 1.0.0
*
* @see bp_core_fetch_avatar() For a description of arguments and return values.
*
* @param array|string $args {
* Arguments are listed here with an explanation of their defaults.
* For more information about the arguments, see {@link bp_core_fetch_avatar()}.
*
* @type string $alt Default: 'Group logo of [group name]'.
* @type string $class Default: 'avatar'.
* @type string $type Default: 'full'.
* @type int|bool $width Default: false.
* @type int|bool $height Default: false.
* @type bool $id Passed to `$css_id` parameter.
* }
* @return string Group avatar string.
*/
function bp_get_group_avatar( $args = '' ) {
global $groups_template;
// Bail if avatars are turned off.
if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) {
return false;
}
// Parse the arguments.
$r = bp_parse_args( $args, array(
'type' => 'full',
'width' => false,
'height' => false,
'class' => 'avatar',
'id' => false,
'alt' => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name )
) );
// Fetch the avatar from the folder.
$avatar = bp_core_fetch_avatar( array(
'item_id' => $groups_template->group->id,
'avatar_dir' => 'group-avatars',
'object' => 'group',
'type' => $r['type'],
'alt' => $r['alt'],
'css_id' => $r['id'],
'class' => $r['class'],
'width' => $r['width'],
'height' => $r['height'],
) );
// If No avatar found, provide some backwards compatibility.
if ( empty( $avatar ) ) {
$avatar = '';
}
/**
* Filters the group avatar while in the groups loop.
*
* @since 1.0.0
*
* @param string $avatar HTML image element holding the group avatar.
* @param array $r Array of parsed arguments for the group avatar.
*/
return apply_filters( 'bp_get_group_avatar', $avatar, $r );
}
/**
* Output the group avatar thumbnail while in the groups loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_avatar_thumb( $group = false ) {
echo bp_get_group_avatar_thumb( $group );
}
/**
* Return the group avatar thumbnail while in the groups loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_avatar_thumb( $group = false ) {
return bp_get_group_avatar( array(
'type' => 'thumb',
'id' => ! empty( $group->id ) ? $group->id : false
) );
}
/**
* Output the miniature group avatar thumbnail while in the groups loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_avatar_mini( $group = false ) {
echo bp_get_group_avatar_mini( $group );
}
/**
* Return the miniature group avatar thumbnail while in the groups loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_avatar_mini( $group = false ) {
return bp_get_group_avatar( array(
'type' => 'thumb',
'width' => 30,
'height' => 30,
'id' => ! empty( $group->id ) ? $group->id : false
) );
}
/** Group cover image *********************************************************/
/**
* Should we use the group's cover image header.
*
* @since 2.4.0
*
* @return bool True if the displayed user has a cover image,
* False otherwise
*/
function bp_group_use_cover_image_header() {
return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads() && bp_attachments_is_wp_version_supported();
}
/**
* Output the 'last active' string for the current group in the loop.
*
* @since 1.0.0
* @since 2.7.0 Added $args as a parameter.
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
* @param array|string $args Optional. {@see bp_get_group_last_active()}.
*/
function bp_group_last_active( $group = false, $args = array() ) {
echo bp_get_group_last_active( $group, $args );
}
/**
* Return the 'last active' string for the current group in the loop.
*
* @since 1.0.0
* @since 2.7.0 Added $args as a parameter.
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
* @param array|string $args {
* Array of optional parameters.
*
* @type bool $relative Optional. If true, returns relative activity date. eg. active 5 months ago.
* If false, returns active date value from database. Default: true.
* }
* @return string
*/
function bp_get_group_last_active( $group = false, $args = array() ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
$r = wp_parse_args( $args, array(
'relative' => true,
) );
$last_active = $group->last_activity;
if ( ! $last_active ) {
$last_active = groups_get_groupmeta( $group->id, 'last_activity' );
}
// We do not want relative time, so return now.
// @todo Should the 'bp_get_group_last_active' filter be applied here?
if ( ! $r['relative'] ) {
return esc_attr( $last_active );
}
if ( empty( $last_active ) ) {
return __( 'not yet active', 'buddypress' );
} else {
/**
* Filters the 'last active' string for the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Determined last active value for the current group.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group );
}
}
/**
* Output the permalink for the current group in the loop.
*
* @since 1.0.0
*
* @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
*/
function bp_group_permalink( $group = null ) {
echo bp_get_group_permalink( $group );
}
/**
* Return the permalink for the current group in the loop.
*
* @since 1.0.0
*
* @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
* @return string
*/
function bp_get_group_permalink( $group = null ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the permalink for the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Permalink for the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_group_slug( $group ) . '/' ), $group );
}
/**
* Output an HTML-formatted link for the current group in the loop.
*
* @since 2.9.0
*
* @param BP_Groups_Group|null $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_link( $group = null ) {
echo bp_get_group_link( $group );
}
/**
* Return an HTML-formatted link for the current group in the loop.
*
* @since 2.9.0
*
* @param BP_Groups_Group|null $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_link( $group = null ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
$link = sprintf(
'%s',
esc_url( bp_get_group_permalink( $group ) ),
esc_attr( bp_get_group_slug( $group ) ),
esc_html( bp_get_group_name( $group ) )
);
/**
* Filters the HTML-formatted link for the current group in the loop.
*
* @since 2.9.0
*
* @param string $value HTML-formatted link for the
* current group in the loop.
* @param BP_Groups_Group $group The current group object.
*/
return apply_filters( 'bp_get_group_link', $link, $group );
}
/**
* Output the permalink for the admin section of the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_admin_permalink( $group = false ) {
echo bp_get_group_admin_permalink( $group );
}
/**
* Return the permalink for the admin section of the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_admin_permalink( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the permalink for the admin section of the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Permalink for the admin section of the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ), $group );
}
/**
* Return the slug for the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_slug( $group = false ) {
echo bp_get_group_slug( $group );
}
/**
* Return the slug for the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_slug( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the slug for the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $slug Slug for the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_slug', $group->slug, $group );
}
/**
* Output the description for the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_description( $group = false ) {
echo bp_get_group_description( $group );
}
/**
* Return the description for the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_description( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the description for the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Description for the current group.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_description', stripslashes( $group->description ), $group );
}
/**
* Output the description for the current group in the loop, for use in a textarea.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_description_editable( $group = false ) {
echo bp_get_group_description_editable( $group );
}
/**
* Return the permalink for the current group in the loop, for use in a textarea.
*
* 'bp_get_group_description_editable' does not have the formatting
* filters that 'bp_get_group_description' has, which makes it
* appropriate for "raw" editing.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_description_editable( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the permalink for the current group in the loop, for use in a textarea.
*
* 'bp_get_group_description_editable' does not have the formatting filters that
* 'bp_get_group_description' has, which makes it appropriate for "raw" editing.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $description Description for the current group in the loop.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_description_editable', $group->description, $group );
}
/**
* Output an excerpt of the group description.
*
* @since 1.0.0
*
* @param object|bool $group Optional. The group being referenced.
* Defaults to the group currently being
* iterated on in the groups loop.
* @param int $length Optional. Length of returned string, including ellipsis.
* Default: 225.
*/
function bp_group_description_excerpt( $group = false, $length = 225 ) {
echo bp_get_group_description_excerpt( $group, $length );
}
/**
* Get an excerpt of a group description.
*
* @since 1.0.0
*
* @param object|bool $group Optional. The group being referenced.
* Defaults to the group currently being
* iterated on in the groups loop.
* @param int $length Optional. Length of returned string, including ellipsis.
* Default: 225.
* @return string Excerpt.
*/
function bp_get_group_description_excerpt( $group = false, $length = 225 ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the excerpt of a group description.
*
* @since 1.0.0
*
* @param string $value Excerpt of a group description.
* @param object $group Object for group whose description is made into an excerpt.
*/
return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description, $length ), $group );
}
/**
* Output the status of the current group in the loop.
*
* Either 'Public' or 'Private'.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_public_status( $group = false ) {
echo bp_get_group_public_status( $group );
}
/**
* Return the status of the current group in the loop.
*
* Either 'Public' or 'Private'.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_public_status( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( $group->is_public ) {
return __( 'Public', 'buddypress' );
} else {
return __( 'Private', 'buddypress' );
}
}
/**
* Output whether the current group in the loop is public.
*
* No longer used in BuddyPress.
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_is_public( $group = false ) {
echo bp_get_group_is_public( $group );
}
/**
* Return whether the current group in the loop is public.
*
* No longer used in BuddyPress.
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return mixed
*/
function bp_get_group_is_public( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters whether the current group in the loop is public.
*
* @since 2.5.0 Added the `$group` parameter.
*
* @param bool $public True if the group is public.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_is_public', $group->is_public, $group );
}
/**
* Output the created date of the current group in the loop.
*
* @since 1.0.0
* @since 2.7.0 Added $args as a parameter.
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
* @param array|string $args {@see bp_get_group_date_created()}.
*/
function bp_group_date_created( $group = false, $args = array() ) {
echo bp_get_group_date_created( $group, $args );
}
/**
* Return the created date of the current group in the loop.
*
* @since 1.0.0
* @since 2.7.0 Added $args as a parameter.
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
* @param array|string $args {
* Array of optional parameters.
*
* @type bool $relative Optional. If true, returns relative created date. eg. active 5 months ago.
* If false, returns created date value from database. Default: true.
* }
* @return string
*/
function bp_get_group_date_created( $group = false, $args = array() ) {
global $groups_template;
$r = wp_parse_args( $args, array(
'relative' => true,
) );
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
// We do not want relative time, so return now.
// @todo Should the 'bp_get_group_date_created' filter be applied here?
if ( ! $r['relative'] ) {
return esc_attr( $group->date_created );
}
/**
* Filters the created date of the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Created date for the current group.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_date_created', bp_core_time_since( $group->date_created ), $group );
}
/**
* Output the username of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_creator_username( $group = false ) {
echo bp_get_group_creator_username( $group );
}
/**
* Return the username of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_creator_username( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the username of the creator of the current group in the loop.
*
* @since 1.7.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Username of the group creator.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ), $group );
}
/**
* Output the user ID of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_creator_id( $group = false ) {
echo bp_get_group_creator_id( $group );
}
/**
* Return the user ID of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return int
*/
function bp_get_group_creator_id( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the user ID of the creator of the current group in the loop.
*
* @since 1.7.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param int $creator_id User ID of the group creator.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_creator_id', $group->creator_id, $group );
}
/**
* Output the permalink of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_creator_permalink( $group = false ) {
echo bp_get_group_creator_permalink( $group );
}
/**
* Return the permalink of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_creator_permalink( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the permalink of the creator of the current group in the loop.
*
* @since 1.7.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Permalink of the group creator.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ), $group );
}
/**
* Determine whether a user is the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop.
* @param int $user_id ID of the user.
* @return bool
*/
function bp_is_group_creator( $group = null, $user_id = 0 ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( empty( $user_id ) ) {
$user_id = bp_loggedin_user_id();
}
return (bool) ( $group->creator_id == $user_id );
}
/**
* Output the avatar of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @param array $args {
* Array of optional arguments. See {@link bp_get_group_creator_avatar()}
* for description.
* }
*/
function bp_group_creator_avatar( $group = false, $args = array() ) {
echo bp_get_group_creator_avatar( $group, $args );
}
/**
* Return the avatar of the creator of the current group in the loop.
*
* @since 1.7.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @param array $args {
* Array of optional arguments. See {@link bp_core_fetch_avatar()}
* for detailed description of arguments.
* @type string $type Default: 'full'.
* @type int $width Default: false.
* @type int $height Default: false.
* @type int $class Default: 'avatar'.
* @type string $id Passed to 'css_id'. Default: false.
* @type string $alt Alt text. Default: 'Group creator profile
* photo of [user display name]'.
* }
* @return string
*/
function bp_get_group_creator_avatar( $group = false, $args = array() ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
$defaults = array(
'type' => 'full',
'width' => false,
'height' => false,
'class' => 'avatar',
'id' => false,
'alt' => sprintf( __( 'Group creator profile photo of %s', 'buddypress' ), bp_core_get_user_displayname( $group->creator_id ) )
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$avatar = bp_core_fetch_avatar( array( 'item_id' => $group->creator_id, 'type' => $type, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'alt' => $alt ) );
/**
* Filters the avatar of the creator of the current group in the loop.
*
* @since 1.7.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $avatar Avatar of the group creator.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_creator_avatar', $avatar, $group );
}
/**
* Determine whether the current user is the admin of the current group.
*
* Alias of {@link bp_is_item_admin()}.
*
* @since 1.1.0
*
* @return bool
*/
function bp_group_is_admin() {
return bp_is_item_admin();
}
/**
* Determine whether the current user is a mod of the current group.
*
* Alias of {@link bp_is_item_mod()}.
*
* @since 1.1.0
*
* @return bool
*/
function bp_group_is_mod() {
return bp_is_item_mod();
}
/**
* Output markup listing group admins.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
*/
function bp_group_list_admins( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( ! empty( $group->admins ) ) { ?>
group;
}
$admin_ids = array();
if ( $group->admins ) {
foreach( $group->admins as $admin ) {
$admin_ids[] = $admin->user_id;
}
}
if ( 'string' == $format ) {
$admin_ids = implode( ',', $admin_ids );
}
/**
* Filters a list of user IDs for a group's admins.
*
* This filter may return either an array or a comma separated string.
*
* @since 1.5.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param array|string $admin_ids List of user IDs for a group's admins.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_admin_ids', $admin_ids, $group );
}
/**
* Return a list of user IDs for a group's moderators.
*
* @since 1.5.0
*
* @param BP_Groups_Group|bool $group Optional. The group being queried.
* Defaults to the current group in the loop.
* @param string $format Optional. 'string' to get a comma-separated string,
* 'array' to get an array.
* @return mixed $mod_ids A string or array of user IDs.
*/
function bp_group_mod_ids( $group = false, $format = 'string' ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
$mod_ids = array();
if ( $group->mods ) {
foreach( $group->mods as $mod ) {
$mod_ids[] = $mod->user_id;
}
}
if ( 'string' == $format ) {
$mod_ids = implode( ',', $mod_ids );
}
/**
* Filters a list of user IDs for a group's moderators.
*
* This filter may return either an array or a comma separated string.
*
* @since 1.5.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param array|string $admin_ids List of user IDs for a group's moderators.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_mod_ids', $mod_ids, $group );
}
/**
* Output the permalink of the current group's Members page.
*
* @since 1.0.0
*/
function bp_group_all_members_permalink() {
echo bp_get_group_all_members_permalink();
}
/**
* Return the permalink of the Members page of the current group in the loop.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_all_members_permalink( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the permalink of the Members page for the current group in the loop.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Permalink of the Members page for the current group.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_all_members_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'members' ), $group );
}
/**
* Display a Groups search form.
*
* No longer used in BuddyPress.
*
* @todo Deprecate.
*/
function bp_group_search_form() {
$action = bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/search/';
$label = __('Filter Groups', 'buddypress');
$name = 'group-filter-box';
$search_form_html = '';
echo apply_filters( 'bp_group_search_form', $search_form_html );
}
/**
* Determine whether the displayed user has no groups.
*
* No longer used in BuddyPress.
*
* @todo Deprecate.
*
* @return bool True if the displayed user has no groups, otherwise false.
*/
function bp_group_show_no_groups_message() {
if ( !groups_total_groups_for_user( bp_displayed_user_id() ) ) {
return true;
}
return false;
}
/**
* Determine whether the current page is a group activity permalink.
*
* No longer used in BuddyPress.
*
* @todo Deprecate.
*
* @return bool True if this is a group activity permalink, otherwise false.
*/
function bp_group_is_activity_permalink() {
if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( bp_get_activity_slug() ) ) {
return false;
}
return true;
}
/**
* Output the pagination HTML for a group loop.
*
* @since 1.2.0
*/
function bp_groups_pagination_links() {
echo bp_get_groups_pagination_links();
}
/**
* Get the pagination HTML for a group loop.
*
* @since 1.2.0
*
* @return string
*/
function bp_get_groups_pagination_links() {
global $groups_template;
/**
* Filters the pagination HTML for a group loop.
*
* @since 1.2.0
*
* @param string $pag_links HTML markup for the pagination links.
*/
return apply_filters( 'bp_get_groups_pagination_links', $groups_template->pag_links );
}
/**
* Output the "Viewing x-y of z groups" pagination message.
*
* @since 1.2.0
*/
function bp_groups_pagination_count() {
echo bp_get_groups_pagination_count();
}
/**
* Generate the "Viewing x-y of z groups" pagination message.
*
* @since 1.5.0
*
* @return string
*/
function bp_get_groups_pagination_count() {
global $groups_template;
$start_num = intval( ( $groups_template->pag_page - 1 ) * $groups_template->pag_num ) + 1;
$from_num = bp_core_number_format( $start_num );
$to_num = bp_core_number_format( ( $start_num + ( $groups_template->pag_num - 1 ) > $groups_template->total_group_count ) ? $groups_template->total_group_count : $start_num + ( $groups_template->pag_num - 1 ) );
$total = bp_core_number_format( $groups_template->total_group_count );
if ( 1 == $groups_template->total_group_count ) {
$message = __( 'Viewing 1 group', 'buddypress' );
} else {
$message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s group', 'Viewing %1$s - %2$s of %3$s groups', $groups_template->total_group_count, 'buddypress' ), $from_num, $to_num, $total );
}
/**
* Filters the "Viewing x-y of z groups" pagination message.
*
* @since 1.5.0
*
* @param string $message "Viewing x-y of z groups" text.
* @param string $from_num Total amount for the low value in the range.
* @param string $to_num Total amount for the high value in the range.
* @param string $total Total amount of groups found.
*/
return apply_filters( 'bp_get_groups_pagination_count', $message, $from_num, $to_num, $total );
}
/**
* Determine whether groups auto-join is enabled.
*
* "Auto-join" is the toggle that determines whether users are joined to a
* public group automatically when creating content in that group.
*
* @since 1.2.6
*
* @return bool
*/
function bp_groups_auto_join() {
/**
* Filters whether groups auto-join is enabled.
*
* @since 1.2.6
*
* @param bool $value Enabled status.
*/
return apply_filters( 'bp_groups_auto_join', (bool) buddypress()->groups->auto_join );
}
/**
* Output the total member count for a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
*/
function bp_group_total_members( $group = false ) {
echo bp_get_group_total_members( $group );
}
/**
* Get the total member count for a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return int
*/
function bp_get_group_total_members( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the total member count for a group.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param int $total_member_count Total member count for a group.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_total_members', $group->total_member_count, $group );
}
/**
* Output the "x members" count string for a group.
*
* @since 1.2.0
*/
function bp_group_member_count() {
echo bp_get_group_member_count();
}
/**
* Generate the "x members" count string for a group.
*
* @since 1.2.0
*
* @return string
*/
function bp_get_group_member_count() {
global $groups_template;
if ( isset( $groups_template->group->total_member_count ) ) {
$count = (int) $groups_template->group->total_member_count;
} else {
$count = 0;
}
$count_string = sprintf( _n( '%s member', '%s members', $count, 'buddypress' ), bp_core_number_format( $count ) );
/**
* Filters the "x members" count string for a group.
*
* @since 1.2.0
*
* @param string $count_string The "x members" count string for a group.
*/
return apply_filters( 'bp_get_group_member_count', $count_string );
}
/**
* Output the URL of the Forum page of the current group in the loop.
*
* @since 1.0.0
*/
function bp_group_forum_permalink() {
echo bp_get_group_forum_permalink();
}
/**
* Generate the URL of the Forum page of a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in loop.
* @return string
*/
function bp_get_group_forum_permalink( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the URL of the Forum page of a group.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value URL permalink for the Forum Page.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_forum_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'forum' ), $group );
}
/**
* Output the topic count for a group forum.
*
* @since 1.2.0
*
* @param array|string $args See {@link bp_get_group_forum_topic_count()}.
*/
function bp_group_forum_topic_count( $args = '' ) {
echo bp_get_group_forum_topic_count( $args );
}
/**
* Generate the topic count string for a group forum.
*
* @since 1.2.0
*
* @param array|string $args {
* Array of arguments.
* @type bool $showtext Optional. If true, result will be formatted as "x topics".
* If false, just a number will be returned.
* Default: false.
* }
* @return string|int
*/
function bp_get_group_forum_topic_count( $args = '' ) {
global $groups_template;
$defaults = array(
'showtext' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) {
return false;
}
if ( !bp_is_active( 'forums' ) ) {
return false;
}
if ( !$groups_template->group->forum_counts ) {
$groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
}
if ( (bool) $showtext ) {
if ( 1 == (int) $groups_template->group->forum_counts[0]->topics ) {
$total_topics = sprintf( __( '%d topic', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
} else {
$total_topics = sprintf( __( '%d topics', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
}
} else {
$total_topics = (int) $groups_template->group->forum_counts[0]->topics;
}
/**
* Filters the topic count string for a group forum.
*
* @since 1.2.0
*
* @param string $total_topics Total topic count string.
* @param bool $showtext Whether or not to return as formatted string.
*/
return apply_filters( 'bp_get_group_forum_topic_count', $total_topics, (bool)$showtext );
}
/**
* Output the post count for a group forum.
*
* @since 1.2.0
*
* @param array|string $args See {@link bp_get_group_forum_post_count()}.
*/
function bp_group_forum_post_count( $args = '' ) {
echo bp_get_group_forum_post_count( $args );
}
/**
* Generate the post count string for a group forum.
*
* @since 1.2.0
*
* @param array|string $args {
* Array of arguments.
* @type bool $showtext Optional. If true, result will be formatted as "x posts".
* If false, just a number will be returned.
* Default: false.
* }
* @return string|int
*/
function bp_get_group_forum_post_count( $args = '' ) {
global $groups_template;
$defaults = array(
'showtext' => false
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) ) {
return false;
}
if ( !bp_is_active( 'forums' ) ) {
return false;
}
if ( !$groups_template->group->forum_counts ) {
$groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
}
if ( (bool) $showtext ) {
if ( 1 == (int) $groups_template->group->forum_counts[0]->posts ) {
$total_posts = sprintf( __( '%d post', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
} else {
$total_posts = sprintf( __( '%d posts', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
}
} else {
$total_posts = (int) $groups_template->group->forum_counts[0]->posts;
}
/**
* Filters the post count string for a group forum.
*
* @since 1.2.0
*
* @param string $total_posts Total post count string.
* @param bool $showtext Whether or not to return as formatted string.
*/
return apply_filters( 'bp_get_group_forum_post_count', $total_posts, (bool)$showtext );
}
/**
* Determine whether forums are enabled for a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
* @return bool
*/
function bp_group_is_forum_enabled( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( ! empty( $group->enable_forum ) ) {
return true;
}
return false;
}
/**
* Output the 'checked' attribute for the group forums settings UI.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object. Default: current group in loop.
*/
function bp_group_show_forum_setting( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( $group->enable_forum ) {
echo ' checked="checked"';
}
}
/**
* Output the 'checked' attribute for a given status in the settings UI.
*
* @since 1.0.0
*
* @param string $setting Group status. 'public', 'private', 'hidden'.
* @param object|bool $group Optional. Group object. Default: current group in loop.
*/
function bp_group_show_status_setting( $setting, $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( $setting == $group->status ) {
echo ' checked="checked"';
}
}
/**
* Output the 'checked' value, if needed, for a given invite_status on the group create/admin screens
*
* @since 1.5.0
*
* @param string $setting The setting you want to check against ('members',
* 'mods', or 'admins').
* @param object|bool $group Optional. Group object. Default: current group in loop.
*/
function bp_group_show_invite_status_setting( $setting, $group = false ) {
$group_id = isset( $group->id ) ? $group->id : false;
$invite_status = bp_group_get_invite_status( $group_id );
if ( $setting == $invite_status ) {
echo ' checked="checked"';
}
}
/**
* Get the invite status of a group.
*
* 'invite_status' became part of BuddyPress in BP 1.5. In order to provide
* backward compatibility with earlier installations, groups without a status
* set will default to 'members', ie all members in a group can send
* invitations. Filter 'bp_group_invite_status_fallback' to change this
* fallback behavior.
*
* This function can be used either in or out of the loop.
*
* @since 1.5.0
*
* @param int|bool $group_id Optional. The ID of the group whose status you want to
* check. Default: the displayed group, or the current group
* in the loop.
* @return bool|string Returns false when no group can be found. Otherwise
* returns the group invite status, from among 'members',
* 'mods', and 'admins'.
*/
function bp_group_get_invite_status( $group_id = false ) {
global $groups_template;
if ( !$group_id ) {
$bp = buddypress();
if ( isset( $bp->groups->current_group->id ) ) {
// Default to the current group first.
$group_id = $bp->groups->current_group->id;
} elseif ( isset( $groups_template->group->id ) ) {
// Then see if we're in the loop.
$group_id = $groups_template->group->id;
} else {
return false;
}
}
$invite_status = groups_get_groupmeta( $group_id, 'invite_status' );
// Backward compatibility. When 'invite_status' is not set, fall back to a default value.
if ( !$invite_status ) {
$invite_status = apply_filters( 'bp_group_invite_status_fallback', 'members' );
}
/**
* Filters the invite status of a group.
*
* Invite status in this case means who from the group can send invites.
*
* @since 1.5.0
*
* @param string $invite_status Membership level needed to send an invite.
* @param int $group_id ID of the group whose status is being checked.
*/
return apply_filters( 'bp_group_get_invite_status', $invite_status, $group_id );
}
/**
* Can a user send invitations in the specified group?
*
* @since 1.5.0
* @since 2.2.0 Added the $user_id parameter.
*
* @param int $group_id The group ID to check.
* @param int $user_id The user ID to check.
* @return bool
*/
function bp_groups_user_can_send_invites( $group_id = 0, $user_id = 0 ) {
$can_send_invites = false;
$invite_status = false;
// If $user_id isn't specified, we check against the logged-in user.
if ( ! $user_id ) {
$user_id = bp_loggedin_user_id();
}
// If $group_id isn't specified, use existing one if available.
if ( ! $group_id ) {
$group_id = bp_get_current_group_id();
}
if ( $user_id ) {
// Users with the 'bp_moderate' cap can always send invitations.
if ( user_can( $user_id, 'bp_moderate' ) ) {
$can_send_invites = true;
} else {
$invite_status = bp_group_get_invite_status( $group_id );
switch ( $invite_status ) {
case 'admins' :
if ( groups_is_user_admin( $user_id, $group_id ) ) {
$can_send_invites = true;
}
break;
case 'mods' :
if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) {
$can_send_invites = true;
}
break;
case 'members' :
if ( groups_is_user_member( $user_id, $group_id ) ) {
$can_send_invites = true;
}
break;
}
}
}
/**
* Filters whether a user can send invites in a group.
*
* @since 1.5.0
* @since 2.2.0 Added the $user_id parameter.
*
* @param bool $can_send_invites Whether the user can send invites
* @param int $group_id The group ID being checked
* @param bool $invite_status The group's current invite status
* @param int $user_id The user ID being checked
*/
return apply_filters( 'bp_groups_user_can_send_invites', $can_send_invites, $group_id, $invite_status, $user_id );
}
/**
* Since BuddyPress 1.0, this generated the group settings admin/member screen.
* As of BuddyPress 1.5 (r4489), and because this function outputs HTML, it was moved into /bp-default/groups/single/admin.php.
*
* @deprecated 1.5
* @deprecated No longer used.
* @since 1.0.0
* @todo Remove in 1.4
*
* @param bool $admin_list
* @param bool $group
*/
function bp_group_admin_memberlist( $admin_list = false, $group = false ) {
global $groups_template;
_deprecated_function( __FUNCTION__, '1.5', 'No longer used. See /bp-default/groups/single/admin.php' );
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( $admins = groups_get_group_admins( $group->id ) ) : ?>
group;
}
/**
* Filters whether a group has moderators.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param array $value Array of user IDs who are a moderator of the provided group.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ), $group );
}
/**
* Output a URL for promoting a user to moderator.
*
* @since 1.1.0
*
* @param array|string $args See {@link bp_get_group_member_promote_mod_link()}.
*/
function bp_group_member_promote_mod_link( $args = '' ) {
echo bp_get_group_member_promote_mod_link( $args );
}
/**
* Generate a URL for promoting a user to moderator.
*
* @since 1.1.0
*
* @param array|string $args {
* @type int $user_id ID of the member to promote. Default:
* current member in a group member loop.
* @type object $group Group object. Default: current group.
* }
* @return string
*/
function bp_get_group_member_promote_mod_link( $args = '' ) {
global $members_template, $groups_template;
$defaults = array(
'user_id' => $members_template->member->user_id,
'group' => &$groups_template->group
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
/**
* Filters a URL for promoting a user to moderator.
*
* @since 1.1.0
*
* @param string $value URL to use for promoting a user to moderator.
*/
return apply_filters( 'bp_get_group_member_promote_mod_link', wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/mod/' . $user_id ), 'groups_promote_member' ) );
}
/**
* Output a URL for promoting a user to admin.
*
* @since 1.1.0
*
* @param array|string $args See {@link bp_get_group_member_promote_admin_link()}.
*/
function bp_group_member_promote_admin_link( $args = '' ) {
echo bp_get_group_member_promote_admin_link( $args );
}
/**
* Generate a URL for promoting a user to admin.
*
* @since 1.1.0
*
* @param array|string $args {
* @type int $user_id ID of the member to promote. Default:
* current member in a group member loop.
* @type object $group Group object. Default: current group.
* }
* @return string
*/
function bp_get_group_member_promote_admin_link( $args = '' ) {
global $members_template, $groups_template;
$defaults = array(
'user_id' => !empty( $members_template->member->user_id ) ? $members_template->member->user_id : false,
'group' => &$groups_template->group
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
/**
* Filters a URL for promoting a user to admin.
*
* @since 1.1.0
*
* @param string $value URL to use for promoting a user to admin.
*/
return apply_filters( 'bp_get_group_member_promote_admin_link', wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/admin/' . $user_id ), 'groups_promote_member' ) );
}
/**
* Output a URL for demoting a user to member.
*
* @since 1.0.0
*
* @param int $user_id ID of the member to demote. Default: current member in
* a member loop.
*/
function bp_group_member_demote_link( $user_id = 0 ) {
global $members_template;
if ( !$user_id ) {
$user_id = $members_template->member->user_id;
}
echo bp_get_group_member_demote_link( $user_id );
}
/**
* Generate a URL for demoting a user to member.
*
* @since 1.0.0
*
* @param int $user_id ID of the member to demote. Default: current
* member in a member loop.
* @param object|bool $group Optional. Group object. Default: current group.
* @return string
*/
function bp_get_group_member_demote_link( $user_id = 0, $group = false ) {
global $members_template, $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( !$user_id ) {
$user_id = $members_template->member->user_id;
}
/**
* Filters a URL for demoting a user to member.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value URL to use for demoting a user to member.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_member_demote_link', wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members/demote/' . $user_id ), 'groups_demote_member' ), $group );
}
/**
* Output a URL for banning a member from a group.
*
* @since 1.0.0
*
* @param int $user_id ID of the member to ban.
* Default: current member in a member loop.
*/
function bp_group_member_ban_link( $user_id = 0 ) {
global $members_template;
if ( !$user_id ) {
$user_id = $members_template->member->user_id;
}
echo bp_get_group_member_ban_link( $user_id );
}
/**
* Generate a URL for banning a member from a group.
*
* @since 1.0.0
*
* @param int $user_id ID of the member to ban.
* Default: current member in a member loop.
* @param object|bool $group Optional. Group object. Default: current group.
* @return string
*/
function bp_get_group_member_ban_link( $user_id = 0, $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters a URL for banning a member from a group.
*
* @since 1.0.0
*
* @param string $value URL to use for banning a member.
*/
return apply_filters( 'bp_get_group_member_ban_link', wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members/ban/' . $user_id ), 'groups_ban_member' ) );
}
/**
* Output a URL for unbanning a member from a group.
*
* @since 1.0.0
*
* @param int $user_id ID of the member to unban.
* Default: current member in a member loop.
*/
function bp_group_member_unban_link( $user_id = 0 ) {
global $members_template;
if ( !$user_id ) {
$user_id = $members_template->member->user_id;
}
echo bp_get_group_member_unban_link( $user_id );
}
/**
* Generate a URL for unbanning a member from a group.
*
* @since 1.0.0
*
* @param int $user_id ID of the member to unban.
* Default: current member in a member loop.
* @param object|bool $group Optional. Group object. Default: current group.
* @return string
*/
function bp_get_group_member_unban_link( $user_id = 0, $group = false ) {
global $members_template, $groups_template;
if ( !$user_id ) {
$user_id = $members_template->member->user_id;
}
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters a URL for unbanning a member from a group.
*
* @since 1.0.0
*
* @param string $value URL to use for unbanning a member.
*/
return apply_filters( 'bp_get_group_member_unban_link', wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members/unban/' . $user_id ), 'groups_unban_member' ) );
}
/**
* Output a URL for removing a member from a group.
*
* @since 1.2.6
*
* @param int $user_id ID of the member to remove.
* Default: current member in a member loop.
*/
function bp_group_member_remove_link( $user_id = 0 ) {
global $members_template;
if ( !$user_id ) {
$user_id = $members_template->member->user_id;
}
echo bp_get_group_member_remove_link( $user_id );
}
/**
* Generate a URL for removing a member from a group.
*
* @since 1.2.6
*
* @param int $user_id ID of the member to remove.
* Default: current member in a member loop.
* @param object|bool $group Optional. Group object. Default: current group.
* @return string
*/
function bp_get_group_member_remove_link( $user_id = 0, $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters a URL for removing a member from a group.
*
* @since 1.2.6
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value URL to use for removing a member.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_member_remove_link', wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members/remove/' . $user_id ), 'groups_remove_member' ), $group );
}
/**
* HTML admin subnav items for group pages.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in the loop.
*/
function bp_group_admin_tabs( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group = ( $groups_template->group ) ? $groups_template->group : groups_get_current_group();
}
$css_id = 'manage-members';
if ( 'private' == $group->status ) {
$css_id = 'membership-requests';
}
add_filter( "bp_get_options_nav_{$css_id}", 'bp_group_admin_tabs_backcompat', 10, 3 );
bp_get_options_nav( $group->slug . '_manage' );
remove_filter( "bp_get_options_nav_{$css_id}", 'bp_group_admin_tabs_backcompat', 10 );
}
/**
* BackCompat for plugins/themes directly hooking groups_admin_tabs
* without using the Groups Extension API.
*
* @since 2.2.0
*
* @param string $subnav_output Subnav item output.
* @param string $subnav_item subnav item params.
* @param string $selected_item Surrent selected tab.
* @return string HTML output
*/
function bp_group_admin_tabs_backcompat( $subnav_output = '', $subnav_item = '', $selected_item = '' ) {
if ( ! has_action( 'groups_admin_tabs' ) ) {
return $subnav_output;
}
$group = groups_get_current_group();
ob_start();
do_action( 'groups_admin_tabs', $selected_item, $group->slug );
$admin_tabs_backcompat = trim( ob_get_contents() );
ob_end_clean();
if ( ! empty( $admin_tabs_backcompat ) ) {
_doing_it_wrong( "do_action( 'groups_admin_tabs' )", __( 'This action should not be used directly. Please use the BuddyPress Group Extension API to generate Manage tabs.', 'buddypress' ), '2.2.0' );
$subnav_output .= $admin_tabs_backcompat;
}
return $subnav_output;
}
/**
* Output the group count for the displayed user.
*
* @since 1.1.0
*/
function bp_group_total_for_member() {
echo bp_get_group_total_for_member();
}
/**
* Get the group count for the displayed user.
*
* @since 1.1.0
*
* @return string
*/
function bp_get_group_total_for_member() {
/**
* FIlters the group count for a displayed user.
*
* @since 1.1.0
*
* @param int $value Total group count for a displayed user.
*/
return apply_filters( 'bp_get_group_total_for_member', BP_Groups_Member::total_group_count() );
}
/**
* Output the 'action' attribute for a group form.
*
* @since 1.0.0
*
* @param string $page Page slug.
*/
function bp_group_form_action( $page ) {
echo bp_get_group_form_action( $page );
}
/**
* Generate the 'action' attribute for a group form.
*
* @since 1.0.0
*
* @param string $page Page slug.
* @param object|bool $group Optional. Group object.
* Default: current group in the loop.
* @return string
*/
function bp_get_group_form_action( $page, $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the 'action' attribute for a group form.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Action attribute for a group form.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_form_action', trailingslashit( bp_get_group_permalink( $group ) . $page ), $group );
}
/**
* Output the 'action' attribute for a group admin form.
*
* @since 1.0.0
*
* @param string|bool $page Optional. Page slug.
*/
function bp_group_admin_form_action( $page = false ) {
echo bp_get_group_admin_form_action( $page );
}
/**
* Generate the 'action' attribute for a group admin form.
*
* @since 1.0.0
*
* @param string|bool $page Optional. Page slug.
* @param object|bool $group Optional. Group object.
* Default: current group in the loop.
* @return string
*/
function bp_get_group_admin_form_action( $page = false, $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( empty( $page ) ) {
$page = bp_action_variable( 0 );
}
/**
* Filters the 'action' attribute for a group admin form.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Action attribute for a group admin form.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_admin_form_action', trailingslashit( bp_get_group_permalink( $group ) . 'admin/' . $page ), $group );
}
/**
* Determine whether the logged-in user has requested membership to a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in the loop.
* @return bool
*/
function bp_group_has_requested_membership( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( groups_check_for_membership_request( bp_loggedin_user_id(), $group->id ) ) {
return true;
}
return false;
}
/**
* Check if current user is member of a group.
*
* @since 1.0.0
*
* @global object $groups_template
*
* @param object|bool $group Optional. Group to check is_member.
* Default: current group in the loop.
* @return bool If user is member of group or not.
*/
function bp_group_is_member( $group = false ) {
global $groups_template;
// Site admins always have access.
if ( bp_current_user_can( 'bp_moderate' ) ) {
return true;
}
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters whether current user is member of a group.
*
* @since 1.2.4
* @since 2.5.0 Added the `$group` parameter.
*
* @param bool $is_member If user is a member of group or not.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_is_member', ! empty( $group->is_member ), $group );
}
/**
* Check whether the current user has an outstanding invite to the current group in the loop.
*
* @since 2.1.0
*
* @param object|bool $group Optional. Group data object.
* Default: the current group in the groups loop.
* @return bool True if the user has an outstanding invite, otherwise false.
*/
function bp_group_is_invited( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters whether current user has an outstanding invite to current group in loop.
*
* @since 2.1.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param bool $is_invited If user has an outstanding group invite.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_is_invited', ! empty( $group->is_invited ), $group );
}
/**
* Check if a user is banned from a group.
*
* If this function is invoked inside the groups template loop, then we check
* $groups_template->group->is_banned instead of using {@link groups_is_user_banned()}
* and making another SQL query.
*
* In BuddyPress 2.1, to standardize this function, we are defaulting the
* return value to a boolean. In previous versions, using this function would
* return either a string of the integer (0 or 1) or null if a result couldn't
* be found from the database. If the logged-in user had the 'bp_moderate'
* capability, the return value would be boolean false.
*
* @since 1.5.0
*
* @global BP_Groups_Template $groups_template Group template loop object.
*
* @param BP_Groups_Group|bool $group Group to check if user is banned.
* @param int $user_id The user ID to check.
* @return bool True if user is banned. False if user isn't banned.
*/
function bp_group_is_user_banned( $group = false, $user_id = 0 ) {
global $groups_template;
// Site admins always have access.
if ( bp_current_user_can( 'bp_moderate' ) ) {
return false;
}
// Check groups loop first
// @see BP_Groups_Group::get_group_extras().
if ( ! empty( $groups_template->in_the_loop ) && isset( $groups_template->group->is_banned ) ) {
$retval = $groups_template->group->is_banned;
// Not in loop.
} else {
// Default to not banned.
$retval = false;
if ( empty( $group ) ) {
$group = $groups_template->group;
}
if ( empty( $user_id ) ) {
$user_id = bp_loggedin_user_id();
}
if ( ! empty( $user_id ) && ! empty( $group->id ) ) {
$retval = groups_is_user_banned( $user_id, $group->id );
}
}
/**
* Filters whether current user has been banned from current group in loop.
*
* @since 1.5.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param bool $is_invited If user has been from current group.
* @param object $group Group object.
*/
return (bool) apply_filters( 'bp_group_is_user_banned', $retval, $group );
}
/**
* Output the URL for accepting an invitation to the current group in the loop.
*
* @since 1.0.0
*/
function bp_group_accept_invite_link() {
echo bp_get_group_accept_invite_link();
}
/**
* Generate the URL for accepting an invitation to a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: Current group in the loop.
* @return string
*/
function bp_get_group_accept_invite_link( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
$bp = buddypress();
/**
* Filters the URL for accepting an invitation to a group.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value URL for accepting an invitation to a group.
* @param object $group Group object.
*/
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 );
}
/**
* Output the URL for accepting an invitation to the current group in the loop.
*
* @since 1.0.0
*/
function bp_group_reject_invite_link() {
echo bp_get_group_reject_invite_link();
}
/**
* Generate the URL for rejecting an invitation to a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: Current group in the loop.
* @return string
*/
function bp_get_group_reject_invite_link( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
$bp = buddypress();
/**
* Filters the URL for rejecting an invitation to a group.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value URL for rejecting an invitation to a group.
* @param object $group Group object.
*/
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 );
}
/**
* Output the URL for confirming a request to leave a group.
*
* @since 1.0.0
*/
function bp_group_leave_confirm_link() {
echo bp_get_group_leave_confirm_link();
}
/**
* Generate the URL for confirming a request to leave a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: Current group in the loop.
* @return string
*/
function bp_get_group_leave_confirm_link( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the URL for confirming a request to leave a group.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value URL for confirming a request to leave a group.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_leave_confirm_link', wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'leave-group/yes' ), 'groups_leave_group' ), $group );
}
/**
* Output the URL for rejecting a request to leave a group.
*
* @since 1.0.0
*/
function bp_group_leave_reject_link() {
echo bp_get_group_leave_reject_link();
}
/**
* Generate the URL for rejecting a request to leave a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: Current group in the loop.
* @return string
*/
function bp_get_group_leave_reject_link( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the URL for rejecting a request to leave a group.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value URL for rejecting a request to leave a group.
* @param object $group Group object.
*/
return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_permalink( $group ), $group );
}
/**
* Output the 'action' attribute for a group send invite form.
*
* @since 1.0.0
*/
function bp_group_send_invite_form_action() {
echo bp_get_group_send_invite_form_action();
}
/**
* Output the 'action' attribute for a group send invite form.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in the loop.
* @return string
*/
function bp_get_group_send_invite_form_action( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
/**
* Filters the 'action' attribute for a group send invite form.
*
* @since 1.0.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $value Action attribute for a group send invite form.
* @param object $group Group object.
*/
return apply_filters( 'bp_group_send_invite_form_action', trailingslashit( bp_get_group_permalink( $group ) . 'send-invites/send' ), $group );
}
/**
* Determine whether the current user has friends to invite to a group.
*
* @since 1.0.0
*
* @param object|bool $group Optional. Group object.
* Default: current group in the loop.
* @return bool
*/
function bp_has_friends_to_invite( $group = false ) {
global $groups_template;
if ( !bp_is_active( 'friends' ) ) {
return false;
}
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( !friends_check_user_has_friends( bp_loggedin_user_id() ) || !friends_count_invitable_friends( bp_loggedin_user_id(), $group->id ) ) {
return false;
}
return true;
}
/**
* Output a 'New Topic' button for a group.
*
* @since 1.2.7
*
* @param BP_Groups_Group|bool $group The BP Groups_Group object if passed,
* boolean false if not passed.
*/
function bp_group_new_topic_button( $group = false ) {
echo bp_get_group_new_topic_button( $group );
}
/**
* Returns a 'New Topic' button for a group.
*
* @since 1.2.7
*
* @param BP_Groups_Group|bool $group The BP Groups_Group object if
* passed, boolean false if not passed.
* @return false|string HTML code for the button.
*/
function bp_get_group_new_topic_button( $group = false ) {
global $groups_template;
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
if ( !is_user_logged_in() || bp_group_is_user_banned() || !bp_is_group_forum() || bp_is_group_forum_topic() ) {
return false;
}
$button = array(
'id' => 'new_topic',
'component' => 'groups',
'must_be_logged_in' => true,
'block_self' => true,
'wrapper_class' => 'group-button',
'link_href' => '#post-new',
'link_class' => 'group-button show-hide-new',
'link_id' => 'new-topic-button',
'link_text' => __( 'New Topic', 'buddypress' ),
);
/**
* Filters the HTML button for creating a new topic in a group.
*
* @since 1.5.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param string $button HTML button for a new topic.
* @param object $group Group object.
*/
return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button, $group ) );
}
/**
* Output button to join a group.
*
* @since 1.0.0
*
* @param object|bool $group Single group object.
*/
function bp_group_join_button( $group = false ) {
echo bp_get_group_join_button( $group );
}
/**
* Return button to join a group.
*
* @since 1.0.0
*
* @param object|bool $group Single group object.
* @return false|string
*/
function bp_get_group_join_button( $group = false ) {
global $groups_template;
// Set group to current loop group if none passed.
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
// Don't show button if not logged in or previously banned.
if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) {
return false;
}
// Group creation was not completed or status is unknown.
if ( empty( $group->status ) ) {
return false;
}
// Already a member.
if ( ! empty( $group->is_member ) ) {
// Stop sole admins from abandoning their group.
$group_admins = groups_get_group_admins( $group->id );
if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) {
return false;
}
// Setup button attributes.
$button = array(
'id' => 'leave_group',
'component' => 'groups',
'must_be_logged_in' => true,
'block_self' => false,
'wrapper_class' => 'group-button ' . $group->status,
'wrapper_id' => 'groupbutton-' . $group->id,
'link_href' => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'leave-group' ), 'groups_leave_group' ),
'link_text' => __( 'Leave Group', 'buddypress' ),
'link_class' => 'group-button leave-group',
);
// Not a member.
} else {
// Show different buttons based on group status.
switch ( $group->status ) {
case 'hidden' :
return false;
case 'public':
$button = array(
'id' => 'join_group',
'component' => 'groups',
'must_be_logged_in' => true,
'block_self' => false,
'wrapper_class' => 'group-button ' . $group->status,
'wrapper_id' => 'groupbutton-' . $group->id,
'link_href' => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'join' ), 'groups_join_group' ),
'link_text' => __( 'Join Group', 'buddypress' ),
'link_class' => 'group-button join-group',
);
break;
case 'private' :
// Member has outstanding invitation -
// show an "Accept Invitation" button.
if ( $group->is_invited ) {
$button = array(
'id' => 'accept_invite',
'component' => 'groups',
'must_be_logged_in' => true,
'block_self' => false,
'wrapper_class' => 'group-button ' . $group->status,
'wrapper_id' => 'groupbutton-' . $group->id,
'link_href' => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
'link_text' => __( 'Accept Invitation', 'buddypress' ),
'link_class' => 'group-button accept-invite',
);
// Member has requested membership but request is pending -
// show a "Request Sent" button.
} elseif ( $group->is_pending ) {
$button = array(
'id' => 'membership_requested',
'component' => 'groups',
'must_be_logged_in' => true,
'block_self' => false,
'wrapper_class' => 'group-button pending ' . $group->status,
'wrapper_id' => 'groupbutton-' . $group->id,
'link_href' => bp_get_group_permalink( $group ),
'link_text' => __( 'Request Sent', 'buddypress' ),
'link_class' => 'group-button pending membership-requested',
);
// Member has not requested membership yet -
// show a "Request Membership" button.
} else {
$button = array(
'id' => 'request_membership',
'component' => 'groups',
'must_be_logged_in' => true,
'block_self' => false,
'wrapper_class' => 'group-button ' . $group->status,
'wrapper_id' => 'groupbutton-' . $group->id,
'link_href' => wp_nonce_url( trailingslashit( bp_get_group_permalink( $group ) . 'request-membership' ), 'groups_request_membership' ),
'link_text' => __( 'Request Membership', 'buddypress' ),
'link_class' => 'group-button request-membership',
);
}
break;
}
}
/**
* Filters the HTML button for joining a group.
*
* @since 1.2.6
* @since 2.4.0 Added $group parameter to filter args.
*
* @param string $button HTML button for joining a group.
* @param object $group BuddyPress group object
*/
return bp_get_button( apply_filters( 'bp_get_group_join_button', $button, $group ) );
}
/**
* Output the Create a Group button.
*
* @since 2.0.0
*/
function bp_group_create_button() {
echo bp_get_group_create_button();
}
/**
* Get the Create a Group button.
*
* @since 2.0.0
*
* @return false|string
*/
function bp_get_group_create_button() {
if ( ! is_user_logged_in() ) {
return false;
}
if ( ! bp_user_can_create_groups() ) {
return false;
}
$button_args = array(
'id' => 'create_group',
'component' => 'groups',
'link_text' => __( 'Create a Group', 'buddypress' ),
'link_class' => 'group-create no-ajax',
'link_href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),
'wrapper' => false,
'block_self' => false,
);
/**
* Filters the HTML button for creating a group.
*
* @since 2.0.0
*
* @param string $button HTML button for creating a group.
*/
return bp_get_button( apply_filters( 'bp_get_group_create_button', $button_args ) );
}
/**
* Output the Create a Group nav item.
*
* @since 2.2.0
*/
function bp_group_create_nav_item() {
echo bp_get_group_create_nav_item();
}
/**
* Get the Create a Group nav item.
*
* @since 2.2.0
*
* @return string
*/
function bp_get_group_create_nav_item() {
// Get the create a group button.
$create_group_button = bp_get_group_create_button();
// Make sure the button is available.
if ( empty( $create_group_button ) ) {
return;
}
$output = '
' . $create_group_button . '
';
/**
* Filters the Create a Group nav item.
*
* @since 2.2.0
*
* @param string $output HTML output for nav item.
*/
return apply_filters( 'bp_get_group_create_nav_item', $output );
}
/**
* Checks if a specific theme is still filtering the Groups directory title
* if so, transform the title button into a Groups directory nav item.
*
* @since 2.2.0
*
* @return string|null HTML Output
*/
function bp_group_backcompat_create_nav_item() {
// Bail if the Groups nav item is already used by bp-legacy.
if ( has_action( 'bp_groups_directory_group_filter', 'bp_legacy_theme_group_create_nav', 999 ) ) {
return;
}
// Bail if the theme is not filtering the Groups directory title.
if ( ! has_filter( 'bp_groups_directory_header' ) ) {
return;
}
bp_group_create_nav_item();
}
add_action( 'bp_groups_directory_group_filter', 'bp_group_backcompat_create_nav_item', 1000 );
/**
* Prints a message if the group is not visible to the current user (it is a
* hidden or private group, and the user does not have access).
*
* @since 1.0.0
*
* @global BP_Groups_Template $groups_template Groups template object.
*
* @param object|null $group Group to get status message for. Optional; defaults to current group.
*/
function bp_group_status_message( $group = null ) {
global $groups_template;
// Group not passed so look for loop.
if ( empty( $group ) ) {
$group =& $groups_template->group;
}
// Group status is not set (maybe outside of group loop?).
if ( empty( $group->status ) ) {
$message = __( 'This group is not currently accessible.', 'buddypress' );
// Group has a status.
} else {
switch( $group->status ) {
// Private group.
case 'private' :
if ( ! bp_group_has_requested_membership( $group ) ) {
if ( is_user_logged_in() ) {
if ( bp_group_is_invited( $group ) ) {
$message = __( 'You must accept your pending invitation before you can access this private group.', 'buddypress' );
} else {
$message = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
}
} else {
$message = __( 'This is a private group. To join you must be a registered site member and request group membership.', 'buddypress' );
}
} else {
$message = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );
}
break;
// Hidden group.
case 'hidden' :
default :
$message = __( 'This is a hidden group and only invited members can join.', 'buddypress' );
break;
}
}
/**
* Filters a message if the group is not visible to the current user.
*
* This will be true if it is a hidden or private group, and the user does not have access.
*
* @since 1.6.0
*
* @param string $message Message to display to the current user.
* @param object $group Group to get status message for.
*/
echo apply_filters( 'bp_group_status_message', $message, $group );
}
/**
* Output hidden form fields for group.
*
* This function is no longer used, but may still be used by older themes.
*
* @since 1.0.0
*/
function bp_group_hidden_fields() {
$query_arg = bp_core_get_component_search_query_arg( 'groups' );
if ( isset( $_REQUEST[ $query_arg ] ) ) {
echo '';
}
if ( isset( $_REQUEST['letter'] ) ) {
echo '';
}
if ( isset( $_REQUEST['groups_search'] ) ) {
echo '';
}
}
/**
* Output the total number of groups.
*
* @since 1.0.0
*/
function bp_total_group_count() {
echo bp_get_total_group_count();
}
/**
* Return the total number of groups.
*
* @since 1.0.0
*
* @return int
*/
function bp_get_total_group_count() {
/**
* Filters the total number of groups.
*
* @since 1.0.0
*
* @param int $value Total number of groups found.
*/
return apply_filters( 'bp_get_total_group_count', groups_get_total_group_count() );
}
/**
* Output the total number of groups a user belongs to.
*
* @since 1.0.0
*
* @param int $user_id User ID to get group membership count.
*/
function bp_total_group_count_for_user( $user_id = 0 ) {
echo bp_get_total_group_count_for_user( $user_id );
}
/**
* Return the total number of groups a user belongs to.
*
* Filtered by `bp_core_number_format()` by default
*
* @since 1.0.0
*
* @param int $user_id User ID to get group membership count.
* @return string
*/
function bp_get_total_group_count_for_user( $user_id = 0 ) {
$count = groups_total_groups_for_user( $user_id );
/**
* Filters the total number of groups a user belongs to.
*
* @since 1.2.0
*
* @param int $count Total number of groups for the user.
* @param int $user_id ID of the user being checked.
*/
return apply_filters( 'bp_get_total_group_count_for_user', $count, $user_id );
}
/* Group Members *************************************************************/
/**
* Initialize a group member query loop.
*
* @since 1.0.0
*
* @param array|string $args {
* An array of optional arguments.
* @type int $group_id ID of the group whose members are being queried.
* Default: current group ID.
* @type int $page Page of results to be queried. Default: 1.
* @type int $per_page Number of items to return per page of results.
* Default: 20.
* @type int $max Optional. Max number of items to return.
* @type array $exclude Optional. Array of user IDs to exclude.
* @type bool|int $exclude_admin_mods True (or 1) to exclude admins and mods from results.
* Default: 1.
* @type bool|int $exclude_banned True (or 1) to exclude banned users from results.
* Default: 1.
* @type array $group_role Optional. Array of group roles to include.
* @type string $type Optional. Sort order of results. 'last_joined',
* 'first_joined', or any of the $type params available in
* {@link BP_User_Query}. Default: 'last_joined'.
* @type string $search_terms Optional. Search terms to match. Pass an
* empty string to force-disable search, even in
* the presence of $_REQUEST['s']. Default: false.
* }
*
* @return bool
*/
function bp_group_has_members( $args = '' ) {
global $members_template;
$exclude_admins_mods = 1;
if ( bp_is_group_members() ) {
$exclude_admins_mods = 0;
}
/*
* Use false as the search_terms default so that BP_User_Query
* doesn't add a search clause.
*/
$search_terms_default = false;
$search_query_arg = bp_core_get_component_search_query_arg( 'members' );
if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
$search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
}
$r = wp_parse_args( $args, array(
'group_id' => bp_get_current_group_id(),
'page' => 1,
'per_page' => 20,
'max' => false,
'exclude' => false,
'exclude_admins_mods' => $exclude_admins_mods,
'exclude_banned' => 1,
'group_role' => false,
'search_terms' => $search_terms_default,
'type' => 'last_joined',
) );
/*
* If an empty search_terms string has been passed,
* the developer is force-disabling search.
*/
if ( '' === $r['search_terms'] ) {
// Set the search_terms to false for BP_User_Query efficiency.
$r['search_terms'] = false;
} elseif ( ! empty( $_REQUEST['s'] ) ) {
$r['search_terms'] = $_REQUEST['s'];
}
$members_template = new BP_Groups_Group_Members_Template( $r );
/**
* Filters whether or not a group member query has members to display.
*
* @since 1.1.0
*
* @param bool $value Whether there are members to display.
* @param BP_Groups_Group_Members_Template $members_template Object holding the member query results.
*/
return apply_filters( 'bp_group_has_members', $members_template->has_members(), $members_template );
}
/**
* @since 1.0.0
*
* @return mixed
*/
function bp_group_members() {
global $members_template;
return $members_template->members();
}
/**
* @since 1.0.0
*
* @return mixed
*/
function bp_group_the_member() {
global $members_template;
return $members_template->the_member();
}
/**
* Output the group member avatar while in the groups members loop.
*
* @since 1.0.0
*
* @param array|string $args {@see bp_core_fetch_avatar()}.
*/
function bp_group_member_avatar( $args = '' ) {
echo bp_get_group_member_avatar( $args );
}
/**
* Return the group member avatar while in the groups members loop.
*
* @since 1.0.0
*
* @param array|string $args {@see bp_core_fetch_avatar()}.
* @return string
*/
function bp_get_group_member_avatar( $args = '' ) {
global $members_template;
$r = bp_parse_args( $args, array(
'item_id' => $members_template->member->user_id,
'type' => 'full',
'email' => $members_template->member->user_email,
'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name )
) );
/**
* Filters the group member avatar while in the groups members loop.
*
* @since 1.0.0
*
* @param string $value HTML markup for group member avatar.
* @param array $r Parsed args used for the avatar query.
*/
return apply_filters( 'bp_get_group_member_avatar', bp_core_fetch_avatar( $r ), $r );
}
/**
* Output the group member avatar while in the groups members loop.
*
* @since 1.0.0
*
* @param array|string $args {@see bp_core_fetch_avatar()}.
*/
function bp_group_member_avatar_thumb( $args = '' ) {
echo bp_get_group_member_avatar_thumb( $args );
}
/**
* Return the group member avatar while in the groups members loop.
*
* @since 1.0.0
*
* @param array|string $args {@see bp_core_fetch_avatar()}.
* @return string
*/
function bp_get_group_member_avatar_thumb( $args = '' ) {
global $members_template;
$r = bp_parse_args( $args, array(
'item_id' => $members_template->member->user_id,
'type' => 'thumb',
'email' => $members_template->member->user_email,
'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name )
) );
/**
* Filters the group member avatar thumb while in the groups members loop.
*
* @since 1.1.0
*
* @param string $value HTML markup for group member avatar thumb.
* @param array $r Parsed args used for the avatar query.
*/
return apply_filters( 'bp_get_group_member_avatar_thumb', bp_core_fetch_avatar( $r ), $r );
}
/**
* Output the group member avatar while in the groups members loop.
*
* @since 1.0.0
*
* @param int $width Width of avatar to fetch.
* @param int $height Height of avatar to fetch.
*/
function bp_group_member_avatar_mini( $width = 30, $height = 30 ) {
echo bp_get_group_member_avatar_mini( $width, $height );
}
/**
* Output the group member avatar while in the groups members loop.
*
* @since 1.0.0
*
* @param int $width Width of avatar to fetch.
* @param int $height Height of avatar to fetch.
* @return string
*/
function bp_get_group_member_avatar_mini( $width = 30, $height = 30 ) {
global $members_template;
$r = bp_parse_args( array(), array(
'item_id' => $members_template->member->user_id,
'type' => 'thumb',
'email' => $members_template->member->user_email,
'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ),
'width' => absint( $width ),
'height' => absint( $height )
) );
/**
* Filters the group member avatar mini while in the groups members loop.
*
* @since 1.0.0
*
* @param string $value HTML markup for group member avatar mini.
* @param array $r Parsed args used for the avatar query.
*/
return apply_filters( 'bp_get_group_member_avatar_mini', bp_core_fetch_avatar( $r ), $r );
}
/**
* @since 1.0.0
*/
function bp_group_member_name() {
echo bp_get_group_member_name();
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_member_name() {
global $members_template;
/**
* Filters the group member display name of the current user in the loop.
*
* @since 1.0.0
*
* @param string $display_name Display name of the current user.
*/
return apply_filters( 'bp_get_group_member_name', $members_template->member->display_name );
}
/**
* @since 1.0.0
*/
function bp_group_member_url() {
echo bp_get_group_member_url();
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_member_url() {
global $members_template;
/**
* Filters the group member url for the current user in the loop.
*
* @since 1.0.0
*
* @param string $value URL for the current user.
*/
return apply_filters( 'bp_get_group_member_url', bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) );
}
/**
* @since 1.0.0
*/
function bp_group_member_link() {
echo bp_get_group_member_link();
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_member_link() {
global $members_template;
/**
* Filters the group member HTML link for the current user in the loop.
*
* @since 1.0.0
*
* @param string $value HTML link for the current user.
*/
return apply_filters( 'bp_get_group_member_link', '' . $members_template->member->display_name . '' );
}
/**
* @since 1.2.0
*/
function bp_group_member_domain() {
echo bp_get_group_member_domain();
}
/**
* @since 1.2.0
*
* @return mixed|void
*/
function bp_get_group_member_domain() {
global $members_template;
/**
* Filters the group member domain for the current user in the loop.
*
* @since 1.2.0
*
* @param string $value Domain for the current user.
*/
return apply_filters( 'bp_get_group_member_domain', bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) );
}
/**
* @since 1.2.0
*/
function bp_group_member_is_friend() {
echo bp_get_group_member_is_friend();
}
/**
* @since 1.2.0
*
* @return mixed|void
*/
function bp_get_group_member_is_friend() {
global $members_template;
if ( !isset( $members_template->member->is_friend ) ) {
$friend_status = 'not_friends';
} else {
$friend_status = ( 0 == $members_template->member->is_friend )
? 'pending'
: 'is_friend';
}
/**
* Filters the friendship status between current user and displayed user in group member loop.
*
* @since 1.2.0
*
* @param string $friend_status Current status of the friendship.
*/
return apply_filters( 'bp_get_group_member_is_friend', $friend_status );
}
/**
* @since 1.0.0
*/
function bp_group_member_is_banned() {
echo bp_get_group_member_is_banned();
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_member_is_banned() {
global $members_template;
/**
* Filters whether the member is banned from the current group.
*
* @since 1.0.0
*
* @param bool $is_banned Whether or not the member is banned.
*/
return apply_filters( 'bp_get_group_member_is_banned', $members_template->member->is_banned );
}
/**
* @since 1.2.6
*/
function bp_group_member_css_class() {
global $members_template;
if ( $members_template->member->is_banned ) {
/**
* Filters the class to add to the HTML if member is banned.
*
* @since 1.2.6
*
* @param string $value HTML class to add.
*/
echo apply_filters( 'bp_group_member_css_class', 'banned-user' );
}
}
/**
* Output the joined date for the current member in the group member loop.
*
* @since 1.0.0
* @since 2.7.0 Added $args as a parameter.
*
* @param array|string $args {@see bp_get_group_member_joined_since()}
* @return string|null
*/
function bp_group_member_joined_since( $args = array() ) {
echo bp_get_group_member_joined_since( $args );
}
/**
* Return the joined date for the current member in the group member loop.
*
* @since 1.0.0
* @since 2.7.0 Added $args as a parameter.
*
* @param array|string $args {
* Array of optional parameters.
*
* @type bool $relative Optional. If true, returns relative joined date. eg. joined 5 months ago.
* If false, returns joined date value from database. Default: true.
* }
* @return string
*/
function bp_get_group_member_joined_since( $args = array() ) {
global $members_template;
$r = wp_parse_args( $args, array(
'relative' => true,
) );
// We do not want relative time, so return now.
// @todo Should the 'bp_get_group_member_joined_since' filter be applied here?
if ( ! $r['relative'] ) {
return esc_attr( $members_template->member->date_modified );
}
/**
* Filters the joined since time for the current member in the loop.
*
* @since 1.0.0
*
* @param string $value Joined since time.
*/
return apply_filters( 'bp_get_group_member_joined_since', bp_core_get_last_activity( $members_template->member->date_modified, __( 'joined %s', 'buddypress') ) );
}
/**
* @since 1.0.0
*/
function bp_group_member_id() {
echo bp_get_group_member_id();
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_member_id() {
global $members_template;
/**
* Filters the member's user ID for group members loop.
*
* @since 1.0.0
*
* @param int $user_id User ID of the member.
*/
return apply_filters( 'bp_get_group_member_id', $members_template->member->user_id );
}
/**
* @since 1.0.0
*
* @return bool
*/
function bp_group_member_needs_pagination() {
global $members_template;
if ( $members_template->total_member_count > $members_template->pag_num ) {
return true;
}
return false;
}
/**
* @since 1.0.0
*/
function bp_group_pag_id() {
echo bp_get_group_pag_id();
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_pag_id() {
/**
* Filters the string to be used as the group pag id.
*
* @since 1.0.0
*
* @param string $value Value to use for the pag id.
*/
return apply_filters( 'bp_get_group_pag_id', 'pag' );
}
/**
* @since 1.0.0
*/
function bp_group_member_pagination() {
echo bp_get_group_member_pagination();
wp_nonce_field( 'bp_groups_member_list', '_member_pag_nonce' );
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_member_pagination() {
global $members_template;
/**
* Filters the HTML markup to be used for group member listing pagination.
*
* @since 1.0.0
*
* @param string $pag_links HTML markup for the pagination.
*/
return apply_filters( 'bp_get_group_member_pagination', $members_template->pag_links );
}
/**
* @since 1.0.0
*/
function bp_group_member_pagination_count() {
echo bp_get_group_member_pagination_count();
}
/**
* @since 1.0.0
*
* @return mixed|void
*/
function bp_get_group_member_pagination_count() {
global $members_template;
$start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
$from_num = bp_core_number_format( $start_num );
$to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
$total = bp_core_number_format( $members_template->total_member_count );
if ( 1 == $members_template->total_member_count ) {
$message = __( 'Viewing 1 member', 'buddypress' );
} else {
$message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s member', 'Viewing %1$s - %2$s of %3$s members', $members_template->total_member_count, 'buddypress' ), $from_num, $to_num, $total );
}
/**
* Filters the "Viewing x-y of z members" pagination message.
*
* @since 1.0.0
*
* @param string $value "Viewing x-y of z members" text.
* @param string $from_num Total amount for the low value in the range.
* @param string $to_num Total amount for the high value in the range.
* @param string $total Total amount of members found.
*/
return apply_filters( 'bp_get_group_member_pagination_count', $message, $from_num, $to_num, $total );
}
/**
* @since 1.0.0
*/
function bp_group_member_admin_pagination() {
echo bp_get_group_member_admin_pagination();
wp_nonce_field( 'bp_groups_member_admin_list', '_member_admin_pag_nonce' );
}
/**
* @since 1.0.0
*
* @return mixed
*/
function bp_get_group_member_admin_pagination() {
global $members_template;
return $members_template->pag_links;
}
/**
* Output the contents of the current group's home page.
*
* You should only use this when on a single group page.
*
* @since 2.4.0
*/
function bp_groups_front_template_part() {
$located = bp_groups_get_front_template();
if ( false !== $located ) {
$slug = str_replace( '.php', '', $located );
/**
* Let plugins adding an action to bp_get_template_part get it from here
*
* @param string $slug Template part slug requested.
* @param string $name Template part name requested.
*/
do_action( 'get_template_part_' . $slug, $slug, false );
load_template( $located, true );
} else if ( bp_is_active( 'activity' ) ) {
bp_get_template_part( 'groups/single/activity' );
} else if ( bp_is_active( 'members' ) ) {
bp_groups_members_template_part();
}
return $located;
}
/**
* Locate a custom group front template if it exists.
*
* @since 2.4.0
* @since 2.6.0 Adds the Group Type to the front template hierarchy.
*
* @param BP_Groups_Group|null $group Optional. Falls back to current group if not passed.
* @return string|bool Path to front template on success; boolean false on failure.
*/
function bp_groups_get_front_template( $group = null ) {
if ( ! is_a( $group, 'BP_Groups_Group' ) ) {
$group = groups_get_current_group();
}
if ( ! isset( $group->id ) ) {
return false;
}
if ( isset( $group->front_template ) ) {
return $group->front_template;
}
$template_names = array(
'groups/single/front-id-' . sanitize_file_name( $group->id ) . '.php',
'groups/single/front-slug-' . sanitize_file_name( $group->slug ) . '.php',
);
if ( bp_groups_get_group_types() ) {
$group_type = bp_groups_get_group_type( $group->id );
if ( ! $group_type ) {
$group_type = 'none';
}
$template_names[] = 'groups/single/front-group-type-' . sanitize_file_name( $group_type ) . '.php';
}
$template_names = array_merge( $template_names, array(
'groups/single/front-status-' . sanitize_file_name( $group->status ) . '.php',
'groups/single/front.php'
) );
/**
* Filters the hierarchy of group front templates corresponding to a specific group.
*
* @since 2.4.0
* @since 2.5.0 Added the `$group` parameter.
*
* @param array $template_names Array of template paths.
* @param object $group Group object.
*/
return bp_locate_template( apply_filters( 'bp_groups_get_front_template', $template_names, $group ), false, true );
}
/**
* Output the Group members template
*
* @since 2.0.0
*/
function bp_groups_members_template_part() {
?>