gaintsev
9/3/2015 - 7:47 AM

Wordpress Custom Post Type Capabilities (admin only)

Wordpress Custom Post Type Capabilities (admin only)

<?php

function add_test_type()
    {
        $labels = array(
            'name'               => _x('Тест',                'test'),
            'singular_name'      => _x('Тест',                'test'),
            'menu_name'          => _x('Тест',                'test'),
            'name_admin_bar'     => _x('Тест',                'test'),
            'add_new'            => _x('Добавить новый',      'test'),
            'add_new_item'       => _x('Добавить новый тест', 'test'),
            'new_item'           => _x('Новый тест',          'test'),
            'edit_item'          => _x('Редактировать тест',  'test'),
            'view_item'          => _x('Просмотр тест',       'test'),
            'all_items'          => _x('Все тест',            'test'),
            'search_items'       => _x('Поиск тест',          'test'),
            'parent_item_colon'  => _x('Родительское тест',   'test'),
            'not_found'          => _x('Не найдено',          'test'),
            'not_found_in_trash' => _x('Не найдено',          'test'),
        );

        $supports = array(
            'title',
            'editor',
            'thumbnail',
            'excerpt',
        );

        $args = array(
            'labels'             => $labels,
            'public'             => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'query_var'          => true,
            'rewrite'            => array('slug' => 'test'),
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => $supports,
            'menu_icon'          => 'dashicons-megaphone',
            //it happens here:
            'capabilities' => array(
                'edit_post'          => 'update_core',
                'read_post'          => 'update_core',
                'delete_post'        => 'update_core',
                'edit_posts'         => 'update_core',
                'edit_others_posts'  => 'update_core',
                'delete_posts'       => 'update_core',
                'publish_posts'      => 'update_core',
                'read_private_posts' => 'update_core'
            ),
        );

        register_post_type('test', $args);
    }

add_action('init', 'add_test_type');