Add and apply fcn_classic_editor cap

This commit is contained in:
Tetrakern 2023-08-19 20:35:58 +02:00
parent 54a57117c6
commit 17f78df3e7
3 changed files with 106 additions and 7 deletions

View File

@ -208,12 +208,15 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| WORDPRESS HOOK | FICTIONEER ACTIONS
| ---: | :--- |
| `add_meta_boxes` | `fictioneer_add_seo_metabox`
| `add_meta_boxes` | `fictioneer_add_seo_metabox`, `fictioneer_restrict_classic_metaboxes`
| `add_meta_boxes_comment` | `fictioneer_add_comment_meta_box`
| `admin_bar_menu` | `fictioneer_remove_comments_from_admin_bar`
| `admin_enqueue_scripts` | `fictioneer_admin_scripts`, `fictioneer_admin_styles`, `fictioneer_disable_moderator_comment_edit`, `fictioneer_hide_private_data`
| `admin_footer-post.php` | `fictioneer_classic_editor_js_restrictions`, `fictioneer_hide_permalink_with_js`
| `admin_footer-post-new.php` | `fictioneer_classic_editor_js_restrictions`
| `admin_head` | `fictioneer_remove_update_notice`, `fictioneer_hide_epub_inputs`, `fictioneer_hide_story_sticky_checkbox`
| `admin_head-post.php` | `fictioneer_hide_permalink`
| `admin_head-post.php` | `fictioneer_hide_permalink_with_css`, `fictioneer_classic_editor_css_restrictions`
| `admin_head-post-new.php` | `fictioneer_classic_editor_css_restrictions`
| `admin_head-profile.php` | `fictioneer_remove_profile_blocks`
| `admin_init` | `fictioneer_register_settings`, `fictioneer_skip_dashboard`, `fictioneer_initialize_roles`, `fictioneer_bring_out_legacy_trash`
| `admin_menu` | `fictioneer_add_admin_menu`, `fictioneer_remove_dashboard_menu`, `fictioneer_remove_comments_menu_page`, `fictioneer_remove_sub_menus`
@ -300,6 +303,7 @@ Fictioneer customizes WordPress by using as many standard action and filter hook
| `theme_templates` | `fictioneer_disallow_page_template_select`
| `update_post_metadata` | `fictioneer_prevent_page_template_update`
| `upload_size_limit` | `fictioneer_upload_size_limit`
| `use_block_editor_for_post_type` | `__return_false`
| `user_contactmethods` | `fictioneer_user_contact_methods`
| `user_has_cap` | `fictioneer_edit_only_comments`
| `wp_list_comments_args` | `fictioneer_comment_list_args`

View File

@ -1325,18 +1325,28 @@ if ( ! current_user_can( 'manage_options' ) ) {
}
/**
* Hide the permalink field
* Hide the permalink field with CSS
*
* @since 5.6.0
*/
function fictioneer_hide_permalink_with_css() {
echo '<style type="text/css">.edit-post-post-url, #edit-slug-buttons{display: none !important;}</style>';
}
function fictioneer_hide_permalink() {
echo '<style type="text/css">.edit-post-post-url{display: none !important;}</style>';
/**
* Hide the permalink field with JS
*
* @since 5.6.2
*/
function fictioneer_hide_permalink_with_js() {
echo '<script type="text/javascript">document.querySelectorAll("#edit-slug-buttons").forEach(element => {element.remove();});</script>';
}
if ( ! current_user_can( 'fcn_edit_permalink' ) ) {
add_action( 'admin_head-post.php', 'fictioneer_hide_permalink' );
add_action( 'admin_head-post.php', 'fictioneer_hide_permalink_with_css' );
add_action( 'admin_footer-post.php', 'fictioneer_hide_permalink_with_js' );
add_filter( 'wp_insert_post_data', 'fictioneer_prevent_permalink_edit', 99 );
}
@ -1372,6 +1382,90 @@ if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( 'fcn_edit_date' ) ) {
add_filter( 'wp_insert_post_data', 'fictioneer_prevent_publish_date_update', 1, 2 );
}
// === FCN_CLASSIC_EDITOR ====================================================
/**
* Inject CSS for the classic editor
*
* @since 5.6.2
*/
function fictioneer_classic_editor_css_restrictions() {
echo '<style type="text/css">.selectit[for="ping_status"], #add-new-comment {display: none !important;}</style>';
}
/**
* Inject javascript for the classic editor
*
* @since 5.6.2
*/
function fictioneer_classic_editor_js_restrictions() {
echo '<script type="text/javascript">document.querySelectorAll(".selectit[for=ping_status], #add-new-comment").forEach(element => {element.remove();});</script>';
}
/**
* Restrict metaboxes in the classic editor
*
* @since 5.6.2
*/
function fictioneer_restrict_classic_metaboxes() {
$post_types = ['post', 'page', 'fcn_story', 'fcn_chapter', 'fcn_collection', 'fcn_recommendation'];
// Trackbacks
remove_meta_box( 'trackbacksdiv', $post_types, 'normal' );
// Tags
if ( ! current_user_can( 'assign_post_tags' ) ) {
remove_meta_box( 'tagsdiv-post_tag', $post_types, 'side' );
}
// Categories
if ( ! current_user_can( 'assign_categories' ) ) {
remove_meta_box( 'categorydiv', $post_types, 'side' );
}
// Genres
if ( ! current_user_can( 'assign_fcn_genres' ) ) {
remove_meta_box( 'fcn_genrediv', $post_types, 'side' );
}
// Fandoms
if ( ! current_user_can( 'assign_fcn_fandoms' ) ) {
remove_meta_box( 'fcn_fandomdiv', $post_types, 'side' );
}
// Characters
if ( ! current_user_can( 'assign_fcn_characters' ) ) {
remove_meta_box( 'fcn_characterdiv', $post_types, 'side' );
}
// Content Warnings
if ( ! current_user_can( 'assign_fcn_content_warnings' ) ) {
remove_meta_box( 'fcn_content_warningdiv', $post_types, 'side' );
}
// Permalink
if ( ! current_user_can( 'fcn_edit_permalink' ) ) {
remove_meta_box( 'slugdiv', $post_types, 'normal' );
}
// Page template
if ( ! current_user_can( 'fcn_select_page_template' ) ) {
remove_meta_box( 'pageparentdiv', $post_types, 'side' );
}
}
if ( current_user_can( 'fcn_classic_editor' ) ) {
add_filter( 'use_block_editor_for_post_type', '__return_false' );
add_action( 'add_meta_boxes', 'fictioneer_restrict_classic_metaboxes' );
add_action( 'admin_head-post.php', 'fictioneer_classic_editor_css_restrictions' );
add_action( 'admin_head-post-new.php', 'fictioneer_classic_editor_css_restrictions' );
add_action( 'admin_footer-post.php', 'fictioneer_classic_editor_js_restrictions' );
add_action( 'admin_footer-post-new.php', 'fictioneer_classic_editor_js_restrictions' );
}
}
?>

View File

@ -44,7 +44,8 @@ $restrictions = array(
'fcn_reduced_profile',
'fcn_edit_only_others_comments',
'fcn_upload_limit',
'fcn_upload_restrictions'
'fcn_upload_restrictions',
'fcn_classic_editor'
);
$advanced_caps = array(