Last active
May 15, 2020 02:01
-
-
Save jgalea/5983652 to your computer and use it in GitHub Desktop.
Creating a new post type with capabilities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', 'create_my_post_types' ); | |
function create_my_post_types() { | |
register_post_type( | |
'movie', | |
array( | |
'public' => true, | |
'capability_type' => 'movie', | |
'capabilities' => array( | |
'publish_posts' => 'publish_movies', | |
'edit_posts' => 'edit_movies', | |
'edit_others_posts' => 'edit_others_movies', | |
'read_private_posts' => 'read_private_movies', | |
'edit_post' => 'edit_movie', | |
'delete_post' => 'delete_movie', | |
'read_post' => 'read_movie', | |
), | |
) | |
); | |
} |
When you create a post type and assign it custom capabilities, you have to assign those capabilities to users or roles. By default these capabilities are not assigned to any roles or users, hence you don't see them, even though they exist.
Use a plugin like Members to view the capability to find MOVIE and give yourself access to it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I am learning wordpress, I am trying to use the code you wrote above, it seems not creating the post type movie (i don't see it in the menu)
If i change the capability_type to 'post', it will be created , but i want to use different capability_type (other than post) can you help please ?