2014-01-08 43 views

回答

6

你可以嘗試這樣的事情。

/** 
* Allow access to own content only 
*/ 
function my_authored_content($query) { 

//get current user info to see if they are allowed to access ANY posts and pages 
$current_user = wp_get_current_user(); 
// set current user to $is_user 
$is_user = $current_user->user_login; 

//if is admin or 'is_user' does not equal #username 
if (!current_user_can('manage_options')){ 
    //if in the admin panel 
    if($query->is_admin) { 

     global $user_ID; 
     $query->set('author', $user_ID); 

    } 
    return $query; 
} 
return $query; 
} 
add_filter('pre_get_posts', 'my_authored_content'); 

這隻會讓管理員和作者看到內容。

您可以將其添加到主要功能文件或將其變成插件。

+0

謝謝,這真棒:),其工作完全正常。我是新的WP,如果可能的話,你可以指導我如何使這個插件。 –

2

將其創建爲一個插件:

  1. 創建一個新的文件
  2. 從這裏添加代碼:將它保存http://pastebin.com/rfMLM0BU
  3. 爲我的創作,content.php
  4. 上傳到你的插件目錄。

希望這可以幫助你! :-)

0

適合我這樣的:

function mymo_parse_query_useronly($wp_query) { 
    if(isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'attachment'){ 
    if (!current_user_can('level_5')) { 
     $wp_query->set('author', get_current_user_id()); 
    } 
    } 
} 
add_filter('parse_query', 'mymo_parse_query_useronly'); 

我在前端用這個上傳資料圖片爲用戶配置