Created
July 17, 2015 02:48
-
-
Save petenelson/523c66e1fd4d90533d90 to your computer and use it in GitHub Desktop.
WordPress REST API: Restrict access to the media endpoint to only authenticated users
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 | |
// restrict access to the media endpoint | |
add_action( 'init', function() { | |
// _add_extra_api_post_type_arguments() in the WP REST API sets this to true | |
// we'll turn it off for unauthenticated requests | |
global $wp_post_types; | |
$wp_post_types['attachment']->show_in_rest = is_user_logged_in(); | |
}, 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment