Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Created May 17, 2017 17:38
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 jazzsequence/c749aa425546365d1132ea4345e9c0b4 to your computer and use it in GitHub Desktop.
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
<?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