Skip to content

Instantly share code, notes, and snippets.

@torounit
Created July 2, 2013 05:48
Show Gist options
  • Save torounit/5907032 to your computer and use it in GitHub Desktop.
Save torounit/5907032 to your computer and use it in GitHub Desktop.
WordPress の User Role Editor 等で、カスタム投稿タイプに独自に権限設定する場合に、カスタム投稿タイプ用の権限を自動的に追加する。
<?php
function add_custom_post_type_role( $post_type ,$arg ) {
$role = get_role('administrator');
if( "post" != $arg->capability_type and !$arg->_builtin ) {
$role->add_cap( "edit_{$arg->name}" );
$role->add_cap( "read_{$arg->name}" );
$role->add_cap( "delete_{$arg->name}" );
$role->add_cap( "delete_{$arg->name}s" );
$role->add_cap( "edit_{$arg->name}s" );
$role->add_cap( "edit_others_{$arg->name}s" );
$role->add_cap( "delete_others_{$arg->name}s" );
$role->add_cap( "publish_{$arg->name}s" );
$role->add_cap( "edit_published_{$arg->name}s" );
$role->add_cap( "delete_published_{$arg->name}s" );
$role->add_cap( "delete_private_{$arg->name}s" );
$role->add_cap( "edit_private_{$arg->name}s" );
$role->add_cap( "read_private_{$arg->name}s" );
}
}
add_action( "registered_post_type", "add_custom_post_type_role", 10, 2 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment