Add event mode to REST API

This commit is contained in:
savvasha
2021-04-26 13:03:23 +03:00
parent 3203f092f2
commit 9bd808e270
2 changed files with 44 additions and 23 deletions

View File

@@ -120,21 +120,37 @@ class SP_REST_API {
) )
); );
register_rest_field( 'sp_event', register_rest_field( 'sp_event',
'format', 'format',
array( array(
'get_callback' => 'SP_REST_API::get_post_data', 'get_callback' => 'SP_REST_API::get_post_data',
'update_callback' => 'SP_REST_API::update_post_meta', 'update_callback' => 'SP_REST_API::update_post_meta',
'schema' => array( 'schema' => array(
'description' => __( 'Format', 'sportspress' ), 'description' => __( 'Format', 'sportspress' ),
'type' => 'string', 'type' => 'string',
'context' => array( 'view', 'edit', 'embed' ), 'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array( 'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field', 'sanitize_callback' => 'sanitize_text_field',
), ),
), ),
) )
); );
register_rest_field( 'sp_event',
'mode',
array(
'get_callback' => 'SP_REST_API::get_post_data',
'update_callback' => 'SP_REST_API::update_post_meta',
'schema' => array(
'description' => __( 'Mode', 'sportspress' ),
'type' => 'string',
'context' => array( 'view', 'edit', 'embed' ),
'arg_options' => array(
'sanitize_callback' => 'sanitize_text_field',
),
),
)
);
register_rest_field( 'sp_event', register_rest_field( 'sp_event',
'day', 'day',

View File

@@ -26,15 +26,20 @@ class SP_Event extends SP_Custom_Post{
return $post_status; return $post_status;
} }
public function format() { public function format() {
$format = get_post_meta( $this->ID, 'sp_format', true ); $format = get_post_meta( $this->ID, 'sp_format', true );
return $format; return $format;
} }
public function day() { public function day() {
$day = get_post_meta( $this->ID, 'sp_day', true ); $day = get_post_meta( $this->ID, 'sp_day', true );
return $day; return $day;
} }
public function mode() {
$mode = get_post_meta( $this->ID, 'sp_mode', true );
return $mode;
}
public function minutes() { public function minutes() {
$minutes = get_post_meta( $this->ID, 'sp_minutes', true ); $minutes = get_post_meta( $this->ID, 'sp_minutes', true );