diff --git a/includes/class-sensei-learner.php b/includes/class-sensei-learner.php index 090e50251d..41cc0f3a7e 100644 --- a/includes/class-sensei-learner.php +++ b/includes/class-sensei-learner.php @@ -393,18 +393,6 @@ private function get_enrolled_courses_query_by_progress_status( $user_id, $base_ $course_ids = [ -1 ]; } - /** - * Filters the course IDs for a learner's enrolled courses query by progress status. - * - * @hook sensei_learner_enrolled_courses_query_by_progress_status_course_ids - * - * @param {int[]} $course_ids Course IDs. - * @param {int} $user_id User ID. - * @param {string} $type Progress status type. - * @return {int[]} Course IDs. - */ - $course_ids = apply_filters( 'sensei_learner_enrolled_courses_query_by_progress_status_course_ids', $course_ids, $user_id, $type ); - $query_args['post__in'] = $course_ids; return new WP_Query( $query_args ); @@ -441,8 +429,17 @@ public function get_enrolled_courses_query_args( $user_id, $base_query_args = [] $query_args = array_merge( $default_args, $base_query_args ); $learner_term = self::get_learner_term( $user_id ); - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound - $term_id = apply_filters( 'wpml_object_id', $learner_term->term_id, Sensei_PostTypes::LEARNER_TAXONOMY_NAME, true ); + /** + * Filters the term ID used in the query to fetch a learner's enrolled courses. + * + * @hook sensei_learner_get_enrolled_courses_query_args_term_id + * + * @since $$next-version$$ + * + * @param {int} $term_id The term ID. + * @return {int} The term ID. + */ + $term_id = apply_filters( 'sensei_learner_get_enrolled_courses_query_args_term_id', $learner_term->term_id ); $query_args['post_type'] = 'course'; $query_args['tax_query'][] = [ @@ -512,6 +509,18 @@ private function get_course_ids_by_progress_status( $user_id, $status ) { $course_ids[] = intval( $status->comment_post_ID ); } + /** + * Filters the course IDs when getting them for a user by progress status. + * + * @hook sensei_learner_get_course_ids_by_progress_status_course_ids + * + * @param {int[]} $course_ids Course IDs. + * @param {int} $user_id User ID. + * @param {string} $status Progress status. + * @return {int[]} Course IDs. + */ + $course_ids = apply_filters( 'sensei_learner_get_course_ids_by_progress_status_course_ids', $course_ids, $user_id, $status ); + return $course_ids; } diff --git a/includes/wpml/class-course-progress.php b/includes/wpml/class-course-progress.php index 1a49e9691c..96209b8f43 100644 --- a/includes/wpml/class-course-progress.php +++ b/includes/wpml/class-course-progress.php @@ -8,6 +8,7 @@ namespace Sensei\WPML; use Sensei_Course_Enrolment_Manager; +use Sensei_PostTypes; if ( ! defined( 'ABSPATH' ) ) { exit; @@ -38,7 +39,8 @@ public function init() { add_filter( 'sensei_course_progress_find_course_id', array( $this, 'translate_course_id' ) ); add_filter( 'sensei_lesson_progress_count_course_id', array( $this, 'translate_course_id' ) ); add_filter( 'sensei_course_start_course_id', array( $this, 'translate_course_id' ) ); - add_filter( 'sensei_learner_enrolled_courses_query_by_progress_status_course_ids', array( $this, 'translate_course_ids' ) ); + add_filter( 'sensei_learner_get_course_ids_by_progress_status_course_ids', array( $this, 'translate_course_ids' ) ); + add_filter( 'sensei_learner_get_enrolled_courses_query_args_term_id', array( $this, 'translate_term_id' ) ); add_action( 'sensei_manual_enrolment_learner_enrolled', array( $this, 'enrol_learner' ), 10, 2 ); add_action( 'sensei_manual_enrolment_learner_withdrawn', array( $this, 'withdraw_learner' ), 10, 2 ); @@ -136,4 +138,19 @@ public function translate_course_ids( array $course_ids ): array { return $course_ids; } + + /** + * Translate term ID. + * + * @since $$next-version$$ + * + * @internal + * + * @param int $term_id Term ID. + * @return int + */ + public function translate_term_id( $term_id ): int { + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound + return (int) apply_filters( 'wpml_object_id', $term_id, Sensei_PostTypes::LEARNER_TAXONOMY_NAME, true ); + } }