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