角色功能删除多个岗位类型的帖子不起作用

时间:2015-05-04 作者:Robbert

我正在创建一个名为“销售”的新角色,我在其中添加了功能,因此销售人员只能在管理面板中阅读、编辑和删除潜在客户。

一切正常,只是我不能选择多个潜在客户(帖子)并一次删除它们。我添加了“delete\\u lead”和“delete\\u lead”功能,因此我认为这应该是可行的。

// Create sales role
add_role( \'sales\', __( \'Sales\', \'gtp_translate\' ) );

// Add sales capabilities to sales
$roles = array( \'sales\', \'editor\', \'administrator\' );
foreach( $roles as $the_role ) {
    // Get role object by role name
    $role = get_role( $the_role );
    // Add capabilities to this role
    $role->add_cap( \'edit_lead\' );
    $role->add_cap( \'read_lead\' );  
    $role->add_cap( \'delete_lead\' );
    $role->add_cap( \'edit_others_leads\' );
    $role->add_cap( \'publish_leads\' );
    $role->add_cap( \'edit_leads\' );
    $role->add_cap( \'read_private_leads\' );
    $role->add_cap( \'delete_leads\' );
    $role->add_cap( \'delete_private_leads\' );
    $role->add_cap( \'delete_published_leads\' );
    $role->add_cap( \'delete_others_leads\' );
    $role->add_cap( \'edit_private_leads\' );
    $role->add_cap( \'edit_published_leads\' );
}  
通常情况下,您的帖子类型操作下拉列表应该与图像相似,但“移至垃圾箱”现在不存在。

enter image description here

My Leads custom post type

// Leads
$labels = array(
    \'name\'                => _x( \'Leads\', \'Post Type General Name\', \'gtp_translate\' ),
    \'singular_name\'       => _x( \'Lead\', \'Post Type Singular Name\', \'gtp_translate\' ),
    \'menu_name\'           => __( \'Leads\', \'gtp_translate\' ),
    \'parent_item_colon\'   => __( \'Parent Lead:\', \'gtp_translate\' ),
    \'all_items\'           => __( \'All Leads\', \'gtp_translate\' ),
    \'view_item\'           => __( \'View Lead\', \'gtp_translate\' ),
    \'add_new_item\'        => __( \'Add New Lead\', \'gtp_translate\' ),
    \'add_new\'             => __( \'Add New\', \'gtp_translate\' ),
    \'edit_item\'           => __( \'Edit Lead\', \'gtp_translate\' ),
    \'update_item\'         => __( \'Update Lead\', \'gtp_translate\' ),
    \'search_items\'        => __( \'Search Leads\', \'gtp_translate\' ),
    \'not_found\'           => __( \'Not found\', \'gtp_translate\' ),
    \'not_found_in_trash\'  => __( \'Not found in Trash\', \'gtp_translate\' ),
);
$args = array(
    \'label\'               => \'leads\',
    \'description\'         => \'Leads\',
    \'labels\'              => $labels,
    \'supports\'            => array( \'title\', \'editor\', \'author\', \'revisions\', \'custom-fields\', ),
    \'hierarchical\'        => false,
    \'public\'              => false,
    \'show_ui\'             => true,
    \'show_in_menu\'        => true,
    \'show_in_nav_menus\'   => false,
    \'show_in_admin_bar\'   => true,
    \'menu_position\'       => 3,
    \'menu_icon\'           => \'\',
    \'can_export\'          => true,
    \'has_archive\'         => false,
    \'exclude_from_search\' => true,
    \'publicly_queryable\'  => false,
    \'capability_type\'     => array( \'lead\', \'leads\' ),
);
register_post_type( \'leads\', $args );

1 个回复
最合适的回答,由SO网友:Alfredo Cebrián 整理而成

您需要添加

map_meta_cap => true,

args 属于register_post_type

    \'publicly_queryable\'  => false,
    \'map_meta_cap\'  => true,
    \'capability_type\'     => array( \'lead\', \'leads\' ),
);
register_post_type( \'leads\', $args );

结束

相关推荐

PHP致命错误:无法为wp-includes/capabilities.php中的非对象调用重载函数

我在apache日志中遇到了太多以下错误。PHP Fatal error: Cannot call overloaded function for non-object in wp-includes/capabilities.php on line 1187这是函数current\\u user\\u can($capability)的内部,第1187行如下所示:$current_user = wp_get_current_user(); 我不知道问题出在哪里?