From d9b58d27e717a63088c69f8b59e9bca48e7c54e4 Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Wed, 26 Aug 2026 13:10:06 +0600 Subject: [PATCH 1/6] Fix: in content bank not showing correct count for instructors --- classes/Instructor.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/classes/Instructor.php b/classes/Instructor.php index 5a242a37fc..dda4f0ae8b 100644 --- a/classes/Instructor.php +++ b/classes/Instructor.php @@ -77,6 +77,36 @@ public function __construct( $register_hook = true ) { add_action( 'wp_ajax_tutor_save_instructor_home_sections_order', array( $this, 'ajax_save_home_sections_order' ) ); add_action( 'wp_ajax_tutor_save_instructor_home_sections_visibility', array( $this, 'ajax_save_home_section_visibility' ) ); + add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_for_instructor' ), 10, 4 ); + } + + /** + * Map meta capability for instructor. + * + * @since 4.0.8 + * + * @param array $caps Array of capabilities. + * @param string $cap Capability name. + * @param int $user_id User ID. + * @param array $args Array of arguments. + * @return array Array of capabilities. + */ + public function map_meta_cap_for_instructor( $caps, $cap, $user_id, $args ) { + if ( 'edit_post' !== $cap ) { + return $caps; + } + + $course_id = isset( $args[0] ) ? (int) $args[0] : null; + + if ( ! $course_id || ! $user_id || tutor()->course_post_type !== get_post_type( $course_id ) ) { + return $caps; + } + + if ( tutor_utils()->is_instructor_of_this_course( $user_id, $course_id ) ) { + return array( 'edit_tutor_course' ); + } + + return $caps; } /** From 681e3dc109a90ca070bbbc364bf1eb324b8cbbf2 Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Wed, 2 Sep 2026 16:37:03 +0600 Subject: [PATCH 2/6] removed hook and added 'edit_published_posts' capability --- classes/Instructor.php | 30 ------------------------------ classes/Tutor.php | 1 + 2 files changed, 1 insertion(+), 30 deletions(-) diff --git a/classes/Instructor.php b/classes/Instructor.php index dda4f0ae8b..5a242a37fc 100644 --- a/classes/Instructor.php +++ b/classes/Instructor.php @@ -77,36 +77,6 @@ public function __construct( $register_hook = true ) { add_action( 'wp_ajax_tutor_save_instructor_home_sections_order', array( $this, 'ajax_save_home_sections_order' ) ); add_action( 'wp_ajax_tutor_save_instructor_home_sections_visibility', array( $this, 'ajax_save_home_section_visibility' ) ); - add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_for_instructor' ), 10, 4 ); - } - - /** - * Map meta capability for instructor. - * - * @since 4.0.8 - * - * @param array $caps Array of capabilities. - * @param string $cap Capability name. - * @param int $user_id User ID. - * @param array $args Array of arguments. - * @return array Array of capabilities. - */ - public function map_meta_cap_for_instructor( $caps, $cap, $user_id, $args ) { - if ( 'edit_post' !== $cap ) { - return $caps; - } - - $course_id = isset( $args[0] ) ? (int) $args[0] : null; - - if ( ! $course_id || ! $user_id || tutor()->course_post_type !== get_post_type( $course_id ) ) { - return $caps; - } - - if ( tutor_utils()->is_instructor_of_this_course( $user_id, $course_id ) ) { - return array( 'edit_tutor_course' ); - } - - return $caps; } /** diff --git a/classes/Tutor.php b/classes/Tutor.php index e873452ca1..ea56e71937 100644 --- a/classes/Tutor.php +++ b/classes/Tutor.php @@ -1114,6 +1114,7 @@ public static function manage_tutor_roles_and_permissions() { if ( $instructor ) { $instructor_cap = array( 'edit_posts', + 'edit_published_posts', 'read', 'upload_files', ); From 68158ed35cb1aa5c50f988f73c1a3cc29629ea6f Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Wed, 2 Sep 2026 17:43:30 +0600 Subject: [PATCH 3/6] readded map meta capability so that instructors without edit_published_posts capability gets edit_tutor_course --- classes/Instructor.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/classes/Instructor.php b/classes/Instructor.php index e5b1700d65..9bbfa74ab0 100644 --- a/classes/Instructor.php +++ b/classes/Instructor.php @@ -100,6 +100,36 @@ public function __construct( $register_hook = true ) { add_action( 'wp_ajax_tutor_save_instructor_home_sections_order', array( $this, 'ajax_save_home_sections_order' ) ); add_action( 'wp_ajax_tutor_save_instructor_home_sections_visibility', array( $this, 'ajax_save_home_section_visibility' ) ); + add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_for_instructor' ), 10, 4 ); + } + + /** + * Map meta capability for instructor. + * + * @since 4.0.8 + * + * @param array $caps Array of capabilities. + * @param string $cap Capability name. + * @param int $user_id User ID. + * @param array $args Array of arguments. + * @return array Array of capabilities. + */ + public function map_meta_cap_for_instructor( $caps, $cap, $user_id, $args ) { + if ( 'edit_post' !== $cap ) { + return $caps; + } + + $course_id = isset( $args[0] ) ? (int) $args[0] : null; + + if ( ! $course_id || ! $user_id || tutor()->course_post_type !== get_post_type( $course_id ) ) { + return $caps; + } + + if ( tutor_utils()->is_instructor_of_this_course( $user_id, $course_id ) ) { + return array( 'edit_tutor_course' ); + } + + return $caps; } /** From 3c3920d0375a6628321383322db541b148edb82d Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Thu, 3 Sep 2026 12:07:24 +0600 Subject: [PATCH 4/6] removed hook and added instructor capability migrator --- classes/Instructor.php | 30 ----- migrations/InstructorCapabilityMigrator.php | 132 ++++++++++++++++++++ migrations/Migration.php | 1 + 3 files changed, 133 insertions(+), 30 deletions(-) create mode 100644 migrations/InstructorCapabilityMigrator.php diff --git a/classes/Instructor.php b/classes/Instructor.php index 9bbfa74ab0..e5b1700d65 100644 --- a/classes/Instructor.php +++ b/classes/Instructor.php @@ -100,36 +100,6 @@ public function __construct( $register_hook = true ) { add_action( 'wp_ajax_tutor_save_instructor_home_sections_order', array( $this, 'ajax_save_home_sections_order' ) ); add_action( 'wp_ajax_tutor_save_instructor_home_sections_visibility', array( $this, 'ajax_save_home_section_visibility' ) ); - add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_for_instructor' ), 10, 4 ); - } - - /** - * Map meta capability for instructor. - * - * @since 4.0.8 - * - * @param array $caps Array of capabilities. - * @param string $cap Capability name. - * @param int $user_id User ID. - * @param array $args Array of arguments. - * @return array Array of capabilities. - */ - public function map_meta_cap_for_instructor( $caps, $cap, $user_id, $args ) { - if ( 'edit_post' !== $cap ) { - return $caps; - } - - $course_id = isset( $args[0] ) ? (int) $args[0] : null; - - if ( ! $course_id || ! $user_id || tutor()->course_post_type !== get_post_type( $course_id ) ) { - return $caps; - } - - if ( tutor_utils()->is_instructor_of_this_course( $user_id, $course_id ) ) { - return array( 'edit_tutor_course' ); - } - - return $caps; } /** diff --git a/migrations/InstructorCapabilityMigrator.php b/migrations/InstructorCapabilityMigrator.php new file mode 100644 index 0000000000..378b7a74ec --- /dev/null +++ b/migrations/InstructorCapabilityMigrator.php @@ -0,0 +1,132 @@ + + * @link https://themeum.com + * @since 4.0.8 + */ + +namespace Tutor\Migrations; + +use Tutor\Migrations\Contracts\SingleProcessor; +use Tutor\Models\UserModel; + +/** + * Class InstructorCapabilityMigrator + * + * @since 4.0.8 + */ +class InstructorCapabilityMigrator extends BatchProcessor implements SingleProcessor { + + /** + * User model + * + * @var UserModel + */ + private $user_model; + + /** + * Name of the migration + * + * @since 4.0.8 + * + * @var string + */ + protected $name = 'Instructor Capability Migrator'; + + /** + * Action + * + * @since 4.0.8 + * + * @var string + */ + protected $action = 'instructor_capability_migrator'; + + /** + * Batch size + * + * @since 4.0.8 + * + * @var integer + */ + protected $batch_size = 100; + + /** + * Schedule interval. + * + * @since 4.0.8 + * + * @var integer + */ + protected $schedule_interval = 10; + + /** + * Get total unprocessed result. + * + * @since 4.0.8 + * + * @return int + */ + protected function get_total_items(): int { + $this->user_model = new UserModel(); + $users = $this->user_model->get_users_list( + array( + 'role' => tutor()->instructor_role, + 'fields' => 'ID', + ) + ); + return $users->get_total(); + } + + /** + * Get items to batch process. + * + * @since 4.0.8 + * + * @param int $offset offset. + * @param int $limit limit. + * + * @return array + */ + protected function get_items( $offset, $limit ): array { + $this->user_model = new UserModel(); + $users = $this->user_model->get_users_list( + array( + 'role' => tutor()->instructor_role, + 'number' => $limit, + 'offset' => $offset, + ) + ); + return $users->get_results(); + } + + /** + * Process instructor to add capability. + * + * @since 4.0.8 + * + * @param object $item item. + * + * @return void + */ + public function process_item( $item ): void { + $user = new \WP_User( $item->ID ); + if ( ! $user->has_cap( 'edit_published_posts' ) ) { + $user->add_cap( 'edit_published_posts' ); + } + } + + /** + * On migration complete event. + * + * @since 4.0.8 + * + * @return void + */ + protected function on_complete() { + error_log( 'Instructor capability migration completed!' ); + } +} diff --git a/migrations/Migration.php b/migrations/Migration.php index 998d99bdaf..96891cc145 100644 --- a/migrations/Migration.php +++ b/migrations/Migration.php @@ -30,6 +30,7 @@ public function __construct() { */ public function schedule_migrations() { $migrators = array( + InstructorCapabilityMigrator::instance(), QuizAttemptMigrator::instance(), ); From 0572ef03a8c1dc1b13473c73d602671b4dbb2d72 Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Thu, 3 Sep 2026 17:58:53 +0600 Subject: [PATCH 5/6] added instructor status approval check --- migrations/InstructorCapabilityMigrator.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/migrations/InstructorCapabilityMigrator.php b/migrations/InstructorCapabilityMigrator.php index 378b7a74ec..2e76d6746d 100644 --- a/migrations/InstructorCapabilityMigrator.php +++ b/migrations/InstructorCapabilityMigrator.php @@ -74,8 +74,10 @@ protected function get_total_items(): int { $this->user_model = new UserModel(); $users = $this->user_model->get_users_list( array( - 'role' => tutor()->instructor_role, - 'fields' => 'ID', + 'role' => tutor()->instructor_role, + 'meta_key' => '_tutor_instructor_status', + 'meta_value' => 'approved', + 'fields' => 'ID', ) ); return $users->get_total(); @@ -95,9 +97,11 @@ protected function get_items( $offset, $limit ): array { $this->user_model = new UserModel(); $users = $this->user_model->get_users_list( array( - 'role' => tutor()->instructor_role, - 'number' => $limit, - 'offset' => $offset, + 'role' => tutor()->instructor_role, + 'meta_key' => '_tutor_instructor_status', + 'meta_value' => 'approved', + 'number' => $limit, + 'offset' => $offset, ) ); return $users->get_results(); From 4de998f4a91815bc6ed0da4ba15e58416e0ab405 Mon Sep 17 00:00:00 2001 From: Anindra Das Bivas Date: Fri, 4 Sep 2026 11:27:53 +0600 Subject: [PATCH 6/6] removed meta check --- migrations/InstructorCapabilityMigrator.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/migrations/InstructorCapabilityMigrator.php b/migrations/InstructorCapabilityMigrator.php index 2e76d6746d..378b7a74ec 100644 --- a/migrations/InstructorCapabilityMigrator.php +++ b/migrations/InstructorCapabilityMigrator.php @@ -74,10 +74,8 @@ protected function get_total_items(): int { $this->user_model = new UserModel(); $users = $this->user_model->get_users_list( array( - 'role' => tutor()->instructor_role, - 'meta_key' => '_tutor_instructor_status', - 'meta_value' => 'approved', - 'fields' => 'ID', + 'role' => tutor()->instructor_role, + 'fields' => 'ID', ) ); return $users->get_total(); @@ -97,11 +95,9 @@ protected function get_items( $offset, $limit ): array { $this->user_model = new UserModel(); $users = $this->user_model->get_users_list( array( - 'role' => tutor()->instructor_role, - 'meta_key' => '_tutor_instructor_status', - 'meta_value' => 'approved', - 'number' => $limit, - 'offset' => $offset, + 'role' => tutor()->instructor_role, + 'number' => $limit, + 'offset' => $offset, ) ); return $users->get_results();