*/ // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } require_once('includes/class.make-endpoint.php'); require_once('includes/class.make-sticky.php'); require_once('includes/class.make-sortby.php'); add_action( 'rest_api_init', function () { /** * The standard wordpress post_types */ $page_controller = new Make_Endpoint_For('page'); $page_controller->register_custom_route('pages'); $media_controller = new Make_Endpoint_For('media'); $media_controller->register_custom_route('media'); $post_controller = new Make_Endpoint_For('post'); $post_controller->register_custom_route('posts'); /** * Craft in America custom post_types */ $episode_controller = new Make_Endpoint_For('episode'); $episode_controller->register_custom_route('episodes'); $artist_controller = new Make_Endpoint_For('artist'); $artist_controller->register_custom_route('artists'); $event_controller = new Make_Endpoint_For('event'); $event_controller->register_custom_route('events'); $exhibition_controller = new Make_Endpoint_For('exhibition'); $exhibition_controller->register_custom_route('exhibitions'); $sticky_controller = new Make_Sticky_Endpoint(); $sticky_controller->register_custom_route('sticky'); /** * Craft in America custom sort_types */ $sort_controller = new Make_Sort_By('artist', 'by_alpha'); $sort_controller->register_custom_route('artists/by-alpha'); $sort_controller = new Make_Sort_By('artist', 'by_material'); $sort_controller->register_custom_route('artists/by-material'); $sort_controller = new Make_Sort_By('event', 'by_past'); $sort_controller->register_custom_route('events/by-past'); $sort_controller = new Make_Sort_By('exhibition', 'by_past'); $sort_controller->register_custom_route('exhibitions/by-past'); $sort_controller = new Make_Sort_By('event', 'by_current'); $sort_controller->register_custom_route('events/by-current'); $sort_controller = new Make_Sort_By('exhibition', 'by_current'); $sort_controller->register_custom_route('exhibitions/by-current'); $sort_controller = new Make_Sort_By('event', 'by_upcoming'); $sort_controller->register_custom_route('events/by-upcoming'); $sort_controller = new Make_Sort_By('exhibition', 'by_upcoming'); $sort_controller->register_custom_route('exhibitions/by-upcoming'); $sort_controller = new Make_Sort_By('event', 'by_current_and_upcoming'); $sort_controller->register_custom_route('events/by-current-and-upcoming'); $sort_controller = new Make_Sort_By('exhibition', 'by_current_and_upcoming'); $sort_controller->register_custom_route('exhibitions/by-current-and-upcoming'); }); /** * Register the /wp-json/craft/v2/ so it will be cached * Depends on: WP REST Cache * https://medium.com/@lodewijkm/our-headless-wordpress-journey-part-i-speeding-up-the-rest-api-aef76a898418 */ add_filter('wp_rest_cache/allowed_endpoints', function () { // The standard wordpress post_types if ( !isset($allowed_endpoints['craft/v2']) || !in_array('posts', $allowed_endpoints['craft/v2']) ) $allowed_endpoints['craft/v2'][] = 'posts'; if ( !isset($allowed_endpoints['craft/v2']) || !in_array('pages', $allowed_endpoints['craft/v2']) ) $allowed_endpoints['craft/v2'][] = 'pages'; if ( !isset($allowed_endpoints['craft/v2']) || !in_array('media', $allowed_endpoints['craft/v2']) ) $allowed_endpoints['craft/v2'][] = 'media'; // Craft in America custom post_types if ( !isset($allowed_endpoints['craft/v2']) || !in_array('episodes', $allowed_endpoints['craft/v2']) ) $allowed_endpoints['craft/v2'][] = 'episodes'; if ( !isset($allowed_endpoints['craft/v2']) || !in_array('events', $allowed_endpoints['craft/v2']) ) $allowed_endpoints['craft/v2'][] = 'events'; if ( !isset($allowed_endpoints['craft/v2']) || !in_array('exhibitions', $allowed_endpoints['craft/v2']) ) $allowed_endpoints['craft/v2'][] = 'exhibitions'; if ( !isset($allowed_endpoints['craft/v2']) || !in_array('artists', $allowed_endpoints['craft/v2']) ) $allowed_endpoints['craft/v2'][] = 'artists'; return $allowed_endpoints; }, 10, 1); add_filter('excerpt_length', function ($length) { return 20; });