Last active
July 28, 2017 21:09
-
-
Save Shelob9/daac4798052afb0f13a6949ed0ed7506 to your computer and use it in GitHub Desktop.
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 | |
add_action( 'rest_endpoints', function( $endpoints ){ | |
if( isset( $endpoints[ 'wp/v2/posts' ] ) ){ | |
foreach( $endpoints[ 'wp/v2/posts' ] as &$post_endpoint ){ | |
if( 'GET' == $post_endpoint[ 'METHOD' ] ){ | |
$post_endpoint[ 'args' ][ 'type' ] = array( | |
'description' => 'Post types', | |
'type' => 'array', | |
'required' => false, | |
'default' => 'post' | |
); | |
} | |
} | |
} | |
return $endpoints; | |
}, 15 ); |
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 | |
add_action( 'rest_post_query', function( $args, $request ){ | |
$post_types = $request->get_param( 'type' ); | |
if( ! empty( $post_types ) ){ | |
if( is_string( $post_types ) ){ | |
$post_types = array( $post_types ); | |
foreach ( $post_types as $i => $post_type ){ | |
$object= get_post_type_object( $post_type ); | |
if( ! $object || ! $object->show_in_rest ){ | |
unset( $post_types[ $i ] ); | |
} | |
} | |
} | |
$args[ 'post_type' ] = $post_types; | |
} | |
return $args; | |
}, 10, 2 ); |
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 | |
add_action( 'rest_post_query', function( $args, $request ){ | |
$post_types = $request->get_param( 'type' ); | |
if( ! empty( $post_types ) ){ | |
if( is_string( $post_types ) ){ | |
$post_types = array( $post_types ); | |
foreach ( $post_types as $i => $post_type ){ | |
$object= get_post_type_object( $post_type ); | |
if( ! $object || ! $object->show_in_rest ){ | |
unset( $post_types[ $i ] ); | |
} | |
} | |
} | |
$post_types[] = $args[ 'post_type' ]; | |
$args[ 'post_type' ] = $post_types; | |
} | |
return $args; | |
}, 10, 2 ); | |
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 | |
add_action( 'rest_endpoints', function( $endpoints) { | |
foreach ( $endpoints as $endpoint => $args ){ | |
if( false !== strpos( '/wp/v2/users', $endpoint ) ){ | |
unset( $endpoints[ $endpoint ] ); | |
} | |
} | |
return $endpoints; | |
}); |
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 | |
/** @var WP_REST_Request $request */ | |
$type = $request->get_param( 'type' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment