add rest routes for calendars

This commit is contained in:
Brian Miyaji
2016-04-11 01:51:02 +10:00
parent a6e1fce9ab
commit 9697f67314

View File

@@ -33,6 +33,8 @@ class SportsPress_Calendars {
add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 10 );
add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) );
add_action( 'sportspress_widgets', array( $this, 'include_widgets' ) );
add_action( 'sportspress_create_rest_routes', array( $this, 'create_rest_routes' ) );
add_action( 'sportspress_register_rest_fields', array( $this, 'register_rest_fields' ) );
// Filters
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
@@ -85,8 +87,11 @@ class SportsPress_Calendars {
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
'has_archive' => false,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_event',
'show_in_menu' => 'edit.php?post_type=sp_event',
'show_in_admin_bar' => true,
'show_in_rest' => true,
'rest_controller_class' => 'SP_REST_Posts_Controller',
'rest_base' => 'calendars',
)
)
);
@@ -110,8 +115,6 @@ class SportsPress_Calendars {
/**
* Add widgets.
*
* @return array
*/
public function include_widgets() {
include_once( SP()->plugin_path() . '/includes/widgets/class-sp-widget-event-calendar.php' );
@@ -119,6 +122,50 @@ class SportsPress_Calendars {
include_once( SP()->plugin_path() . '/includes/widgets/class-sp-widget-event-blocks.php' );
}
/**
* Create REST API routes.
*/
public function create_rest_routes() {
$controller = new SP_REST_Posts_Controller( 'sp_calendar' );
$controller->register_routes();
}
/**
* Register REST API fields.
*/
public function register_rest_fields() {
register_rest_field( 'sp_calendar',
'format',
array(
'get_callback' => 'SP_REST_API::get_post_meta',
'update_callback' => 'SP_REST_API::update_post_meta',
'schema' => array(
'description' => __( 'Layout', 'sportspress' ),
'type' => 'array',
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => 'rest_sanitize_request_arg',
),
),
)
);
register_rest_field( 'sp_calendar',
'data',
array(
'get_callback' => 'SP_REST_API::get_post_data',
'schema' => array(
'description' => __( 'Events', 'sportspress' ),
'type' => 'array',
'context' => array( 'view', 'embed' ),
'arg_options' => array(
'sanitize_callback' => 'rest_sanitize_request_arg',
),
),
)
);
}
/**
* Add meta boxes to calendars.
*