← All changes
|
integrations/fluentcommunity/includes/functions.php
+54
-0
7.9.9
→
8.0.5
View file →
| @@ -92,8 +92,34 @@ | ||
| 92 | 92 | // Return our results |
| 93 | 93 | wp_send_json_success( $results ); |
| 94 | 94 | die; |
| 95 | 95 | |
| 96 | + } else if( isset( $_REQUEST['post_type'] ) && in_array( 'fluentcommunity_lessons', $_REQUEST['post_type'] ) ) { | |
| 97 | + | |
| 98 | + // Return lessons | |
| 99 | + $lessons = $wpdb->get_results( | |
| 100 | + $wpdb->prepare( | |
| 101 | + "SELECT id, title FROM {$wpdb->prefix}fcom_posts WHERE type = %s AND content_type = %s AND status = %s", | |
| 102 | + 'course_lesson', | |
| 103 | + 'text', | |
| 104 | + 'published' | |
| 105 | + ) | |
| 106 | + ); | |
| 107 | + | |
| 108 | + foreach ( $lessons as $lesson ) { | |
| 109 | + | |
| 110 | + // Results should meet same structure like posts | |
| 111 | + $results[] = array( | |
| 112 | + 'ID' => $lesson->id, | |
| 113 | + 'post_title' => $lesson->title, | |
| 114 | + ); | |
| 115 | + | |
| 116 | + } | |
| 117 | + | |
| 118 | + // Return our results | |
| 119 | + wp_send_json_success( $results ); | |
| 120 | + die; | |
| 121 | + | |
| 96 | 122 | } |
| 97 | 123 | |
| 98 | 124 | } |
| 99 | 125 | add_action( 'wp_ajax_gamipress_get_posts', 'gamipress_fluentcommunity_ajax_get_posts', 5 ); |
| @@ -168,6 +194,34 @@ | ||
| 168 | 194 | ) |
| 169 | 195 | ); |
| 170 | 196 | |
| 171 | 197 | return $quiz; |
| 198 | + | |
| 199 | +} | |
| 200 | + | |
| 201 | +/** | |
| 202 | + * Get the lesson title | |
| 203 | + * | |
| 204 | + * @param int $lesson_id | |
| 205 | + * | |
| 206 | + * @since 1.0.0 | |
| 207 | + */ | |
| 208 | +function gamipress_fluentcommunity_get_lesson_title( $lesson_id ) { | |
| 209 | + | |
| 210 | + global $wpdb; | |
| 211 | + | |
| 212 | + // Empty title if no ID provided | |
| 213 | + if( absint( $lesson_id ) === 0 ) { | |
| 214 | + return ''; | |
| 215 | + } | |
| 216 | + | |
| 217 | + // Get lesson title | |
| 218 | + $lesson = $wpdb->get_var( | |
| 219 | + $wpdb->prepare( | |
| 220 | + "SELECT title FROM {$wpdb->prefix}fcom_posts WHERE id = %d", | |
| 221 | + absint( $lesson_id ) | |
| 222 | + ) | |
| 223 | + ); | |
| 224 | + | |
| 225 | + return $lesson; | |
| 172 | 226 | |
| 173 | 227 | } |