Community Forums › Forums › Archived Forums › Design Tips and Tricks › Add Gamipress details below avatar in comment section
This topic is: not resolved
Tagged: avatar, Comment Section, gamipress, gravatar
- This topic has 1 reply, 1 voice, and was last updated 6 years, 6 months ago by
jeremyers1.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
July 22, 2018 at 12:15 pm #221914July 24, 2018 at 6:04 pm #221957
jeremyers1
MemberIf it helps, here are the pertinent code snippets from Genesis Framework and the gamipress for bbpress plugin. I want to somehow combine the two so that the gamipress achievements show up beneath the avatar in the comment section.
Genesis Framework (in /lib/structure/comments.php)
function genesis_html5_comment_callback( $comment, array $args, $depth ) { $GLOBALS['comment'] = $comment; ?> <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>"> <article <?php echo genesis_attr( 'comment' ); ?>> <?php /** * Fires inside single comment callback, before comment markup. * * @since 1.1.0 */ do_action( 'genesis_before_comment' ); ?> <header <?php echo genesis_attr( 'comment-header' ); ?>> <p <?php echo genesis_attr( 'comment-author' ); ?>> <?php echo get_avatar( $comment, $args['avatar_size'] ); $author = get_comment_author(); $url = get_comment_author_url(); if ( ! empty( $url ) && 'http://' !== $url ) { $author = sprintf( '<a href="%s" %s>%s</a>', esc_url( $url ), genesis_attr( 'comment-author-link' ), $author ); } /** * Filter the "comment author says" text. * * Allows developer to filter the "comment author says" text so it can say something different, or nothing at all. * * @since unknown * * @param string $text Comment author says text. */ $comment_author_says_text = apply_filters( 'comment_author_says_text', __( 'says', 'genesis' ) ); if ( ! empty( $comment_author_says_text ) ) { $comment_author_says_text = '<span class="says">' . $comment_author_says_text . '</span>'; } printf( '<span itemprop="name">%s</span> %s', $author, $comment_author_says_text ); ?> </p> <?php /** * Allows developer to control whether to print the comment date. * * @since 2.2.0 * * @param bool $comment_date Whether to print the comment date. * @param string $post_type The current post type. */ $comment_date = apply_filters( 'genesis_show_comment_date', true, get_post_type() ); if ( $comment_date ) { printf( '<p %s>', genesis_attr( 'comment-meta' ) ); printf( '<time %s>', genesis_attr( 'comment-time' ) ); printf( '<a href="%s" %s>', esc_url( get_comment_link( $comment->comment_ID ) ), genesis_attr( 'comment-time-link' ) ); echo esc_html( get_comment_date() ) . ' ' . __( 'at', 'genesis' ) . ' ' . esc_html( get_comment_time() ); echo '</a></time></p>'; } edit_comment_link( __( '(Edit)', 'genesis' ), ' ' ); ?> </header> <div <?php echo genesis_attr( 'comment-content' ); ?>> <?php if ( ! $comment->comment_approved ) : ?> <?php /** * Filter the "comment awaiting moderation" text. * * Allows developer to filter the "comment awaiting moderation" text so it can say something different, or nothing at all. * * @since unknown * * @param string $text Comment awaiting moderation text. */ $comment_awaiting_moderation_text = apply_filters( 'genesis_comment_awaiting_moderation', __( 'Your comment is awaiting moderation.', 'genesis' ) ); ?> <p class="alert"><?php echo $comment_awaiting_moderation_text; ?></p> <?php endif; ?> <?php comment_text(); ?> </div> <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'before' => sprintf( '<div %s>', genesis_attr( 'comment-reply' ) ), 'after' => '</div>', ) ) ); ?> <?php /** * Fires inside legacy single comment callback, after comment markup. * * @since 1.1.0 */ do_action( 'genesis_after_comment' ); ?> </article> <?php // No ending </li> tag because of comment threading. }
Gamipress BBPress Integration Plugin (found in /includes/content-filters.php)
<?php /** * Content Filters * * @package GamiPress\bbPress\Content_Filters * @since 1.0.4 */ // Exit if accessed directly if( !defined( 'ABSPATH' ) ) exit; function gamipress_bbp_author_details() { $reply_id = bbp_get_reply_id(); // User is not a guest if ( bbp_is_reply_anonymous( $reply_id ) ) { return; } // Get the author ID $user_id = bbp_get_reply_author_id( $reply_id ); /* ------------------------------- * Points Types ------------------------------- */ // Setup points types vars $points_types = gamipress_get_points_types(); $points_types_slugs = gamipress_get_points_types_slugs(); // Get points type display settings $points_types_to_show = gamipress_bbp_get_points_types(); $points_types_thumbnail = (bool) gamipress_bbp_get_option( 'points_types_thumbnail', false ); $points_types_thumbnail_size = (int) gamipress_bbp_get_option( 'points_types_thumbnail_size', 25 ); $points_types_label = (bool) gamipress_bbp_get_option( 'points_types_label', false ); // Parse thumbnail size if( $points_types_thumbnail_size > 0 ) { $points_types_thumbnail_size = array( $points_types_thumbnail_size, $points_types_thumbnail_size ); } else { $points_types_thumbnail_size = 'gamipress-points'; } if( ! empty( $points_types_to_show ) ) : ?> <div class="gamipress-bbpress-points"> <?php foreach( $points_types_to_show as $points_type_to_show ) : // If points type not registered, skip if( ! in_array( $points_type_to_show, $points_types_slugs ) ) continue; $points_type = $points_types[$points_type_to_show]; $user_points = gamipress_get_user_points( $user_id, $points_type_to_show ); ?> <div class="gamipress-bbpress-points-type gamipress-bbpress-<?php echo $points_type_to_show; ?>"> <?php // The points thumbnail ?> <?php if( $points_types_thumbnail ) : ?> <span class="gamipress-bbpress-points-thumbnail gamipress-bbpress-<?php echo $points_type_to_show; ?>-thumbnail"> <?php echo gamipress_get_points_type_thumbnail( $points_type_to_show, $points_types_thumbnail_size ); ?> </span> <?php endif; ?> <?php // The user points amount ?> <span class="gamipress-bbpress-user-points gamipress-bbpress-user-<?php echo $points_type_to_show; ?>"> <?php echo $user_points; ?> </span> <?php // The points label ?> <?php if( $points_types_label ) : ?> <span class="gamipress-bbpress-points-label gamipress-bbpress-<?php echo $points_type_to_show; ?>-label"> <?php echo _n( $points_type['singular_name'], $points_type['plural_name'], $user_points, 'gamipress-bbp' ); ?> </span> <?php endif; ?> </div> <?php endforeach; ?> </div> <?php endif; /* ------------------------------- * Achievement Types ------------------------------- */ // Setup achievement types vars $achievement_types = gamipress_get_achievement_types(); $achievement_types_slugs = gamipress_get_achievement_types_slugs(); // Get achievement type display settings $achievement_types_to_show = gamipress_bbp_get_achievement_types(); $achievement_types_thumbnail = (bool) gamipress_bbp_get_option( 'achievement_types_thumbnail', false ); $achievement_types_thumbnail_size = (int) gamipress_bbp_get_option( 'achievement_types_thumbnail_size', 25 ); $achievement_types_title = (bool) gamipress_bbp_get_option( 'achievement_types_title', false ); $achievement_types_link = (bool) gamipress_bbp_get_option( 'achievement_types_link', false ); // Parse thumbnail size if( $achievement_types_thumbnail_size > 0 ) { $achievement_types_thumbnail_size = array( $achievement_types_thumbnail_size, $achievement_types_thumbnail_size ); } else { $achievement_types_thumbnail_size = 'gamipress-achievement'; } if( ! empty( $achievement_types_to_show ) ) : ?> <div class="gamipress-bbpress-achievements"> <?php foreach( $achievement_types_to_show as $achievement_type_to_show ) : // If achievements type not registered, skip if( ! in_array( $achievement_type_to_show, $achievement_types_slugs ) ) continue; $achievement_type = $achievement_types[$achievement_type_to_show]; $user_achievements = gamipress_get_user_achievements( array( 'user_id' => $user_id, 'achievement_type' => $achievement_type_to_show, 'display' => true, ) ); // If user has not earned any achievements of this type, skip if( empty( $user_achievements ) ) { continue; } ?> <div class="gamipress-bbpress-achievement gamipress-bbpress-<?php echo $achievement_type_to_show; ?>"> <?php // The achievement type label ?> <span class="gamipress-bbpress-achievement-type-label gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-label"> <?php echo $achievement_type['plural_name']; ?>: </span> <?php // Lets to get just the achievement thumbnail and title foreach( $user_achievements as $user_achievement ) : ?> <?php // The achievement thumbnail ?> <?php if( $achievement_types_thumbnail ) : ?> <?php // The achievement link ?> <?php if( $achievement_types_link ) : ?> <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-bbpress-achievement-thumbnail gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-thumbnail"> <?php echo gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $achievement_types_thumbnail_size ); ?> </a> <?php else : ?> <span title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-bbpress-achievement-thumbnail gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-thumbnail"> <?php echo gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $achievement_types_thumbnail_size ); ?> </span> <?php endif; ?> <?php endif; ?> <?php // The achievement title ?> <?php if( $achievement_types_title ) : ?> <?php // The achievement link ?> <?php if( $achievement_types_link ) : ?> <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-bbpress-achievement-title gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-title"> <?php echo get_the_title( $user_achievement->ID ); ?> </a> <?php else : ?> <span class="gamipress-bbpress-achievement-title gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-title"> <?php echo get_the_title( $user_achievement->ID ); ?> </span> <?php endif; ?> <?php endif; ?> <?php endforeach; ?> </div> <?php endforeach; ?> </div> <?php endif; /* ------------------------------- * Rank Types ------------------------------- */ // Setup rank types vars $rank_types = gamipress_get_rank_types(); $rank_types_slugs = gamipress_get_rank_types_slugs(); // Get rank type display settings $rank_types_to_show = gamipress_bbp_get_rank_types(); $rank_types_thumbnail = (bool) gamipress_bbp_get_option( 'rank_types_thumbnail', false ); $rank_types_thumbnail_size = (int) gamipress_bbp_get_option( 'rank_types_thumbnail_size', 25 ); $rank_types_title = (bool) gamipress_bbp_get_option( 'rank_types_title', false ); $rank_types_link = (bool) gamipress_bbp_get_option( 'rank_types_link', false ); // Parse thumbnail size if( $rank_types_thumbnail_size > 0 ) { $rank_types_thumbnail_size = array( $rank_types_thumbnail_size, $rank_types_thumbnail_size ); } else { $rank_types_thumbnail_size = 'gamipress-rank'; } if( ! empty( $rank_types_to_show ) ) : ?> <div class="gamipress-bbpress-ranks"> <?php foreach( $rank_types_to_show as $rank_type_to_show ) : // If points type not registered, skip if( ! in_array( $rank_type_to_show, $rank_types_slugs ) ) continue; $rank_type = $rank_types[$rank_type_to_show]; $user_rank = gamipress_get_user_rank( $user_id, $rank_type_to_show ); ?> <div class="gamipress-bbpress-rank gamipress-bbpress-<?php echo $rank_type_to_show; ?>"> <?php // The rank type label ?> <span class="gamipress-bbpress-rank-label gamipress-bbpress-<?php echo $rank_type_to_show; ?>-label"> <?php echo $rank_type['singular_name']; ?>: </span> <?php // The rank thumbnail ?> <?php if( $rank_types_thumbnail ) : ?> <?php // The rank link ?> <?php if( $rank_types_link ) : ?> <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="gamipress-bbpress-rank-thumbnail gamipress-bbpress-<?php echo $rank_type_to_show; ?>-thumbnail"> <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $rank_types_thumbnail_size ); ?> </a> <?php else : ?> <span title="<?php echo $user_rank->post_title; ?>" class="gamipress-bbpress-rank-thumbnail gamipress-bbpress-<?php echo $rank_type_to_show; ?>-thumbnail"> <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $rank_types_thumbnail_size ); ?> </span> <?php endif; ?> <?php endif; ?> <?php // The rank title ?> <?php if( $rank_types_title ) : ?> <?php // The rank link ?> <?php if( $rank_types_link ) : ?> <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="gamipress-bbpress-rank-title gamipress-bbpress-<?php echo $rank_type_to_show; ?>-title"> <?php echo $user_rank->post_title; ?> </a> <?php else : ?> <span class="gamipress-bbpress-rank-title gamipress-bbpress-<?php echo $rank_type_to_show; ?>-title"> <?php echo $user_rank->post_title; ?> </span> <?php endif; ?> <?php endif; ?> </div> <?php endforeach; ?> </div> <?php endif; } add_action( 'bbp_theme_after_reply_author_details', 'gamipress_bbp_author_details' ); /** * Helper function to retrieve the points types configured at author details screen * * @since 1.0.4 * * @return array */ function gamipress_bbp_get_points_types() { $points_types = array(); $points_types_slugs = gamipress_get_points_types_slugs(); $points_types_to_show = gamipress_bbp_get_option( 'points_types', array() ); foreach( $points_types_to_show as $points_type_slug ) { if( ! in_array( $points_type_slug, $points_types_slugs ) ) { continue; } $points_types[] = $points_type_slug; } return $points_types; } /** * Helper function to retrieve the achievement types configured at author details screen * * @since 1.0.4 * * @return array */ function gamipress_bbp_get_achievement_types() { $achievements_types = array(); $achievement_types_slugs = gamipress_get_achievement_types_slugs(); $achievements_types_to_show = gamipress_bbp_get_option( 'achievement_types', array() ); foreach( $achievements_types_to_show as $achievement_type_slug ) { // Skip if not registered if( ! in_array( $achievement_type_slug, $achievement_types_slugs ) ) { continue; } $achievements_types[] = $achievement_type_slug; } return $achievements_types; } /** * Helper function to retrieve the rank types configured at author details screen * * @since 1.0.4 * * @return array */ function gamipress_bbp_get_rank_types() { $ranks_types = array(); $rank_types_slugs = gamipress_get_rank_types_slugs(); $ranks_types_to_show = gamipress_bbp_get_option( 'rank_types', array() ); foreach( $ranks_types_to_show as $rank_type_slug ) { // Skip if not registered if( ! in_array( $rank_type_slug, $rank_types_slugs ) ) { continue; } $ranks_types[] = $rank_type_slug; } return $ranks_types; }
Blogger and Author
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.