2013-10-13 1 views
0

"Food"라는 워드 프레스에서 새로운 게시물 유형을 만들고이 게시물 유형에 새 게시물을 추가해야 내 사이트에 등록됩니다.Wordpress : 새로운 게시물 유형에 사용자 블록을 추가하는 방법

그래서 내 게시물 유형 "음식"에 새 게시물을 추가 할 때이 게시물을 어떤 사용자로 선택해야합니까?

어떻게 만들 수 있습니까? 내가 현재 당신이 :)

워드 프레스를 요구하는 일을하고 있습니다로

+1

질문이 명확하지 않다. 그것을 다시 말하려고 할 수 있습니까? 게시물 유형과 동일한 새 사용자를 만들고 싶습니까? 혹은 그 반대로도? –

+0

@Chris Herbert이 게시물을이 사용자에게 올리려면 내 사이트에 모든 사용자 등록 정보를 표시해야합니다.이 뉴스를 작성자에게 추가해야하는 뉴스를 추가 할 때 뉴스와 마찬가지로 – kamkam

+0

역할 또는 추가 권한이 있습니까? 사용자가 사용자 정의 게시 유형을 관리 할 수있는 기능을 제공하며이 사용자를 게시자 편집 화면의'authors' 메타 상자에 표시 하시겠습니까? – gwillie

답변

0

당신이 운이 오늘있어 thankx

author의 역할이 할당 된 사용자를 표시합니다. 기본적으로 authordiv 메타 박스를 제거하고 원래 authordiv과 동일한 HTML을 가진 다른 메타 박스를 추가하고 올바른 역할/기능을 가진 사용자를 찾고 선택을 작성해야합니다. 아래의 코드가 구현 된 것이므로 수정해야합니다. 사용자의 요구에 맞게 :

// add authordiv if user is admin or is allowed to change author of post !important 
global $current_user; 
if(in_array(array('administrator','change_post_author'), $current_user->allcaps)) 
    add_meta_box('authordiv', 'Change Author', 'my_add_author_metabox', get_post_type(), 'side'); 

// make new author metabox that contains users that can manage this cpt 
function my_add_author_metabox() 
{ 
    $post_type_name = isset($_GET['post_type']) ? $_GET['post_type'] : get_post_type($_GET['post']); 
    $roles = get_editable_roles(); 
    // i unset these as they are never used 
    unset(
    $roles['administrator'], 
    $roles['contributor'], 
    $roles['author'], 
    $roles['editor'], 
    $roles['subscriber'] 
); 

    // get role that manages this cpt 
    $cpt_name = ''; 
    $cap = 'edit_' . $post_type_name; 
    foreach($roles as $role_name => $args){ 
    if(array_key_exists($cap, $args['capabilities'])){ 
     $cpt_name = $role_name; 
     break; 
    } 
    } 

    // get users that can manage this cpt 
    global $post; 
    $users = get_users('role=' . $cpt_name); 
    $author_id = $post->post_author; 
    $select = ' 
<label class="screen-reader-text" for="post_author_override">Change Author</label> 
<select name="post_author_override" id="post_author_override" class=""> 
'; 
    foreach($users as $user){ 
    if($user->ID == $author_id) 
     $select .= "<option value=\"{$user->ID}\" selected=\"selected\">{$user->display_name}</option>"; 
    else 
     $select .= "<option value=\"{$user->ID}\">{$user->display_name}</option>"; 
    } 

    $select .= '</select>'; 
    echo $select; 

} 

지금 내 CPT에서 내가 지원 author을 해달라고하지만 다음 할 경우 register_post_type() 또는

remove_meta_box('authordiv'); 

희망이 당신을 위해 작동을 사용하는 경우 중 하나가 작동, supports에서 author을 제거 나를. 아마 거기에 더 나은, 그리고 만약 당신이 그것을 가로 질러 여기에 게시 :

관련 문제