From 3e0bbe05ed7e38b93a7aed0b4b60409901a26450 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Thu, 6 Jun 2024 16:37:57 -0300 Subject: [PATCH 1/6] Update taxonomies to have the default capability --- includes/class-sensei-modules.php | 6 ------ includes/class-sensei-posttypes.php | 6 ------ 2 files changed, 12 deletions(-) diff --git a/includes/class-sensei-modules.php b/includes/class-sensei-modules.php index 808d42c079..3e50b111f5 100644 --- a/includes/class-sensei-modules.php +++ b/includes/class-sensei-modules.php @@ -2179,12 +2179,6 @@ public function setup_modules_taxonomy() { 'public' => true, 'hierarchical' => true, 'show_admin_column' => false, - 'capabilities' => array( - 'manage_terms' => 'manage_categories', - 'edit_terms' => 'edit_courses', - 'delete_terms' => 'manage_categories', - 'assign_terms' => 'edit_courses', - ), 'show_in_nav_menus' => false, 'show_in_quick_edit' => false, 'show_ui' => true, diff --git a/includes/class-sensei-posttypes.php b/includes/class-sensei-posttypes.php index 9f4c085b43..5317e1281c 100755 --- a/includes/class-sensei-posttypes.php +++ b/includes/class-sensei-posttypes.php @@ -891,12 +891,6 @@ public function setup_lesson_tag_taxonomy() { 'show_ui' => true, 'query_var' => true, 'show_in_nav_menus' => true, - 'capabilities' => array( - 'manage_terms' => 'manage_categories', - 'edit_terms' => 'edit_lessons', - 'delete_terms' => 'manage_categories', - 'assign_terms' => 'edit_lessons', - ), 'rewrite' => array( /** * Filter the rewrite slug for the lesson tag taxonomy. From 936e5add50b3fceef5e8536c20bda0340e662a4b Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Thu, 6 Jun 2024 16:59:47 -0300 Subject: [PATCH 2/6] Add question capability to teachers --- includes/class-sensei-data-cleaner.php | 1 + includes/class-sensei-teacher.php | 1 + includes/class-sensei-updates.php | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/includes/class-sensei-data-cleaner.php b/includes/class-sensei-data-cleaner.php index b421ac6406..6c79e2a513 100644 --- a/includes/class-sensei-data-cleaner.php +++ b/includes/class-sensei-data-cleaner.php @@ -210,6 +210,7 @@ class Sensei_Data_Cleaner { // Teacher caps. 'manage_lesson_categories', 'manage_course_categories', + 'manage_question_categories', 'publish_quizzes', 'edit_quizzes', 'edit_published_quizzes', diff --git a/includes/class-sensei-teacher.php b/includes/class-sensei-teacher.php index c4e4caa856..23d63eb2b7 100755 --- a/includes/class-sensei-teacher.php +++ b/includes/class-sensei-teacher.php @@ -204,6 +204,7 @@ protected function add_capabilities() { // Questions 'publish_questions' => true, + 'manage_question_categories' => true, 'edit_questions' => true, 'edit_published_questions' => true, 'edit_private_questions' => true, diff --git a/includes/class-sensei-updates.php b/includes/class-sensei-updates.php index 2605b1231b..38c2565ee4 100755 --- a/includes/class-sensei-updates.php +++ b/includes/class-sensei-updates.php @@ -88,11 +88,21 @@ public function run_updates() { $this->v4_10_update_install_time(); $this->v4_12_create_default_emails(); $this->v4_19_2_update_legacy_quiz_data(); + $this->v4_24_1_update_teacher_capabilities(); // Flush rewrite cache. Sensei()->initiate_rewrite_rules_flush(); } + /** + * Update teacher capabilities. + * + * @since 4.24.1 + */ + private function v4_24_1_update_teacher_capabilities() { + Sensei()->teacher->create_role(); + } + /** * Enqueue job to update the legacy quiz data. * From 1db8c3083450369e5e64b1e8de680adc087633e9 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Thu, 6 Jun 2024 17:00:11 -0300 Subject: [PATCH 3/6] Update taxonomy capabilities --- includes/class-sensei-posttypes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-sensei-posttypes.php b/includes/class-sensei-posttypes.php index 5317e1281c..ac87a4b719 100755 --- a/includes/class-sensei-posttypes.php +++ b/includes/class-sensei-posttypes.php @@ -688,7 +688,7 @@ public function setup_course_category_taxonomy() { 'show_in_nav_menus' => true, 'capabilities' => array( 'manage_terms' => 'manage_categories', - 'edit_terms' => 'edit_courses', + 'edit_terms' => 'manage_course_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_courses', ), @@ -840,7 +840,7 @@ public function setup_question_category_taxonomy() { 'show_in_rest' => true, 'capabilities' => array( 'manage_terms' => 'manage_categories', - 'edit_terms' => 'edit_questions', + 'edit_terms' => 'manage_question_categories', 'delete_terms' => 'manage_categories', 'assign_terms' => 'edit_questions', ), From 05dc46278a69bafa940428e3e66653d5eed31cda Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Thu, 6 Jun 2024 17:17:55 -0300 Subject: [PATCH 4/6] Add taxonomy capabilities --- includes/class-sensei-updates.php | 11 ++++++++--- includes/class-sensei.php | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/includes/class-sensei-updates.php b/includes/class-sensei-updates.php index 38c2565ee4..b5cfbb2a8a 100755 --- a/includes/class-sensei-updates.php +++ b/includes/class-sensei-updates.php @@ -88,19 +88,24 @@ public function run_updates() { $this->v4_10_update_install_time(); $this->v4_12_create_default_emails(); $this->v4_19_2_update_legacy_quiz_data(); - $this->v4_24_1_update_teacher_capabilities(); + $this->v4_24_1_update_capabilities(); // Flush rewrite cache. Sensei()->initiate_rewrite_rules_flush(); } /** - * Update teacher capabilities. + * Update capabilities. * * @since 4.24.1 */ - private function v4_24_1_update_teacher_capabilities() { + private function v4_24_1_update_capabilities() { + // Add new `manage_question_categories` capabilitiy to teacher. Sensei()->teacher->create_role(); + + // Update the other roles capabilities. + Sensei()->add_sensei_admin_caps(); + Sensei()->add_editor_caps(); } /** diff --git a/includes/class-sensei.php b/includes/class-sensei.php index 31d87e8b0e..8a55ddfab5 100644 --- a/includes/class-sensei.php +++ b/includes/class-sensei.php @@ -1844,6 +1844,10 @@ public function add_editor_caps() { if ( ! is_null( $role ) ) { $role->add_cap( 'manage_sensei_grades' ); + + $role->add_cap( 'manage_lesson_categories' ); + $role->add_cap( 'manage_course_categories' ); + $role->add_cap( 'manage_question_categories' ); } return true; @@ -1860,6 +1864,10 @@ public function add_sensei_admin_caps() { if ( ! is_null( $role ) ) { $role->add_cap( 'manage_sensei' ); $role->add_cap( 'manage_sensei_grades' ); + + $role->add_cap( 'manage_lesson_categories' ); + $role->add_cap( 'manage_course_categories' ); + $role->add_cap( 'manage_question_categories' ); } return true; From 64dd35feaccd659f931fb16f9e79097fa0d1a979 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Thu, 6 Jun 2024 17:59:16 -0300 Subject: [PATCH 5/6] Add specific capabilities to the taxonomies --- includes/class-sensei-data-cleaner.php | 1 + includes/class-sensei-modules.php | 6 ++++++ includes/class-sensei-posttypes.php | 14 ++++++++++---- includes/class-sensei-teacher.php | 5 ++++- includes/class-sensei.php | 2 ++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/includes/class-sensei-data-cleaner.php b/includes/class-sensei-data-cleaner.php index 6c79e2a513..4ceafc23a7 100644 --- a/includes/class-sensei-data-cleaner.php +++ b/includes/class-sensei-data-cleaner.php @@ -211,6 +211,7 @@ class Sensei_Data_Cleaner { 'manage_lesson_categories', 'manage_course_categories', 'manage_question_categories', + 'manage_modules', 'publish_quizzes', 'edit_quizzes', 'edit_published_quizzes', diff --git a/includes/class-sensei-modules.php b/includes/class-sensei-modules.php index 3e50b111f5..14849972f5 100644 --- a/includes/class-sensei-modules.php +++ b/includes/class-sensei-modules.php @@ -2179,6 +2179,12 @@ public function setup_modules_taxonomy() { 'public' => true, 'hierarchical' => true, 'show_admin_column' => false, + 'capabilities' => array( + 'manage_terms' => 'manage_modules', + 'edit_terms' => 'manage_modules', + 'delete_terms' => 'manage_modules', + 'assign_terms' => 'edit_courses', + ), 'show_in_nav_menus' => false, 'show_in_quick_edit' => false, 'show_ui' => true, diff --git a/includes/class-sensei-posttypes.php b/includes/class-sensei-posttypes.php index ac87a4b719..aae8e5a870 100755 --- a/includes/class-sensei-posttypes.php +++ b/includes/class-sensei-posttypes.php @@ -687,9 +687,9 @@ public function setup_course_category_taxonomy() { 'query_var' => true, 'show_in_nav_menus' => true, 'capabilities' => array( - 'manage_terms' => 'manage_categories', + 'manage_terms' => 'manage_course_categories', 'edit_terms' => 'manage_course_categories', - 'delete_terms' => 'manage_categories', + 'delete_terms' => 'manage_course_categories', 'assign_terms' => 'edit_courses', ), 'rewrite' => array( @@ -839,9 +839,9 @@ public function setup_question_category_taxonomy() { 'show_admin_column' => true, 'show_in_rest' => true, 'capabilities' => array( - 'manage_terms' => 'manage_categories', + 'manage_terms' => 'manage_question_categories', 'edit_terms' => 'manage_question_categories', - 'delete_terms' => 'manage_categories', + 'delete_terms' => 'manage_question_categories', 'assign_terms' => 'edit_questions', ), 'rewrite' => array( @@ -891,6 +891,12 @@ public function setup_lesson_tag_taxonomy() { 'show_ui' => true, 'query_var' => true, 'show_in_nav_menus' => true, + 'capabilities' => array( + 'manage_terms' => 'manage_lesson_categories', + 'edit_terms' => 'manage_lesson_categories', + 'delete_terms' => 'manage_lesson_categories', + 'assign_terms' => 'edit_lessons', + ), 'rewrite' => array( /** * Filter the rewrite slug for the lesson tag taxonomy. diff --git a/includes/class-sensei-teacher.php b/includes/class-sensei-teacher.php index 23d63eb2b7..8a843c837a 100755 --- a/includes/class-sensei-teacher.php +++ b/includes/class-sensei-teacher.php @@ -195,6 +195,9 @@ protected function add_capabilities() { 'read_private_courses' => true, 'delete_published_courses' => true, + // Modules + 'manage_modules' => true, + // Quiz 'publish_quizzes' => true, 'edit_quizzes' => true, @@ -228,7 +231,7 @@ protected function add_capabilities() { foreach ( $caps as $cap => $grant ) { - // load the capability on to the teacher role + // load the capability on to the teacher role. $this->teacher_role->add_cap( $cap, $grant ); } diff --git a/includes/class-sensei.php b/includes/class-sensei.php index 8a55ddfab5..1169fb55eb 100644 --- a/includes/class-sensei.php +++ b/includes/class-sensei.php @@ -1848,6 +1848,7 @@ public function add_editor_caps() { $role->add_cap( 'manage_lesson_categories' ); $role->add_cap( 'manage_course_categories' ); $role->add_cap( 'manage_question_categories' ); + $role->add_cap( 'manage_modules' ); } return true; @@ -1868,6 +1869,7 @@ public function add_sensei_admin_caps() { $role->add_cap( 'manage_lesson_categories' ); $role->add_cap( 'manage_course_categories' ); $role->add_cap( 'manage_question_categories' ); + $role->add_cap( 'manage_modules' ); } return true; From bbc71c7bebf8f4febdbcc1aa329de914c1dbc5a6 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Fri, 7 Jun 2024 10:27:08 -0300 Subject: [PATCH 6/6] Add changelog --- changelog/fix-capability-issue | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/fix-capability-issue diff --git a/changelog/fix-capability-issue b/changelog/fix-capability-issue new file mode 100644 index 0000000000..33077391a1 --- /dev/null +++ b/changelog/fix-capability-issue @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Change some taxonomy capabilities to fix some behaviors