PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
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 / give / includes / requirements.php

requirements.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at integrations/give/includes/requirements.php

73 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Requirements
4 *
5 * @package GamiPress\Give\Requirements
6 * @since 1.0.0
7 */
8
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Add the amount field to the requirement object
14 *
15 * @since 1.0.0
16 *
17 * @param $requirement
18 * @param $requirement_id
19 *
20 * @return array
21 */
22 function gamipress_give_requirement_object( $requirement, $requirement_id ) {
23
24 if( isset( $requirement['trigger_type'] )
25 && ( $requirement['trigger_type'] === 'gamipress_give_new_donation_min_amount' ) ) {
26
27 // Minimum grade percent
28 $requirement['give_amount'] = get_post_meta( $requirement_id, '_gamipress_give_amount', true );
29
30 }
31
32 return $requirement;
33 }
34 add_filter( 'gamipress_requirement_object', 'gamipress_give_requirement_object', 10, 2 );
35
36 /**
37 * Amount field on requirements UI
38 *
39 * @since 1.0.0
40 *
41 * @param $requirement_id
42 * @param $post_id
43 */
44 function gamipress_give_requirement_ui_fields( $requirement_id, $post_id ) {
45
46 $amount = absint( get_post_meta( $requirement_id, '_gamipress_give_amount', true ) );
47 ?>
48
49 <span class="give-amount"><input type="number" value="<?php echo $amount; ?>" placeholder="100" /></span>
50
51 <?php
52 }
53 add_action( 'gamipress_requirement_ui_html_after_achievement_post', 'gamipress_give_requirement_ui_fields', 10, 2 );
54
55 /**
56 * Custom handler to save the amount on requirements UI
57 *
58 * @since 1.0.0
59 *
60 * @param $requirement_id
61 * @param $requirement
62 */
63 function gamipress_give_ajax_update_requirement( $requirement_id, $requirement ) {
64
65 if( isset( $requirement['trigger_type'] )
66 && ( $requirement['trigger_type'] === 'gamipress_give_new_donation_min_amount' ) ) {
67
68 // Save the amount field
69 update_post_meta( $requirement_id, '_gamipress_give_amount', $requirement['give_amount'] );
70
71 }
72 }
73 add_action( 'gamipress_ajax_update_requirement', 'gamipress_give_ajax_update_requirement', 10, 2 );