Skip to content

Commit

Permalink
Change function call into single call
Browse files Browse the repository at this point in the history
  • Loading branch information
Archinj committed Sep 12, 2024
1 parent 2538820 commit 06023ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ public static function get_instance() {
return self::$instance;
}

/**
* Autocomplete a lesson.
*
* Checks if the lesson is set to autocomplete and if the user has access to it.
* If the lesson is set to autocomplete and the user does not have access, it marks the lesson as complete for the user.
*
* @param int $post_id The ID of the lesson.
* @param int $course_id The ID of the course.
* @param int $user_id The ID of the user.
* @return void
*/
public function ld_custom_autocomplete_lesson( $post_id, $course_id, $user_id ) {
$this->ld_custom_autocomplete_checker( $post_id, $course_id, $user_id, true );
}

/**
* Handles the timer completion ajax request.
*
Expand Down Expand Up @@ -112,30 +97,17 @@ public function ld_custom_autocomplete_timer() {
);
}

/**
* Autocompletes a topic.
*
* @param int $post_id The ID of the topic.
* @param int $course_id The ID of the course.
* @param int $user_id The ID of the user.
* @return void
*/
public function ld_custom_autocomplete_topic( $post_id, $course_id, $user_id ) {
$this->ld_custom_autocomplete_checker( $post_id, $course_id, $user_id, false );
}

/**
* Autocomplete a lesson or topic.
*
* Checks if the lesson or topic is set to autocomplete and if the user has access to it.
*
* @param int $post_id The ID of the lesson or topic.
* @param int $course_id The ID of the course.
* @param int $user_id The ID of the user.
* @param bool $is_lesson Whether the current content is a lesson or topic. Defaults to true.
* @param int $post_id The ID of the lesson or topic.
* @param int $course_id The ID of the course.
* @param int $user_id The ID of the user.
* @return void
*/
public function ld_custom_autocomplete_checker( $post_id, $course_id, $user_id, $is_lesson = true ) {
public function ld_custom_autocomplete_checker( $post_id, $course_id, $user_id ) {
$is_autocomplete_on = get_post_meta( $post_id, LD_CUSTOM_AUTO_COMPLETE_META, true );
if ( 'on' !== $is_autocomplete_on ) {
return;
Expand All @@ -147,7 +119,7 @@ public function ld_custom_autocomplete_checker( $post_id, $course_id, $user_id,
return;
}

if ( ! $is_lesson ) {
if ( 'sfwd-topic' === get_post_type( $post_id ) ) {
$lesson_id = learndash_get_lesson_id( $post_id, $course_id );
$is_available_lesson = ld_lesson_access_from( $lesson_id, $user_id, $course_id );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ private function add_learndash_setting() {
*/
private function autocomplete_handler() {
$handler = Ld_Custom_Auto_Complete_Handler::get_instance();
$this->loader->add_action( 'learndash-lesson-before', $handler, 'ld_custom_autocomplete_lesson', 1, 3 );
$this->loader->add_action( 'learndash-topic-before', $handler, 'ld_custom_autocomplete_topic', 1, 3 );
$this->loader->add_action( 'learndash-lesson-before', $handler, 'ld_custom_autocomplete_checker', 1, 3 );
$this->loader->add_action( 'learndash-topic-before', $handler, 'ld_custom_autocomplete_checker', 1, 3 );
$this->loader->add_action( 'wp_ajax_mark_complete', $handler, 'ld_custom_autocomplete_timer' );
}
}

0 comments on commit 06023ab

Please sign in to comment.