BP_Email_Tokens::token__group_card( BP_Email $bp_email, array $formatted_tokens, array $tokens )

Generate the output for token group.card

Description

Parameters

$bp_email

(Required)

$formatted_tokens

(Required)

$tokens

(Required)

Return

(string) html for the output

Source

File: bp-core/classes/class-bp-email-tokens.php

	public function token__group_card( $bp_email, $formatted_tokens, $tokens ) {
		$output = '';

		$group = isset( $tokens['group'] ) ? $tokens['group'] : false;
		if ( empty( $group ) ) {
			$group_id = isset( $tokens['group.id'] ) ? $tokens['group.id'] : false;
			if ( empty( $group_id ) ) {
				return $output;
			}

			$group = groups_get_group( $group_id );
		}

		if ( empty( $group ) ) {
			return $output;
		}

		ob_start();
		?>
        <div class="card_wrapper card_group card_group_small" style="border-radius: 5px; padding: 10px;">
            <table cellspacing="0" cellpadding="0" border="0" width="100%">
				<?php
				if ( bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_cover_image_uploads() && bp_attachments_is_wp_version_supported() ) {
					$cover_image = bp_attachments_get_attachment( 'url', array(
						'object_dir' => 'groups',
						'item_id'    => $group_id,
					) );
					echo "<tr><td colspan='100%'><img src='{$cover_image}'></td></tr>";
				}
				?>

                <tr>
                    <td>
                        <a href="<?php echo bp_get_group_permalink( $group ); ?>"
                           style="border: 1px solid <?php echo esc_attr( $settings['body_border_color'] ); ?>; display: block; border-radius: 3px; width: 100px;">
                            <img alt="" src="<?php echo bp_core_fetch_avatar( array(
								'item_id'    => $group->id,
								'avatar_dir' => 'group-avatars',
								'object'     => 'group',
								'type'       => 'full',
								'width'      => 200,
								'height'     => 200,
								'html'       => false
							) ); ?>" width="100" height="100"
                                 style="margin:0; padding:0; box-sizing: border-box; border-radius: 3px; border:3px solid <?php echo esc_attr( $settings['body_bg'] ); ?>; display:block;"
                                 border="0"/>
                        </a>
                    </td>
                    <td>
                        <h3><?php echo $group->name; ?></h3>
                        <div class="spacer" style="font-size: 7px; line-height: 7px; height: 7px;">&nbsp;</div>
						<?php echo ucfirst( $group->status ) . " " . __( 'Group', 'buddyboss' ); ?><br>
                        <table cellspacing="0" cellpadding="0" border="0" width="100%">
                            <tr>
                                <td align="left">
									<?php
									if ( bp_is_active( 'activity' ) ) {

										global $wpdb;

										$activity_table = buddypress()->activity->table_name;

										$sql = array(
											'select'  => "SELECT user_id, max( date_recorded ) as date_recorded FROM {$activity_table}",
											'where'   => array(),
											'groupby' => 'GROUP BY user_id',
											'orderby' => 'ORDER BY date_recorded',
											'order'   => 'DESC',
										);

										$sql['where'] = array(
											'item_id = ' . absint( $group->id ),
											$wpdb->prepare( "component = %s", buddypress()->groups->id ),
										);

										$sql['where'] = 'WHERE ' . implode( ' AND ', $sql['where'] );

										$sql['limit'] = 'LIMIT 4';

										$group_user_ids = $wpdb->get_results( "{$sql[ 'select' ]} {$sql[ 'where' ]} {$sql[ 'groupby' ]} {$sql[ 'orderby' ]} {$sql[ 'order' ]} {$sql[ 'limit' ]}" );

										$group_user_ids = wp_list_pluck( $group_user_ids, 'user_id' );

										$output = "<span class='bs-group-members'>";
										foreach ( $group_user_ids as $user_id ) {
											$avatar = bp_core_fetch_avatar( array(
												'item_id'    => $user_id,
												'avatar_dir' => 'avatars',
												'object'     => 'user',
												'type'       => 'full',
												'html'       => false
											) );

											if ( ! empty( $avatar ) ) {
												$output .= sprintf( "<img src='%s' alt='%s'>", $avatar, bp_core_get_user_displayname( $user_id ) );
											}
										}
										$output .= "</span>";

										$output .= "<span class='members'>" . groups_get_total_member_count( $group->id ) . " " . __( 'Members', 'buddyboss' ) . "</span>";
										echo $output;
									}
									?>
                                </td>

                                <td align="right">
                                    <a class="button-primary" href="<?php echo bp_get_group_permalink( $group ); ?>">
										<?php
										$joined_status = 'unknown';
										$recepients    = $bp_email->get_to();
										if ( ! empty( $recepients ) && count( $recepients ) === 1 ) {
											// BP_Email_Recipient
											$recepient = reset( $recepients );
											$user      = $recepient->get_user();
											if ( ! empty( $user ) ) {
												if ( groups_is_user_member( $user->ID, $group->id ) ) {
													$joined_status = 'joined';
												} else {
													$joined_status = 'not-joined';
												}
											}
										}

										switch ( $joined_status ) {
											case 'joined':
												_e( 'Leave Group', 'buddyboss' );
												break;
											case 'not-joined':
												_e( 'Join Group', 'buddyboss' );
												break;
											default:
												_e( 'Visit Group', 'buddyboss' );
												break;
										}
										?>
                                    </a>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <div class="spacer" style="font-size: 10px; line-height: 10px; height: 10px;">&nbsp;</div>
        </div>

		<?php
		$output = str_replace( array( "\r", "\n" ), '', ob_get_clean() );

		return $output;
	}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.