Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Admin_Builder::get_existing_posts( string $post_type = '', string $search_term = '', int $page = 1 )
Retrieve a list of lessons the current user is allowed to clone/attach
Description Description
Used for ajax searching to add existing lessons.
Parameters Parameters
- $post_type
-
(string) (Optional) Search specific post type(s). By default searches for all post types.
Default value: ''
- $search_term
-
(string) (Optional) Search term (searches post_title). Default is empty string.
Default value: ''
- $page
-
(int) (Optional) Used when paginating search results. Default is
1
.Default value: 1
Return Return
(array)
Source Source
File: includes/admin/class.llms.admin.builder.php
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | private static function get_existing_posts( $post_type = '' , $search_term = '' , $page = 1 ) { $args = array ( 'order' => 'ASC' , 'orderby' => 'post_title' , 'paged' => $page , 'post_status' => array ( 'publish' , 'draft' , 'pending' ), 'posts_per_page' => 10, ); if ( $post_type ) { $args [ 'post_type' ] = $post_type ; } if ( ! current_user_can( 'manage_lifterlms' ) ) { $instructor = llms_get_instructor(); $parents = $instructor ->get( 'parent_instructors' ); if ( ! $parents ) { $parents = array (); } $args [ 'author__in' ] = array_unique ( array_merge ( array ( get_current_user_id() ), $instructor ->get_assistants(), $parents ) ); } self:: $search_term = $search_term ; add_filter( 'posts_where' , array ( __CLASS__ , 'get_existing_posts_where' ), 10, 2 ); $query = new WP_Query( $args ); remove_filter( 'posts_where' , array ( __CLASS__ , 'get_existing_posts_where' ), 10, 2 ); $posts = array (); if ( $query ->have_posts() ) { foreach ( $query ->posts as $post ) { $post = llms_get_post( $post ); $parents = array (); if ( method_exists( $post , 'is_orphan' ) && $post ->is_orphan() ) { $action = 'attach' ; } else { $action = 'clone' ; $course_id = false; $lesson_id = false; if ( 'lesson' === $post ->get( 'type' ) ) { $course_id = $post ->get( 'parent_course' ); } elseif ( 'llms_quiz' === $post ->get( 'type' ) ) { $lesson_id = $post ->get( 'lesson_id' ); $course = $post ->get_course(); if ( $course ) { $course_id = $course ->get( 'id' ); } } if ( $lesson_id ) { // Translators: %1$s = Lesson title; %2$d = Lesson id. $parents [ 'lesson' ] = sprintf( __( 'Lesson: %1$s (#%2$d)' , 'lifterlms' ), '<em>' . get_the_title( $lesson_id ) . '</em>' , $lesson_id ); } if ( $course_id ) { // Translators: %1$s = Course title; %2$d - Course id. $parents [ 'course' ] = sprintf( __( 'Course: %1$s (#%2$d)' , 'lifterlms' ), '<em>' . get_the_title( $course_id ) . '</em>' , $course_id ); } } $posts [] = array ( 'action' => $action , 'data' => $post , 'id' => $post ->get( 'id' ), 'parents' => $parents , 'text' => sprintf( '%1$s (#%2$d)' , $post ->get( 'title' ), $post ->get( 'id' ) ), ); } } $ret = array ( 'results' => $posts , 'pagination' => array ( 'more' => ( $page < $query ->max_num_pages ), ), ); return $ret ; } |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.8.0 | Allow LMS managers to get all lessons. https://github.com/gocodebox/lifterlms/issues/1849. Removed unused $course_id parameter. |
3.16.12 | Unknown. |
3.14.8 | Introduced. |