自定义帖子类型不使用功能

时间:2013-09-20 作者:BobbyDank

我在我的一个网站上使用以下自定义帖子类型:

function careers_post_type() {

    $labels = array(
        \'name\'                => _x( \'Careers\', \'Post Type General Name\', \'text_domain\' ),
        \'singular_name\'       => _x( \'Career\', \'Post Type Singular Name\', \'text_domain\' ),
        \'menu_name\'           => __( \'Careers\', \'text_domain\' ),
        \'parent_item_colon\'   => __( \'Parent career:\', \'text_domain\' ),
        \'all_items\'           => __( \'All careers\', \'text_domain\' ),
        \'view_item\'           => __( \'View career\', \'text_domain\' ),
        \'add_new_item\'        => __( \'Add New career\', \'text_domain\' ),
        \'add_new\'             => __( \'New career\', \'text_domain\' ),
        \'edit_item\'           => __( \'Edit career\', \'text_domain\' ),
        \'update_item\'         => __( \'Update career\', \'text_domain\' ),
        \'search_items\'        => __( \'Search careers\', \'text_domain\' ),
        \'not_found\'           => __( \'No careers found\', \'text_domain\' ),
        \'not_found_in_trash\'  => __( \'No careers found in Trash\', \'text_domain\' ),
    );
    $args = array(
        \'label\'               => __( \'career\', \'text_domain\' ),
        \'description\'         => __( \'career information pages\', \'text_domain\' ),
        \'labels\'              => $labels,
        \'supports\'            => array( ),
        \'taxonomies\'          => array( ),
        \'hierarchical\'        => false,
        \'public\'              => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'show_in_nav_menus\'   => true,
        \'show_in_admin_bar\'   => true,
        \'menu_position\'       => 5,
        \'can_export\'          => true,
        \'has_archive\'         => true,
        \'exclude_from_search\' => false,
        \'publicly_queryable\'  => true,
        \'capability_type\' => \'post\',
    );
    register_post_type( \'career\', $args );

}
吸盘工作得很好。但是,我想为其添加一个自定义功能。我使用了本教程:http://justintadlock.com/archives/2010/07/10/meta-capabilities-for-custom-post-types 一旦我将代码设置为这样,它就会停止工作:

// Register Custom Post Type
function careers_post_type() {

    $labels = array(
        \'name\'                => _x( \'Careers\', \'Post Type General Name\', \'text_domain\' ),
        \'singular_name\'       => _x( \'Career\', \'Post Type Singular Name\', \'text_domain\' ),
        \'menu_name\'           => __( \'Careers\', \'text_domain\' ),
        \'parent_item_colon\'   => __( \'Parent career:\', \'text_domain\' ),
        \'all_items\'           => __( \'All careers\', \'text_domain\' ),
        \'view_item\'           => __( \'View career\', \'text_domain\' ),
        \'add_new_item\'        => __( \'Add New career\', \'text_domain\' ),
        \'add_new\'             => __( \'New career\', \'text_domain\' ),
        \'edit_item\'           => __( \'Edit career\', \'text_domain\' ),
        \'update_item\'         => __( \'Update career\', \'text_domain\' ),
        \'search_items\'        => __( \'Search careers\', \'text_domain\' ),
        \'not_found\'           => __( \'No careers found\', \'text_domain\' ),
        \'not_found_in_trash\'  => __( \'No careers found in Trash\', \'text_domain\' ),
    );
    $args = array(
        \'label\'               => __( \'career\', \'text_domain\' ),
        \'description\'         => __( \'career information pages\', \'text_domain\' ),
        \'labels\'              => $labels,
        \'supports\'            => array( ),
        \'taxonomies\'          => array( ),
        \'hierarchical\'        => false,
        \'public\'              => true,
        \'show_ui\'             => true,
        \'show_in_menu\'        => true,
        \'show_in_nav_menus\'   => true,
        \'show_in_admin_bar\'   => true,
        \'menu_position\'       => 5,
        \'can_export\'          => true,
        \'has_archive\'         => true,
        \'exclude_from_search\' => false,
        \'publicly_queryable\'  => true,
        \'capability_type\' => \'career_editor\',
        \'capabilities\' => array(
            \'publish_posts\' => \'publish_career\',
            \'edit_posts\' => \'edit_career\',
            \'edit_others_posts\' => \'edit_others_career\',
            \'delete_posts\' => \'delete_career\',
            \'delete_others_posts\' => \'delete_others_career\',
            \'read_private_posts\' => \'read_private_career\',
            \'edit_post\' => \'edit_career\',
            \'delete_post\' => \'delete_career\',
            \'read_post\' => \'read_career\',
        ),
    );
    register_post_type( \'career\', $args );

}
我甚至尝试过去掉功能数组,但内容类型仍然消失了。我做错了什么?

2 个回复
SO网友:gmazzap

\'capability_type\' 是必须是有效的参数post type.

因此,或者您使用一种默认的帖子类型(post、page),或者一旦定义了自己的功能数组,就必须使用自己的帖子类型。

因此,使用:

....
\'capability_type\' => \'career\'
....
您的代码应该可以工作。

但是,一旦定义了所有功能,它也应该可以工作,而无需设置任何\'capability_type\' 完全

SO网友:cybmeta

您需要将这些功能添加到某个现有角色或添加您自己的用户角色。

例如:

    add_role(\'career_editor\', \'Carreer Editor\', array (
        \'publish_career\'        => true,
        \'edit_career\'           => true,
        \'edit_others_careerr\'   => true,
        \'delete_career\'         => true,
        \'delete_others_career\'  => true,
        \'read_career\'           => true,
        \'edit_career\'           => true,
        \'delete_career\'         => true,
        \'read_career\'           => true,
        \'read_private_carreer\'  => true,
        \'read\'                  => true,
   ));
现在我们有了一个新的用户角色,career_editor, 与我们的定制职位类型相关的定制能力。现在您必须有一个角色为的用户career_editor 已分配。

结束

相关推荐

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(); 我不知道问题出在哪里?