Skip to content

Instantly share code, notes, and snippets.

@dboutote
Created April 6, 2018 17:09
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 dboutote/81a720e4989e2a1a54d0b77a90c73b31 to your computer and use it in GitHub Desktop.
Save dboutote/81a720e4989e2a1a54d0b77a90c73b31 to your computer and use it in GitHub Desktop.
Filter the generated REST routes by filtering the show_in_rest arg in register_post_type function
<?php
function dbdb_unset_rest_routes( $args, $post_type ) {
$allowed_post_types = array( 'page', 'post', 'company', 'job' );
$allowed_post_types = apply_filters( 'dbdb_unset_rest_routes_types', $allowed_post_types );
if( in_array( $post_type, $allowed_post_types ) ){
return $args;
} else {
$args['show_in_rest'] = 0;
}
return $args;
}
add_filter( 'register_post_type_args', 'dbdb_unset_rest_routes', 20, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment