bp_members_render_members_block( array $attributes = array() )
Callback function to render the BP Members Block.
Parameters Parameters
- $attributes
-
(array) (Optional) The block attributes.
Default value: array()
Return Return
(string) HTML output.
Source Source
File: bp-members/bp-members-blocks.php
function bp_members_render_members_block( $attributes = array() ) { $bp = buddypress(); $block_args = wp_parse_args( $attributes, array( 'itemIDs' => array(), 'avatarSize' => 'full', 'displayMentionSlug' => true, 'displayUserName' => true, 'extraData' => 'none', 'layoutPreference' => 'list', 'columns' => '2', ) ); $member_ids = wp_parse_id_list( $block_args['itemIDs'] ); if ( ! array_filter( $member_ids ) ) { return ''; } $container_classes = sprintf( 'bp-block-members avatar-%s', $block_args['avatarSize'] ); if ( 'grid' === $block_args['layoutPreference'] ) { $container_classes .= sprintf( ' is-grid columns-%d', (int) $block_args['columns'] ); } $query_args = array( 'user_ids' => $member_ids, ); if ( 'none' !== $block_args['extraData'] ) { $query_args['populate_extras'] = true; } $query = bp_core_get_users( $query_args ); // Initialize the output and the members. $output = ''; $members = $query['users']; foreach ( $members as $member ) { $has_activity = false; $member_item_classes = 'member-content'; if ( 'list' === $block_args['layoutPreference'] && 'latest_update' === $block_args['extraData'] && isset( $member->latest_update ) && $member->latest_update ) { $has_activity = true; $member_item_classes = 'member-content has-activity'; } $output .= sprintf( '<div class="%s">', $member_item_classes ); // Get Member link. $member_link = bp_core_get_user_domain( $member->ID ); // Set the Avatar output. if ( $bp->avatar && $bp->avatar->show_avatars && 'none' !== $block_args['avatarSize'] ) { $output .= sprintf( '<div class="item-header-avatar"> <a href="%1$s"> <img class="avatar" alt="%2$s" src="%3$s" /> </a> </div>', esc_url( $member_link ), /* translators: %s: member name */ sprintf( esc_attr__( 'Profile photo of %s', 'buddypress' ), $member->display_name ), esc_url( bp_core_fetch_avatar( array( 'item_id' => $member->ID, 'object' => 'user', 'type' => $block_args['avatarSize'], 'html' => false, ) ) ) ); } $output .= '<div class="member-description">'; // Add the latest activity the member posted. if ( $has_activity ) { $activity_content = ''; $activity_data = maybe_unserialize( $member->latest_update ); if ( isset( $activity_data['content'] ) ) { $activity_content = apply_filters( 'bp_get_activity_content', $activity_data['content'] ); } $display_name = ''; if ( $block_args['displayUserName'] ) { $display_name = $member->display_name; } $mention_name = ''; if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() && $block_args['displayMentionSlug'] ) { $mention_name = '(@' . $member->user_nicename . ')'; } $output .= sprintf( '<blockquote class="wp-block-quote"> %1$s <cite> <span>%2$s</span> %3$s </cite> </blockquote>', $activity_content, esc_html( $display_name ), esc_html( $mention_name ) ); } else { if ( $block_args['displayUserName'] ) { $output .= sprintf( '<strong><a href="%1$s">%2$s</a></strong>', esc_url( $member_link ), esc_html( $member->display_name ) ); } if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() && $block_args['displayMentionSlug'] ) { $output .= sprintf( '<span class="user-nicename">@%s</span>', esc_html( $member->user_nicename ) ); } if ( 'last_activity' === $block_args['extraData'] ) { $output .= sprintf( '<time datetime="%1$s">%2$s</time>', esc_attr( bp_core_get_iso8601_date( $member->last_activity ) ), /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ sprintf( esc_html__( 'Active %s', 'buddypress' ), bp_core_time_since( $member->last_activity ) ) ); } } $output .= '</div></div>'; } // Set the final output. $output = sprintf( '<div class="%1$s">%2$s</div>', $container_classes, $output ); /** * Filter here to edit the output of the members block. * * @since 7.0.0 * * @param string $output The HTML output of the block. * @param array $block_args The block arguments. * @param array $members The list of WP_User objects. */ return apply_filters( 'bp_members_render_members_block_output', $output, $block_args, $members ); }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
7.0.0 | Introduced. |