Add permalink options
This commit is contained in:
@@ -19,7 +19,7 @@ function sportspress_calendar_post_init() {
|
|||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'author', 'thumbnail' ),
|
'supports' => array( 'title', 'author', 'thumbnail' ),
|
||||||
'register_meta_box_cb' => 'sportspress_calendar_meta_init',
|
'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_menu' => 'edit.php?post_type=sp_event',
|
||||||
'show_in_admin_bar' => true,
|
'show_in_admin_bar' => true,
|
||||||
'capability_type' => 'sp_calendar'
|
'capability_type' => 'sp_calendar'
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function sportspress_directory_post_init() {
|
|||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'author', 'thumbnail' ),
|
'supports' => array( 'title', 'author', 'thumbnail' ),
|
||||||
'register_meta_box_cb' => 'sportspress_directory_meta_init',
|
'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_menu' => 'edit.php?post_type=sp_player',
|
||||||
'show_in_admin_bar' => true,
|
'show_in_admin_bar' => true,
|
||||||
'capability_type' => 'sp_directory'
|
'capability_type' => 'sp_directory'
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function sportspress_event_post_init() {
|
|||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'author', 'thumbnail', 'comments' ),
|
'supports' => array( 'title', 'author', 'thumbnail', 'comments' ),
|
||||||
'register_meta_box_cb' => 'sportspress_event_meta_init',
|
'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',
|
'menu_icon' => 'dashicons-calendar',
|
||||||
'capability_type' => 'sp_event'
|
'capability_type' => 'sp_event'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function sportspress_list_post_init() {
|
|||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'author', 'thumbnail' ),
|
'supports' => array( 'title', 'author', 'thumbnail' ),
|
||||||
'register_meta_box_cb' => 'sportspress_list_meta_init',
|
'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_menu' => 'edit.php?post_type=sp_player',
|
||||||
'show_in_admin_bar' => true,
|
'show_in_admin_bar' => true,
|
||||||
'capability_type' => 'sp_list'
|
'capability_type' => 'sp_list'
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function sportspress_player_post_init() {
|
|||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'page-attributes' ),
|
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'page-attributes' ),
|
||||||
'register_meta_box_cb' => 'sportspress_player_meta_init',
|
'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',
|
'menu_icon' => 'dashicons-groups',
|
||||||
'capability_type' => 'sp_player',
|
'capability_type' => 'sp_player',
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function sportspress_staff_post_init() {
|
|||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'author', 'thumbnail' ),
|
'supports' => array( 'title', 'author', 'thumbnail' ),
|
||||||
'register_meta_box_cb' => 'sportspress_staff_meta_init',
|
'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',
|
'show_in_menu' => 'edit.php?post_type=sp_player',
|
||||||
'capability_type' => 'sp_staff'
|
'capability_type' => 'sp_staff'
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function sportspress_table_post_init() {
|
|||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'author', 'thumbnail' ),
|
'supports' => array( 'title', 'author', 'thumbnail' ),
|
||||||
'register_meta_box_cb' => 'sportspress_table_meta_init',
|
'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_menu' => 'edit.php?post_type=sp_team',
|
||||||
'show_in_admin_bar' => true,
|
'show_in_admin_bar' => true,
|
||||||
'capability_type' => 'sp_table'
|
'capability_type' => 'sp_table'
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function sportspress_team_post_init() {
|
|||||||
'hierarchical' => true,
|
'hierarchical' => true,
|
||||||
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
|
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
|
||||||
'register_meta_box_cb' => 'sportspress_team_meta_init',
|
'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',
|
'menu_icon' => 'dashicons-shield-alt',
|
||||||
'capability_type' => 'sp_team'
|
'capability_type' => 'sp_team'
|
||||||
);
|
);
|
||||||
|
|||||||
71
admin/settings/options-permalink.php
Normal file
71
admin/settings/options-permalink.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
class SportsPressPermalinkSettingsSection {
|
||||||
|
public function __construct() {
|
||||||
|
$this->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 <strong>not using "default" permalinks above</strong>.', 'sportspress' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function slug_callback( $test ) {
|
||||||
|
$slug = array_shift( $this->slugs );
|
||||||
|
$key = $slug[0];
|
||||||
|
$text = get_option( 'sportspress_' . $key . '_slug', null );
|
||||||
|
?><fieldset><input id="sportspress_<?php echo $key; ?>_slug" name="sportspress_<?php echo $key; ?>_slug" type="text" class="regular-text code" value="<?php echo $text; ?>" placeholder="<?php echo $key; ?>"></fieldset><?php
|
||||||
|
}
|
||||||
|
|
||||||
|
public function settings_save() {
|
||||||
|
if ( ! is_admin() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) && isset( $_POST['product_permalink'] ) ):
|
||||||
|
foreach ( $this->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();
|
||||||
@@ -21,7 +21,7 @@ function sportspress_league_term_init() {
|
|||||||
'show_in_nav_menus' => false,
|
'show_in_nav_menus' => false,
|
||||||
'show_tagcloud' => false,
|
'show_tagcloud' => false,
|
||||||
'hierarchical' => true,
|
'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' );
|
$object_types = array( 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' );
|
||||||
register_taxonomy( 'sp_league', $object_types, $args );
|
register_taxonomy( 'sp_league', $object_types, $args );
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function sportspress_position_term_init() {
|
|||||||
'show_in_nav_menus' => false,
|
'show_in_nav_menus' => false,
|
||||||
'show_tagcloud' => false,
|
'show_tagcloud' => false,
|
||||||
'hierarchical' => true,
|
'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' );
|
$object_types = array( 'sp_player', 'sp_statistic', 'sp_metric', 'attachment' );
|
||||||
register_taxonomy( 'sp_position', $object_types, $args );
|
register_taxonomy( 'sp_position', $object_types, $args );
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function sportspress_season_term_init() {
|
|||||||
'show_in_nav_menus' => false,
|
'show_in_nav_menus' => false,
|
||||||
'show_tagcloud' => false,
|
'show_tagcloud' => false,
|
||||||
'hierarchical' => true,
|
'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' );
|
$object_types = array( 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' );
|
||||||
register_taxonomy( 'sp_season', $object_types, $args );
|
register_taxonomy( 'sp_season', $object_types, $args );
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function sportspress_venue_term_init() {
|
|||||||
'show_in_nav_menus' => false,
|
'show_in_nav_menus' => false,
|
||||||
'show_tagcloud' => false,
|
'show_tagcloud' => false,
|
||||||
'hierarchical' => true,
|
'hierarchical' => true,
|
||||||
'rewrite' => array( 'slug' => 'venue' ),
|
'rewrite' => array( 'slug' => get_option( 'sportspress_venue_slug', 'venue' ) ),
|
||||||
);
|
);
|
||||||
$object_types = array( 'sp_event', 'sp_calendar', 'attachment' );
|
$object_types = array( 'sp_event', 'sp_calendar', 'attachment' );
|
||||||
register_taxonomy( 'sp_venue', $object_types, $args );
|
register_taxonomy( 'sp_venue', $object_types, $args );
|
||||||
|
|||||||
@@ -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-team.php';
|
||||||
require_once dirname( __FILE__ ) . '/admin/settings/options-player.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-text.php';
|
||||||
|
require_once dirname( __FILE__ ) . '/admin/settings/options-permalink.php';
|
||||||
|
|
||||||
// Custom post types
|
// Custom post types
|
||||||
require_once dirname( __FILE__ ) . '/admin/post-types/separator.php';
|
require_once dirname( __FILE__ ) . '/admin/post-types/separator.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user