0

在我的插件中,我为订阅者和管理员角色创建了自定义帖子类型并定义了功能。

当我进入后端并查看管理员角色功能列表中的功能时,我添加的所有功能都会被选中。

但是,如果我以管理员身份登录并尝试将类型为“pp_zoekertje”的帖子移动到垃圾箱,wordpress 会告诉我不允许这样做。

当然,我在 stackexchange 和其他各种网站上进行了搜索,但我能找到的唯一解决方案是告诉我完全按照我已经在做的事情去做。

任何帮助表示赞赏。

function create_pp_zoekertje_post_type(){
register_post_type('pp_zoekertje',
    array(
        'labels' => array(
            'name' => 'Zoekertjes',
            'singular_name' => 'Zoekertje',
            'add_new' => __('Nieuw Zoekertje'),
            'add_new_item' => __( 'Nieuw Zoekertje' ),
            'edit' => __( 'Bewerk' ),
            'edit_item' => __( 'Bewerk Zoekertje' ),
            'new_item' => __( 'Nieuw Zoekertje' ),
            'view' => __( 'Bekijk' ),
            'view_item' => __( 'Bekijk Zoekertje' ),
            'search_items' => __( 'Zoek Zoekertjes' ),
            'not_found' => __( 'Geen zoekertjes gevonden' ),
            'not_found_in_trash' => __( 'Geen zoekertjes gevonden in prullenbak' ),
            ),
        'public' => true,
        'has_archive' => true,
        'show_ui' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'hierarchical' => false,
        'query_var' => true,
        'supports' => array(
            'title',
            'editor',
            'revisions',
        ),
        'map_meta_cap' => true,
        'capability_type' => 'pp_zoekertje',
        'capabilities' => array(
            'edit_post' => 'edit_pp_zoekertje',
            'edit_posts' => 'edit_pp_zoekertjes',
            'edit_others_posts' => 'edit_others_pp_zoekertjes',
            'publish_posts' => 'publish_pp_zoekertjes',
            'edit_published_posts' => 'edit_published_pp_zoekertjes',
            'read_post' => 'read_pp_zoekertje',
            'read_private_posts' => 'read_private_pp_zoekertjes',
            'delete_post' => 'delete_pp_zoekertje',
            'delete_others_posts' => 'delete_others_pp_zoekertjes'
        ),
//            'taxonomies' => array('pp_zoekertje_taxonomy','category'),
    )
);

$subscriber_role = get_role('subscriber');
$subscriber_role->add_cap('edit_pp_zoekertje');
$subscriber_role->add_cap('edit_pp_zoekertjes');
$subscriber_role->add_cap('publish_pp_zoekertjes');
$subscriber_role->add_cap('read_pp_zoekertje');
$subscriber_role->add_cap('read_private_pp_zoekertjes');
$subscriber_role->add_cap('delete_pp_zoekertje');
}

function poppunt_classifieds_search_Init() {
    create_pp_zoekertje_post_type();
    if (!is_admin()) {
        wp_enqueue_script('jquery');
        wp_enqueue_script( 'poppunt-classifieds-handlebars', plugins_url( '/js/handlebars.js', __FILE__ ));
    }
}
add_action('init', 'poppunt_classifieds_search_Init');

add_action('admin_init', 'plugin_admin_init');
function plugin_admin_init(){
    $administrator_role = get_role('administrator');
    $administrator_role->add_cap('edit_pp_zoekertje');
    $administrator_role->add_cap('edit_pp_zoekertjes');
    $administrator_role->add_cap('edit_others_pp_zoekertjes');
    $administrator_role->add_cap('publish_pp_zoekertjes');
    $administrator_role->add_cap('read_pp_zoekertje');
    $administrator_role->add_cap('read_private_pp_zoekertjes');
    $administrator_role->add_cap('delete_pp_zoekertje');
    $administrator_role->add_cap('edit_published_pp_zoekertjes');
    $administrator_role->add_cap('delete_others_pp_zoekertjes');

    register_setting( 'pp_options', 'pp-options', 'pp_plugin_options_validate' );

    add_settings_section('pp_options_main', 'Algemene instellingen', 'pp_options_main_output', 'pp_options_menu');

    add_settings_field(
        'pp_zoekertjes_option_input_page',
        __('Pagina met invulformulier voor zoekertje (toevoegen/bewerken)'),
        'pp_zoekertjes_option_input_page',
        'pp_options_menu',
        'pp_options_main');

    add_settings_field(
        'pp_zoekertjes_option_my_ads_page',
        __('Mijn zoekertjes pagina'),
        'pp_zoekertjes_option_my_ads_page',
        'pp_options_menu',
        'pp_options_main');
}
4

1 回答 1

0

而不是通过代码创建您的自定义功能,我更喜欢使用以下插件,然后尝试它很容易安装,这对我有很大帮助。 在这里下载插件

于 2013-10-24T12:06:57.720 回答