将功能添加到自定义POST类型时无法附加媒体

时间:2017-10-02 作者:Paul Cullen

我有一个自定义的帖子类型,我们已经有几个月的时间了,并通过wordpress管理员用户进行管理。我们决定使用高级自定义字段插件来实现不同级别的“供应商”,并为其提供各种字段。

我在帖子类型中添加了下面的“功能”部分,这样我就可以使用“用户角色编辑器”插件管理功能,但是一旦添加了此代码,没有用户可以上传和附加文件,这就是我得到的错误:“抱歉,不允许您将文件附加到此帖子。”

我可以附加预上载的文件,也可以在删除功能代码时附加文件,但是我无法按角色管理功能。

此外,管理员用户不再能够编辑现有供应商条目。我认为我需要在主题函数文件中设置一些角色,但我不知道是哪些角色。我已经为相关用户角色启用了“上载文件”功能。

供应商注册代码如下:

function vendor() {

    $labels = array(
        \'name\'                  => _x( \'Vendors\', \'Post Type General Name\', \'vendor_text_domain\' ),
        \'singular_name\'         => _x( \'Vendor\', \'Post Type Singular Name\', \'vendor_text_domain\' ),
        \'menu_name\'             => __( \'Vendors\', \'vendor_text_domain\' ),
        \'name_admin_bar\'        => __( \'Vendors\', \'vendor_text_domain\' ),
        \'archives\'              => __( \'Vendor Archives\', \'vendor_text_domain\' ),
        \'parent_item_colon\'     => __( \'Parent Item:\', \'vendor_text_domain\' ),
        \'all_items\'             => __( \'All Vendors\', \'vendor_text_domain\' ),
        \'add_new_item\'          => __( \'Add New Vendor\', \'vendor_text_domain\' ),
        \'add_new\'               => __( \'Add New\', \'vendor_text_domain\' ),
        \'new_item\'              => __( \'New Vendor\', \'vendor_text_domain\' ),
        \'edit_item\'             => __( \'Edit Vendor\', \'vendor_text_domain\' ),
        \'update_item\'           => __( \'Update Vendor\', \'vendor_text_domain\' ),
        \'view_item\'             => __( \'View Vendor\', \'vendor_text_domain\' ),
        \'search_items\'          => __( \'Search Vendor\', \'vendor_text_domain\' ),
        \'not_found\'             => __( \'Not found\', \'vendor_text_domain\' ),
        \'not_found_in_trash\'    => __( \'Not found in Trash\', \'vendor_text_domain\' ),
        \'featured_image\'        => __( \'Featured Image\', \'vendor_text_domain\' ),
        \'set_featured_image\'    => __( \'Set featured image\', \'vendor_text_domain\' ),
        \'remove_featured_image\' => __( \'Remove featured image\', \'vendor_text_domain\' ),
        \'use_featured_image\'    => __( \'Use as featured image\', \'vendor_text_domain\' ),
        \'insert_into_item\'      => __( \'Insert into item\', \'vendor_text_domain\' ),
        \'uploaded_to_this_item\' => __( \'Uploaded to this item\', \'vendor_text_domain\' ),
        \'items_list\'            => __( \'Vendor list\', \'vendor_text_domain\' ),
        \'items_list_navigation\' => __( \'Vendor list navigation\', \'vendor_text_domain\' ),
        \'filter_items_list\'     => __( \'Filter items list\', \'vendor_text_domain\' ),
    );
    $args = array(
        \'label\'                 => __( \'Vendor\', \'vendor_text_domain\' ),
        \'description\'           => __( \'Individual Vendors\', \'vendor_text_domain\' ),
        \'labels\'                => $labels,
        \'supports\'              => array( \'title\', \'editor\', \'thumbnail\', \'revisions\', \'page-attributes\', ),
        \'taxonomies\'            => array( \'post_tag\' ),
        \'hierarchical\'          => false,
        \'public\'                => true,
        \'show_ui\'               => true,
        \'show_in_menu\'          => true,
        \'menu_position\'         => 5,
        \'menu_icon\'             => \'dashicons-store\',
        \'show_in_admin_bar\'     => true,
        \'show_in_nav_menus\'     => true,
        \'can_export\'            => true,
        \'upload_files\'          => true,
        \'has_archive\'           => true,        
        \'exclude_from_search\'   => false,
        \'publicly_queryable\'    => true,
        \'capability_type\'       => \'post\',
        \'capabilities\' => array(
          \'edit_post\'          => \'edit_vendor\', 
          \'read_post\'          => \'read_vendor\', 
          \'delete_post\'        => \'delete_vendor\', 
          \'edit_posts\'         => \'edit_vendors\', 
          \'edit_others_posts\'  => \'edit_others_vendors\', 
          \'publish_posts\'      => \'publish_vendors\',       
          \'read_private_posts\' => \'read_private_vendors\', 
          \'create_posts\'       => \'create_vendor\', 
          \'upload_files\'       => \'upload_vendor_files\'
        ),
    );
    register_post_type( \'vendor\', $args );
}

1 个回复
SO网友:Milan Petrovic

您已将自定义功能分配给post类型,但是否已将这些功能分配给用户角色或用户?这不是自动完成的,向帖子类型添加自定义大写并不会将这些大写添加到角色或用户。您有两种解决方案:

注册没有“功能”选项的帖子类型,它将返回到帖子或页面使用的默认功能

结束

相关推荐

Plugin capabilities

我创建了一个界面,允许用户执行一定数量的操作,每个操作都有相关的功能(包括访问该界面)。我想有一个基本的能力(这里是原始的?)如果用户想要执行所有其他操作,则需要具备:如果用户可以删除项目,则用户还必须能够访问该界面。有几个插件允许添加/删除功能:我想防止出现用户可以删除但无法访问界面的情况。我知道,由于帖子类型、元功能和map\\u meta\\u cap filter,我很难将其应用到我的插件中。我可以一直检查这两个选项,但权限层次结构最终会更加复杂(比如,3个级别-用户必须具有访问\\u界面、创建\