Skip to content

Instantly share code, notes, and snippets.

@petenelson
Created July 17, 2015 02:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petenelson/523c66e1fd4d90533d90 to your computer and use it in GitHub Desktop.
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
<?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