The Definitive Guide to Setting Up WordPress in 2024: A Bristol Freelance Web Developer’s Essential Setup
In the ever-evolving landscape of website development, staying ahead of the curve...
To stop any page from being deleted by any user role, including admins, add the following code to your functions.php file.
Update the $post_id variable to the ID of the page or post you want to protect from deletion.
function prevent_views($allcaps, $caps, $args) {
$post_id = 6293;
if ( isset( $args[0] ) && isset( $args[2] ) && $args[2] == $post_id && $args[0] == 'delete_post' ) {
$allcaps[ $caps[0] ] = false;
}
return $allcaps;
}
add_filter ('user_has_cap', 'prevent_views', 10, 3);
Coding Tips, PHP, Wordpress, WordPress Tips
Share
In the ever-evolving landscape of website development, staying ahead of the curve...
In the digital realm, your website serves as the cornerstone of your...
In the ever-evolving world of e-commerce, having a robust and flexible platform...
A quick snipped of code that can be used attach a function to the escape key. Great for adding or...
In the ever-evolving landscape of website development, staying ahead of the curve is essential. As a freelance web developer based...
A useful bit of code to prevent files from being accessed (or hotlinked) in WordPress. Prevent files from being directly...