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
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. |