2

Is it possible to 'filter' which pages are shown in the 'edit' screen for pages ( http://cl.ly/6nLC ) in Wordpress? I have looked in the action / hook section of Wordpress for plugin developers but I could not find any.

What I am trying to accomplish is is that certain users can edit certain pages (and child pages) and other persons cannot edit those pages but might be able to edit other pages.

I have allready written a plugin which makes it possible to put different users in differtent groups, which now just needs to have different rights, which user is member of which group is stored in the user_meta table.

However if there is 'any' filter hook / method for this, can someone point this out, I think I will be able to go further from there.

Kind regards.

4

1 回答 1

5

您可以使用posts_where过滤器向 SQL 查询添加条件以过滤掉某些页面。load-{filename}可以使用操作来确保仅在管理页面时应用过滤器。

add_action('load-edit.php', 'my_load_edit_php_action');
function my_load_edit_php_action() {
  if ($_GET['post_type'] !== 'page') return;
  add_filter('posts_where', 'my_posts_where_filter');
}

function my_posts_where_filter($sql) {
  if (current_user_can('your_capability')) {
    global $wpdb;
    $sql = " AND $wpdb->posts.ID NOT IN (1,2,3)" . $sql;
  }
  return $sql;
}
于 2011-05-16T01:24:59.873 回答