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( int $course_id, string $post_type = '', string $search_term = '', integer $page = 1 )
Retrieve a list of lessons the current user is allowed to clone/attach Used for ajax searching to add existing lessons
Description Description
Parameters Parameters
- $course_id
-
(int) (Required) WP Post ID of the course
- $post_type
-
(string) (Optional) y search specific post type(s)
Default value: ''
- $search_term
-
(string) (Optional) search term (searches post_title)
Default value: ''
- $page
-
(integer) (Optional) page, used when paginating search results
Default value: 1
Return Return
(array)
Source Source
File: includes/admin/class.llms.admin.builder.php
private static function get_existing_posts( $course_id, $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_options' ) ) { $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 ) { $parents['lesson'] = sprintf( __( 'Lesson: %1$s (#%2$d)', 'lifterlms' ), '<em>' . get_the_title( $lesson_id ) . '</em>', $lesson_id ); } if ( $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' ) ), ); }// End foreach(). }// End if(). $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 |
---|---|
3.14.8 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: