{"id":11109,"date":"2024-08-13T14:48:12","date_gmt":"2024-08-13T11:48:12","guid":{"rendered":"https:\/\/creativethemes.com\/blocksy\/?post_type=documentation&#038;p=11109"},"modified":"2024-08-15T15:25:48","modified_gmt":"2024-08-15T12:25:48","slug":"change-access-to-certain-features-per-user-role","status":"publish","type":"documentation","link":"https:\/\/creativethemes.com\/blocksy\/docs\/code-snippets\/change-access-to-certain-features-per-user-role\/","title":{"rendered":"Change access to certain features per user role"},"content":{"rendered":"\n<p>By default, managing the options of most features from Blocksy are locked to users who have administrative rights. This is to protect against various abuse cases that could arise. By default, most of the features default to requiring the <code>manage_options<\/code> capability from the user that tries to make changes.<\/p>\n\n\n\n<p>With the <code>blocksy:capabilities:wp_capability<\/code> we are introducing a way to make changes in that process. The filter allows changing the capability for multiple places (called scopes) and it allows you to target individual instances within the scope (that said, you can target one specific custom post type if you want or just all at once).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Places where the filter is supported right now<\/h4>\n\n\n\n<p>The following table will show all of the supported scopes and their respective default values.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Scope<\/th><th>Default Value<\/th><\/tr><\/thead><tbody><tr><td><strong>Content Blocks<\/strong><br>Scope: <code>custom_post_type<\/code><br>Scope details: <code>['post_type' =&gt; 'ct_content_block']<\/code><\/td><td><code>manage_options<\/code><\/td><\/tr><tr><td><strong>Thank You Pages<\/strong><br>Scope: <code>custom_post_type<\/code><br>Scope details: <code>['post_type' =&gt; 'ct_thank_you_page']<\/code><\/td><td><code>manage_options<\/code><\/td><\/tr><tr><td><strong>Product Tabs<\/strong><br>Scope: <code>custom_post_type<\/code><br>Scope details: <code>['post_type' =&gt; 'ct_product_tab']<\/code><\/td><td><code>manage_options<\/code><\/td><\/tr><tr><td><strong>Size Guides<\/strong><br>Scope: <code>custom_post_type<\/code><br>Scope details: <code>['post_type' =&gt; 'ct_size_guide']<\/code><\/td><td><code>manage_options<\/code><\/td><\/tr><tr><td><strong>Size Guides<\/strong><br>Scope: <code>conditions<\/code><br>Scope details: <code>[]<\/code><\/td><td><code>manage_options<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Example usage. By knowing the <code>$scope<\/code> and <code>$scope_details<\/code> you can change the capability in a very targeted fashion.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter(\n\t'blocksy:capabilities:wp_capability',\n\tfunction ($capability, $scope, $scope_details) {\n\t\tif ($scope === 'custom_post_type') {\n\t\t\tif (\n\t\t\t\t$scope_details&#91;'post_type'] === 'ct_content_block'\n\t\t\t\t||\n\t\t\t\t$scope_details&#91;'post_type'] === 'ct_product_tab'\n\t\t\t) {\n\t\t\t\treturn 'shop_manager';\n\t\t\t}\n\t\t}\n\n\t\treturn $capability;\n\t},\n\t10,\n\t3\n);<\/code><\/pre>\n\n\n\n<p>This specific example permits editing of Content Blocks and Custom Tabs post types by a user that has the <code>shop_manager<\/code> capability.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By default, managing the options of most features from Blocksy are locked to users who have administrative rights. This is to protect against various abuse cases that could arise. By default, most of the features default to requiring the manage_options capability from the user that tries to make changes. With the blocksy:capabilities:wp_capability we are introducing [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"doc_categories":[125],"class_list":["post-11109","documentation","type-documentation","status-publish","hentry","doc_categories-code-snippets"],"blocksy_meta":[],"acf":[],"_links":{"self":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/11109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/types\/documentation"}],"author":[{"embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/comments?post=11109"}],"version-history":[{"count":6,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/11109\/revisions"}],"predecessor-version":[{"id":11119,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/documentation\/11109\/revisions\/11119"}],"wp:attachment":[{"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/media?parent=11109"}],"wp:term":[{"taxonomy":"doc_categories","embeddable":true,"href":"https:\/\/creativethemes.com\/blocksy\/wp-json\/wp\/v2\/doc_categories?post=11109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}