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 / fluentcommunity / includes / functions.php

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

173 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package GamiPress\FluentCommunity\Functions
6 * @since 1.0.0
7 */
8
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Overrides GamiPress AJAX Helper for selecting posts
14 *
15 * @since 1.0.0
16 */
17 function gamipress_fluentcommunity_ajax_get_posts() {
18
19 // Security check, forces to die if not security passed
20 check_ajax_referer( 'gamipress_admin', 'nonce' );
21
22 // Check if user can manage GamiPress
23 if( ! current_user_can( gamipress_get_manager_capability() ) ) {
24 wp_send_json_error( __( 'You\'re not allowed to perform this action.', 'gamipress' ) );
25 }
26
27 global $wpdb;
28
29 $results = array();
30
31 // Pull back the search string
32 $search = isset( $_REQUEST['q'] ) ? $wpdb->esc_like( sanitize_text_field( $_REQUEST['q'] ) ) : '';
33
34 if( isset( $_REQUEST['post_type'] ) && in_array( 'fluentcommunity_spaces', $_REQUEST['post_type'] ) ) {
35
36 $spaces = \FluentCommunity\App\Functions\Utility::getSpaces();
37
38 foreach ( $spaces as $space ) {
39
40 // Results should meet same structure like posts
41 $results[] = array(
42 'ID' => $space['id'],
43 'post_title' => $space['title'],
44 );
45
46 }
47
48 // Return our results
49 wp_send_json_success( $results );
50 die;
51
52 } else if( isset( $_REQUEST['post_type'] ) && in_array( 'fluentcommunity_courses', $_REQUEST['post_type'] ) ) {
53
54 $courses = \FluentCommunity\App\Functions\Utility::getCourses();
55
56 foreach ( $courses as $course ) {
57
58 // Results should meet same structure like posts
59 $results[] = array(
60 'ID' => $course['id'],
61 'post_title' => $course['title'],
62 );
63
64 }
65
66 // Return our results
67 wp_send_json_success( $results );
68 die;
69
70 } else if( isset( $_REQUEST['post_type'] ) && in_array( 'fluentcommunity_quizzes', $_REQUEST['post_type'] ) ) {
71
72 // Return quizzes
73 $quizzes = $wpdb->get_results(
74 $wpdb->prepare(
75 "SELECT id, title FROM {$wpdb->prefix}fcom_posts WHERE type = %s AND content_type = %s AND status = %s",
76 'course_lesson',
77 'quiz',
78 'published'
79 )
80 );
81
82 foreach ( $quizzes as $quiz ) {
83
84 // Results should meet same structure like posts
85 $results[] = array(
86 'ID' => $quiz->id,
87 'post_title' => $quiz->title,
88 );
89
90 }
91
92 // Return our results
93 wp_send_json_success( $results );
94 die;
95
96 }
97
98 }
99 add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_fluentcommunity_ajax_get_posts', 5 );
100
101 /**
102 * Get the space title
103 *
104 * @param int $space_id
105 *
106 * @since 1.0.0
107 */
108 function gamipress_fluentcommunity_get_space_title( $space_id ) {
109
110 if( absint( $space_id ) === 0 ) {
111 return '';
112 }
113
114 $spaces = \FluentCommunity\App\Functions\Utility::getSpaces();
115
116 foreach ( $spaces as $space ) {
117 if ( absint( $space['id'] ) === absint( $space_id ) ) {
118 return $space['title'];
119 }
120 }
121
122 }
123
124 /**
125 * Get the course title
126 *
127 * @param int $course_id
128 *
129 * @since 1.0.0
130 */
131 function gamipress_fluentcommunity_get_course_title( $course_id ) {
132
133 if( absint( $course_id ) === 0 ) {
134 return '';
135 }
136
137 $courses = \FluentCommunity\App\Functions\Utility::getCourses();
138
139 foreach ( $courses as $course ) {
140 if ( absint( $course['id'] ) === absint( $course_id ) ) {
141 return $course['title'];
142 }
143 }
144
145 }
146
147 /**
148 * Get the quiz title
149 *
150 * @param int $quiz_id
151 *
152 * @since 1.0.0
153 */
154 function gamipress_fluentcommunity_get_quiz_title( $quiz_id ) {
155
156 global $wpdb;
157
158 // Empty title if no ID provided
159 if( absint( $quiz_id ) === 0 ) {
160 return '';
161 }
162
163 // Get quiz title
164 $quiz = $wpdb->get_var(
165 $wpdb->prepare(
166 "SELECT title FROM {$wpdb->prefix}fcom_posts WHERE id = %d",
167 absint( $quiz_id )
168 )
169 );
170
171 return $quiz;
172
173 }