[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/ -> bp-members-blocks.php (source)

   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 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  }


Generated: Thu Aug 6 01:01:32 2020 Cross-referenced by PHPXref 0.7.1