2013-05-06 28 views
1

我正在开发一个带有Edit Flow插件的Wordpress网站,因此我可以创建自定义发布状态以更轻松地管理作者和撰稿人帖子。Wordpress限制编辑,但允许预览自定义发布状态

所以我已经创建了自定义发布状态,并且我有以下过滤器来限制该帖子的编辑功能。它工作正常,但问题是用户(除管理员)无法预览帖子。其他用户仍然可以看到仪表板后列表中的“预览”链接,但如果他们点击它,并转到发布预览页面(../post-with-custom-status/?preview=true)它说,后可以”不被发现。

function restrict_edit_custom_status_posts($allcaps, $cap, $args) { 

    // Bail out if we're not asking to edit a post ... 
    if('edit_post' != $args[0] 
     // ... or user is admin 
     || !empty($allcaps['manage_options']) 
     // ... or user already cannot edit the post 
     || empty($allcaps['edit_posts'])) 
     return $allcaps; 

    // Load the post data: 
    $post = get_post($args[2]); 

    // If post have custom status 
    if('my_custom_status' == $post->post_status) { 
    // Then disallow editing 
    $allcaps["edit_posts"] = FALSE; 
     return $allcaps; 
    } 

    return $allcaps; 
} 

add_filter('user_has_cap', restrict_edit_custom_status_posts10, 3); 

那么有什么办法可以限制编辑功能,但允许预览?

+1

[重复的问题在WPSE上](http://wordpress.stackexchange.com/questions/98505/restrict-edit-but-allow-preview-for-custom-post-status)。 – montrealist 2013-05-06 14:55:28

+4

无限循环评论。 – Magicode 2013-08-19 14:01:16

回答

1

您可以使用“posts_results”过滤器仅用于预览和管理与良好的作用,以“改变”您的文章状态“发布”:(更换不会被保存)

add_filter('posts_results', array(get_class(), 'change_post'), 10, 2); 

public static function change_post($posts) { 


    if (empty($posts)) { 
     return; 
    } 

    if(!empty($_GET['preview'])){ 

     if($_GET['preview'] == true){ 
      if(current_user_can('preview_your_post_type')){ 
       $post_id = $posts[0]->ID; 
       $post_type = $posts[0]->post_type; 
       $posts[0]->post_status = 'publish'; 
      } 
     } 
    } 

    return $posts; 
} 
相关问题