Created
April 6, 2018 17:09
-
-
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
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 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