filters – Prevent posts with certain post_meta to be edited


So I am looking at adding some custom post_meta to posts and I want those posts to not be editable, which will be some content that I am pulling in.

Here is what I have:

I have solved the issues when visiting the Post post_type and attempting to edit a post with a specific post_meta using this (This works great in the UI):

add_filter('post_row_actions', function($actions, $post) {
    if (get_post_meta($post->ID, 'global_post', true)) {
        unset($actions['inline hide-if-no-js']);

    return $actions;
}, 10, 2);

The above hides the “edit” and “quick edit” buttons for posts with specific post_meta in the UI.

However, when visiting the edit link directly (Example: – I was still able to edit the post.

Is there a way that I can prevent a post from being edited when visiting a link directly? I was able to successfully hide the buttons in the UI, but this would also be helpful.

Sem 2 years 2022-05-05T13:25:01-05:00 0 Answers 0 views 0

Leave an answer