Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Last active June 22, 2018 21:04
Show Gist options
  • Save kellenmace/a21628da0d9c25f2090f16cece826ef6 to your computer and use it in GitHub Desktop.
Save kellenmace/a21628da0d9c25f2090f16cece826ef6 to your computer and use it in GitHub Desktop.
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