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_Generator::handle_prerequisites()
Updates course and lesson prerequisites If the prerequisite was included in the import, updates to the new imported version If the prereq is not included but the source matches, leaves the prereq intact as long as the prereq exists Otherwise removes prerequisite data from the new course / lesson
Description Description
Removes prereq track associations if there’s no source or source doesn’t match or if the track doesn’t exist
Return Return
(void)
Source Source
File: includes/class.llms.generator.php
private function handle_prerequisites() { foreach ( array( 'course', 'lesson' ) as $obj_type ) { $ids = $this->tempids[ $obj_type ]; // courses have two kinds of prereqs $has_prereq_param = ( 'course' === $obj_type ) ? 'course' : null; // loop through all then created lessons foreach ( $ids as $old_id => $new_id ) { // instantiate the new instance of the object $obj = llms_get_post( $new_id ); // if this is a course and there isn't a source or the source doesn't match the current site // we should remove the track prerequisites if ( 'course' === $obj_type && ( ! isset( $raw['_source'] ) || get_site_url() !== $raw['_source'] ) ) { // remove prereq track settings if ( $obj->has_prerequisite( 'course_track' ) ) { $obj->set( 'prerequisite_track', 0 ); if ( ! $obj->has_prerequisite( 'course' ) ) { $obj->set( 'has_prerequisite', 'no' ); } } } // if the object has a prereq if ( $obj->has_prerequisite( $has_prereq_param ) ) { // get the old preqeq's id $old_prereq = $obj->get( 'prerequisite' ); // if the old prereq is a key in the array of created objects // we can replace it with the new id if ( in_array( $old_prereq, array_keys( $ids ) ) ) { $obj->set( 'prerequisite', $ids[ $old_prereq ] ); } // End if(). elseif ( ! isset( $raw['_source'] ) || get_site_url() !== $raw['_source'] ) { $obj->set( 'has_prerequisite', 'no' ); $obj->set( 'prerequisite', 0 ); } // check to be sure old prereq still exists else { $post = get_post( $old_prereq ); // post doesn't exist or the post type doesn't match, get rid of it... if ( ! $post || $obj_type !== $post->post_type ) { $obj->set( 'has_prerequisite', 'no' ); $obj->set( 'prerequisite', 0 ); } } } }// End foreach(). }// End foreach(). }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.3.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: