From 06023abd597de8a2436789b9a0a79e7ff2f08292 Mon Sep 17 00:00:00 2001 From: Archinj Date: Thu, 12 Sep 2024 10:34:32 +0530 Subject: [PATCH] Change function call into single call --- .../class-ld-custom-auto-complete-handler.php | 38 +++---------------- .../class-ld-custom-auto-complete.php | 4 +- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/ld_custom_auto_complete/includes/class-ld-custom-auto-complete-handler.php b/ld_custom_auto_complete/includes/class-ld-custom-auto-complete-handler.php index a740529..6201aa0 100644 --- a/ld_custom_auto_complete/includes/class-ld-custom-auto-complete-handler.php +++ b/ld_custom_auto_complete/includes/class-ld-custom-auto-complete-handler.php @@ -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. * @@ -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; @@ -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 ); diff --git a/ld_custom_auto_complete/includes/class-ld-custom-auto-complete.php b/ld_custom_auto_complete/includes/class-ld-custom-auto-complete.php index 7afdc3f..25ff256 100644 --- a/ld_custom_auto_complete/includes/class-ld-custom-auto-complete.php +++ b/ld_custom_auto_complete/includes/class-ld-custom-auto-complete.php @@ -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' ); } }