Skip to content

Instantly share code, notes, and snippets.

@wpeasy
Created March 19, 2025 08:09
Show Gist options
  • Save wpeasy/7cdd536abc6856dcb5e224398ec12406 to your computer and use it in GitHub Desktop.
Save wpeasy/7cdd536abc6856dcb5e224398ec12406 to your computer and use it in GitHub Desktop.
Disable access to Bricks Templates for non Admininistrators
<?php
function wpe_restrict_bricks_template_access()
{
if (!current_user_can("administrator")) {
// Prevent access to editing bricks_template
add_filter(
"user_has_cap",
function ($allcaps, $caps, $args) {
$post_type = get_post_type($args[2] ?? 0);
if ($post_type === "bricks_template") {
foreach ($caps as $cap) {
if (isset($allcaps[$cap])) {
$allcaps[$cap] = false;
}
}
}
return $allcaps;
},10,3);
}
}
add_action("admin_init", "wpe_restrict_bricks_template_access", 999); // Ensure Bricks is initialized first
function wpe_remove_bricks_template_menu()
{
global $submenu;
// Remove bricks_template from admin menu after Bricks has initialized
remove_submenu_page('bricks', 'edit.php?post_type=bricks_template');
BugFu::log($submenu);
}
add_action('admin_menu', 'wpe_remove_bricks_template_menu',999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment