Add rest api args during post type creation
This commit is contained in:
@@ -28,42 +28,6 @@ class SP_REST_API {
|
||||
// Create REST routes
|
||||
add_action( 'rest_api_init', array( $this, 'create_routes' ) );
|
||||
add_action( 'rest_api_init', array( $this, 'register_fields' ), 0 );
|
||||
|
||||
// Add extra league arguments
|
||||
add_filter( 'sportspress_register_taxonomy_league', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_taxonomy_league', array( $this, 'add_league_args' ), 11 );
|
||||
|
||||
// Add extra season arguments
|
||||
add_filter( 'sportspress_register_taxonomy_season', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_taxonomy_season', array( $this, 'add_season_args' ), 11 );
|
||||
|
||||
// Add extra venue arguments
|
||||
add_filter( 'sportspress_register_taxonomy_venue', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_taxonomy_venue', array( $this, 'add_venue_args' ), 11 );
|
||||
|
||||
// Add extra position arguments
|
||||
add_filter( 'sportspress_register_taxonomy_position', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_taxonomy_position', array( $this, 'add_position_args' ), 11 );
|
||||
|
||||
// Add extra role arguments
|
||||
add_filter( 'sportspress_register_taxonomy_role', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_taxonomy_role', array( $this, 'add_role_args' ), 11 );
|
||||
|
||||
// Add extra event arguments
|
||||
add_filter( 'sportspress_register_post_type_event', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_post_type_event', array( $this, 'add_event_args' ), 11 );
|
||||
|
||||
// Add extra team arguments
|
||||
add_filter( 'sportspress_register_post_type_team', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_post_type_team', array( $this, 'add_team_args' ), 11 );
|
||||
|
||||
// Add extra player arguments
|
||||
add_filter( 'sportspress_register_post_type_player', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_post_type_player', array( $this, 'add_player_args' ), 11 );
|
||||
|
||||
// Add extra staff arguments
|
||||
add_filter( 'sportspress_register_post_type_staff', array( $this, 'add_args' ), 11 );
|
||||
add_filter( 'sportspress_register_post_type_staff', array( $this, 'add_staff_args' ), 11 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -582,96 +546,6 @@ class SP_REST_API {
|
||||
|
||||
return $field_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string to integer if it contains only digits
|
||||
*/
|
||||
public static function string_to_int( &$value ) {
|
||||
if ( ctype_digit( $value ) ) {
|
||||
$value = intval( $value );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra arguments
|
||||
*/
|
||||
public static function add_args( $args = array() ) {
|
||||
$args['show_in_rest'] = true;
|
||||
$args['rest_controller_class'] = 'SP_REST_Posts_Controller';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra league arguments
|
||||
*/
|
||||
public static function add_league_args( $args = array() ) {
|
||||
$args['rest_base'] = 'leagues';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra season arguments
|
||||
*/
|
||||
public static function add_season_args( $args = array() ) {
|
||||
$args['rest_base'] = 'seasons';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra venue arguments
|
||||
*/
|
||||
public static function add_venue_args( $args = array() ) {
|
||||
$args['rest_base'] = 'venues';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra position arguments
|
||||
*/
|
||||
public static function add_position_args( $args = array() ) {
|
||||
$args['rest_base'] = 'positions';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra role arguments
|
||||
*/
|
||||
public static function add_role_args( $args = array() ) {
|
||||
$args['rest_base'] = 'roles';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra event arguments
|
||||
*/
|
||||
public static function add_event_args( $args = array() ) {
|
||||
$args['rest_base'] = 'events';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra team arguments
|
||||
*/
|
||||
public static function add_team_args( $args = array() ) {
|
||||
$args['rest_base'] = 'teams';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra player arguments
|
||||
*/
|
||||
public static function add_player_args( $args = array() ) {
|
||||
$args['rest_base'] = 'players';
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add extra staff arguments
|
||||
*/
|
||||
public static function add_staff_args( $args = array() ) {
|
||||
$args['rest_base'] = 'staff';
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
@@ -55,6 +55,9 @@ class SP_Post_types {
|
||||
'show_tagcloud' => false,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => get_option( 'sportspress_league_slug', 'league' ) ),
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'leagues',
|
||||
) );
|
||||
$object_types = apply_filters( 'sportspress_league_object_types', array( 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' ) );
|
||||
register_taxonomy( 'sp_league', $object_types, $args );
|
||||
@@ -86,6 +89,9 @@ class SP_Post_types {
|
||||
'show_tagcloud' => false,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => get_option( 'sportspress_season_slug', 'season' ) ),
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'seasons',
|
||||
) );
|
||||
$object_types = apply_filters( 'sportspress_season_object_types', array( 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' ) );
|
||||
register_taxonomy( 'sp_season', $object_types, $args );
|
||||
@@ -117,6 +123,9 @@ class SP_Post_types {
|
||||
'show_tagcloud' => false,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => get_option( 'sportspress_venue_slug', 'venue' ) ),
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'venues',
|
||||
) );
|
||||
$object_types = apply_filters( 'sportspress_event_object_types', array( 'sp_event', 'sp_calendar', 'sp_team' ) );
|
||||
register_taxonomy( 'sp_venue', $object_types, $args );
|
||||
@@ -148,6 +157,9 @@ class SP_Post_types {
|
||||
'show_tagcloud' => false,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => get_option( 'sportspress_position_slug', 'position' ) ),
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'positions',
|
||||
) );
|
||||
$object_types = apply_filters( 'sportspress_position_object_types', array( 'sp_player', 'sp_list' ) );
|
||||
register_taxonomy( 'sp_position', $object_types, $args );
|
||||
@@ -179,6 +191,9 @@ class SP_Post_types {
|
||||
'show_tagcloud' => false,
|
||||
'hierarchical' => true,
|
||||
'rewrite' => array( 'slug' => get_option( 'sportspress_role_slug', 'role' ) ),
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'roles',
|
||||
) );
|
||||
$object_types = apply_filters( 'sportspress_role_object_types', array( 'sp_staff' ) );
|
||||
register_taxonomy( 'sp_role', $object_types, $args );
|
||||
@@ -221,7 +236,7 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_menu' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -251,7 +266,7 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_menu' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -281,7 +296,7 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_menu' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -311,7 +326,7 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_menu' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -342,7 +357,7 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_menu' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -373,7 +388,7 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => false,
|
||||
'can_export' => false,
|
||||
'show_in_menu' => false,
|
||||
'show_in_menu' => false,
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -402,6 +417,9 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => true,
|
||||
'menu_icon' => 'dashicons-calendar',
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'events',
|
||||
);
|
||||
|
||||
if ( get_option( 'sportspress_event_comment_status', 'no' ) == 'yes' ):
|
||||
@@ -436,6 +454,9 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => true,
|
||||
'menu_icon' => 'dashicons-shield-alt',
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'teams',
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -466,6 +487,9 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => true,
|
||||
'menu_icon' => 'dashicons-groups',
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'players',
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -496,6 +520,9 @@ class SP_Post_types {
|
||||
'has_archive' => false,
|
||||
'show_in_nav_menus' => true,
|
||||
'menu_icon' => 'dashicons-businessman',
|
||||
'show_in_rest' => true,
|
||||
'rest_controller_class' => 'SP_REST_Posts_Controller',
|
||||
'rest_base' => 'staff',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user