Created
March 19, 2025 08:09
-
-
Save wpeasy/7cdd536abc6856dcb5e224398ec12406 to your computer and use it in GitHub Desktop.
Disable access to Bricks Templates for non Admininistrators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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