PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.1
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.1
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 7.8.5 All 44 releases
gamipress / includes / tags.php

tags.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 8.0.1, at includes/tags.php

676 lines 27.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Tags
4 *
5 * @package GamiPress\Tags
6 * @author GamiPress <contact@gamipress.com>, Ruben Garcia <rubengcdev@gmail.com>
7 * @since 1.8.6
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Get an array of email pattern tags
14 *
15 * @since 1.3.0
16 *
17 * @return array The registered email pattern tags
18 */
19 function gamipress_get_pattern_tags() {
20
21 $pattern_tags = array();
22
23 // Site tags
24 $pattern_tags[] = '<strong>' . __( 'Site Tags', 'gamipress' ) . '</strong>';
25
26 $pattern_tags = array_merge( $pattern_tags, apply_filters( 'gamipress_site_pattern_tags', array(
27 '{site_title}' => __( 'Site name.', 'gamipress' ),
28 '{site_link}' => __( 'Link to the site with site name as text.', 'gamipress' ),
29 ) ) );
30
31 // User Tags
32 $pattern_tags[] = '<strong>' . __( 'User Tags', 'gamipress' ) . '</strong>';
33
34 $pattern_tags = array_merge( $pattern_tags, apply_filters( 'gamipress_user_pattern_tags', array(
35 '{user_id}' => __( 'User ID (useful for shortcodes that user ID can be passed as attribute).', 'gamipress' ),
36 '{user}' => __( 'User display name.', 'gamipress' ),
37 '{user_first}' => __( 'User first name.', 'gamipress' ),
38 '{user_last}' => __( 'User last name.', 'gamipress' ),
39 '{user_email}' => __( 'User email.', 'gamipress' ),
40 '{user_username}' => __( 'User username.', 'gamipress' ),
41 ) ) );
42
43 return apply_filters( 'gamipress_pattern_tags', $pattern_tags );
44
45 }
46
47 /**
48 * Get an array of email pattern tags used on achievement earned email
49 *
50 * @since 1.3.0
51 *
52 * @return array The registered achievement earned email pattern tags
53 */
54 function gamipress_get_achievement_earned_pattern_tags() {
55
56 $pattern_tags = gamipress_get_pattern_tags();
57
58 $pattern_tags[] = '<strong>' . __( 'Achievement Tags', 'gamipress' ) . '</strong>';
59
60 return apply_filters( 'gamipress_achievement_earned_pattern_tags', array_merge( $pattern_tags, array(
61 '{achievement_id}' => __( 'Achievement ID (useful for shortcodes that achievement ID can be passed as attribute).', 'gamipress' ),
62 '{achievement_title}' => __( 'Achievement title.', 'gamipress' ),
63 '{achievement_url}' => __( 'URL to the achievement.', 'gamipress' ),
64 '{achievement_link}' => __( 'Link to the achievement with the achievement title as text.', 'gamipress' ),
65 '{achievement_excerpt}' => __( 'Achievement excerpt.', 'gamipress' ),
66 '{achievement_image}' => __( 'Achievement featured image.', 'gamipress' ),
67 '{achievement_steps}' => __( 'Achievement steps.', 'gamipress' ),
68 '{achievement_congratulations}' => __( 'Achievement congratulations text.', 'gamipress' ),
69 '{achievement_type}' => __( 'Type of the achievement.', 'gamipress' ),
70 '{achievement_points}' => __( 'The amount of points earned.', 'gamipress' ),
71 '{achievement_points_type}' => __( 'The points award points type. Singular or plural is based on the amount of points earned.', 'gamipress' ),
72 ) ) );
73
74 }
75
76 /**
77 * Get an array of email pattern tags used on step completed email
78 *
79 * @since 1.3.0
80 *
81 * @return array The registered step completed email pattern tags
82 */
83 function gamipress_get_step_completed_pattern_tags() {
84
85 $pattern_tags = gamipress_get_pattern_tags();
86
87 $pattern_tags[] = '<strong>' . __( 'Step Tags', 'gamipress' ) . '</strong>';
88
89 return apply_filters( 'gamipress_step_completed_pattern_tags', array_merge( $pattern_tags, array(
90 '{label}' => __( 'Step label.', 'gamipress' ),
91 '{achievement_id}' => __( 'Step achievement ID (useful for shortcodes that achievement ID can be passed as attribute).', 'gamipress' ),
92 '{achievement_title}' => __( 'Step achievement title.', 'gamipress' ),
93 '{achievement_url}' => __( 'URL to the step achievement.', 'gamipress' ),
94 '{achievement_link}' => __( 'Link to the step achievement with the achievement title as text.', 'gamipress' ),
95 '{achievement_excerpt}' => __( 'Step achievement excerpt.', 'gamipress' ),
96 '{achievement_image}' => __( 'Step achievement featured image.', 'gamipress' ),
97 '{achievement_steps}' => __( 'Step achievement steps.', 'gamipress' ),
98 '{achievement_congratulations}' => __( 'Step achievement congratulations text.', 'gamipress' ),
99 '{achievement_type}' => __( 'Type of the step achievement.', 'gamipress' ),
100 ) ) );
101
102 }
103
104 /**
105 * Get an array of email pattern tags used on points award completed email
106 *
107 * @since 1.3.0
108 *
109 * @return array The registered points award completed email pattern tags
110 */
111 function gamipress_get_points_award_completed_pattern_tags() {
112
113 $pattern_tags = gamipress_get_pattern_tags();
114
115 $pattern_tags[] = '<strong>' . __( 'Points Award Tags', 'gamipress' ) . '</strong>';
116
117 return apply_filters( 'gamipress_points_award_completed_pattern_tags', array_merge( $pattern_tags, array(
118 '{label}' => __( 'Points award label.', 'gamipress' ),
119 '{points}' => __( 'The amount of points earned.', 'gamipress' ),
120 '{points_balance}' => __( 'The full amount of points user has earned until this date.', 'gamipress' ),
121 '{points_type}' => __( 'The points award points type. Singular or plural is based on the amount of points earned.', 'gamipress' ),
122 '{points_image}' => __( 'The points type featured image.', 'gamipress' ),
123 ) ) );
124
125 }
126
127 /**
128 * Get an array of email pattern tags used on points deduct completed email
129 *
130 * @since 1.3.7
131 *
132 * @return array The registered points deduct completed email pattern tags
133 */
134 function gamipress_get_points_deduct_completed_pattern_tags() {
135
136 $pattern_tags = gamipress_get_pattern_tags();
137
138 $pattern_tags[] = '<strong>' . __( 'Points Deduction Tags', 'gamipress' ) . '</strong>';
139
140 return apply_filters( 'gamipress_points_deduct_completed_pattern_tags', array_merge( $pattern_tags, array(
141 '{label}' => __( 'Points deduction label.', 'gamipress' ),
142 '{points}' => __( 'The amount of points deducted.', 'gamipress' ),
143 '{points_balance}' => __( 'The full amount of points user has earned until this date.', 'gamipress' ),
144 '{points_type}' => __( 'The points deduction points type. Singular or plural is based on the amount of points deducted.', 'gamipress' ),
145 '{points_image}' => __( 'The points type featured image.', 'gamipress' ),
146 ) ) );
147
148 }
149
150 /**
151 * Get an array of email pattern tags used on rank earned email
152 *
153 * @since 1.3.1
154 *
155 * @return array The registered rank earned email pattern tags
156 */
157 function gamipress_get_rank_earned_pattern_tags() {
158
159 $pattern_tags = gamipress_get_pattern_tags();
160
161 $pattern_tags[] = '<strong>' . __( 'Rank Tags', 'gamipress' ) . '</strong>';
162
163 return apply_filters( 'gamipress_rank_earned_pattern_tags', array_merge( $pattern_tags, array(
164 '{rank_id}' => __( 'Rank ID (useful for shortcodes that rank ID can be passed as attribute).', 'gamipress' ),
165 '{rank_title}' => __( 'Rank title.', 'gamipress' ),
166 '{rank_url}' => __( 'URL to the rank.', 'gamipress' ),
167 '{rank_link}' => __( 'Link to the rank with the rank title as text.', 'gamipress' ),
168 '{rank_excerpt}' => __( 'Rank excerpt.', 'gamipress' ),
169 '{rank_image}' => __( 'Rank featured image.', 'gamipress' ),
170 '{rank_requirements}' => __( 'Rank requirements.', 'gamipress' ),
171 '{rank_congratulations}' => __( 'Rank congratulations text.', 'gamipress' ),
172 '{rank_type}' => __( 'Type of the rank.', 'gamipress' ),
173 ) ) );
174
175 }
176
177 /**
178 * Get an array of email pattern tags used on rank requirement completed email
179 *
180 * @since 1.3.1
181 *
182 * @return array The registered rank requirement completed email pattern tags
183 */
184 function gamipress_get_rank_requirement_completed_pattern_tags() {
185
186 $pattern_tags = gamipress_get_pattern_tags();
187
188 $pattern_tags[] = '<strong>' . __( 'Rank Requirement Tags', 'gamipress' ) . '</strong>';
189
190 return apply_filters( 'gamipress_rank_requirement_completed_pattern_tags', array_merge( $pattern_tags, array(
191 '{label}' => __( 'Requirement label.', 'gamipress' ),
192 '{rank_id}' => __( 'Requirement rank ID (useful for shortcodes that rank ID can be passed as attribute).', 'gamipress' ),
193 '{rank_title}' => __( 'Requirement rank title.', 'gamipress' ),
194 '{rank_url}' => __( 'URL to the requirement rank.', 'gamipress' ),
195 '{rank_link}' => __( 'Link to the requirement rank with the rank title as text.', 'gamipress' ),
196 '{rank_excerpt}' => __( 'Requirement rank excerpt.', 'gamipress' ),
197 '{rank_image}' => __( 'Requirement rank featured image.', 'gamipress' ),
198 '{rank_requirements}' => __( 'Requirement rank requirements.', 'gamipress' ),
199 '{rank_congratulations}' => __( 'Requirement rank congratulations text.', 'gamipress' ),
200 '{rank_type}' => __( 'Type of the rank.', 'gamipress' ),
201 ) ) );
202
203 }
204
205 /**
206 * Get a string with the desired email pattern tags html markup
207 *
208 * @since 1.3.0
209 *
210 * @param string $pattern
211 *
212 * @return string Log pattern tags html markup
213 */
214 function gamipress_get_pattern_tags_html( $pattern = '' ) {
215
216 if( $pattern === 'achievement_earned' ) {
217 $pattern_tags = gamipress_get_achievement_earned_pattern_tags();
218 } else if( $pattern === 'step_completed' ) {
219 $pattern_tags = gamipress_get_step_completed_pattern_tags();
220 } else if( $pattern === 'points_award_completed' ) {
221 $pattern_tags = gamipress_get_points_award_completed_pattern_tags();
222 } else if( $pattern === 'points_deduct_completed' ) {
223 $pattern_tags = gamipress_get_points_deduct_completed_pattern_tags();
224 } else if( $pattern === 'rank_earned' ) {
225 $pattern_tags = gamipress_get_rank_earned_pattern_tags();
226 } else if( $pattern === 'rank_requirement_completed' ) {
227 $pattern_tags = gamipress_get_rank_requirement_completed_pattern_tags();
228 } else {
229 $pattern_tags = gamipress_get_pattern_tags();
230 }
231
232 $output = ' <a href="" class="gamipress-pattern-tags-list-toggle" data-show-text="' . __( 'Show tags', 'gamipress' ) . '" data-hide-text="' . __( 'Show tags', 'gamipress' ) . '">' . __( 'Show tags', 'gamipress' ) . '</a>';
233 $output .= '<ul class="gamipress-pattern-tags-list" style="display: none;">';
234
235 foreach( $pattern_tags as $tag => $description ) {
236
237 if( is_numeric( $tag ) ) {
238 $output .= "<li id='{$tag}'>{$description}</li>";
239 } else {
240 $attr_id = 'tag-' . str_replace( array( '{', '}', '_' ), array( '', '', '-' ), $tag );
241
242 $output .= "<li id='{$attr_id}'><code>{$tag}</code> - {$description}</li>";
243 }
244 }
245
246 $output .= '</ul>';
247
248 return $output;
249
250 }
251
252 /**
253 * Site tags replacements
254 *
255 * @since 1.8.6
256 *
257 * @return array
258 */
259 function gamipress_get_site_tags_replacements() {
260
261 $replacements = array();
262
263 // Setup site replacements
264 $replacements['{site_title}'] = get_bloginfo( 'name' );
265 $replacements['{site_link}'] = '<a href="' . esc_url( home_url() ) . '">' . get_bloginfo( 'name' ) . '</a>';
266
267 return $replacements;
268
269 }
270
271 /**
272 * User tags replacements
273 *
274 * @since 1.8.6
275 *
276 * @param int $user_id The user to get tags values from
277 *
278 * @return array
279 */
280 function gamipress_get_user_tags_replacements( $user_id ) {
281
282 $replacements = array();
283
284 // Setup user replacements
285 $user_id = absint( $user_id );
286 $user = ( $user_id !== 0 ? get_userdata( $user_id ) : false );
287
288 $replacements['{user_id}'] = ( $user ? $user->ID : '' );
289 $replacements['{user}'] = ( $user ? $user->display_name : '' );
290 $replacements['{user_first}'] = ( $user ? $user->first_name : '' );
291 $replacements['{user_last}'] = ( $user ? $user->last_name : '' );
292 $replacements['{user_email}'] = ( $user ? $user->user_email : '' );
293 $replacements['{user_username}'] = ( $user ? $user->user_login : '' );
294
295 return $replacements;
296
297 }
298
299 /**
300 * Achievement earned tags replacements
301 *
302 * @since 1.8.6
303 *
304 * @param int $achievement_id The achievement to get tags values from
305 * @param int $user_id The user to get tags values from
306 *
307 * @return array
308 */
309 function gamipress_get_achievement_earned_tags_replacements( $achievement_id, $user_id ) {
310
311 $replacements = array();
312
313 // Get site and user tags replacements
314 $replacements = array_merge( $replacements, gamipress_get_site_tags_replacements() );
315 $replacements = array_merge( $replacements, gamipress_get_user_tags_replacements( $user_id ) );
316
317 // Get the achievement post object
318 $achievement = gamipress_get_post( $achievement_id );
319
320 if( $achievement ) {
321
322 $achievement_types = gamipress_get_achievement_types();
323 $achievement_type = $achievement_types[$achievement->post_type];
324
325 $achievement_steps_html = '';
326
327 $steps = gamipress_get_achievement_steps( $achievement->ID );
328
329 if( is_array( $steps ) && count( $steps ) ) {
330
331 $list_tag = gamipress_is_achievement_sequential( $achievement->ID ) ? 'ol' : 'ul';
332
333 $achievement_steps_html .= "<{$list_tag}>";
334
335 foreach( $steps as $step ) {
336 // check if user has earned this Achievement, and add an 'earned' class
337 $earned = gamipress_get_earnings_count( array(
338 'user_id' => absint( $user_id ),
339 'post_id' => absint( $step->ID ),
340 'since' => absint( gamipress_achievement_last_user_activity( $achievement->ID, $user_id ) )
341 ) ) > 0;
342
343 $title = $step->post_title;
344 $url = gamipress_get_post_meta( $step->ID, '_gamipress_url' );
345
346 $achievement_steps_html .= '<li style="' . ( $earned ? 'text-decoration: line-through;' : '' ) . '">'
347 . ( ! empty( $url ) ? '<a href="' . $url. '">' : '' )
348 . $title
349 . ( ! empty( $url ) ? '</a>' : '' )
350 . '</li>';
351 }
352
353 $achievement_steps_html .= "</{$list_tag}>";
354 }
355
356 $replacements['{achievement_id}'] = $achievement->ID;
357 $replacements['{achievement_title}'] = $achievement->post_title;
358 $replacements['{achievement_url}'] = get_the_permalink( $achievement->ID );
359 $replacements['{achievement_link}'] = sprintf( '<a href="%s" title="%s">%s</a>', $replacements['{achievement_url}'], $replacements['{achievement_title}'], $replacements['{achievement_title}'] );
360 $replacements['{achievement_excerpt}'] = $achievement->post_excerpt;
361 $replacements['{achievement_image}'] = gamipress_get_achievement_post_thumbnail( $achievement->ID );
362 $replacements['{achievement_steps}'] = $achievement_steps_html;
363 $replacements['{achievement_type}'] = $achievement_type['singular_name'];
364 $replacements['{achievement_congratulations}'] = gamipress_get_post_meta( $achievement->ID, '_gamipress_congratulations_text' );
365
366 // Get the points and points type in achievement
367 $points = absint( gamipress_get_post_meta( $achievement->ID, '_gamipress_points' ) );
368 $points_type_slug = gamipress_get_post_meta( $achievement->ID, '_gamipress_points_type' );
369
370 $replacements['{achievement_points}'] = '';
371 $replacements['{achievement_points_type}'] = '';
372
373 // Check if the point reward is set up in the achievement
374 if ( $points && $points_type_slug ) {
375
376 $points_type = gamipress_get_points_type( $points_type_slug );
377 $singular = $points_type['singular_name'];
378 $plural = $points_type['plural_name'];
379
380 $replacements['{achievement_points}'] = gamipress_format_amount( $points, $points_type['ID'] );
381 $replacements['{achievement_points_type}'] = _n( $singular, $plural, $points );
382 }
383
384 }
385
386 return $replacements;
387
388 }
389
390 /**
391 * Step completed tags replacements
392 *
393 * @since 1.8.6
394 *
395 * @param int $step_id The step to get tags values from
396 * @param int $user_id The user to get tags values from
397 *
398 * @return array
399 */
400 function gamipress_get_step_completed_tags_replacements( $step_id, $user_id ) {
401
402 $replacements = array();
403
404 // Get site and user tags replacements
405 $replacements = array_merge( $replacements, gamipress_get_site_tags_replacements() );
406 $replacements = array_merge( $replacements, gamipress_get_user_tags_replacements( $user_id ) );
407
408 // Get the step post object
409 $step = gamipress_get_post( $step_id );
410
411 if( $step ) {
412 $replacements['{label}'] = $step->post_title;
413
414 // Get the step achievement to parse their tags
415 $achievement = gamipress_get_step_achievement( $step->ID );
416
417 if( $achievement ) {
418 $replacements = array_merge( $replacements, gamipress_get_achievement_earned_tags_replacements( $achievement->ID, $user_id ) );
419 }
420 }
421
422 return $replacements;
423
424 }
425
426 /**
427 * Points award completed tags replacements
428 *
429 * @since 1.8.6
430 *
431 * @param int $points_award_id The points award to get tags values from
432 * @param int $user_id The user to get tags values from
433 *
434 * @return array
435 */
436 function gamipress_get_points_award_completed_tags_replacements( $points_award_id, $user_id ) {
437
438 $replacements = array();
439
440 // Get site and user tags replacements
441 $replacements = array_merge( $replacements, gamipress_get_site_tags_replacements() );
442 $replacements = array_merge( $replacements, gamipress_get_user_tags_replacements( $user_id ) );
443
444 // Get the points award post object
445 $points_award = gamipress_get_post( $points_award_id );
446
447 if( $points_award ) {
448 $replacements['{label}'] = $points_award->post_title;
449
450 // Get the points type to allow specific points type template
451 $points_type = gamipress_get_points_award_points_type( $points_award->ID );
452
453 if( $points_type ) {
454
455 // Setup vars
456 $points = absint( gamipress_get_post_meta( $points_award->ID, '_gamipress_points' ) );
457 $singular = $points_type->post_title;
458 $plural = gamipress_get_post_meta( $points_type->ID, '_gamipress_plural_name' );
459 $points_balance = gamipress_get_user_points( $user_id, $points_type->post_name );
460
461 $replacements['{points}'] = gamipress_format_amount( $points, $points_type->post_name );
462 $replacements['{points_balance}'] = $points_balance;
463 $replacements['{points_type}'] = _n( $singular, $plural, $points );
464 $replacements['{points_image}'] = gamipress_get_points_type_thumbnail( $points_type->ID );
465
466 }
467
468 }
469
470 return $replacements;
471
472 }
473
474 /**
475 * Points deduct completed tags replacements
476 *
477 * @since 1.8.6
478 *
479 * @param int $points_deduct_id The points deduct to get tags values from
480 * @param int $user_id The user to get tags values from
481 *
482 * @return array
483 */
484 function gamipress_get_points_deduct_completed_tags_replacements( $points_deduct_id, $user_id ) {
485
486 $replacements = array();
487
488 // Get site and user tags replacements
489 $replacements = array_merge( $replacements, gamipress_get_site_tags_replacements() );
490 $replacements = array_merge( $replacements, gamipress_get_user_tags_replacements( $user_id ) );
491
492 // Get the points deduct post object
493 $points_deduct = gamipress_get_post( $points_deduct_id );
494
495 if( $points_deduct ) {
496 $replacements['{label}'] = $points_deduct->post_title;
497
498 // Get the points type to allow specific points type template
499 $points_type = gamipress_get_points_deduct_points_type( $points_deduct->ID );
500
501 if( $points_type ) {
502
503 // Setup vars
504 $points = absint( gamipress_get_post_meta( $points_deduct->ID, '_gamipress_points' ) );
505 $singular = $points_type->post_title;
506 $plural = gamipress_get_post_meta( $points_type->ID, '_gamipress_plural_name' );
507 $points_balance = gamipress_get_user_points( $user_id, $points_type->post_name );
508
509 $replacements['{points}'] = gamipress_format_amount( $points, $points_type->post_name );
510 $replacements['{points_balance}'] = $points_balance;
511 $replacements['{points_type}'] = _n( $singular, $plural, $points );
512 $replacements['{points_image}'] = gamipress_get_points_type_thumbnail( $points_type->ID );
513
514 }
515
516 }
517
518 return $replacements;
519
520 }
521
522 /**
523 * Rank earned tags replacements
524 *
525 * @since 1.8.6
526 *
527 * @param int $rank_id The rank to get tags values from
528 * @param int $user_id The user to get tags values from
529 *
530 * @return array
531 */
532 function gamipress_get_rank_earned_tags_replacements( $rank_id, $user_id ) {
533
534 $replacements = array();
535
536 // Get site and user tags replacements
537 $replacements = array_merge( $replacements, gamipress_get_site_tags_replacements() );
538 $replacements = array_merge( $replacements, gamipress_get_user_tags_replacements( $user_id ) );
539
540 // Get the rank post object
541 $rank = gamipress_get_post( $rank_id );
542
543 if( $rank ) {
544
545 $rank_requirements_html = '';
546
547 $requirements = gamipress_get_rank_requirements( $rank->ID );
548
549 if( is_array( $requirements ) && count( $requirements ) ) {
550
551 $list_tag = gamipress_is_achievement_sequential( $rank->ID ) ? 'ol' : 'ul';
552
553 $rank_requirements_html .= "<{$list_tag}>";
554
555 foreach( $requirements as $requirement ) {
556 // check if user has earned this requirement, and add an 'earned' class
557 $earned = gamipress_get_earnings_count( array(
558 'user_id' => absint( $user_id ),
559 'post_id' => absint( $requirement->ID ),
560 'since' => absint( gamipress_achievement_last_user_activity( $requirement->ID, $user_id ) )
561 ) ) > 0;
562
563 $title = $requirement->post_title;
564 $url = gamipress_get_post_meta( $requirement->ID, '_gamipress_url' );
565
566 $rank_requirements_html .= '<li style="' . ( $earned ? 'text-decoration: line-through;' : '' ) . '">'
567 . ( ! empty( $url ) ? '<a href="' . $url. '">' : '' )
568 . $title
569 . ( ! empty( $url ) ? '</a>' : '' )
570 . '</li>';
571 }
572
573 $rank_requirements_html .= "</{$list_tag}>";
574 }
575
576 $replacements['{rank_id}'] = $rank->ID;
577 $replacements['{rank_title}'] = $rank->post_title;
578 $replacements['{rank_url}'] = get_the_permalink( $rank->ID );
579 $replacements['{rank_link}'] = sprintf( '<a href="%s" title="%s">%s</a>', $replacements['{rank_url}'], $replacements['{rank_title}'], $replacements['{rank_title}'] );
580 $replacements['{rank_excerpt}'] = $rank->post_excerpt;
581 $replacements['{rank_image}'] = gamipress_get_rank_post_thumbnail( $rank->ID );
582 $replacements['{rank_requirements}'] = $rank_requirements_html;
583 $replacements['{rank_type}'] = gamipress_get_rank_type_singular( $rank->post_type, true );
584 $replacements['{rank_congratulations}'] = gamipress_get_post_meta( $rank->ID, '_gamipress_congratulations_text' );
585
586 }
587
588 return $replacements;
589
590 }
591
592 /**
593 * Rank requirement tags replacements
594 *
595 * @since 1.8.6
596 *
597 * @param int $rank_requirement_id The rank requirement to get tags values from
598 * @param int $user_id The user to get tags values from
599 *
600 * @return array
601 */
602 function gamipress_get_rank_requirement_completed_tags_replacements( $rank_requirement_id, $user_id ) {
603
604 $replacements = array();
605
606 // Get site and user tags replacements
607 $replacements = array_merge( $replacements, gamipress_get_site_tags_replacements() );
608 $replacements = array_merge( $replacements, gamipress_get_user_tags_replacements( $user_id ) );
609
610 // Get the rank requirement post object
611 $requirement = gamipress_get_post( $rank_requirement_id );
612
613 if( $requirement ) {
614 $replacements['{label}'] = $requirement->post_title;
615
616 // Get the requirement rank to parse their tags
617 $rank = gamipress_get_rank_requirement_rank( $requirement->ID );
618
619 if( $rank ) {
620 $replacements = array_merge( $replacements, gamipress_get_rank_earned_tags_replacements( $rank->ID, $user_id ) );
621 }
622 }
623
624 return $replacements;
625
626 }
627
628 /**
629 * Parse tags
630 *
631 * @since 1.8.6
632 *
633 * @param string $pattern The pattern to get replacements from
634 * @param int $post_id The post to get tags values from
635 * @param int $user_id The user to get tags values from
636 * @param string $content The content to apply tags
637 *
638 * @return string
639 */
640 function gamipress_parse_tags( $pattern, $post_id, $user_id, $content ) {
641
642 if( $pattern === 'achievement_earned' ) {
643 $replacements = gamipress_get_achievement_earned_tags_replacements( $post_id, $user_id );
644 } else if( $pattern === 'step_completed' ) {
645 $replacements = gamipress_get_step_completed_tags_replacements( $post_id, $user_id );
646 } else if( $pattern === 'points_award_completed' ) {
647 $replacements = gamipress_get_points_award_completed_tags_replacements( $post_id, $user_id );
648 } else if( $pattern === 'points_deduct_completed' ) {
649 $replacements = gamipress_get_points_deduct_completed_tags_replacements( $post_id, $user_id );
650 } else if( $pattern === 'rank_earned' ) {
651 $replacements = gamipress_get_rank_earned_tags_replacements( $post_id, $user_id );
652 } else if( $pattern === 'rank_requirement_completed' ) {
653 $replacements = gamipress_get_rank_requirement_completed_tags_replacements( $post_id, $user_id );
654 } else if( $pattern === 'email_footer' ) {
655 $replacements = gamipress_get_site_tags_replacements();
656 $replacements = array_merge( $replacements, gamipress_get_user_tags_replacements( $user_id ) );
657 }
658
659 /**
660 * Filter the replacements to apply to the given content
661 *
662 * @since 1.8.6
663 *
664 * @param array $replacements The replacements to apply to the content
665 * @param string $pattern The pattern to get replacements from
666 * @param int $post_id The post to get tags values from
667 * @param int $user_id The user to get tags values from
668 * @param string $content The content to apply tags
669 *
670 * @return array
671 */
672 $replacements = apply_filters( 'gamipress_parse_tags_replacements', $replacements, $pattern, $post_id, $user_id, $content );
673
674 return str_replace( array_keys( $replacements ), $replacements, $content );
675
676 }