Why is my Custom Post Type not showing up after adding capabilities?

Question

I’m trying to add a custom post types with capabilities, so a custom user role can do certain things with them. Eventually the custom role is a Client, and the post a Website, and I want clients to be able to log in and view their websites. However, the post type is not showing up as soon as I add capabilities => 'website'. Why is is not showing up? I was following this tutorial and here it seems to work at 3:54 (with vehicles as a custom post type).

<?php

// Creating the website post type
function add_website_post_type() {

  $website_post_type_args = array(
    'labels' => $website_post_type_labels,
    'public' => true,
    'menu_position' => 5,
    'menu_icon' => 'dashicons-feedback',
    'hierarchical' => false,
    'supports' => array( 'title' ),
    'has_archive' => true,
    'capability_type' => 'website'
  );

  // Define all the labels
  $website_post_type_labels = array(
    'name' => __( 'Websites' ),
    'singular_name' => __( 'Website' ),
    'add_new_item' => __( 'Add New Website' ),
    'edit_item' => __( 'Edit Website' ),
    'new_item' => __( 'New Website' ),
    'view_item' => __( 'View Website' ),
    'view_items' => __( 'View Websites' ),
    'not_found' => __( 'No Websites Found' ),
    'not_found_in_trash' => __( 'No Deleted Websites Found' ),
    'all_items' => __( 'All Websites' ),
    'archives' => __( 'Website Archives' ),
    'insert_into_item' => __( 'Insert Into Website' ),
    'uploaded_to_this_item' => __( 'Uploaded To This Website' )
  );

  register_post_type( 'website', $website_post_type_args );

}

add_action( 'init', 'add_website_post_type', 10 );

// Create the client user role
function add_client_user_role() {

  $capabilities = array(
    'publish_website'        => true,
    'edit_website'           => true,
    'edit_others_website'    => true,
    'delete_website'         => true,
    'delete_others_website'  => true,
    'read_website'           => true,
    'read_private_website'   => true,
    'read'
  );

  add_role( 'client', 'Client', $capabilities );

}

add_action( 'init', 'add_client_user_role', 10 );
0
Tom 2 years 2020-10-21T13:10:35-05:00 0 Answers 14 views 0

Leave an answer

Browse
Browse