PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.2
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.2
8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 7.8.6 All 45 releases
gamipress / integrations / bbpress / includes / filters.php

filters.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 8.0.2, at integrations/bbpress/includes/filters.php

465 lines 17.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Content Filters
4 *
5 * @package GamiPress\bbPress\Content_Filters
6 * @since 1.0.4
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Reply author details
13 *
14 * @since 1.1.4
15 */
16 function gamipress_bbp_reply_author_details() {
17
18 $reply_id = bbp_get_reply_id();
19
20 // User is not a guest
21 if ( bbp_is_reply_anonymous( $reply_id ) )
22 return;
23
24 // Get the reply author ID
25 $user_id = bbp_get_reply_author_id( $reply_id );
26
27 gamipress_bbp_author_details( $user_id );
28
29 }
30 add_action( 'bbp_theme_after_reply_author_details', 'gamipress_bbp_reply_author_details' );
31
32 /**
33 * Topic author details
34 *
35 * @since 1.1.4
36 */
37 function gamipress_bbp_topic_author_details() {
38
39 $user_id = bbp_get_topic_author_id();
40
41 if( $user_id === 0 )
42 return;
43
44 gamipress_bbp_author_details( $user_id );
45
46 }
47 add_action( 'bbp_theme_after_topic_author_details', 'gamipress_bbp_topic_author_details' );
48
49 /**
50 * Author details
51 *
52 * @since 1.0.0
53 */
54 function gamipress_bbp_author_details( $user_id ) {
55
56 /* -------------------------------
57 * Points Types
58 ------------------------------- */
59
60 // Setup points types vars
61 $points_types = gamipress_get_points_types();
62 $points_types_slugs = gamipress_get_points_types_slugs();
63
64 // Get points type display settings
65 $points_types_to_show = gamipress_bbp_get_points_types( $user_id );
66 $points_types_thumbnail = (bool) gamipress_bbp_get_option( 'points_types_thumbnail', false );
67 $points_types_thumbnail_size = (int) gamipress_bbp_get_option( 'points_types_thumbnail_size', 25 );
68 $points_types_label = (bool) gamipress_bbp_get_option( 'points_types_label', false );
69
70 // Parse thumbnail size
71 if( $points_types_thumbnail_size > 0 ) {
72 $points_types_thumbnail_size = array( $points_types_thumbnail_size, $points_types_thumbnail_size );
73 } else {
74 $points_types_thumbnail_size = 'gamipress-points';
75 }
76
77 if( ! empty( $points_types_to_show ) ) : ?>
78
79 <div class="gamipress-bbpress-points">
80
81 <?php foreach( $points_types_to_show as $points_type_to_show ) :
82
83 // If points type not registered, skip
84 if( ! in_array( $points_type_to_show, $points_types_slugs ) )
85 continue;
86
87 $points_type = $points_types[$points_type_to_show];
88 $label_position = gamipress_get_points_type_label_position( $points_type_to_show );
89 $user_points = gamipress_get_user_points( $user_id, $points_type_to_show ); ?>
90
91 <div class="gamipress-bbpress-points-type gamipress-bbpress-<?php echo $points_type_to_show; ?>">
92
93 <?php // The points thumbnail ?>
94 <?php if( $points_types_thumbnail ) :
95 $points_thumbnail = gamipress_get_points_type_thumbnail( $points_type_to_show, $points_types_thumbnail_size ); ?>
96
97 <?php if( ! empty( $points_thumbnail ) ) : ?>
98 <span class="gamipress-bbpress-points-thumbnail gamipress-bbpress-<?php echo $points_type_to_show; ?>-thumbnail">
99 <?php echo $points_thumbnail; ?>
100 </span>
101 <?php endif; ?>
102
103 <?php endif; ?>
104
105 <?php // The points label (before) ?>
106 <?php if( $points_types_label && $label_position === 'before' ) : ?>
107
108 <span class="gamipress-bbpress-points-label gamipress-bbpress-<?php echo $points_type_to_show; ?>-label">
109 <?php echo _n( $points_type['singular_name'], $points_type['plural_name'], $user_points, 'gamipress-bbp' ); ?>
110 </span>
111
112 <?php endif; ?>
113
114 <?php // The user points amount ?>
115 <span class="gamipress-bbpress-user-points gamipress-bbpress-user-<?php echo $points_type_to_show; ?>">
116 <?php echo gamipress_format_amount( $user_points, $points_type_to_show ); ?>
117 </span>
118
119 <?php // The points label (after) ?>
120 <?php if( $points_types_label && $label_position !== 'before' ) : ?>
121
122 <span class="gamipress-bbpress-points-label gamipress-bbpress-<?php echo $points_type_to_show; ?>-label">
123 <?php echo _n( $points_type['singular_name'], $points_type['plural_name'], $user_points, 'gamipress-bbp' ); ?>
124 </span>
125
126 <?php endif; ?>
127
128 </div>
129
130 <?php endforeach; ?>
131
132 </div>
133
134 <?php endif;
135
136
137 /* -------------------------------
138 * Achievement Types
139 ------------------------------- */
140
141 // Setup achievement types vars
142 $achievement_types = gamipress_get_achievement_types();
143 $achievement_types_slugs = gamipress_get_achievement_types_slugs();
144
145 // Get achievement type display settings
146 $achievement_types_to_show = gamipress_bbp_get_achievement_types();
147 $achievement_types_thumbnail = (bool) gamipress_bbp_get_option( 'achievement_types_thumbnail', false );
148 $achievement_types_thumbnail_size = (int) gamipress_bbp_get_option( 'achievement_types_thumbnail_size', 25 );
149 $achievement_types_title = (bool) gamipress_bbp_get_option( 'achievement_types_title', false );
150 $achievement_types_link = (bool) gamipress_bbp_get_option( 'achievement_types_link', false );
151 $achievement_types_label = (bool) gamipress_bbp_get_option( 'achievement_types_label', false );
152 $achievements_limit = absint( gamipress_bbp_get_option( 'achievements_limit', '' ) );
153
154
155 // Parse thumbnail size
156 if( $achievement_types_thumbnail_size > 0 ) {
157 $achievement_types_thumbnail_size = array( $achievement_types_thumbnail_size, $achievement_types_thumbnail_size );
158 } else {
159 $achievement_types_thumbnail_size = 'gamipress-achievement';
160 }
161
162 if( ! empty( $achievement_types_to_show ) ) : ?>
163
164 <div class="gamipress-bbpress-achievements">
165
166 <?php foreach( $achievement_types_to_show as $achievement_type_to_show ) :
167
168 // If achievements type not registered, skip
169 if( ! in_array( $achievement_type_to_show, $achievement_types_slugs ) )
170 continue;
171
172 $achievement_type = $achievement_types[$achievement_type_to_show];
173 $user_achievements = gamipress_get_user_achievements( array(
174 'user_id' => $user_id,
175 'achievement_type' => $achievement_type_to_show,
176 'limit' => ( $achievements_limit > 0 ? $achievements_limit : -1 ),
177 'groupby' => 'achievement_id',
178 'display' => true,
179 ) );
180
181 // If user has not earned any achievements of this type, skip
182 if( empty( $user_achievements ) ) {
183 continue;
184 } ?>
185
186 <div class="gamipress-bbpress-achievement gamipress-bbpress-<?php echo $achievement_type_to_show; ?>">
187
188 <?php // The achievement type label
189 if( $achievement_types_label) : ?>
190 <span class="gamipress-bbpress-achievement-type-label gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-label">
191 <?php echo $achievement_type['plural_name']; ?>:
192 </span>
193 <?php endif; ?>
194
195 <?php // Lets to get just the achievement thumbnail and title
196 foreach( $user_achievements as $user_achievement ) : ?>
197
198 <?php // The achievement thumbnail ?>
199 <?php if( $achievement_types_thumbnail ) :
200 $achievement_thumbnail = gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $achievement_types_thumbnail_size ); ?>
201
202 <?php if( ! empty( $achievement_thumbnail ) ) : ?>
203
204 <?php // The achievement link ?>
205 <?php if( $achievement_types_link ) : ?>
206
207 <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">
208 <?php echo $achievement_thumbnail; ?>
209 </a>
210
211 <?php else : ?>
212
213 <span title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-bbpress-achievement-thumbnail gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-thumbnail">
214 <?php echo $achievement_thumbnail; ?>
215 </span>
216
217 <?php endif; ?>
218
219 <?php endif; ?>
220
221 <?php endif; ?>
222
223 <?php // The achievement title ?>
224 <?php if( $achievement_types_title ) :
225 $achievement_title = get_the_title( $user_achievement->ID ); ?>
226
227 <?php if( ! empty( $achievement_title ) ) : ?>
228
229 <?php // The achievement link ?>
230 <?php if( $achievement_types_link ) : ?>
231
232 <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">
233 <?php echo $achievement_title; ?>
234 </a>
235
236 <?php else : ?>
237
238 <span class="gamipress-bbpress-achievement-title gamipress-bbpress-<?php echo $achievement_type_to_show; ?>-title">
239 <?php echo $achievement_title; ?>
240 </span>
241
242 <?php endif; ?>
243
244 <?php endif; ?>
245
246 <?php endif; ?>
247
248 <?php endforeach; ?>
249
250 </div>
251
252 <?php endforeach; ?>
253
254 </div>
255
256 <?php endif;
257
258 /* -------------------------------
259 * Rank Types
260 ------------------------------- */
261
262 // Setup rank types vars
263 $rank_types = gamipress_get_rank_types();
264 $rank_types_slugs = gamipress_get_rank_types_slugs();
265
266 // Get rank type display settings
267 $rank_types_to_show = gamipress_bbp_get_rank_types( $user_id );
268 $rank_types_thumbnail = (bool) gamipress_bbp_get_option( 'rank_types_thumbnail', false );
269 $rank_types_thumbnail_size = (int) gamipress_bbp_get_option( 'rank_types_thumbnail_size', 25 );
270 $rank_types_title = (bool) gamipress_bbp_get_option( 'rank_types_title', false );
271 $rank_types_link = (bool) gamipress_bbp_get_option( 'rank_types_link', false );
272 $rank_types_label = (bool) gamipress_bbp_get_option( 'rank_types_label', false );
273
274 // Parse thumbnail size
275 if( $rank_types_thumbnail_size > 0 ) {
276 $rank_types_thumbnail_size = array( $rank_types_thumbnail_size, $rank_types_thumbnail_size );
277 } else {
278 $rank_types_thumbnail_size = 'gamipress-rank';
279 }
280
281 if( ! empty( $rank_types_to_show ) ) : ?>
282
283 <div class="gamipress-bbpress-ranks">
284
285 <?php foreach( $rank_types_to_show as $rank_type_to_show ) :
286
287 // If points type not registered, skip
288 if( ! in_array( $rank_type_to_show, $rank_types_slugs ) )
289 continue;
290
291 $rank_type = $rank_types[$rank_type_to_show];
292 $user_rank = gamipress_get_user_rank( $user_id, $rank_type_to_show ); ?>
293
294 <div class="gamipress-bbpress-rank gamipress-bbpress-<?php echo $rank_type_to_show; ?>">
295
296 <?php // The rank type label
297 if( $rank_types_label ) : ?>
298 <span class="gamipress-bbpress-rank-label gamipress-bbpress-<?php echo $rank_type_to_show; ?>-label">
299 <?php echo $rank_type['singular_name']; ?>:
300 </span>
301 <?php endif; ?>
302
303 <?php // The rank thumbnail ?>
304 <?php if( $rank_types_thumbnail ) :
305 $rank_thumbnail = gamipress_get_rank_post_thumbnail( $user_rank->ID, $rank_types_thumbnail_size ); ?>
306
307 <?php if( ! empty( $rank_thumbnail ) ) : ?>
308 <?php // The rank link ?>
309 <?php if( $rank_types_link ) : ?>
310
311 <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">
312 <?php echo $rank_thumbnail; ?>
313 </a>
314
315 <?php else : ?>
316
317 <span title="<?php echo $user_rank->post_title; ?>" class="gamipress-bbpress-rank-thumbnail gamipress-bbpress-<?php echo $rank_type_to_show; ?>-thumbnail">
318 <?php echo $rank_thumbnail; ?>
319 </span>
320
321 <?php endif; ?>
322 <?php endif; ?>
323
324 <?php endif; ?>
325
326 <?php // The rank title ?>
327 <?php if( $rank_types_title && ! empty( $user_rank->post_title ) ) : ?>
328
329 <?php // The rank link ?>
330 <?php if( $rank_types_link ) : ?>
331
332 <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">
333 <?php echo $user_rank->post_title; ?>
334 </a>
335
336 <?php else : ?>
337
338 <span class="gamipress-bbpress-rank-title gamipress-bbpress-<?php echo $rank_type_to_show; ?>-title">
339 <?php echo $user_rank->post_title; ?>
340 </span>
341
342 <?php endif; ?>
343
344 <?php endif; ?>
345
346 </div>
347
348 <?php endforeach; ?>
349 </div>
350 <?php endif;
351
352 }
353
354 /**
355 * Helper function to retrieve the points types configured at author details screen
356 *
357 * @param int $user_id
358 *
359 * @since 1.0.4
360 *
361 * @return array
362 */
363 function gamipress_bbp_get_points_types( $user_id ) {
364
365 $points_types = array();
366
367 $points_types_slugs = gamipress_get_points_types_slugs();
368
369 $points_types_to_show = gamipress_bbp_get_option( 'points_types', array() );
370
371 $points_types_hide = (bool) gamipress_bbp_get_option( 'points_types_hide', false );
372
373 foreach( $points_types_to_show as $points_type_slug ) {
374
375 if( ! in_array( $points_type_slug, $points_types_slugs ) ) {
376 continue;
377 }
378
379 $user_points = gamipress_get_user_points( $user_id, $points_type_slug );
380
381 // To check if hide option is enabled
382 if ( ! $points_types_hide ) {
383 $points_types[] = $points_type_slug;
384 } else if ( $user_points > 0 ) {
385 $points_types[] = $points_type_slug;
386 }
387
388 }
389
390 return $points_types;
391
392 }
393
394 /**
395 * Helper function to retrieve the achievement types configured at author details screen
396 *
397 * @since 1.0.4
398 *
399 * @return array
400 */
401 function gamipress_bbp_get_achievement_types() {
402
403 $achievements_types = array();
404
405 $achievement_types_slugs = gamipress_get_achievement_types_slugs();
406
407 $achievements_types_to_show = gamipress_bbp_get_option( 'achievement_types', array() );
408
409 foreach( $achievements_types_to_show as $achievement_type_slug ) {
410
411 // Skip if not registered
412 if( ! in_array( $achievement_type_slug, $achievement_types_slugs ) ) {
413 continue;
414 }
415
416 $achievements_types[] = $achievement_type_slug;
417 }
418
419 return $achievements_types;
420
421 }
422
423 /**
424 * Helper function to retrieve the rank types configured at author details screen
425 *
426 * @param int $user_id
427 *
428 * @since 1.0.4
429 *
430 * @return array
431 */
432 function gamipress_bbp_get_rank_types( $user_id ) {
433
434 $ranks_types = array();
435
436 $rank_types_slugs = gamipress_get_rank_types_slugs();
437
438 $ranks_types_to_show = gamipress_bbp_get_option( 'rank_types', array() );
439
440 // Check rank type hide option
441 $rank_types_hide = (bool) gamipress_bbp_get_option( 'rank_types_hide', false );
442
443
444 foreach( $ranks_types_to_show as $rank_type_slug ) {
445
446 // Skip if not registered
447 if( ! in_array( $rank_type_slug, $rank_types_slugs ) ) {
448 continue;
449 }
450
451 $user_rank = gamipress_get_user_rank( $user_id, $rank_type_slug );
452 $user_rank_is_lowest = gamipress_is_lowest_priority_rank( $user_rank->ID );
453
454 // To check if hide option is enabled
455 if ( ! $rank_types_hide ) {
456 $ranks_types[] = $rank_type_slug;
457 } else if ( ! $user_rank_is_lowest ) {
458 $ranks_types[] = $rank_type_slug;
459 }
460
461 }
462
463 return $ranks_types;
464
465 }