Skip to content

Instantly share code, notes, and snippets.

@ravewebdev
Last active July 10, 2020 16:28
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 ravewebdev/fe14393fb72125392fe8e86230f2aa95 to your computer and use it in GitHub Desktop.
Save ravewebdev/fe14393fb72125392fe8e86230f2aa95 to your computer and use it in GitHub Desktop.
3.1.2. Handle permissions callback
<?php
function check_initiative_permissions( WP_REST_Request $request ) : bool {
$post_id = $request->get_param( 'id' ) ?? 0;
if ( ! is_user_logged_in() ) {
return false;
}
if ( current_user_can( 'edit_published_posts' ) ) {
return true;
}
$post = get_post( $post_id );
if ( null === $post ) {
return false;
}
return get_current_user_id() === $post->post_author;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment