I think an elegant way to accomplish this would be to hook into map_meta_cap
and deny users as though they do not have the capability to edit the post. This should also gate any other potential work-arounds, such as modifying the post through the REST API or direct POSTing. As an added benefit, it will also take care of omitting the edit links such that you don’t need to include your current solution.
add_filter( 'map_meta_cap', 'wpse405452_restrict_global_post_editing', 10, 4 );
function wpse405452_restrict_global_post_editing( $caps, $cap, $user_id, $args ) {
if( $cap !== 'edit_post' )
return $caps;
$post_id = $args[0];
if( get_post_meta( $post_id, 'global_post', true ) )
$caps[] = 'do_not_allow';
return $caps;
}
An introduction to roles & capabilities can be found in the Plugin Developer Handbook
Related Posts:
- Update post counts (published, draft, unattached) in admin interface
- How to publish a post with empty title and empty content?
- How to add a “publish” link to the quick actions
- how “manage_posts_custom_column” action hook relate to “manage_${post_type}_columns” filter hook?
- the_posts filter been called multiple time
- How can i do something after head like adding a hook for after head but before post
- How to generate numbers indistinguishable for the IDs of the posts
- Exists filter or action that change Add New Post link?
- the wp_post_update isn’t working all the time
- Is it possible to completely replace a post with an action/filter?
- Modify upload directory to use post category slug in file path on multisite installation
- Is there a action hook for the “Empty Trash” button?
- Apply the_title() filter in post & page title, but not in menu title
- Function to execute when a post is moved to trash .
- add action only on post publish – not update
- Removing any and all inline styles from the_content()
- How to validate XML-RPC post creation and cancel when needed?
- Removing filter dropdown in posts table (in this case Yoast SEO)
- Get old values for post before saving new ones
- Create posts on user registration
- How does filter the_posts work?
- Action hook ‘wp’ firing twice… why?
- Why is wordpress removing some unicode characters (e.g. some emojis) when I save my post?
- Count singular post views automatically
- how to display post content without post image?
- Exclude category on blog list page
- How to remove_filter that filters iframes in posts? [duplicate]
- Remove Posts Quick Edit link for specific user role? WP 3.3
- Filter posts by author and category simultaneously
- Filter post before *editing*
- Filter/Remove HTML Elements on all posts and pages
- Get the post_id of a new post
- Custom function for “Submit for Review” hook
- How to filter content post only on save
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- If specific user role then sticky post
- add_action not using ‘delete_post’ action with wp_delete_post
- Getting post id from wp_insert_post_data function?
- Filter Posts By Tag
- Get post id in wordpress action?
- Custom excerpt length filter doesn’t work
- Only display posts after current date
- How to run a function when post is edited or updated using publish post action?
- Amend wordpress password function
- Custom Post Templates
- Create cron job without a plugin?
- How can I remove posts of a certain category from homepage after a specified time period?
- Modify WP_Post before processing
- How to filter posts that belong to a specific category only if that is the only category
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Filter Custom Post Type by Category with Ajax
- Ajax posts filter by date, comments, top views, top likes
- How to add Tags Filter in wordpress admin dashboard
- pre_get_posts query between 2 dates (date stored in custom post meta)
- Applying $posts_clauses filter to specific queries only
- how to remove dash (-) post status from post title on posts listing page wordpress
- Admin Posts Table Column Fitlering is not working for Custom Post Type
- Get latest posts from WordPress site without header, menu and sidebar
- Modify Image Source With The_Content Filter?
- What is the filter or hook to add admin controls to posts on the front end?
- Change post order random through out the entire WordPress
- Adding custom fields to bbpress reply form
- Adding buttons to Add New Post and Add New Page
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- How to hide html tags on revision comparison pages?
- Add filter by custom field to block of posts
- Ajax post filters not working
- Default to ‘all’ view on the ‘edit-post’ screen for authors
- Display Meta Values in Custom Filter – Admin Custom Posts
- How to filter my search in post if contains a word in title, content or excerpt?
- More then one menu items are assigned with “current-menu-item” class
- Update post_content everytime a custom post is opened in backend
- How to access $post from a callback function
- Posts and Attachments with “Published” status in Search
- Permission issue with custom post type – not added to menu – by plugin
- Set static page/post from another blog on same network
- How to allow visitors to filter posts by multiple taxonomies
- Copy post to separate database with “add_action(….)”
- Trying to alter the post_content through the_post
- Call Web Services on post first publish
- Create new custom post and post category of same name
- How to check if single.php has already called the_post_thumbnail function
- add to end of post in the loop with plugin
- Add filter to the end of the post
- Get post content with all filters applied, knowing post id
- What does WordPress do if I save a post without content/title? [duplicate]
- Adding bootstrap classes to video shortcodes
- Is it possible to filter the main loop to exclude posts from a specific category?
- query post limits
- Divs appearing everywhere in post content
- Modify posts listing at back end
- Filtering posts on Post Administration Page by Week Number instead of by Month
- How to check in functions.php if there is data in a WP_Query?
- Change the default blog post post attribute template name from “default template” to something else
- Hook for changing excerpt content when excerpt not set
- Is it possible to add a shortcode below post title?
- Post filtering is returning blank page
- Update post meta within save_post action
- Automatically set post_parent value
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts