Instantly share code, notes, and snippets.

Embed
What would you like to do?
Set up a custom WordPress REST API controller class for the Page post type.
<?php
/**
* Set up a custom REST API controller class for the Page post type.
*
* @author Kellen Mace
*
* @param array $args The post type arguments.
* @param string $name The name of the post type.
*
* @return array $args The post type arguments, possibly modified.
*/
function km_set_custom_page_rest_controller( $args, $name ) {
// If this post type's name is not 'page', do not modify its args.
if ( 'page' !== $name ) {
return $args;
}
// Tell WordPress to use our KM_REST_Pages_Controller class
// for Page REST API requests.
$args['rest_controller_class'] = 'KM_REST_Pages_Controller';
return $args;
}
add_filter( 'register_post_type_args', 'km_set_custom_page_rest_controller', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment