Restore author role

This commit is contained in:
Tetrakern 2023-08-11 12:17:15 +02:00
parent 610952f9be
commit 58b6955421
5 changed files with 7 additions and 88 deletions

View File

@ -217,7 +217,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `admin_init` | `fictioneer_reduce_subscriber_profile`, `fictioneer_register_settings`, `fictioneer_skip_dashboard`
| `admin_menu` | `fictioneer_add_admin_menu`, `fictioneer_remove_dashboard_menu`, `fictioneer_remove_comments_menu_page`
| `admin_notices` | `fictioneer_admin_profile_notices`, `fictioneer_admin_settings_notices`, `fictioneer_admin_update_notice`
| `admin_post_*` | `fictioneer_purge_all_epubs`, `admin_post_purge_all_seo_schemas`, `fictioneer_purge_seo_meta_caches`, `fictioneer_tools_add_moderator_role`, `fictioneer_tools_remove_moderator_role`, `fictioneer_tools_upgrade_author_role`, `fictioneer_tools_reset_author_role`, `fictioneer_tools_move_story_tags_to_genres`, `fictioneer_tools_duplicate_story_tags_to_genres`, `fictioneer_tools_purge_story_data_caches`, `fictioneer_tools_move_chapter_tags_to_genres`, `fictioneer_tools_duplicate_chapter_tags_to_genres`, `fictioneer_tools_append_default_genres`, `fictioneer_tools_append_default_tags`, `fictioneer_tools_remove_unused_tags`, `fictioneer_tools_reset_post_relationship_registry`, `fictioneer_tools_fix_users`, `fictioneer_tools_fix_stories`, `fictioneer_tools_fix_chapters`, `fictioneer_tools_fix_collections`, `fictioneer_tools_fix_pages`, `fictioneer_tools_fix_posts`, `fictioneer_tools_fix_recommendations`, `fictioneer_admin_profile_unset_oauth`, `fictioneer_admin_profile_clear_data_node`, `fictioneer_update_frontend_profile`, `fictioneer_cancel_frontend_email_change`
| `admin_post_*` | `fictioneer_purge_all_epubs`, `admin_post_purge_all_seo_schemas`, `fictioneer_purge_seo_meta_caches`, `fictioneer_tools_add_moderator_role`, `fictioneer_tools_remove_moderator_role`, `fictioneer_tools_move_story_tags_to_genres`, `fictioneer_tools_duplicate_story_tags_to_genres`, `fictioneer_tools_purge_story_data_caches`, `fictioneer_tools_move_chapter_tags_to_genres`, `fictioneer_tools_duplicate_chapter_tags_to_genres`, `fictioneer_tools_append_default_genres`, `fictioneer_tools_append_default_tags`, `fictioneer_tools_remove_unused_tags`, `fictioneer_tools_reset_post_relationship_registry`, `fictioneer_tools_fix_users`, `fictioneer_tools_fix_stories`, `fictioneer_tools_fix_chapters`, `fictioneer_tools_fix_collections`, `fictioneer_tools_fix_pages`, `fictioneer_tools_fix_posts`, `fictioneer_tools_fix_recommendations`, `fictioneer_admin_profile_unset_oauth`, `fictioneer_admin_profile_clear_data_node`, `fictioneer_update_frontend_profile`, `fictioneer_cancel_frontend_email_change`
| `after_setup_theme` | `fictioneer_theme_setup`
| `comment_post` | `fictioneer_comment_post`, `fictioneer_post_comment_to_discord`
| `current_screen` | , `fictioneer_restrict_admin_only_pages`, `fictioneer_restrict_comment_edit`

View File

@ -473,38 +473,4 @@ if ( ! function_exists( 'fictioneer_convert_taxonomies' ) ) {
}
}
// =============================================================================
// ROLE CUSTOMIZATION ACTIONS
// =============================================================================
/**
* Upgrade author role with additional capabilities
*
* @since Fictioneer 5.0
*/
function fictioneer_upgrade_author_role() {
$role = get_role( 'author' );
$role->add_cap( 'delete_pages' );
$role->add_cap( 'delete_published_pages' );
$role->add_cap( 'edit_pages' );
$role->add_cap( 'edit_published_pages' );
$role->add_cap( 'publish_pages' );
}
/**
* Reset author role to WordPress defaults
*
* @since Fictioneer 5.0
*/
function fictioneer_reset_author_role() {
$role = get_role( 'author' );
$role->remove_cap( 'delete_pages' );
$role->remove_cap( 'delete_published_pages' );
$role->remove_cap( 'edit_pages' );
$role->remove_cap( 'edit_published_pages' );
$role->remove_cap( 'publish_pages' );
}
?>

View File

@ -32,6 +32,7 @@ define(
function fictioneer_initialize_roles() {
// Capabilities
$legacy_removal = ['delete_pages', 'delete_published_pages', 'edit_pages', 'edit_published_pages', 'publish_pages'];
$all = array_merge(
FICTIONEER_BASE_CAPABILITIES,
FICTIONEER_STORY_CAPABILITIES,
@ -119,6 +120,10 @@ function fictioneer_initialize_roles() {
$author->add_cap( $cap );
}
foreach ( $legacy_removal as $cap ) {
$author->remove_cap( $cap ); // Legacy restore
}
// Contributor
$contributor = get_role( 'contributor' );
$contributor_caps = array(
@ -147,7 +152,7 @@ function fictioneer_initialize_roles() {
$contributor->add_cap( $cap );
}
foreach ( ['delete_pages', 'edit_pages', 'edit_published_pages'] as $cap ) {
foreach ( $legacy_removal as $cap ) {
$contributor->remove_cap( $cap ); // Legacy restore
}

View File

@ -94,10 +94,6 @@ if ( ! defined( 'FICTIONEER_ADMIN_SETTINGS_NOTICES' ) ) {
'fictioneer-added-moderator-role' => __( 'Moderator role has been added.', 'fictioneer' ),
'fictioneer-not-added-moderator-role' => __( 'Moderator role could not be added or already exists.', 'fictioneer' ),
'fictioneer-removed-moderator-role' => __( 'Moderator role has been removed.', 'fictioneer' ),
'fictioneer-upgraded-author-role' => __( 'Author role has been upgraded.', 'fictioneer' ),
'fictioneer-reset-author-role' => __( 'Author role has been reset.', 'fictioneer' ),
'fictioneer-upgraded-contributor-role' => __( 'Contributor role has been upgraded.', 'fictioneer' ),
'fictioneer-reset-contributor-role' => __( 'Contributor role has been reset.', 'fictioneer' ),
'fictioneer-reset-post-relationship-registry' => __( 'Post relationship registry reset.', 'fictioneer' ),
'fictioneer-fix-users' => __( 'This function does currently not cover any issues.', 'fictioneer' ),
'fictioneer-fix-stories' => __( 'This function does currently not cover any issues.', 'fictioneer' ),
@ -330,48 +326,6 @@ function fictioneer_tools_remove_moderator_role() {
}
add_action( 'admin_post_fictioneer_remove_moderator_role', 'fictioneer_tools_remove_moderator_role' );
/**
* Upgrade author role
*
* @since Fictioneer 5.2.5
*/
function fictioneer_tools_upgrade_author_role() {
// Verify request
fictioneer_verify_tool_action( 'fictioneer_upgrade_author_role' );
// Upgrade role
fictioneer_upgrade_author_role();
// Log
fictioneer_log( __( 'Author role upgraded.', 'fictioneer' ) );
// Finish
fictioneer_finish_tool_action( 'fictioneer-upgraded-author-role' );
}
add_action( 'admin_post_fictioneer_upgrade_author_role', 'fictioneer_tools_upgrade_author_role' );
/**
* Reset author role
*
* @since Fictioneer 5.2.5
*/
function fictioneer_tools_reset_author_role() {
// Verify request
fictioneer_verify_tool_action( 'fictioneer_reset_author_role' );
// Reset role
fictioneer_reset_author_role();
// Log
fictioneer_log( __( 'Author role reset.', 'fictioneer' ) );
// Finish
fictioneer_finish_tool_action( 'fictioneer-reset-author-role' );
}
add_action( 'admin_post_fictioneer_reset_author_role', 'fictioneer_tools_reset_author_role' );
/**
* Convert story tags to genres
*

View File

@ -25,12 +25,6 @@
<a class="button button--secondary" id="button-move-tags-to-genres" href="<?php echo fictioneer_tool_action( 'fictioneer_add_moderator_role' ); ?>"><?php _e( 'Add Moderator Role', 'fictioneer' ) ?></a>
<a class="button button--secondary" id="button-duplicate-tags-to-genres" href="<?php echo fictioneer_tool_action( 'fictioneer_remove_moderator_role' ); ?>"><?php _e( 'Remove Moderator Role', 'fictioneer' ) ?></a>
</div>
<hr>
<p class="description row"><?php _e( '<strong>Upgrade or reset author role.</strong> The default author role lacks the permissions to work with Fictioneers custom post types, which require page editing capabilities. You can amend this here for a multi-author website, or reset the permissions.', 'fictioneer' ) ?></p>
<div class="row flex gap-6">
<a class="button button--secondary" id="upgrade-author-role" href="<?php echo fictioneer_tool_action( 'fictioneer_upgrade_author_role' ); ?>"><?php _e( 'Upgrade Author Role', 'fictioneer' ) ?></a>
<a class="button button--secondary" id="reset-author-role" href="<?php echo fictioneer_tool_action( 'fictioneer_reset_author_role' ); ?>"><?php _e( 'Reset Author Role', 'fictioneer' ) ?></a>
</div>
</div>
</div>
</div>