| 1 |
<?php |
| 2 |
/** |
| 3 |
* Rank template |
| 4 |
* |
| 5 |
* This template can be overridden by copying it to yourtheme/gamipress/rank.php |
| 6 |
* To override a specific rank just copy it as yourtheme/gamipress/rank-{rank-type}.php |
| 7 |
*/ |
| 8 |
global $gamipress_template_args; |
| 9 |
|
| 10 |
// Shorthand |
| 11 |
$a = $gamipress_template_args; |
| 12 |
|
| 13 |
$user_id = isset( $a['user_id'] ) ? absint( $a['user_id'] ) : get_current_user_id(); |
| 14 |
|
| 15 |
// Check if user has earned this rank, rank is earned by default if is the lowest priority of this type |
| 16 |
if( gamipress_is_lowest_priority_rank( get_the_ID() ) ) { |
| 17 |
$earned = true; |
| 18 |
} else { |
| 19 |
$earned = gamipress_has_user_earned_achievement( get_the_ID(), $user_id ); |
| 20 |
} |
| 21 |
|
| 22 |
// Check if this rank is the current one of the user |
| 23 |
$current = gamipress_get_user_rank_id( $user_id, get_post_type( get_the_ID() ) ) === get_the_ID(); |
| 24 |
|
| 25 |
// Setup thumbnail size |
| 26 |
$thumbnail_size = absint( $a['thumbnail_size'] ); |
| 27 |
|
| 28 |
if( $thumbnail_size === 0 ) { |
| 29 |
$thumbnail_size = 'gamipress-rank'; |
| 30 |
} else { |
| 31 |
$thumbnail_size = array( $thumbnail_size, $thumbnail_size ); |
| 32 |
} |
| 33 |
|
| 34 |
// Sanitize title size |
| 35 |
$a['title_size'] = gamipress_sanitize_title_size_option( $a['title_size'] ); |
| 36 |
|
| 37 |
// Setup rank classes |
| 38 |
$classes = array( |
| 39 |
'gamipress-rank', |
| 40 |
( $earned ? 'user-has-earned' : 'user-has-not-earned' ), |
| 41 |
( $current ? 'current-user-rank' : '' ), |
| 42 |
'gamipress-layout-' . $a['layout'], |
| 43 |
'gamipress-align-' . $a['align'] |
| 44 |
); |
| 45 |
|
| 46 |
/** |
| 47 |
* Rank classes |
| 48 |
* |
| 49 |
* @since 1.4.0 |
| 50 |
* |
| 51 |
* @param array $classes Array of rank classes |
| 52 |
* @param integer $rank_id The Rank ID |
| 53 |
* @param array $template_args Template received arguments |
| 54 |
*/ |
| 55 |
$classes = apply_filters( 'gamipress_rank_classes', $classes, get_the_ID(), $a ); |
| 56 |
?> |
| 57 |
|
| 58 |
|
| 59 |
<div id="gamipress-rank-<?php the_ID(); ?>" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
| 60 |
|
| 61 |
<?php |
| 62 |
/** |
| 63 |
* Before render rank |
| 64 |
* |
| 65 |
* @since 1.0.0 |
| 66 |
* |
| 67 |
* @param integer $rank_id The Rank ID |
| 68 |
* @param array $template_args Template received arguments |
| 69 |
*/ |
| 70 |
do_action( 'gamipress_before_render_rank', get_the_ID(), $a ); ?> |
| 71 |
|
| 72 |
<?php // Rank Image |
| 73 |
if( $a['thumbnail'] === 'yes' ) : ?> |
| 74 |
<div class="gamipress-rank-image"> |
| 75 |
|
| 76 |
<?php // Link to the rank page |
| 77 |
if( $a['link'] === 'yes' ) : ?> |
| 78 |
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo gamipress_get_rank_post_thumbnail( get_the_ID(), $thumbnail_size ); ?></a> |
| 79 |
<?php else : ?> |
| 80 |
<?php echo gamipress_get_rank_post_thumbnail( get_the_ID(), $thumbnail_size ); ?> |
| 81 |
<?php endif; ?> |
| 82 |
|
| 83 |
<?php // Share |
| 84 |
echo gamipress_rank_share_markup( get_the_ID(), $a ); ?> |
| 85 |
|
| 86 |
</div><!-- .gamipress-rank-image --> |
| 87 |
|
| 88 |
<?php |
| 89 |
/** |
| 90 |
* After rank thumbnail |
| 91 |
* |
| 92 |
* @since 1.0.0 |
| 93 |
* |
| 94 |
* @param integer $rank_id The Rank ID |
| 95 |
* @param array $template_args Template received arguments |
| 96 |
*/ |
| 97 |
do_action( 'gamipress_after_rank_thumbnail', get_the_ID(), $a ); ?> |
| 98 |
|
| 99 |
<?php endif; ?> |
| 100 |
|
| 101 |
<?php // Rank Content ?> |
| 102 |
<div class="gamipress-rank-description"> |
| 103 |
|
| 104 |
<?php // Rank Title |
| 105 |
if( $a['title'] === 'yes' ) : ?> |
| 106 |
<<?php echo $a['title_size']; ?> class="gamipress-rank-title"> |
| 107 |
|
| 108 |
<?php // Link to the rank page |
| 109 |
if( $a['link'] === 'yes' ) : ?> |
| 110 |
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> |
| 111 |
<?php else : ?> |
| 112 |
<?php the_title(); ?> |
| 113 |
<?php endif; ?> |
| 114 |
|
| 115 |
</<?php echo $a['title_size']; ?>> |
| 116 |
|
| 117 |
<?php |
| 118 |
/** |
| 119 |
* After rank title |
| 120 |
* |
| 121 |
* @since 1.0.0 |
| 122 |
* |
| 123 |
* @param integer $rank_id The Rank ID |
| 124 |
* @param array $template_args Template received arguments |
| 125 |
*/ |
| 126 |
do_action( 'gamipress_after_rank_title', get_the_ID(), $a ); ?> |
| 127 |
<?php endif; ?> |
| 128 |
|
| 129 |
<?php // Rank Short Description |
| 130 |
if( $a['excerpt'] === 'yes' ) : ?> |
| 131 |
<div class="gamipress-rank-excerpt"> |
| 132 |
<?php |
| 133 |
$excerpt = has_excerpt() ? gamipress_get_post_field( 'post_excerpt', get_the_ID() ) : gamipress_get_post_field( 'post_content', get_the_ID() ); |
| 134 |
echo wpautop( do_blocks( apply_filters( 'get_the_excerpt', $excerpt, get_post() ) ) ); |
| 135 |
?> |
| 136 |
</div><!-- .gamipress-rank-excerpt --> |
| 137 |
|
| 138 |
<?php |
| 139 |
/** |
| 140 |
* After rank excerpt |
| 141 |
* |
| 142 |
* @since 1.0.0 |
| 143 |
* |
| 144 |
* @param integer $rank_id The Rank ID |
| 145 |
* @param array $template_args Template received arguments |
| 146 |
*/ |
| 147 |
do_action( 'gamipress_after_rank_excerpt', get_the_ID(), $a ); ?> |
| 148 |
|
| 149 |
<?php endif; ?> |
| 150 |
|
| 151 |
<?php // Rank Requirements |
| 152 |
if ( $a['requirements'] === 'yes' && $requirements = gamipress_get_rank_requirements( get_the_ID() ) ) : ?> |
| 153 |
<div class="gamipress-rank-requirements"> |
| 154 |
|
| 155 |
<?php if ( $a['toggle'] === 'yes' ) : ?> |
| 156 |
|
| 157 |
<div id="show-more-<?php the_ID(); ?>" class="gamipress-open-close-switch"> |
| 158 |
<a class="show-hide-open" data-rank-id="<?php the_ID(); ?>" data-action="open" data-open-text="<?php _e( 'Show Details', 'gamipress' ); ?>" data-close-text="<?php _e( 'Hide Details', 'gamipress' ); ?>" href="#"><?php _e( 'Show Details', 'gamipress' ); ?></a> |
| 159 |
</div> |
| 160 |
|
| 161 |
<div id="gamipress-toggle-more-window-<?php the_ID(); ?>" class="gamipress-extras-window"> |
| 162 |
<?php echo gamipress_get_rank_requirements_list_markup( $requirements, get_the_ID(), $user_id, $a ); ?> |
| 163 |
</div><!-- .gamipress-extras-window --> |
| 164 |
|
| 165 |
<?php else : ?> |
| 166 |
|
| 167 |
<?php echo gamipress_get_rank_requirements_list_markup( $requirements, get_the_ID(), $user_id, $a ); ?> |
| 168 |
|
| 169 |
<?php endif; ?> |
| 170 |
|
| 171 |
</div><!-- .gamipress-rank-attached --> |
| 172 |
|
| 173 |
<?php |
| 174 |
/** |
| 175 |
* After rank requirements |
| 176 |
* |
| 177 |
* @since 1.0.0 |
| 178 |
* |
| 179 |
* @param integer $rank_id The Rank ID |
| 180 |
* @param array $template_args Template received arguments |
| 181 |
*/ |
| 182 |
do_action( 'gamipress_after_rank_requirements', get_the_ID(), $a ); ?> |
| 183 |
|
| 184 |
<?php endif; ?> |
| 185 |
|
| 186 |
<?php // Rank unlock with points |
| 187 |
if ( $a['unlock_button'] === 'yes' ) : |
| 188 |
echo gamipress_rank_unlock_with_points_markup( get_the_ID(), $a ); |
| 189 |
endif; ?> |
| 190 |
|
| 191 |
<?php // If thumbnail is not displayed, place the share buttons at bottom |
| 192 |
if ( $a['thumbnail'] !== 'yes' ) : |
| 193 |
echo gamipress_rank_share_markup( get_the_ID(), $a ); |
| 194 |
endif; ?> |
| 195 |
|
| 196 |
<?php // Rank Earners |
| 197 |
if ( $a['earners'] === 'yes' ) : |
| 198 |
echo gamipress_get_rank_earners_list( get_the_ID(), array( 'limit' => $a['earners_limit'] ) ); |
| 199 |
|
| 200 |
/** |
| 201 |
* After rank earners |
| 202 |
* |
| 203 |
* @since 1.0.0 |
| 204 |
* |
| 205 |
* @param integer $rank_id The Rank ID |
| 206 |
* @param array $template_args Template received arguments |
| 207 |
*/ |
| 208 |
do_action( 'gamipress_after_rank_earners', get_the_ID(), $a ); ?> |
| 209 |
|
| 210 |
<?php endif; ?> |
| 211 |
|
| 212 |
<?php |
| 213 |
/** |
| 214 |
* Rank description bottom |
| 215 |
* |
| 216 |
* @since 1.4.0 |
| 217 |
* |
| 218 |
* @param integer $rank_id The Rank ID |
| 219 |
* @param array $template_args Template received arguments |
| 220 |
*/ |
| 221 |
do_action( 'gamipress_rank_description_bottom', get_the_ID(), $a ); ?> |
| 222 |
|
| 223 |
</div><!-- .gamipress-rank-description --> |
| 224 |
|
| 225 |
<?php |
| 226 |
/** |
| 227 |
* After render rank |
| 228 |
* |
| 229 |
* @since 1.0.0 |
| 230 |
* |
| 231 |
* @param integer $rank_id The Rank ID |
| 232 |
* @param array $template_args Template received arguments |
| 233 |
*/ |
| 234 |
do_action( 'gamipress_after_render_rank', get_the_ID(), $a ); ?> |
| 235 |
|
| 236 |
</div><!-- .gamipress-rank --> |