How to lock a post or page

How to lock a post or page from editing or deleting but can be viewed on site? I am not able to lock a post, I read several articles but can’t find my answer.

Any help?

Related posts

2 comments

  1. You can use the 'wp_insert_post_data' filter to set the data being updated to the ones post has right now:

    add_filter('wp_insert_post_data', 'prevent_post_edit', 99, 2);
    
    prevent_post_edit ($data, $postarr) {
      if ( ! isset($postarr['ID']) || empty($postarr['ID']) ) return $data;
      if ( current_user_can('edit_files') ) return $data; // admin can edit posts
      // prevent the update only for post and pages, change this according to tour needs
      $prevent_types = array('post', 'page');
      if ( ! in_array($data['post_type'], $prevent_types) ) return data;
      // get the post how is before the update
      $old = get_post($postarr[ID]);
      return get_object_vars($old);
    }
    
  2. Try Role Scoper plugin.

    Users of any level can be elevated to read or edit content of your
    choice. Restricted content can be withheld from users lacking a
    content-specific role, regardless of their WP role.

    Edit: Also there is Members Plugin that has content-level pemissions.

Comments are closed.