Hello @bill_hodgson,
Thank you for your thoughs.
Which other elements are you referring to? As requested, the code should unregister all prefab elements and leave the Section, Div, Row, Col, and Components for the editor role. We updated the code to remove all remaining prefab elements.
add_action('cs_register_prefab_elements', function() {
if (!is_user_logged_in()) {
return;
}
$user = wp_get_current_user();
$roles = (array) $user->roles;
if (!in_array('editor', $roles)) {
return;
}
$elements_to_unregister = [
['group' => 'post', 'element' => 'terms-cloud'],
['group' => 'post', 'element' => 'terms-minimal'],
['group' => 'post', 'element' => 'terms-column'],
['group' => 'post', 'element' => 'posts-tiles'],
['group' => 'post', 'element' => 'posts-minimal'],
['group' => 'post', 'element' => 'posts-list'],
['group' => 'post', 'element' => 'posts-magazine'],
['group' => 'post', 'element' => 'author-horizontal'],
['group' => 'post', 'element' => 'author-vertical'],
['group' => 'post', 'element' => 'meta-line'],
['group' => 'dynamic', 'element' => 'looper-list-baseline'],
['group' => 'dynamic', 'element' => 'looper-list-centered'],
['group' => 'content', 'element' => 'static-list-baseline'],
['group' => 'content', 'element' => 'static-list-centered'],
['group' => 'interactive', 'element' => 'link-box'],
['group' => 'layout', 'element' => 'h-flex'],
['group' => 'layout', 'element' => 'v-flex'],
['group' => 'layout', 'element' => 'layout-div-global-margin'],
['group' => 'slider', 'element' => 'slider-inline'],
['group' => 'slider', 'element' => 'slide-navigation'],
['group' => 'slider', 'element' => 'slider-stacked'],
['group' => 'woocommerce', 'element' => 'product-long-description'],
['group' => 'navigation', 'element' => 'breadcrumb-elements'],
];
foreach ($elements_to_unregister as $element) {
cs_unregister_prefab_element($element['group'], $element['element']);
}
}, 10);
Result:
We might need another hook to remove the Breadcrumbs element, but overall, the modification above should be enough to control the visibility of elements for a specific user role.
Best regards.