From 99bae4b6d5c10cda2433f60e0facbcd869d7264d Mon Sep 17 00:00:00 2001 From: jorge-vitrubio Date: Wed, 30 Mar 2022 18:36:20 +0200 Subject: [PATCH] capabilities properly added to plugin. --- arcHIVE-wp-plugin.php | 2 + .../arcHIVE-custom-post-type-resources.php | 55 ++++++++++++------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/arcHIVE-wp-plugin.php b/arcHIVE-wp-plugin.php index 5d1d927..ba7c688 100644 --- a/arcHIVE-wp-plugin.php +++ b/arcHIVE-wp-plugin.php @@ -56,7 +56,9 @@ include( ARCHIVE_WPPLUGIN_PATH . 'includes/arcHIVE-init-textdomain.php'); include( ARCHIVE_WPPLUGIN_PATH . 'includes/arcHIVE-enable-svg.php'); + // disabled for now +// include( ARCHIVE_WPPLUGIN_PATH . 'includes/arcHIVE-delete-capabilities.php'); // include_once( ARCHIVE_WPPLUGIN_PATH . 'includes/arcHIVE-add-roles.php'); if ( is_admin() ) { diff --git a/includes/arcHIVE-custom-post-type-resources.php b/includes/arcHIVE-custom-post-type-resources.php index f939c12..cd1ef63 100644 --- a/includes/arcHIVE-custom-post-type-resources.php +++ b/includes/arcHIVE-custom-post-type-resources.php @@ -52,17 +52,15 @@ // https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types#108375 // https://developer.wordpress.org/reference/functions/register_post_type/#capability_type $capabilities = array( - 'read' => 'read_archive_resource', - 'publish_posts' => 'publish_archive_resources', - 'edit_posts' => 'edit_archive_resources', - 'edit_published_posts' => 'edit_archive_published_resources', - 'edit_others_posts' => 'edit_other_archive_resources', - 'delete_posts' => 'delete_archive_resources', - 'delete_published_posts' => 'delete_archive_published_resources', - 'delete_others_posts' => 'delete_archive_others_resources', - 'delete_private_posts' => 'delete_archive_private_resources', - 'upload_files' => 'upload_media_files', - 'manage_categories' => 'manage_archive_resources_types', + 'read' => 'archive_read_resource', + 'publish_posts' => 'archive_publish_resources', + 'edit_posts' => 'archive_edit_resources', + 'edit_published_posts' => 'archive_edit_published_resources', + 'edit_others_posts' => 'archive_edit_other_resources', + 'delete_posts' => 'archive_delete_resources', + 'delete_published_posts' => 'archive_delete_published_resources', + 'delete_others_posts' => 'archive_delete_others_resources', + // 'delete_private_posts' => 'archive_delete_private_resources', ); $args = array( 'label' => __( 'archive_resource', 'text_domain' ), @@ -112,6 +110,7 @@ add_action( 'admin_init', 'archive_wpplugin_add_caps'); * Start custom taxonomies * ---------------------------------------------------------------------------- * https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/ + * https://developer.wordpress.org/reference/functions/register_taxonomy/ */ // Register Custom Taxonomy Category for Resources @@ -137,15 +136,24 @@ add_action( 'admin_init', 'archive_wpplugin_add_caps'); $rewrite = array( 'slug' => 'resource-type', ); + $capabilities = array( + 'manage_terms' => 'archive_manage_resources_types', + 'edit_terms' => 'archive_edit_resources_types', + 'delete_terms' => 'archive_delete_resources_types', + 'assign_terms' => 'archive_assign_resources_types', + ); $args = array( - 'labels' => $labels, - 'hierarchical' => true, - 'public' => true, - 'show_ui' => true, - 'show_admin_column' => true, - 'show_in_nav_menus' => true, - 'show_tagcloud' => false, - 'rewrite' => $rewrite, + 'labels' => $labels, + 'hierarchical' => true, + 'public' => true, + 'show_ui' => true, + 'show_admin_column' => true, + 'show_in_nav_menus' => true, + 'show_tagcloud' => false, + 'rewrite' => $rewrite, + 'capabilities' => $capabilities, + 'map_meta_cap' => true //neded to apply the new capabilities. + ); register_taxonomy( 'archive_resource_category', array( 'archive_resource' ) , $args ); } @@ -177,6 +185,13 @@ add_action( 'admin_init', 'archive_wpplugin_add_caps'); 'slug' => 'resource-tag', // 'with_front' => false, ); + $capabilities = array( + 'manage_terms' => 'archive_manage_resources_tag', + 'edit_terms' => 'archive_edit_resources_tag', + 'delete_terms' => 'archive_delete_resources_tag', + 'assign_terms' => 'archive_assign_resources_tag', + ); + $args = array( 'labels' => $labels, 'hierarchical' => false, @@ -186,6 +201,8 @@ add_action( 'admin_init', 'archive_wpplugin_add_caps'); 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'rewrite' => $rewrite, + 'capabilities' => $capabilities, + 'map_meta_cap' => true //neded to apply the new capabilities. ); register_taxonomy( 'archive_resource_tag', array( 'archive_resource' ) , $args ); }