diff --git a/admin/post-types/calendar.php b/admin/post-types/calendar.php index 1d207158..bab4ba1e 100644 --- a/admin/post-types/calendar.php +++ b/admin/post-types/calendar.php @@ -19,7 +19,7 @@ function sportspress_calendar_post_init() { 'hierarchical' => false, 'supports' => array( 'title', 'author', 'thumbnail' ), 'register_meta_box_cb' => 'sportspress_calendar_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_calendar_slug', 'calendar' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_calendar_slug', 'calendar' ) ), 'show_in_menu' => 'edit.php?post_type=sp_event', 'show_in_admin_bar' => true, 'capability_type' => 'sp_calendar' diff --git a/admin/post-types/directory.php b/admin/post-types/directory.php index 4b29e0db..b500cbd9 100644 --- a/admin/post-types/directory.php +++ b/admin/post-types/directory.php @@ -19,7 +19,7 @@ function sportspress_directory_post_init() { 'hierarchical' => false, 'supports' => array( 'title', 'author', 'thumbnail' ), 'register_meta_box_cb' => 'sportspress_directory_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_directory_slug', 'list' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_directory_slug', 'directory' ) ), 'show_in_menu' => 'edit.php?post_type=sp_player', 'show_in_admin_bar' => true, 'capability_type' => 'sp_directory' diff --git a/admin/post-types/event.php b/admin/post-types/event.php index c81873fb..49f9bad6 100644 --- a/admin/post-types/event.php +++ b/admin/post-types/event.php @@ -20,7 +20,7 @@ function sportspress_event_post_init() { 'hierarchical' => false, 'supports' => array( 'title', 'author', 'thumbnail', 'comments' ), 'register_meta_box_cb' => 'sportspress_event_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_event_slug', 'events' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_events_slug', 'events' ) ), 'menu_icon' => 'dashicons-calendar', 'capability_type' => 'sp_event' ); diff --git a/admin/post-types/list.php b/admin/post-types/list.php index 4ba6d324..ae1394c7 100644 --- a/admin/post-types/list.php +++ b/admin/post-types/list.php @@ -19,7 +19,7 @@ function sportspress_list_post_init() { 'hierarchical' => false, 'supports' => array( 'title', 'author', 'thumbnail' ), 'register_meta_box_cb' => 'sportspress_list_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_list_slug', 'list' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_list_slug', 'list' ) ), 'show_in_menu' => 'edit.php?post_type=sp_player', 'show_in_admin_bar' => true, 'capability_type' => 'sp_list' diff --git a/admin/post-types/player.php b/admin/post-types/player.php index 218575b0..44c94d6a 100644 --- a/admin/post-types/player.php +++ b/admin/post-types/player.php @@ -21,7 +21,7 @@ function sportspress_player_post_init() { 'hierarchical' => false, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'page-attributes' ), 'register_meta_box_cb' => 'sportspress_player_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_player_slug', 'players' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_players_slug', 'players' ) ), 'menu_icon' => 'dashicons-groups', 'capability_type' => 'sp_player', ); diff --git a/admin/post-types/staff.php b/admin/post-types/staff.php index 5642daf1..92b55aeb 100644 --- a/admin/post-types/staff.php +++ b/admin/post-types/staff.php @@ -19,7 +19,7 @@ function sportspress_staff_post_init() { 'hierarchical' => false, 'supports' => array( 'title', 'author', 'thumbnail' ), 'register_meta_box_cb' => 'sportspress_staff_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_staff_slug', 'staff' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_staff_slug', 'staff' ) ), 'show_in_menu' => 'edit.php?post_type=sp_player', 'capability_type' => 'sp_staff' ); diff --git a/admin/post-types/table.php b/admin/post-types/table.php index 41cfdce4..5f7838a6 100644 --- a/admin/post-types/table.php +++ b/admin/post-types/table.php @@ -19,7 +19,7 @@ function sportspress_table_post_init() { 'hierarchical' => false, 'supports' => array( 'title', 'author', 'thumbnail' ), 'register_meta_box_cb' => 'sportspress_table_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_table_slug', 'table' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_table_slug', 'table' ) ), 'show_in_menu' => 'edit.php?post_type=sp_team', 'show_in_admin_bar' => true, 'capability_type' => 'sp_table' diff --git a/admin/post-types/team.php b/admin/post-types/team.php index 51798605..bc57eda8 100644 --- a/admin/post-types/team.php +++ b/admin/post-types/team.php @@ -20,7 +20,7 @@ function sportspress_team_post_init() { 'hierarchical' => true, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ), 'register_meta_box_cb' => 'sportspress_team_meta_init', - 'rewrite' => array( 'slug' => get_option( 'sp_team_slug', 'teams' ) ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_teams_slug', 'teams' ) ), 'menu_icon' => 'dashicons-shield-alt', 'capability_type' => 'sp_team' ); diff --git a/admin/settings/options-permalink.php b/admin/settings/options-permalink.php new file mode 100644 index 00000000..e08c6efa --- /dev/null +++ b/admin/settings/options-permalink.php @@ -0,0 +1,71 @@ +slugs = array( + array( 'events', __( 'Events', 'sportspress' ) ), + array( 'venue', __( 'Venues', 'sportspress' ) ), + array( 'calendar', __( 'Calendars', 'sportspress' ) ), + array( 'teams', __( 'Teams', 'sportspress' ) ), + array( 'league', __( 'Leagues', 'sportspress' ) ), + array( 'season', __( 'Seasons', 'sportspress' ) ), + array( 'table', __( 'League Tables', 'sportspress' ) ), + array( 'players', __( 'Players', 'sportspress' ) ), + array( 'position', __( 'Positions', 'sportspress' ) ), + array( 'list', __( 'Player Lists', 'sportspress' ) ), + array( 'staff', __( 'Staff', 'sportspress' ) ), + ); + + add_action( 'admin_init', array( $this, 'settings_init' ) ); + add_action( 'admin_init', array( $this, 'settings_save' ) ); + } + + function settings_init() { + add_settings_section( + 'sportspress', + __( 'SportsPress', 'sportspress' ), + array( $this, 'settings' ), + 'permalink' + ); + + foreach ( $this->slugs as $slug ): + add_settings_field( + $slug[0], + $slug[1], + array( $this, 'slug_callback' ), + 'permalink', + 'sportspress' + ); + endforeach; + } + + public function settings() { + echo wpautop( __( 'These settings control the permalinks used for SportsPress. These settings only apply when not using "default" permalinks above.', 'sportspress' ) ); + } + + public function slug_callback( $test ) { + $slug = array_shift( $this->slugs ); + $key = $slug[0]; + $text = get_option( 'sportspress_' . $key . '_slug', null ); + ?>
slugs as $slug ): + $key = 'sportspress_' . $slug[0] . '_slug'; + $value = sanitize_text_field( $_POST[ $key ] ); + if ( empty( $value ) ) + delete_option( $key ); + else + update_option( $key, $value ); + endforeach; + sportspress_flush_rewrite_rules(); + endif; + } +} + +if ( is_admin() ) + $sportspress_permalink_settings_section = new SportsPressPermalinkSettingsSection(); diff --git a/admin/terms/league.php b/admin/terms/league.php index 0d49a4fe..b3447296 100644 --- a/admin/terms/league.php +++ b/admin/terms/league.php @@ -21,7 +21,7 @@ function sportspress_league_term_init() { 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'league' ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_league_slug', '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 ); diff --git a/admin/terms/position.php b/admin/terms/position.php index fdf97535..4e8e9927 100644 --- a/admin/terms/position.php +++ b/admin/terms/position.php @@ -21,7 +21,7 @@ function sportspress_position_term_init() { 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'position' ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_position_slug', 'position' ) ), ); $object_types = array( 'sp_player', 'sp_statistic', 'sp_metric', 'attachment' ); register_taxonomy( 'sp_position', $object_types, $args ); diff --git a/admin/terms/season.php b/admin/terms/season.php index ab4128af..3fb4680a 100644 --- a/admin/terms/season.php +++ b/admin/terms/season.php @@ -21,7 +21,7 @@ function sportspress_season_term_init() { 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'season' ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_season_slug', '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 ); diff --git a/admin/terms/venue.php b/admin/terms/venue.php index 01388d9f..d8acc565 100644 --- a/admin/terms/venue.php +++ b/admin/terms/venue.php @@ -21,7 +21,7 @@ function sportspress_venue_term_init() { 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'venue' ), + 'rewrite' => array( 'slug' => get_option( 'sportspress_venue_slug', 'venue' ) ), ); $object_types = array( 'sp_event', 'sp_calendar', 'attachment' ); register_taxonomy( 'sp_venue', $object_types, $args ); diff --git a/sportspress.php b/sportspress.php index ffaaac41..b52c433f 100644 --- a/sportspress.php +++ b/sportspress.php @@ -58,6 +58,7 @@ require_once dirname( __FILE__ ) . '/admin/settings/options-event.php'; require_once dirname( __FILE__ ) . '/admin/settings/options-team.php'; require_once dirname( __FILE__ ) . '/admin/settings/options-player.php'; require_once dirname( __FILE__ ) . '/admin/settings/options-text.php'; +require_once dirname( __FILE__ ) . '/admin/settings/options-permalink.php'; // Custom post types require_once dirname( __FILE__ ) . '/admin/post-types/separator.php';