Created
May 17, 2017 17:38
-
-
Save jazzsequence/c749aa425546365d1132ea4345e9c0b4 to your computer and use it in GitHub Desktop.
check if a user has a post type "edit" capability without knowing the name of that capability
This file contains 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 | |
function get_post_type_edit_capability( $post_type = 'post' ) { | |
$post_type_obj = get_post_type_object( $post_type ); | |
return $post_type_obj->cap->edit_posts; | |
} | |
/** | |
* Usage example: | |
*/ | |
$cap = get_post_type_edit_capability( $post->post_type ); | |
if ( current_user_can( $cap ) { | |
// do stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment