From 906ed2c28e9c78a02c06d5e73f04a70e20ebc08f Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 10 Aug 2023 21:09:52 +0200 Subject: [PATCH 001/122] Add custom capabilities to custom post types --- includes/functions/_cpt_and_taxonomies.php | 289 +++++++++++++++------ 1 file changed, 205 insertions(+), 84 deletions(-) diff --git a/includes/functions/_cpt_and_taxonomies.php b/includes/functions/_cpt_and_taxonomies.php index 41270b9a..c6817563 100644 --- a/includes/functions/_cpt_and_taxonomies.php +++ b/includes/functions/_cpt_and_taxonomies.php @@ -1,5 +1,104 @@ __( 'Story', 'fictioneer' ), - 'description' => __( 'Holds stories and details about them.', 'fictioneer' ), - 'labels' => $labels, - 'menu_icon' => 'dashicons-book', - 'supports' => array( 'title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions' ), - 'taxonomies' => array( 'category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning' ), - 'hierarchical' => false, - 'public' => true, - 'rewrite' => array( 'slug' => 'story' ), - 'show_in_rest' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'menu_position' => 5, - 'show_in_admin_bar' => true, - 'show_in_nav_menus' => true, - 'can_export' => true, - 'has_archive' => false, - 'exclude_from_search' => false, - 'publicly_queryable' => true, - 'capability_type' => 'page', + 'label' => __( 'Story', 'fictioneer' ), + 'description' => __( 'Holds stories and details about them.', 'fictioneer' ), + 'labels' => $labels, + 'menu_icon' => 'dashicons-book', + 'supports' => ['title', 'author', 'editor', 'excerpt', 'thumbnail', 'revisions'], + 'taxonomies' => ['category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning'], + 'hierarchical' => false, + 'public' => true, + 'rewrite' => array( 'slug' => 'story' ), + 'show_in_rest' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 5, + 'show_in_admin_bar' => true, + 'show_in_nav_menus' => true, + 'can_export' => true, + 'has_archive' => false, + 'exclude_from_search' => false, + 'publicly_queryable' => true, + 'capability_type' => ['fcn_story', 'fcn_stories'], + 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_STORY_CAPABILITIES ), + 'map_meta_cap' => true ); register_post_type( 'fcn_story', $args ); @@ -106,28 +207,32 @@ function fictioneer_fcn_chapter_post_type() { 'items_list_navigation' => __( 'Chapters list navigation', 'fictioneer' ), 'filter_items_list' => __( 'Filter chapters list', 'fictioneer' ), ); + $args = array( - 'label' => __( 'Chapter', 'fictioneer' ), - 'description' => __( 'Holds chapters and details about them.', 'fictioneer' ), - 'labels' => $labels, - 'menu_icon' => 'dashicons-text-page', - 'supports' => array( 'title', 'author', 'editor', 'excerpt', 'thumbnail', 'comments', 'revisions' ), - 'taxonomies' => array( 'category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning' ), - 'hierarchical' => false, - 'public' => true, - 'rewrite' => array( 'slug' => 'chapter' ), - 'show_in_rest' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'menu_position' => 6, - 'show_in_admin_bar' => true, - 'show_in_nav_menus' => true, - 'can_export' => true, - 'has_archive' => false, - 'exclude_from_search' => false, - 'publicly_queryable' => true, - 'capability_type' => 'page', + 'label' => __( 'Chapter', 'fictioneer' ), + 'description' => __( 'Holds chapters and details about them.', 'fictioneer' ), + 'labels' => $labels, + 'menu_icon' => 'dashicons-text-page', + 'supports' => ['title', 'author', 'editor', 'excerpt', 'thumbnail', 'comments', 'revisions'], + 'taxonomies' => ['category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning'], + 'hierarchical' => false, + 'public' => true, + 'rewrite' => array( 'slug' => 'chapter' ), + 'show_in_rest' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 6, + 'show_in_admin_bar' => true, + 'show_in_nav_menus' => true, + 'can_export' => true, + 'has_archive' => false, + 'exclude_from_search' => false, + 'publicly_queryable' => true, + 'capability_type' => ['fcn_chapter', 'fcn_chapters'], + 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_CHAPTER_CAPABILITIES ), + 'map_meta_cap' => true ); + register_post_type( 'fcn_chapter', $args ); } add_action( 'init', 'fictioneer_fcn_chapter_post_type', 0 ); @@ -171,28 +276,32 @@ function fictioneer_fcn_collection_post_type() { 'items_list_navigation' => __( 'Collections list navigation', 'fictioneer' ), 'filter_items_list' => __( 'Filter collections list', 'fictioneer' ), ); + $args = array( - 'label' => __( 'Collection', 'fictioneer' ), - 'description' => __( 'Collections of stories, chapters, and recommendations.', 'fictioneer' ), - 'labels' => $labels, - 'menu_icon' => 'dashicons-category', - 'supports' => array( 'title', 'author', 'editor', 'thumbnail' ), - 'taxonomies' => array( 'category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning' ), - 'hierarchical' => false, - 'public' => true, - 'rewrite' => array( 'slug' => 'collection' ), - 'show_in_rest' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'menu_position' => 7, - 'show_in_admin_bar' => true, - 'show_in_nav_menus' => true, - 'can_export' => true, - 'has_archive' => false, - 'exclude_from_search' => false, - 'publicly_queryable' => true, - 'capability_type' => 'page', + 'label' => __( 'Collection', 'fictioneer' ), + 'description' => __( 'Collections of stories, chapters, and recommendations.', 'fictioneer' ), + 'labels' => $labels, + 'menu_icon' => 'dashicons-category', + 'supports' => ['title', 'author', 'editor', 'thumbnail'], + 'taxonomies' => ['category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning'], + 'hierarchical' => false, + 'public' => true, + 'rewrite' => array( 'slug' => 'collection' ), + 'show_in_rest' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 7, + 'show_in_admin_bar' => true, + 'show_in_nav_menus' => true, + 'can_export' => true, + 'has_archive' => false, + 'exclude_from_search' => false, + 'publicly_queryable' => true, + 'capability_type' => ['fcn_collection', 'fcn_collections'], + 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_COLLECTION_CAPABILITIES ), + 'map_meta_cap' => true ); + register_post_type( 'fcn_collection', $args ); } add_action( 'init', 'fictioneer_fcn_collection_post_type', 0 ); @@ -236,28 +345,32 @@ function fictioneer_fcn_recommendation_post_type() { 'items_list_navigation' => __( 'Recommendations list navigation', 'fictioneer' ), 'filter_items_list' => __( 'Filter recommendations list', 'fictioneer' ), ); + $args = array( - 'label' => __( 'Recommendation', 'fictioneer' ), - 'description' => __( 'Recommendations for external stories.', 'fictioneer' ), - 'labels' => $labels, - 'menu_icon' => 'dashicons-star-filled', - 'supports' => array( 'title', 'author', 'editor', 'excerpt', 'thumbnail' ), - 'taxonomies' => array( 'category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning' ), - 'hierarchical' => false, - 'public' => true, - 'rewrite' => array( 'slug' => 'recommendation' ), - 'show_in_rest' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'menu_position' => 8, - 'show_in_admin_bar' => true, - 'show_in_nav_menus' => false, - 'can_export' => true, - 'has_archive' => false, - 'exclude_from_search' => false, - 'publicly_queryable' => true, - 'capability_type' => 'page', + 'label' => __( 'Recommendation', 'fictioneer' ), + 'description' => __( 'Recommendations for external stories.', 'fictioneer' ), + 'labels' => $labels, + 'menu_icon' => 'dashicons-star-filled', + 'supports' => ['title', 'author', 'editor', 'excerpt', 'thumbnail'], + 'taxonomies' => ['category', 'post_tag', 'fcn_fandom', 'fcn_character', 'fcn_genre', 'fcn_content_warning'], + 'hierarchical' => false, + 'public' => true, + 'rewrite' => array( 'slug' => 'recommendation' ), + 'show_in_rest' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 8, + 'show_in_admin_bar' => true, + 'show_in_nav_menus' => false, + 'can_export' => true, + 'has_archive' => false, + 'exclude_from_search' => false, + 'publicly_queryable' => true, + 'capability_type' => ['fcn_recommendation', 'fcn_recommendations'], + 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_RECOMMENDATION_CAPABILITIES ), + 'map_meta_cap' => true ); + register_post_type( 'fcn_recommendation', $args ); } add_action( 'init', 'fictioneer_fcn_recommendation_post_type', 0 ); @@ -286,6 +399,7 @@ function fictioneer_add_genre_taxonomy() { 'add_new_item' => __( 'Add New Genre', 'textdomain' ), 'new_item_name' => __( 'New Genre Name', 'textdomain' ) ); + $args = array( 'hierarchical' => true, 'labels' => $labels, @@ -295,7 +409,8 @@ function fictioneer_add_genre_taxonomy() { 'query_var' => true, 'rewrite' => array( 'slug' => 'genre' ), ); - register_taxonomy( 'fcn_genre', array( 'fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation' ), $args ); + + register_taxonomy( 'fcn_genre', ['fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation'], $args ); } add_action( 'init', 'fictioneer_add_genre_taxonomy', 0 ); @@ -323,6 +438,7 @@ function fictioneer_add_fandom_taxonomy() { 'add_new_item' => __( 'Add New Fandom', 'textdomain' ), 'new_item_name' => __( 'New Fandom Name', 'textdomain' ) ); + $args = array( 'hierarchical' => true, 'labels' => $labels, @@ -332,7 +448,8 @@ function fictioneer_add_fandom_taxonomy() { 'query_var' => true, 'rewrite' => array( 'slug' => 'fandom' ), ); - register_taxonomy( 'fcn_fandom', array( 'fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation' ), $args ); + + register_taxonomy( 'fcn_fandom', ['fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation'], $args ); } add_action( 'init', 'fictioneer_add_fandom_taxonomy', 0 ); @@ -360,6 +477,7 @@ function fictioneer_add_character_taxonomy() { 'add_new_item' => __( 'Add New Character', 'textdomain' ), 'new_item_name' => __( 'New Character Name', 'textdomain' ) ); + $args = array( 'hierarchical' => true, 'labels' => $labels, @@ -369,7 +487,8 @@ function fictioneer_add_character_taxonomy() { 'query_var' => true, 'rewrite' => array( 'slug' => 'character' ), ); - register_taxonomy( 'fcn_character', array( 'fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation' ), $args ); + + register_taxonomy( 'fcn_character', ['fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation'], $args ); } add_action( 'init', 'fictioneer_add_character_taxonomy', 0 ); @@ -397,6 +516,7 @@ function fictioneer_add_content_warning_taxonomy() { 'add_new_item' => __( 'Add New Content Warning', 'textdomain' ), 'new_item_name' => __( 'New Content Warning Name', 'textdomain' ) ); + $args = array( 'hierarchical' => true, 'labels' => $labels, @@ -406,7 +526,8 @@ function fictioneer_add_content_warning_taxonomy() { 'query_var' => true, 'rewrite' => array( 'slug' => 'content-warning' ), ); - register_taxonomy( 'fcn_content_warning', array( 'fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation' ), $args ); + + register_taxonomy( 'fcn_content_warning', ['fcn_chapter', 'fcn_story', 'fcn_collection', 'fcn_recommendation'], $args ); } add_action( 'init', 'fictioneer_add_content_warning_taxonomy', 0 ); -- 2.47.1 From 4a210a855133e5a405d009d6477d100d13294181 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 10 Aug 2023 21:10:45 +0200 Subject: [PATCH 002/122] Prototype to initialize roles New caps need to be added, starting with the admin. Should not always run on init but for now this is fine. --- includes/functions/_roles.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/includes/functions/_roles.php b/includes/functions/_roles.php index 22d7510f..1f4cf36b 100644 --- a/includes/functions/_roles.php +++ b/includes/functions/_roles.php @@ -1,5 +1,34 @@ add_cap( $cap ); + } + +} +add_action( 'init', 'fictioneer_initialize_roles' ); + + + + + + + // ============================================================================= // ROLE CUSTOMIZATION ACTIONS // ============================================================================= -- 2.47.1 From 6295169cdd8f87806397663a2128418fd051ac73 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 10 Aug 2023 22:30:20 +0200 Subject: [PATCH 003/122] Fix post type setup --- includes/functions/_cpt_and_taxonomies.php | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/includes/functions/_cpt_and_taxonomies.php b/includes/functions/_cpt_and_taxonomies.php index c6817563..5088a3b7 100644 --- a/includes/functions/_cpt_and_taxonomies.php +++ b/includes/functions/_cpt_and_taxonomies.php @@ -1,25 +1,25 @@ false, 'publicly_queryable' => true, 'capability_type' => ['fcn_story', 'fcn_stories'], - 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_STORY_CAPABILITIES ), + 'capabilities' => array_combine( FICTIONEER_WP_CAPABILITIES, FICTIONEER_STORY_CAPABILITIES ), 'map_meta_cap' => true ); @@ -229,7 +229,7 @@ function fictioneer_fcn_chapter_post_type() { 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => ['fcn_chapter', 'fcn_chapters'], - 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_CHAPTER_CAPABILITIES ), + 'capabilities' => array_combine( FICTIONEER_WP_CAPABILITIES, FICTIONEER_CHAPTER_CAPABILITIES ), 'map_meta_cap' => true ); @@ -298,7 +298,7 @@ function fictioneer_fcn_collection_post_type() { 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => ['fcn_collection', 'fcn_collections'], - 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_COLLECTION_CAPABILITIES ), + 'capabilities' => array_combine( FICTIONEER_WP_CAPABILITIES, FICTIONEER_COLLECTION_CAPABILITIES ), 'map_meta_cap' => true ); @@ -367,7 +367,7 @@ function fictioneer_fcn_recommendation_post_type() { 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => ['fcn_recommendation', 'fcn_recommendations'], - 'capabilities' => array_combine( FICTIONEER_BASE_CAPABILITIES, FICTIONEER_RECOMMENDATION_CAPABILITIES ), + 'capabilities' => array_combine( FICTIONEER_WP_CAPABILITIES, FICTIONEER_RECOMMENDATION_CAPABILITIES ), 'map_meta_cap' => true ); -- 2.47.1 From 58121bdfef5d86b4d9664d887cb9a0253c4646d8 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 10 Aug 2023 22:30:34 +0200 Subject: [PATCH 004/122] Setup all roles --- includes/functions/_roles.php | 157 +++++++++++++++++++++++++++++++++- 1 file changed, 154 insertions(+), 3 deletions(-) diff --git a/includes/functions/_roles.php b/includes/functions/_roles.php index 1f4cf36b..6326bb5a 100644 --- a/includes/functions/_roles.php +++ b/includes/functions/_roles.php @@ -1,12 +1,33 @@ add_cap( $cap ); + $administrator->add_cap( $cap ); + } + + // Editor + $editor = get_role( 'editor' ); + $editor_caps = array_merge( + // Base + array( + 'fcn_read_others_media', + 'fcn_edit_others_media', + 'fcn_delete_others_media', + 'fcn_admin_profile_access', + 'fcn_adminbar_access', + 'fcn_dashboard_access' + ), + FICTIONEER_STORY_CAPABILITIES, + FICTIONEER_CHAPTER_CAPABILITIES, + FICTIONEER_COLLECTION_CAPABILITIES, + FICTIONEER_RECOMMENDATION_CAPABILITIES + ); + + foreach ( $editor_caps as $cap ) { + $editor->add_cap( $cap ); + } + + // Author + $author = get_role( 'author' ); + $author_caps = array( + // Base + 'fcn_admin_profile_access', + 'fcn_adminbar_access', + // Stories + 'read_fcn_story', + 'edit_fcn_stories', + 'publish_fcn_stories', + 'delete_fcn_stories', + 'delete_published_fcn_stories', + 'edit_published_fcn_stories', + // Chapters + 'read_fcn_chapter', + 'edit_fcn_chapters', + 'publish_fcn_chapters', + 'delete_fcn_chapters', + 'delete_published_fcn_chapters', + 'edit_published_fcn_chapters', + // Collections + 'read_fcn_collection', + 'edit_fcn_collections', + 'publish_fcn_collections', + 'delete_fcn_collections', + 'delete_published_fcn_collections', + 'edit_published_fcn_collections', + // Recommendations + 'read_fcn_recommendation', + 'edit_fcn_recommendations', + 'publish_fcn_recommendations', + 'delete_fcn_recommendations', + 'delete_published_fcn_recommendations', + 'edit_published_fcn_recommendations' + ); + + foreach ( $author_caps as $cap ) { + $author->add_cap( $cap ); + } + + // Contributor + $contributor = get_role( 'contributor' ); + $contributor_caps = array( + // Base + 'fcn_admin_profile_access', + 'fcn_adminbar_access', + // Stories + 'read_fcn_story', + 'edit_fcn_stories', + 'delete_fcn_stories', + // Chapters + 'read_fcn_chapter', + 'edit_fcn_chapters', + 'delete_fcn_chapters', + // Collections + 'read_fcn_collection', + 'edit_fcn_collections', + 'delete_fcn_collections', + // Recommendations + 'read_fcn_recommendation', + 'edit_fcn_recommendations', + 'delete_fcn_recommendations' + ); + + foreach ( $contributor_caps as $cap ) { + $contributor->add_cap( $cap ); + } + + // Moderator + fictioneer_add_moderator_role(); + $moderator = get_role( 'fcn_moderator' ); + $moderator_caps = array( + // Base + 'fcn_admin_profile_access', + 'fcn_adminbar_access', + // Stories + 'read_fcn_story', + // Chapters + 'read_fcn_chapter', + // Collections + 'read_fcn_collection', + // Recommendations + 'read_fcn_recommendation' + ); + + foreach ( $moderator_caps as $cap ) { + $moderator->add_cap( $cap ); + } + + // Subscriber + $subscriber = get_role( 'subscriber' ); + $subscriber_caps = array( + // Base + 'fcn_admin_profile_access', + // Stories + 'read_fcn_story', + // Chapters + 'read_fcn_chapter', + // Collections + 'read_fcn_collection', + // Recommendations + 'read_fcn_recommendation' + ); + + foreach ( $subscriber_caps as $cap ) { + $subscriber->add_cap( $cap ); } } -- 2.47.1 From 4f019a15db99b08b553f32330d618a295a6563ff Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 10 Aug 2023 22:34:25 +0200 Subject: [PATCH 005/122] Move things and docs --- includes/functions/_admin.php | 23 --------------- includes/functions/_roles.php | 53 +++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/includes/functions/_admin.php b/includes/functions/_admin.php index 18e27e38..00ef89f7 100644 --- a/includes/functions/_admin.php +++ b/includes/functions/_admin.php @@ -528,29 +528,6 @@ if ( ! function_exists( 'fictioneer_convert_taxonomies' ) ) { // ROLE CUSTOMIZATION ACTIONS // ============================================================================= -/** - * Add custom moderator role - * - * @since Fictioneer 5.0 - */ - -function fictioneer_add_moderator_role() { - return add_role( - 'fcn_moderator', - __( 'Moderator', 'fictioneer' ), - array( - 'read' => true, - 'edit_posts' => true, - 'edit_others_posts' => true, - 'edit_published_posts' => true, - 'moderate_comments' => true, - 'edit_comment' => true, - 'delete_posts' => false, - 'delete_others_posts' => false - ) - ); -} - /** * Upgrade author role with additional capabilities * diff --git a/includes/functions/_roles.php b/includes/functions/_roles.php index 6326bb5a..ed383e13 100644 --- a/includes/functions/_roles.php +++ b/includes/functions/_roles.php @@ -7,23 +7,29 @@ define( 'FICTIONEER_BASE_CAPABILITIES', array( - 'fcn_read_others_files', // Fictioneer - 'fcn_edit_others_files', // Fictioneer - 'fcn_delete_others_files', // Fictioneer + 'fcn_read_others_files', // Fictioneer + 'fcn_edit_others_files', // Fictioneer + 'fcn_delete_others_files', // Fictioneer 'fcn_select_page_template', // Fictioneer 'fcn_admin_profile_access', // Fictioneer - 'fcn_adminbar_access', // Fictioneer - 'fcn_dashboard_access', // Fictioneer - 'fcn_privacy_clearance', // Fictioneer - 'fcn_shortcodes', // Fictioneer - 'unfiltered_html', // Default - 'edit_users', // Default - 'add_users', // Default - 'create_users', // Default - 'delete_users' // Default + 'fcn_adminbar_access', // Fictioneer + 'fcn_dashboard_access', // Fictioneer + 'fcn_privacy_clearance', // Fictioneer + 'fcn_shortcodes', // Fictioneer + 'unfiltered_html', // Default + 'edit_users', // Default + 'add_users', // Default + 'create_users', // Default + 'delete_users' // Default ) ); +/** + * Initialize user roles with custom capabilities + * + * @since Fictioneer 5.6.0 + */ + function fictioneer_initialize_roles() { // Capabilities $all = array_merge( @@ -133,6 +139,7 @@ function fictioneer_initialize_roles() { // Moderator fictioneer_add_moderator_role(); + $moderator = get_role( 'fcn_moderator' ); $moderator_caps = array( // Base @@ -174,6 +181,28 @@ function fictioneer_initialize_roles() { } add_action( 'init', 'fictioneer_initialize_roles' ); +/** + * Add custom moderator role + * + * @since Fictioneer 5.0 + */ + +function fictioneer_add_moderator_role() { + return add_role( + 'fcn_moderator', + __( 'Moderator', 'fictioneer' ), + array( + 'read' => true, + 'edit_posts' => true, + 'edit_others_posts' => true, + 'edit_published_posts' => true, + 'moderate_comments' => true, + 'edit_comment' => true, + 'delete_posts' => false, + 'delete_others_posts' => false + ) + ); +} -- 2.47.1 From 06c5751e61bbf246df2d209a41e244af735b1bcc Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 10 Aug 2023 22:39:15 +0200 Subject: [PATCH 006/122] Apply fcn_adminbar_access cap --- includes/functions/_oauth.php | 1 - includes/functions/_roles.php | 13 ++++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/functions/_oauth.php b/includes/functions/_oauth.php index 9879b90c..8f8b8c8f 100644 --- a/includes/functions/_oauth.php +++ b/includes/functions/_oauth.php @@ -684,7 +684,6 @@ if ( ! function_exists( 'fictioneer_make_oauth_user' ) ) { // Nice name, and hide admin bar for new subscribers if ( $new ) { - update_user_meta( $wp_user->ID, 'show_admin_bar_front', false ); update_user_meta( $wp_user->ID, 'nickname', $args['nickname'] ); wp_update_user( array( 'ID' => $wp_user->ID, 'display_name' => $args['nickname'] ) ); } diff --git a/includes/functions/_roles.php b/includes/functions/_roles.php index ed383e13..aa647d1c 100644 --- a/includes/functions/_roles.php +++ b/includes/functions/_roles.php @@ -204,6 +204,18 @@ function fictioneer_add_moderator_role() { ); } +// ============================================================================= +// APPLY CAPABILITY RULES +// ============================================================================= + +/** + * Admin bar + */ + +if ( ! current_user_can( 'fcn_adminbar_access' ) ) { + add_filter( 'show_admin_bar', '__return_false' ); +} + @@ -279,7 +291,6 @@ function fictioneer_reduce_subscriber_admin_panel() { if ( fictioneer_has_role( get_current_user_id(), 'subscriber' ) ) { add_action( 'wp_dashboard_setup', 'fictioneer_reduce_subscriber_dashboard_widgets' ); add_action( 'admin_menu', 'fictioneer_reduce_subscriber_admin_panel' ); - add_filter( 'show_admin_bar', '__return_false' ); } // ============================================================================= -- 2.47.1 From 5891892d4a2c646e44203ea42339638da436fcff Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 10 Aug 2023 22:46:40 +0200 Subject: [PATCH 007/122] Apply fcn_admin_panel_access cap --- DEVELOPMENT.md | 2 +- includes/functions/_roles.php | 61 +++++++++---------- .../functions/settings/_register_settings.php | 7 --- .../settings/_settings_page_general.php | 8 --- 4 files changed, 30 insertions(+), 48 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index d016d5d2..32ecbe41 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -229,7 +229,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook | `edit_user_profile` | `fictioneer_custom_profile_fields` | `edit_user_profile_update` | `fictioneer_update_admin_user_profile`, `fictioneer_update_my_user_profile` | `get_header` | `fictioneer_maintenance_mode` -| `init` | `fictioneer_add_character_taxonomy`, `fictioneer_add_content_warning_taxonomy`, `fictioneer_add_epub_download_endpoint`, `fictioneer_add_fandom_taxonomy`, `fictioneer_add_genre_taxonomy`, `fictioneer_add_logout_endpoint`, `fictioneer_add_oauth2_endpoint`, `fictioneer_block_subscribers_from_admin`, `fictioneer_disable_heartbeat`, `fictioneer_fcn_chapter_post_type`, `fictioneer_fcn_collection_post_type`, `fictioneer_fcn_recommendation_post_type`, `fictioneer_fcn_story_post_type`, `fictioneer_modify_allowed_tags`, `fictioneer_story_rss` +| `init` | `fictioneer_add_character_taxonomy`, `fictioneer_add_content_warning_taxonomy`, `fictioneer_add_epub_download_endpoint`, `fictioneer_add_fandom_taxonomy`, `fictioneer_add_genre_taxonomy`, `fictioneer_add_logout_endpoint`, `fictioneer_add_oauth2_endpoint`, `fictioneer_prevent_admin_panel_access`, `fictioneer_disable_heartbeat`, `fictioneer_fcn_chapter_post_type`, `fictioneer_fcn_collection_post_type`, `fictioneer_fcn_recommendation_post_type`, `fictioneer_fcn_story_post_type`, `fictioneer_modify_allowed_tags`, `fictioneer_story_rss` | `kses_allowed_protocols` | `fictioneer_extend_allowed_protocols` | `login_form` | `fictioneer_after_logout_cleanup` | `manage_comments_custom_column` | `fictioneer_add_comments_report_column_content` diff --git a/includes/functions/_roles.php b/includes/functions/_roles.php index aa647d1c..dbd8f255 100644 --- a/includes/functions/_roles.php +++ b/includes/functions/_roles.php @@ -11,7 +11,7 @@ define( 'fcn_edit_others_files', // Fictioneer 'fcn_delete_others_files', // Fictioneer 'fcn_select_page_template', // Fictioneer - 'fcn_admin_profile_access', // Fictioneer + 'fcn_admin_panel_access', // Fictioneer 'fcn_adminbar_access', // Fictioneer 'fcn_dashboard_access', // Fictioneer 'fcn_privacy_clearance', // Fictioneer @@ -55,7 +55,7 @@ function fictioneer_initialize_roles() { 'fcn_read_others_media', 'fcn_edit_others_media', 'fcn_delete_others_media', - 'fcn_admin_profile_access', + 'fcn_admin_panel_access', 'fcn_adminbar_access', 'fcn_dashboard_access' ), @@ -73,7 +73,7 @@ function fictioneer_initialize_roles() { $author = get_role( 'author' ); $author_caps = array( // Base - 'fcn_admin_profile_access', + 'fcn_admin_panel_access', 'fcn_adminbar_access', // Stories 'read_fcn_story', @@ -113,7 +113,7 @@ function fictioneer_initialize_roles() { $contributor = get_role( 'contributor' ); $contributor_caps = array( // Base - 'fcn_admin_profile_access', + 'fcn_admin_panel_access', 'fcn_adminbar_access', // Stories 'read_fcn_story', @@ -143,7 +143,7 @@ function fictioneer_initialize_roles() { $moderator = get_role( 'fcn_moderator' ); $moderator_caps = array( // Base - 'fcn_admin_profile_access', + 'fcn_admin_panel_access', 'fcn_adminbar_access', // Stories 'read_fcn_story', @@ -163,7 +163,7 @@ function fictioneer_initialize_roles() { $subscriber = get_role( 'subscriber' ); $subscriber_caps = array( // Base - 'fcn_admin_profile_access', + 'fcn_admin_panel_access', // Stories 'read_fcn_story', // Chapters @@ -216,6 +216,29 @@ if ( ! current_user_can( 'fcn_adminbar_access' ) ) { add_filter( 'show_admin_bar', '__return_false' ); } +/** + * Prevent users from accessing the admin panel + * + * @since Fictioneer 5.6.0 + */ + +function fictioneer_prevent_admin_panel_access() { + // Redirect back to Home (but always allow administrators) + if ( + is_admin() && + ! current_user_can( 'manage_options' ) && + ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) + ) { + wp_redirect( home_url() ); + exit; + } +} + +if ( ! current_user_can( 'fcn_admin_panel_access' ) ) { + add_filter( 'init', 'fictioneer_prevent_admin_panel_access' ); +} + + @@ -231,32 +254,6 @@ if ( ! current_user_can( 'fcn_adminbar_access' ) ) { // RESTRICT SUBSCRIBERS ROLE // ============================================================================= -/** - * Prevent subscribers from accessing the admin panel - * - * Subscribers have a custom frontend user profile and therefore no need to - * access the admin panel at all. Only higher roles are granted access, although - * admin-specific actions such as AJAX requests are still permitted. - * - * @since Fictioneer 4.0 - */ - -function fictioneer_block_subscribers_from_admin() { - // Redirect back to Home - if ( - is_admin() && - ! current_user_can( 'edit_posts' ) && - ! current_user_can( 'moderate_comments' ) && - ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) - ) { - wp_redirect( home_url() ); - exit; - } -} - -if ( get_option( 'fictioneer_block_subscribers_from_admin' ) ) { - add_action( 'init', 'fictioneer_block_subscribers_from_admin' ); -} /** * Remove admin dashboard widgets for subscribers diff --git a/includes/functions/settings/_register_settings.php b/includes/functions/settings/_register_settings.php index 9cd757ff..2d52b641 100644 --- a/includes/functions/settings/_register_settings.php +++ b/includes/functions/settings/_register_settings.php @@ -306,13 +306,6 @@ define( 'FICTIONEER_OPTIONS', array( 'sanitize_callback' => 'fictioneer_sanitize_checkbox', 'label' => __( 'Do not save comment IP addresses', 'fictioneer' ), 'default' => false - ), - 'fictioneer_block_subscribers_from_admin' => array( - 'name' => 'fictioneer_block_subscribers_from_admin', - 'group' => 'fictioneer-settings-general-group', - 'sanitize_callback' => 'fictioneer_sanitize_checkbox', - 'label' => __( 'Block admin panel access for subscribers', 'fictioneer' ), - 'default' => false ), 'fictioneer_logout_redirects_home' => array( 'name' => 'fictioneer_logout_redirects_home', diff --git a/includes/functions/settings/_settings_page_general.php b/includes/functions/settings/_settings_page_general.php index 8e5685ae..9a6cc964 100644 --- a/includes/functions/settings/_settings_page_general.php +++ b/includes/functions/settings/_settings_page_general.php @@ -753,14 +753,6 @@ - - - - - - - - - - - - - - - -