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 / thrive-quiz-builder / includes / requirements.php

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

107 lines 4.3 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\Thrive_Quiz_Builder\Requirements
6 * @since 1.0.0
7 */
8
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Add custom fields to the requirement object
14 *
15 * @param $requirement
16 * @param $requirement_id
17 *
18 * @return array
19 */
20 function gamipress_thrive_quiz_builder_requirement_object( $requirement, $requirement_id ) {
21
22 if( isset( $requirement['trigger_type'] )
23 && ( $requirement['trigger_type'] === 'gamipress_thrive_quiz_builder_complete_percentage_quiz'
24 || $requirement['trigger_type'] === 'gamipress_thrive_quiz_builder_complete_specific_percentage_quiz' ) ) {
25
26 // Percentage
27 $requirement['thrive_quiz_builder_percentage_condition'] = get_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_percentage_condition', true );
28 $requirement['thrive_quiz_builder_percentage'] = get_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_percentage', true );
29
30 }
31
32 if( isset( $requirement['trigger_type'] )
33 && ( $requirement['trigger_type'] === 'gamipress_thrive_quiz_builder_complete_quiz_type' ) ) {
34
35 // Quiz type
36 $requirement['thrive_quiz_builder_quiz_type'] = get_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_quiz_type', true );
37
38 }
39
40 return $requirement;
41 }
42 add_filter( 'gamipress_requirement_object', 'gamipress_thrive_quiz_builder_requirement_object', 10, 2 );
43
44 /**
45 * Category field on requirements UI
46 *
47 * @param $requirement_id
48 * @param $post_id
49 */
50 function gamipress_thrive_quiz_builder_requirement_ui_fields( $requirement_id, $post_id ) {
51
52 $percentage_conditions = gamipress_thrive_quiz_builder_get_percentage_conditions();
53 $percentage_condition = get_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_percentage_condition', true );
54 $percentage = absint( get_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_percentage', true ) );
55
56 $quiz_types = gamipress_thrive_quiz_builder_get_quiz_types();
57 $quiz_type = get_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_quiz_type', true );
58 ?>
59
60 <span class="thrive-quiz-builder-quiz-percentage">
61 <select>
62 <?php foreach( $percentage_conditions as $id => $name ) : ?>
63 <option value="<?php echo esc_attr( $id ); ?>" <?php selected( $percentage_condition, $id ); ?>><?php echo esc_html( $name ); ?></option>
64 <?php endforeach; ?>
65 </select>
66 <input type="text" value="<?php echo esc_attr( $percentage ); ?>" size="3" maxlength="3" placeholder="100" />%
67 </span>
68
69 <span class="thrive-quiz-builder-quiz-type">
70 <select>
71 <?php foreach( $quiz_types as $id => $name ) : ?>
72 <option value="<?php echo esc_attr( $id ); ?>" <?php selected( $quiz_type, $id ); ?>><?php echo esc_html( $name ); ?></option>
73 <?php endforeach; ?>
74 </select>
75 </span>
76
77 <?php
78 }
79 add_action( 'gamipress_requirement_ui_html_after_achievement_post', 'gamipress_thrive_quiz_builder_requirement_ui_fields', 10, 2 );
80
81 /**
82 * Custom handler to save the custom fields on requirements UI
83 *
84 * @param $requirement_id
85 * @param $requirement
86 */
87 function gamipress_thrive_quiz_builder_ajax_update_requirement( $requirement_id, $requirement ) {
88
89 if( isset( $requirement['trigger_type'] )
90 && ( $requirement['trigger_type'] === 'gamipress_thrive_quiz_builder_complete_percentage_quiz'
91 || $requirement['trigger_type'] === 'gamipress_thrive_quiz_builder_complete_specific_percentage_quiz' ) ) {
92
93 // Percentage
94 update_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_percentage_condition', $requirement['thrive_quiz_builder_percentage_condition'] );
95 update_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_percentage', $requirement['thrive_quiz_builder_percentage'] );
96
97 }
98
99 if( isset( $requirement['trigger_type'] )
100 && ( $requirement['trigger_type'] === 'gamipress_thrive_quiz_builder_complete_quiz_type' ) ) {
101
102 // Quiz type
103 update_post_meta( $requirement_id, '_gamipress_thrive_quiz_builder_quiz_type', $requirement['thrive_quiz_builder_quiz_type'] );
104
105 }
106 }
107 add_action( 'gamipress_ajax_update_requirement', 'gamipress_thrive_quiz_builder_ajax_update_requirement', 10, 2 );