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.4 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 All 46 releases
gamipress / integrations / wpdiscuz / includes / filters.php

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

398 lines 15.3 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\wpDiscuz\Content_Filters
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Comment author details
13 *
14 * @since 1.0.0
15 *
16 * @param string $html
17 * @param WP_Comment $comment
18 *
19 * @return string
20 */
21 function gamipress_wpdiscuz_reply_author_details( $html, $comment ) {
22
23 // Get the comment author ID
24 $user_id = gamipress_wpdiscuz_get_commment_user_id( $comment );
25
26 if( $user_id === 0 ) return $html;
27
28 ob_start();
29 gamipress_wpdiscuz_author_details( $user_id );
30 $html .= ob_get_clean();
31
32 return $html;
33
34 }
35 add_filter( 'wpdiscuz_after_label', 'gamipress_wpdiscuz_reply_author_details', 10, 2 );
36
37 /**
38 * Author details
39 *
40 * @since 1.0.0
41 */
42 function gamipress_wpdiscuz_author_details( $user_id ) {
43
44 /* -------------------------------
45 * Points Types
46 ------------------------------- */
47
48 // Setup points types vars
49 $points_types = gamipress_get_points_types();
50 $points_types_slugs = gamipress_get_points_types_slugs();
51
52 // Get points type display settings
53 $points_types_to_show = gamipress_wpdiscuz_get_points_types();
54 $points_types_thumbnail = (bool) gamipress_wpdiscuz_get_option( 'points_types_thumbnail', false );
55 $points_types_thumbnail_size = (int) gamipress_wpdiscuz_get_option( 'points_types_thumbnail_size', 25 );
56 $points_types_label = (bool) gamipress_wpdiscuz_get_option( 'points_types_label', false );
57
58 // Parse thumbnail size
59 if( $points_types_thumbnail_size > 0 ) {
60 $points_types_thumbnail_size = array( $points_types_thumbnail_size, $points_types_thumbnail_size );
61 } else {
62 $points_types_thumbnail_size = 'gamipress-points';
63 }
64
65 if( ! empty( $points_types_to_show ) ) : ?>
66
67 <div class="gamipress-wpdiscuz-points">
68
69 <?php foreach( $points_types_to_show as $points_type_to_show ) :
70
71 // If points type not registered, skip
72 if( ! in_array( $points_type_to_show, $points_types_slugs ) )
73 continue;
74
75 $points_type = $points_types[$points_type_to_show];
76 $user_points = gamipress_get_user_points( $user_id, $points_type_to_show ); ?>
77
78 <div class="gamipress-wpdiscuz-points-type gamipress-wpdiscuz-<?php echo $points_type_to_show; ?>">
79
80 <?php // The points thumbnail ?>
81 <?php if( $points_types_thumbnail ) : ?>
82
83 <span class="gamipress-wpdiscuz-points-thumbnail gamipress-wpdiscuz-<?php echo $points_type_to_show; ?>-thumbnail">
84 <?php echo gamipress_get_points_type_thumbnail( $points_type_to_show, $points_types_thumbnail_size ); ?>
85 </span>
86
87 <?php endif; ?>
88
89 <?php // The user points amount ?>
90 <span class="gamipress-wpdiscuz-user-points gamipress-wpdiscuz-user-<?php echo $points_type_to_show; ?>">
91 <?php echo $user_points; ?>
92 </span>
93
94 <?php // The points label ?>
95 <?php if( $points_types_label ) : ?>
96
97 <span class="gamipress-wpdiscuz-points-label gamipress-wpdiscuz-<?php echo $points_type_to_show; ?>-label">
98 <?php echo _n( $points_type['singular_name'], $points_type['plural_name'], $user_points, 'gamipress' ); ?>
99 </span>
100
101 <?php endif; ?>
102
103 </div>
104
105 <?php endforeach; ?>
106
107 </div>
108
109 <?php endif;
110
111
112 /* -------------------------------
113 * Achievement Types
114 ------------------------------- */
115
116 // Setup achievement types vars
117 $achievement_types = gamipress_get_achievement_types();
118 $achievement_types_slugs = gamipress_get_achievement_types_slugs();
119
120 // Get achievement type display settings
121 $achievement_types_to_show = gamipress_wpdiscuz_get_achievement_types();
122 $achievement_types_thumbnail = (bool) gamipress_wpdiscuz_get_option( 'achievement_types_thumbnail', false );
123 $achievement_types_thumbnail_size = (int) gamipress_wpdiscuz_get_option( 'achievement_types_thumbnail_size', 25 );
124 $achievement_types_title = (bool) gamipress_wpdiscuz_get_option( 'achievement_types_title', false );
125 $achievement_types_link = (bool) gamipress_wpdiscuz_get_option( 'achievement_types_link', false );
126 $achievement_types_label = (bool) gamipress_wpdiscuz_get_option( 'achievement_types_label', false );
127 $achievements_limit = absint( gamipress_wpdiscuz_get_option( 'achievements_limit', '' ) );
128
129
130 // Parse thumbnail size
131 if( $achievement_types_thumbnail_size > 0 ) {
132 $achievement_types_thumbnail_size = array( $achievement_types_thumbnail_size, $achievement_types_thumbnail_size );
133 } else {
134 $achievement_types_thumbnail_size = 'gamipress-achievement';
135 }
136
137 if( ! empty( $achievement_types_to_show ) ) : ?>
138
139 <div class="gamipress-wpdiscuz-achievements">
140
141 <?php foreach( $achievement_types_to_show as $achievement_type_to_show ) :
142
143 // If achievements type not registered, skip
144 if( ! in_array( $achievement_type_to_show, $achievement_types_slugs ) )
145 continue;
146
147 $achievement_type = $achievement_types[$achievement_type_to_show];
148 $user_achievements = gamipress_get_user_achievements( array(
149 'user_id' => $user_id,
150 'achievement_type' => $achievement_type_to_show,
151 'limit' => ( $achievements_limit > 0 ? $achievements_limit : -1 ),
152 'groupby' => 'achievement_id',
153 'display' => true,
154 ) );
155
156 // If user has not earned any achievements of this type, skip
157 if( empty( $user_achievements ) ) {
158 continue;
159 } ?>
160
161 <div class="gamipress-wpdiscuz-achievement gamipress-wpdiscuz-<?php echo $achievement_type_to_show; ?>">
162
163 <?php // The achievement type label
164 if( $achievement_types_label ) : ?>
165 <span class="gamipress-wpdiscuz-achievement-type-label gamipress-wpdiscuz-<?php echo $achievement_type_to_show; ?>-label">
166 <?php echo $achievement_type['plural_name']; ?>:
167 </span>
168 <?php endif; ?>
169
170 <?php // Lets to get just the achievement thumbnail and title
171 foreach( $user_achievements as $user_achievement ) : ?>
172
173 <?php // The achievement thumbnail ?>
174 <?php if( $achievement_types_thumbnail ) : ?>
175
176 <?php // The achievement link ?>
177 <?php if( $achievement_types_link ) : ?>
178
179 <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-wpdiscuz-achievement-thumbnail gamipress-wpdiscuz-<?php echo $achievement_type_to_show; ?>-thumbnail">
180 <?php echo gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $achievement_types_thumbnail_size ); ?>
181 </a>
182
183 <?php else : ?>
184
185 <span title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-wpdiscuz-achievement-thumbnail gamipress-wpdiscuz-<?php echo $achievement_type_to_show; ?>-thumbnail">
186 <?php echo gamipress_get_achievement_post_thumbnail( $user_achievement->ID, $achievement_types_thumbnail_size ); ?>
187 </span>
188
189 <?php endif; ?>
190
191 <?php endif; ?>
192
193 <?php // The achievement title ?>
194 <?php if( $achievement_types_title ) : ?>
195
196 <?php // The achievement link ?>
197 <?php if( $achievement_types_link ) : ?>
198
199 <a href="<?php echo get_permalink( $user_achievement->ID ); ?>" title="<?php echo get_the_title( $user_achievement->ID ); ?>" class="gamipress-wpdiscuz-achievement-title gamipress-wpdiscuz-<?php echo $achievement_type_to_show; ?>-title">
200 <?php echo get_the_title( $user_achievement->ID ); ?>
201 </a>
202
203 <?php else : ?>
204
205 <span class="gamipress-wpdiscuz-achievement-title gamipress-wpdiscuz-<?php echo $achievement_type_to_show; ?>-title">
206 <?php echo get_the_title( $user_achievement->ID ); ?>
207 </span>
208
209 <?php endif; ?>
210
211 <?php endif; ?>
212
213 <?php endforeach; ?>
214
215 </div>
216
217 <?php endforeach; ?>
218
219 </div>
220
221 <?php endif;
222
223 /* -------------------------------
224 * Rank Types
225 ------------------------------- */
226
227 // Setup rank types vars
228 $rank_types = gamipress_get_rank_types();
229 $rank_types_slugs = gamipress_get_rank_types_slugs();
230
231 // Get rank type display settings
232 $rank_types_to_show = gamipress_wpdiscuz_get_rank_types();
233 $rank_types_thumbnail = (bool) gamipress_wpdiscuz_get_option( 'rank_types_thumbnail', false );
234 $rank_types_thumbnail_size = (int) gamipress_wpdiscuz_get_option( 'rank_types_thumbnail_size', 25 );
235 $rank_types_title = (bool) gamipress_wpdiscuz_get_option( 'rank_types_title', false );
236 $rank_types_link = (bool) gamipress_wpdiscuz_get_option( 'rank_types_link', false );
237 $rank_types_label = (bool) gamipress_wpdiscuz_get_option( 'rank_types_label', false );
238
239 // Parse thumbnail size
240 if( $rank_types_thumbnail_size > 0 ) {
241 $rank_types_thumbnail_size = array( $rank_types_thumbnail_size, $rank_types_thumbnail_size );
242 } else {
243 $rank_types_thumbnail_size = 'gamipress-rank';
244 }
245
246 if( ! empty( $rank_types_to_show ) ) : ?>
247
248 <div class="gamipress-wpdiscuz-ranks">
249
250 <?php foreach( $rank_types_to_show as $rank_type_to_show ) :
251
252 // If points type not registered, skip
253 if( ! in_array( $rank_type_to_show, $rank_types_slugs ) )
254 continue;
255
256 $rank_type = $rank_types[$rank_type_to_show];
257 $user_rank = gamipress_get_user_rank( $user_id, $rank_type_to_show ); ?>
258
259 <div class="gamipress-wpdiscuz-rank gamipress-wpdiscuz-<?php echo $rank_type_to_show; ?>">
260
261 <?php // The rank type label
262 if( $rank_types_label ) : ?>
263 <span class="gamipress-wpdiscuz-rank-label gamipress-wpdiscuz-<?php echo $rank_type_to_show; ?>-label">
264 <?php echo $rank_type['singular_name']; ?>:
265 </span>
266 <?php endif; ?>
267
268 <?php // The rank thumbnail ?>
269 <?php if( $rank_types_thumbnail ) : ?>
270
271 <?php // The rank link ?>
272 <?php if( $rank_types_link ) : ?>
273
274 <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="gamipress-wpdiscuz-rank-thumbnail gamipress-wpdiscuz-<?php echo $rank_type_to_show; ?>-thumbnail">
275 <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $rank_types_thumbnail_size ); ?>
276 </a>
277
278 <?php else : ?>
279
280 <span title="<?php echo $user_rank->post_title; ?>" class="gamipress-wpdiscuz-rank-thumbnail gamipress-wpdiscuz-<?php echo $rank_type_to_show; ?>-thumbnail">
281 <?php echo gamipress_get_rank_post_thumbnail( $user_rank->ID, $rank_types_thumbnail_size ); ?>
282 </span>
283
284 <?php endif; ?>
285
286 <?php endif; ?>
287
288 <?php // The rank title ?>
289 <?php if( $rank_types_title ) : ?>
290
291 <?php // The rank link ?>
292 <?php if( $rank_types_link ) : ?>
293
294 <a href="<?php echo get_permalink( $user_rank->ID ); ?>" title="<?php echo $user_rank->post_title; ?>" class="gamipress-wpdiscuz-rank-title gamipress-wpdiscuz-<?php echo $rank_type_to_show; ?>-title">
295 <?php echo $user_rank->post_title; ?>
296 </a>
297
298 <?php else : ?>
299
300 <span class="gamipress-wpdiscuz-rank-title gamipress-wpdiscuz-<?php echo $rank_type_to_show; ?>-title">
301 <?php echo $user_rank->post_title; ?>
302 </span>
303
304 <?php endif; ?>
305
306 <?php endif; ?>
307
308 </div>
309
310 <?php endforeach; ?>
311 </div>
312 <?php endif;
313
314 }
315
316 /**
317 * Helper function to retrieve the points types configured at author details screen
318 *
319 * @since 1.0.0
320 *
321 * @return array
322 */
323 function gamipress_wpdiscuz_get_points_types() {
324
325 $points_types = array();
326
327 $points_types_slugs = gamipress_get_points_types_slugs();
328
329 $points_types_to_show = gamipress_wpdiscuz_get_option( 'points_types', array() );
330
331 foreach( $points_types_to_show as $points_type_slug ) {
332
333 // Skip if not registered
334 if( ! in_array( $points_type_slug, $points_types_slugs ) )
335 continue;
336
337 $points_types[] = $points_type_slug;
338 }
339
340 return $points_types;
341
342 }
343
344 /**
345 * Helper function to retrieve the achievement types configured at author details screen
346 *
347 * @since 1.0.0
348 *
349 * @return array
350 */
351 function gamipress_wpdiscuz_get_achievement_types() {
352
353 $achievements_types = array();
354
355 $achievement_types_slugs = gamipress_get_achievement_types_slugs();
356
357 $achievements_types_to_show = gamipress_wpdiscuz_get_option( 'achievement_types', array() );
358
359 foreach( $achievements_types_to_show as $achievement_type_slug ) {
360
361 // Skip if not registered
362 if( ! in_array( $achievement_type_slug, $achievement_types_slugs ) )
363 continue;
364
365 $achievements_types[] = $achievement_type_slug;
366 }
367
368 return $achievements_types;
369
370 }
371
372 /**
373 * Helper function to retrieve the rank types configured at author details screen
374 *
375 * @since 1.0.0
376 *
377 * @return array
378 */
379 function gamipress_wpdiscuz_get_rank_types() {
380
381 $ranks_types = array();
382
383 $rank_types_slugs = gamipress_get_rank_types_slugs();
384
385 $ranks_types_to_show = gamipress_wpdiscuz_get_option( 'rank_types', array() );
386
387 foreach( $ranks_types_to_show as $rank_type_slug ) {
388
389 // Skip if not registered
390 if( ! in_array( $rank_type_slug, $rank_types_slugs ) )
391 continue;
392
393 $ranks_types[] = $rank_type_slug;
394 }
395
396 return $ranks_types;
397
398 }