[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BP Members Blocks Functions. 4 * 5 * @package BuddyPress 6 * @subpackage MembersBlocks 7 * @since 6.0.0 8 */ 9 10 // Exit if accessed directly. 11 if ( ! defined( 'ABSPATH' ) ) { 12 exit; 13 } 14 15 /** 16 * Add BP Members blocks specific settings to the BP Blocks Editor ones. 17 * 18 * @since 6.0.0 19 * 20 * @param array $bp_editor_settings BP blocks editor settings. 21 * @return array BP Members blocks editor settings. 22 */ 23 function bp_members_editor_settings( $bp_editor_settings = array() ) { 24 $bp = buddypress(); 25 26 return array_merge( 27 $bp_editor_settings, 28 array( 29 'members' => array( 30 'isMentionEnabled' => bp_is_active( 'activity' ) && bp_activity_do_mentions(), 31 'isAvatarEnabled' => $bp->avatar && $bp->avatar->show_avatars, 32 'isCoverImageEnabled' => bp_is_active( 'members', 'cover_image' ), 33 ), 34 ) 35 ); 36 } 37 add_filter( 'bp_blocks_editor_settings', 'bp_members_editor_settings' ); 38 39 /** 40 * Callback function to render the BP Member Block. 41 * 42 * @since 6.0.0 43 * 44 * @param array $attributes The block attributes. 45 * @return string HTML output. 46 */ 47 function bp_members_render_member_block( $attributes = array() ) { 48 $bp = buddypress(); 49 50 $block_args = wp_parse_args( 51 $attributes, 52 array( 53 'itemID' => 0, 54 'avatarSize' => 'full', 55 'displayMentionSlug' => true, 56 'displayActionButton' => true, 57 'displayCoverImage' => true, 58 ) 59 ); 60 61 if ( ! $block_args['itemID'] ) { 62 return; 63 } 64 65 // Set the member ID and container classes. 66 $member_id = (int) $block_args['itemID']; 67 $container_classes = array( 'bp-block-member' ); 68 69 // Mention variables. 70 $username = bp_core_get_username( $member_id ); 71 $at_mention = ''; 72 73 // Avatar variables. 74 $avatar = ''; 75 $avatar_container = ''; 76 77 // Cover image variable. 78 $cover_image = ''; 79 $cover_style = ''; 80 $cover_container = ''; 81 82 // Member name variables. 83 $display_name = bp_core_get_user_displayname( $member_id ); 84 $member_link = bp_core_get_user_domain( $member_id ); 85 86 // Member action button. 87 $action_button = ''; 88 $display_action_button = (bool) $block_args['displayActionButton']; 89 90 if ( $bp->avatar && $bp->avatar->show_avatars && in_array( $block_args['avatarSize'], array( 'thumb', 'full' ), true ) ) { 91 $avatar = bp_core_fetch_avatar( 92 array( 93 'item_id' => $member_id, 94 'object' => 'user', 95 'type' => $block_args['avatarSize'], 96 'html' => false, 97 ) 98 ); 99 100 $container_classes[] = 'avatar-' . $block_args['avatarSize']; 101 } else { 102 $container_classes[] = 'avatar-none'; 103 } 104 105 if ( $avatar ) { 106 $avatar_container = sprintf( 107 '<div class="item-header-avatar"> 108 <a href="%1$s"> 109 <img loading="lazy" src="%2$s" alt="%3$s" class="avatar"> 110 </a> 111 </div>', 112 esc_url( $member_link ), 113 esc_url( $avatar ), 114 /* translators: %s: member name */ 115 sprintf( esc_html__( 'Profile photo of %s', 'buddypress' ), $display_name ) 116 ); 117 } 118 119 $display_cover_image = (bool) $block_args['displayCoverImage']; 120 if ( bp_is_active( 'members', 'cover_image' ) && $display_cover_image ) { 121 $cover_image = bp_attachments_get_attachment( 122 'url', 123 array( 124 'item_id' => $member_id, 125 ) 126 ); 127 128 if ( $cover_image ) { 129 $cover_style = sprintf( 130 ' style="background-image: url( %s );"', 131 esc_url( $cover_image ) 132 ); 133 } 134 135 $cover_container = sprintf( 136 '<div class="bp-member-cover-image"%s></div>', 137 $cover_style 138 ); 139 140 $container_classes[] = 'has-cover'; 141 } 142 143 $display_mention_slug = (bool) $block_args['displayMentionSlug']; 144 if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() && $display_mention_slug ) { 145 $at_mention = sprintf( 146 '<span class="user-nicename">@%s</span>', 147 esc_html( $username ) 148 ); 149 } 150 151 if ( $display_action_button ) { 152 $action_button = sprintf( 153 '<div class="bp-profile-button"> 154 <a href="%1$s" class="button large primary button-primary" role="button">%2$s</a> 155 </div>', 156 esc_url( $member_link ), 157 esc_html__( 'View Profile', 'buddypress' ) 158 ); 159 } 160 161 $output = sprintf( 162 '<div class="%1$s"> 163 %2$s 164 <div class="member-content"> 165 %3$s 166 <div class="member-description"> 167 <strong><a href="%4$s">%5$s</a></strong> 168 %6$s 169 %7$s 170 </div> 171 </div> 172 </div>', 173 implode( ' ', array_map( 'sanitize_html_class', $container_classes ) ), 174 $cover_container, 175 $avatar_container, 176 esc_url( $member_link ), 177 esc_html( $display_name ), 178 $at_mention, 179 $action_button 180 ); 181 182 // Compact all interesting parameters. 183 $params = array_merge( $block_args, compact( 'username', 'display_name', 'member_link', 'avatar', 'cover_image' ) ); 184 185 /** 186 * Filter here to edit the output of the single member block. 187 * 188 * @since 6.0.0 189 * 190 * @param string $output The HTML output of the block. 191 * @param array $params The block extended parameters. 192 */ 193 return apply_filters( 'bp_members_render_member_block_output', $output, $params ); 194 } 195 196 /** 197 * Callback function to render the BP Members Block. 198 * 199 * @since 7.0.0 200 * 201 * @param array $attributes The block attributes. 202 * @return string HTML output. 203 */ 204 function bp_members_render_members_block( $attributes = array() ) { 205 $bp = buddypress(); 206 207 $block_args = wp_parse_args( 208 $attributes, 209 array( 210 'itemIDs' => array(), 211 'avatarSize' => 'full', 212 'displayMentionSlug' => true, 213 'displayUserName' => true, 214 'extraData' => 'none', 215 'layoutPreference' => 'list', 216 'columns' => '2', 217 ) 218 ); 219 220 $member_ids = wp_parse_id_list( $block_args['itemIDs'] ); 221 if ( ! array_filter( $member_ids ) ) { 222 return ''; 223 } 224 225 $container_classes = sprintf( 'bp-block-members avatar-%s', $block_args['avatarSize'] ); 226 if ( 'grid' === $block_args['layoutPreference'] ) { 227 $container_classes .= sprintf( ' is-grid columns-%d', (int) $block_args['columns'] ); 228 } 229 230 $query_args = array( 231 'user_ids' => $member_ids, 232 ); 233 234 if ( 'none' !== $block_args['extraData'] ) { 235 $query_args['populate_extras'] = true; 236 } 237 238 $query = bp_core_get_users( $query_args ); 239 240 // Initialize the output and the members. 241 $output = ''; 242 $members = $query['users']; 243 244 foreach ( $members as $member ) { 245 $has_activity = false; 246 $member_item_classes = 'member-content'; 247 248 if ( 'list' === $block_args['layoutPreference'] && 'latest_update' === $block_args['extraData'] && isset( $member->latest_update ) && $member->latest_update ) { 249 $has_activity = true; 250 $member_item_classes = 'member-content has-activity'; 251 } 252 253 $output .= sprintf( '<div class="%s">', $member_item_classes ); 254 255 // Get Member link. 256 $member_link = bp_core_get_user_domain( $member->ID ); 257 258 // Set the Avatar output. 259 if ( $bp->avatar && $bp->avatar->show_avatars && 'none' !== $block_args['avatarSize'] ) { 260 $output .= sprintf( 261 '<div class="item-header-avatar"> 262 <a href="%1$s"> 263 <img class="avatar" alt="%2$s" src="%3$s" /> 264 </a> 265 </div>', 266 esc_url( $member_link ), 267 /* translators: %s: member name */ 268 sprintf( esc_attr__( 'Profile photo of %s', 'buddypress' ), $member->display_name ), 269 esc_url( 270 bp_core_fetch_avatar( 271 array( 272 'item_id' => $member->ID, 273 'object' => 'user', 274 'type' => $block_args['avatarSize'], 275 'html' => false, 276 ) 277 ) 278 ) 279 ); 280 } 281 282 $output .= '<div class="member-description">'; 283 284 // Add the latest activity the member posted. 285 if ( $has_activity ) { 286 $activity_content = ''; 287 $activity_data = maybe_unserialize( $member->latest_update ); 288 289 if ( isset( $activity_data['content'] ) ) { 290 $activity_content = apply_filters( 'bp_get_activity_content', $activity_data['content'] ); 291 } 292 293 $display_name = ''; 294 if ( $block_args['displayUserName'] ) { 295 $display_name = $member->display_name; 296 } 297 298 $mention_name = ''; 299 if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() && $block_args['displayMentionSlug'] ) { 300 $mention_name = '(@' . $member->user_nicename . ')'; 301 } 302 303 $output .= sprintf( 304 '<blockquote class="wp-block-quote"> 305 %1$s 306 <cite> 307 <span>%2$s</span> 308 %3$s 309 </cite> 310 </blockquote>', 311 $activity_content, 312 esc_html( $display_name ), 313 esc_html( $mention_name ) 314 ); 315 } else { 316 if ( $block_args['displayUserName'] ) { 317 $output .= sprintf( 318 '<strong><a href="%1$s">%2$s</a></strong>', 319 esc_url( $member_link ), 320 esc_html( $member->display_name ) 321 ); 322 } 323 324 if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() && $block_args['displayMentionSlug'] ) { 325 $output .= sprintf( 326 '<span class="user-nicename">@%s</span>', 327 esc_html( $member->user_nicename ) 328 ); 329 } 330 331 if ( 'last_activity' === $block_args['extraData'] ) { 332 $output .= sprintf( 333 '<time datetime="%1$s">%2$s</time>', 334 esc_attr( bp_core_get_iso8601_date( $member->last_activity ) ), 335 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ 336 sprintf( esc_html__( 'Active %s', 'buddypress' ), bp_core_time_since( $member->last_activity ) ) 337 ); 338 } 339 } 340 341 $output .= '</div></div>'; 342 } 343 344 // Set the final output. 345 $output = sprintf( '<div class="%1$s">%2$s</div>', $container_classes, $output ); 346 347 /** 348 * Filter here to edit the output of the members block. 349 * 350 * @since 7.0.0 351 * 352 * @param string $output The HTML output of the block. 353 * @param array $block_args The block arguments. 354 * @param array $members The list of WP_User objects. 355 */ 356 return apply_filters( 'bp_members_render_members_block_output', $output, $block_args, $members ); 357 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Apr 19 01:01:38 2021 | Cross-referenced by PHPXref 0.7.1 |