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?
- 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()
- Action hook ‘wp’ firing twice… why?
- how to display post content without post image?
- Exclude category on blog list page
- How to remove_filter that filters iframes in posts? [duplicate]
- Filter posts by author and category simultaneously
- 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 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?
- Get post id in wordpress action?
- Only display posts after current date
- How to run a function when post is edited or updated using publish post action?
- 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
- 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
- What is the filter or hook to add admin controls to posts on the front end?
- Adding custom fields to bbpress reply form
- Adding buttons to Add New Post and Add New Page
- How to hide html tags on revision comparison pages?
- Ajax post filters not working
- 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
- Posts and Attachments with “Published” status in Search
- Permission issue with custom post type – not added to menu – by plugin
- Copy post to separate database with “add_action(….)”
- Trying to alter the post_content through the_post
- 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
- Adding bootstrap classes to video shortcodes
- query post limits
- 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
- 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
- How include css class based on post ( in loop ) slug?
- wp_list_categories() Exclude All Categories Except One
- Get current taxonomy and display query accordingly
- Show only posts with titles/permalinks that do not contain certain words
- How do I display main query posts in random order using add_filter
- Rewrite image links from attachment id to attachment link
- Is there a way to know when a page has been updated and do some action only once?
- Filter posts by month (dropdown)
- Restricting displayed posts to posts from only select authors
- Run a function when a custom post is update?
- Send email to user when I publish a new post
- How to add a custom class attribute into code wrapper? [duplicate]
- Is update_post_meta used when save_post action hook is invoked?
- Filtering private Posts
- how to filter posts by category without page load (ajax) in wordpress?
- Remove status ‘archived’ from the default post and page view
- Dropdown Select Post Filter
- long-title posts do not want published
- How to add a block to a category page?
- Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
- How do i search post by jquery datepicker?
- Add id attribute to h1 element of wordpress post
- How can i take all ids from untrash_post action?
- Filter question list on substring of metavalue
- Add review box by function at top or bottom of content
- Get results from the main wp_query
- Admin Post List Only Show One Category
- How to modify specific parts of a post content in WordPress
- Authors can edit all posts, except when an owner is specified?
- wp_query posts sorting doesn’t work
- Action while post is being published
- Do anything on post_status change [duplicate]
- Filters do not work when there are multiple (one works)