Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenbrent/420859 to your computer and use it in GitHub Desktop.
Save thenbrent/420859 to your computer and use it in GitHub Desktop.
Custom post type caps experiment
<?php
/*
Plugin Name: Custom Post Type Capabiltiies Test
Plugin URI: http://wordpress.org/
Description: Testing to see if a subscriber without edit_others capability can edit posts.
Author: Brent
Version: 1
*/
function ppt_register_post_type() {
$role = get_role( 'subscriber' );
$add = true;
if( $add ){
$role->add_cap( 'publish_movies' );
$role->add_cap( 'edit_movie' );
$role->add_cap( 'edit_movies' );
//$role->add_cap( 'edit_others_movies' );
//$role->add_cap( 'read_private_movies' );
//$role->add_cap( 'delete_movie' );
}
if( !$add ){
$role->remove_cap( 'publish_movies' );
$role->remove_cap( 'edit_movie' );
$role->remove_cap( 'edit_movies' );
$role->remove_cap( 'edit_others_movies' );
$role->remove_cap( 'read_private_movies' );
$role->remove_cap( 'delete_movie' );
}
register_post_type( 'movie', array(
'label' => 'Movies',
'labels' => array( 'singular_name' => 'Movie' ),
'public' => TRUE,
'query_var' => TRUE,
'rewrite' => TRUE,
'capability_type' => 'movie'
)
);
error_log('$role = ' . print_r( $role, true ) );
}
add_action( 'init', 'ppt_register_post_type' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment