Wordpress:自定义帖子类型的功能在后端可见但不起作用

时间:2013-10-24 11:41:09

标签: wordpress

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

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

但是,如果我以管理员身份登录并尝试将“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');
}

1 个答案:

答案 0 :(得分:0)

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