• Le Van Toan

    (@levantoan)


    I create custom post type with:

    $capabilities = array(
            'edit_post'             => 'edit_khoahoc',
            'read_post'             => 'read_khoahoc',
            'delete_post'           => 'delete_khoahoc',
            'edit_posts'            => 'edit_khoahoc',
            'edit_others_posts'     => 'edit_others_khoahoc',
            'publish_posts'         => 'publish_khoahoc',
            'read_private_posts'    => 'read_private_khoahoc',
        );

    but it return Notice:
    Notice: Undefined property: stdClass::$delete_posts in \wp-admin\includes\class-wp-posts-list-table.php on line 403

    Pls, tel me why and how to make fine?

    Full code:

    
    function khoahoc_func() {
    
        $labels = array(
            'name'                  => _x( 'Khóa học', 'Post Type General Name', 'devvn' ),
            'singular_name'         => _x( 'Khóa học', 'Post Type Singular Name', 'devvn' ),
            'menu_name'             => __( 'Khóa học', 'devvn' ),
            'name_admin_bar'        => __( 'Khóa học', 'devvn' ),
            'archives'              => __( 'Khóa học', 'devvn' ),
            'attributes'            => __( 'Item Attributes', 'devvn' ),
            'parent_item_colon'     => __( 'Parent Item:', 'devvn' ),
            'all_items'             => __( 'All Items', 'devvn' ),
            'add_new_item'          => __( 'Add New Item', 'devvn' ),
            'add_new'               => __( 'Add New', 'devvn' ),
            'new_item'              => __( 'New Item', 'devvn' ),
            'edit_item'             => __( 'Edit Item', 'devvn' ),
            'update_item'           => __( 'Update Item', 'devvn' ),
            'view_item'             => __( 'View Item', 'devvn' ),
            'view_items'            => __( 'View Items', 'devvn' ),
            'search_items'          => __( 'Search Item', 'devvn' ),
            'not_found'             => __( 'Not found', 'devvn' ),
            'not_found_in_trash'    => __( 'Not found in Trash', 'devvn' ),
            'featured_image'        => __( 'Featured Image', 'devvn' ),
            'set_featured_image'    => __( 'Set featured image', 'devvn' ),
            'remove_featured_image' => __( 'Remove featured image', 'devvn' ),
            'use_featured_image'    => __( 'Use as featured image', 'devvn' ),
            'insert_into_item'      => __( 'Insert into item', 'devvn' ),
            'uploaded_to_this_item' => __( 'Uploaded to this item', 'devvn' ),
            'items_list'            => __( 'Items list', 'devvn' ),
            'items_list_navigation' => __( 'Items list navigation', 'devvn' ),
            'filter_items_list'     => __( 'Filter items list', 'devvn' ),
        );
        $rewrite = array(
            'slug'                  => 'khoa-hoc',
            'with_front'            => true,
            'pages'                 => true,
            'feeds'                 => true,
        );
        $capabilities = array(
            'edit_post'             => 'edit_khoahoc',
            'read_post'             => 'read_khoahoc',
            'delete_post'           => 'delete_khoahoc',
            'edit_posts'            => 'edit_khoahoc',
            'edit_others_posts'     => 'edit_others_khoahoc',
            'publish_posts'         => 'publish_khoahoc',
            'read_private_posts'    => 'read_private_khoahoc',
        );
        $args = array(
            'label'                 => __( 'Khóa học', 'devvn' ),
            'description'           => __( 'Thông tin Khóa học', 'devvn' ),
            'labels'                => $labels,
            'supports'              => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', ),
            'taxonomies'            => array( 'chuong_trinh' ),
            'hierarchical'          => false,
            'public'                => true,
            'show_ui'               => true,
            'show_in_menu'          => true,
            'menu_position'         => 5,
            'menu_icon'             => 'dashicons-welcome-learn-more',
            'show_in_admin_bar'     => true,
            'show_in_nav_menus'     => true,
            'can_export'            => true,
            'has_archive'           => true,
            'exclude_from_search'   => false,
            'publicly_queryable'    => true,
            'rewrite'               => $rewrite,
            'capabilities'          => $capabilities,
        );
        register_post_type( 'khoa_hoc', $args );
    
    }
    add_action( 'init', 'khoahoc_func', 0 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s because you mapped your delete capability to “delete_post” (singular) instead of “delete_posts” (plural). Generally, you would not be concerned with the singular meta capabilities. Only map the plural capabilities. Thus you should correct “edit_post” and “read_post” as well.

    If you were to check the capabilities assigned to roles, none of the post related singular meta capabilities are listed (except read), only plural. The singular meta capabilities are only used internally. I’m not sure in what way, all I know is I’ve never dealt with them and never had any trouble.

    I will agree that the post type capabilities mapping is confusing. It doesn’t matter what custom capability terms you use as long as they are mapped to the right primitives. I’d urge you to be consistent though, all plural or all singular, if the concept even applies in Vietnamese. Some languages don’t, others have more than 2 forms, as in single, a few, or many.

    BTW, it probably doesn’t matter for you, but when using translation functions like _x(), __(), etc., the passed string is supposed to be in English so translators can consistently translate from English to another language. It’s not expected to translate from Vietnamese to say, Finnish. If you are not expecting to have your theme translated, then you can pass whatever you want. But in that case it does not make sense to use the translation functions at all, just assign your desired string directly.
    'description' => 'Thông tin Khóa học',

    Thread Starter Le Van Toan

    (@levantoan)

    Thank to @bcworkz ,
    I change to

    $capabilities = array(
            'edit_post'             => 'edit_khoahoc',
            'read_post'             => 'read_khoahoc',
            'delete_post'           => 'delete_khoahoc',
            'delete_posts'           => 'delete_khoahoc',
            'edit_posts'            => 'edit_khoahoc',
            'edit_others_posts'     => 'edit_others_khoahoc',
            'publish_posts'         => 'publish_khoahoc',
            'read_private_posts'    => 'read_private_khoahoc',
        );

    It work fine now 😀

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Notice: Undefined property: stdClass::$delete_posts’ is closed to new replies.