2017-03-02 14 views
0

私はかなり新しいWordPressです。カスタム機能を作成してカスタムロールに割り当てようとしていますが、私は立ち往生しています。wordpressカスタムユーザーの機能とロール

これは私が持っているものですが、私が手にプラグイン内の関数を呼び出すには、「致命的なエラー:)(未定義の関数add_capに呼び出し」:

function setupCapabilities() { 
    //create custom capabilities 
    add_cap('view_all_holds'); 
    add_cap('view_advertiser_lockouts'); 
    add_cap('view_overages'); 
    add_cap('view_all_booked'); 
    add_cap('create_makegood_order'); 
    add_cap('edit_reports'); 

    //array for custom admin capabilities 
    $adminCaps = array(
     'view_all_holds' => true, 
     'view_advertiser_lockouts' => true, 
     'view_overages' => true, 
     'view_all_booked' => true, 
     'create_makegood_order' => true, 
     'edit_reports' => true 
    ); 

    //create new role with custom capabilities 
    add_role('bam_admin', 'BAM Administrator', $adminCaps); 

    //get user id 
    $userID = get_current_user_id(); 

    //if the user id is me then add new role 
    if ($userID == 46) { //me 
     $user = new WP_User($userID); 
     $user->add_role('bam_admin'); 
    } 

    //check if the role was successfully applied 
    if (in_array('bam_admin', (array) $userID->roles)) { 
     echo 'You have succesfully created and checked a role.'; 
    } else { 
     echo 'Something messed up'; 
    } 


} 

答えて

0

私は同じのために私が持っている私のコードを掲載します。

function add_capability() 
{ 
    $role = get_role('players'); //user role 

    $rolePerms = array('player_image','player_video'); //post types perms 

    foreach($rolePerms as $rolePerm) { 

     $role->add_cap('publish_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('edit_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('delete_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('edit_published_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('delete_published_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('edit_others_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('delete_others_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('read_private_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('edit_private_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('delete_private_'.$rolePerm); // add ,false to remove the perm 
     $role->add_cap('manage_categories_'.$rolePerm); // add ,false to remove the perm 

    } 

} 
add_action('admin_init', 'add_capability'); 

はので、私はあなたがfollowiを使用することができます

'capability_type'  => 'player_image'´ 
0

私post_type機能にパーマを追加する必要がありました役割のプラグインは&です。

Click here

関連する問題