Last active
July 10, 2020 16:28
-
-
Save ravewebdev/fe14393fb72125392fe8e86230f2aa95 to your computer and use it in GitHub Desktop.
3.1.2. Handle permissions callback
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 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