Move settings and remaining globals to includes directory
This commit is contained in:
30
includes/admin/settings/globals.php
Normal file
30
includes/admin/settings/globals.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
function sportspress_define_globals() {
|
||||
|
||||
// Options
|
||||
global $sportspress_options;
|
||||
|
||||
$sportspress_options = (array)get_option( 'sportspress', array() );
|
||||
|
||||
// Sports
|
||||
global $sportspress_sports;
|
||||
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/soccer.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/football.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/footy.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/baseball.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/basketball.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/gaming.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/cricket.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/golf.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/handball.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/hockey.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/racing.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/rugby.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/swimming.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/tennis.php';
|
||||
include_once dirname( SP_PLUGIN_FILE ) . '/presets/sports/volleyball.php';
|
||||
|
||||
uasort( $sportspress_sports, 'sportspress_sort_sports' );
|
||||
}
|
||||
add_action( 'init', 'sportspress_define_globals' );
|
||||
194
includes/admin/settings/options-event.php
Normal file
194
includes/admin/settings/options-event.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
class SportsPressEventSettingsPage {
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
add_action( 'admin_init', array( $this, 'page_init' ), 1 );
|
||||
}
|
||||
|
||||
function page_init() {
|
||||
register_setting(
|
||||
'sportspress_events',
|
||||
'sportspress',
|
||||
'sportspress_options_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'event',
|
||||
__( 'Events', 'sportspress' ),
|
||||
'',
|
||||
'sportspress_events'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'delimiter',
|
||||
__( 'Delimiter', 'sportspress' ),
|
||||
array( $this, 'delimiter_callback' ),
|
||||
'sportspress_events',
|
||||
'event'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'performance',
|
||||
__( 'Performance', 'sportspress' ),
|
||||
array( $this, 'performance_callback' ),
|
||||
'sportspress_events',
|
||||
'event'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'results',
|
||||
__( 'Results', 'sportspress' ),
|
||||
array( $this, 'results_callback' ),
|
||||
'sportspress_events',
|
||||
'event'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'outcomes',
|
||||
__( 'Outcomes', 'sportspress' ),
|
||||
array( $this, 'outcomes_callback' ),
|
||||
'sportspress_events',
|
||||
'event'
|
||||
);
|
||||
}
|
||||
|
||||
function delimiter_callback() {
|
||||
$teams_delimiter = sportspress_array_value( $this->options, 'event_teams_delimiter', __( 'vs', 'sportspress' ) );
|
||||
?>
|
||||
<fieldset class="sp-custom-input-wrapper">
|
||||
<legend class="screen-reader-text"><span><?php _e( 'Delimiter', 'sportspress' ); ?></span></legend>
|
||||
<?php $delimiters = array( 'vs', 'v', '—', '/' ); ?>
|
||||
<?php foreach ( $delimiters as $delimiter ): ?>
|
||||
<label title="<?php echo $delimiter; ?>"><input type="radio" class="preset" name="sportspress_event_teams_delimiter_preset" value="<?php echo $delimiter; ?>" data-example="<?php _e( 'Team', 'sportspress' ); ?> <?php echo $delimiter; ?> <?php _e( 'Team', 'sportspress' ); ?>" <?php checked( $delimiter, $teams_delimiter ); ?>> <span><?php _e( 'Team', 'sportspress' ); ?> <?php echo $delimiter; ?> <?php _e( 'Team', 'sportspress' ); ?></span></label><br>
|
||||
<?php endforeach; ?>
|
||||
<label><input type="radio" class="preset" name="sportspress_event_teams_delimiter_preset" value="\c\u\s\t\o\m" <?php checked( false, in_array( $teams_delimiter, $delimiters ) ); ?>> <?php _e( 'Custom:', 'sportspress' ); ?> </label><input type="text" class="small-text value" name="sportspress[event_teams_delimiter]" value="<?php echo $teams_delimiter; ?>" data-example-format="<?php _e( 'Team', 'sportspress' ); ?> __val__ <?php _e( 'Team', 'sportspress' ); ?>">
|
||||
<span class="example"><?php _e( 'Team', 'sportspress' ); ?> <?php echo $teams_delimiter; ?> <?php _e( 'Team', 'sportspress' ); ?></span>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function performance_callback() {
|
||||
$responsive = sportspress_array_value( $this->options, 'event_performance_responsive', true );
|
||||
$sortable = sportspress_array_value( $this->options, 'event_performance_sortable', true );
|
||||
$link_posts = sportspress_array_value( $this->options, 'event_performance_link_posts', true );
|
||||
?>
|
||||
<fieldset>
|
||||
<label for="sportspress_event_performance_responsive">
|
||||
<input id="sportspress_event_performance_responsive_default" name="sportspress[event_performance_responsive]" type="hidden" value="0">
|
||||
<input id="sportspress_event_performance_responsive" name="sportspress[event_performance_responsive]" type="checkbox" value="1" <?php checked( $responsive ); ?>>
|
||||
<?php _e( 'Responsive', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="sportspress_event_performance_sortable">
|
||||
<input id="sportspress_event_performance_sortable_default" name="sportspress[event_performance_sortable]" type="hidden" value="0">
|
||||
<input id="sportspress_event_performance_sortable" name="sportspress[event_performance_sortable]" type="checkbox" value="1" <?php checked( $sortable ); ?>>
|
||||
<?php _e( 'Sortable', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="sportspress_event_performance_link_posts">
|
||||
<input id="sportspress_event_performance_link_posts_default" name="sportspress[event_performance_link_posts]" type="hidden" value="0">
|
||||
<input id="sportspress_event_performance_link_posts" name="sportspress[event_performance_link_posts]" type="checkbox" value="1" <?php checked( $link_posts ); ?>>
|
||||
<?php _e( 'Link players', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function results_callback() {
|
||||
$main_result = sportspress_array_value( $this->options, 'main_result', 0 );
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_result',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<fieldset>
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th class="radio"><input type="radio" id="sportspress_main_result_0" name="sportspress[main_result]" value="0" <?php checked( $main_result, 0 ); ?>></th>
|
||||
<th colspan="2"><label for="sportspress_main_result_0">
|
||||
<?php
|
||||
if ( sizeof( $data ) > 0 ):
|
||||
$default = end( $data );
|
||||
reset( $data );
|
||||
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
|
||||
else:
|
||||
_e( 'Default', 'sportspress' );
|
||||
endif;
|
||||
?>
|
||||
</label></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="radio"><input type="radio" id="sportspress_main_result_<?php echo $row->post_name; ?>" name="sportspress[main_result]" value="<?php echo $row->post_name; ?>" <?php checked( $main_result, $row->post_name ); ?>></td>
|
||||
<td class="row-title"><label for="sportspress_main_result_<?php echo $row->post_name; ?>"><?php echo $row->post_title; ?></label></td>
|
||||
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function outcomes_callback() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<fieldset>
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo $row->post_name; ?></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_outcome' ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_outcome' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_admin() )
|
||||
$sportspress_event_settings_page = new SportsPressEventSettingsPage();
|
||||
53
includes/admin/settings/options-general.php
Normal file
53
includes/admin/settings/options-general.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
class SportsPressGeneralSettingsPage {
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
add_action( 'admin_init', array( $this, 'page_init' ), 1 );
|
||||
}
|
||||
|
||||
function page_init() {
|
||||
register_setting(
|
||||
'sportspress_general',
|
||||
'sportspress',
|
||||
'sportspress_options_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'general',
|
||||
__( 'General Options', 'sportspress' ),
|
||||
'',
|
||||
'sportspress_general'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'sport',
|
||||
__( 'Sport', 'sportspress' ),
|
||||
array( $this, 'sport_callback' ),
|
||||
'sportspress_general',
|
||||
'general'
|
||||
);
|
||||
}
|
||||
|
||||
function sport_callback() {
|
||||
global $sportspress_options, $sportspress_sports;
|
||||
|
||||
$selected = sportspress_array_value( $sportspress_options, 'sport', null );
|
||||
$custom_sport_name = sportspress_array_value( $sportspress_options, 'custom_sport_name', null );
|
||||
?>
|
||||
<fieldset>
|
||||
<select id="sportspress_sport" name="sportspress[sport]">
|
||||
<option value><?php _e( '— Select —', 'sportspress' ); ?></option>
|
||||
<?php foreach( $sportspress_sports as $slug => $sport ): ?>
|
||||
<option value="<?php echo $slug; ?>" <?php selected( $selected, $slug ); ?>><?php echo $sport['name']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
<option value="custom" <?php selected( $selected, 'custom' ); ?>><?php _e( 'Custom', 'sportspress' ); ?></option>
|
||||
</select>
|
||||
<input id="sportspress_custom_sport_name" name="sportspress[custom_sport_name]" type="text" placeholder="<?php _e( 'Sport', 'sportspress' ); ?>" value="<?php echo $custom_sport_name; ?>"<?php if ( $selected != 'custom' ): ?> class="hidden"<?php endif; ?>>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_admin() )
|
||||
$sportspress_general_settings_page = new SportsPressGeneralSettingsPage();
|
||||
71
includes/admin/settings/options-permalink.php
Normal file
71
includes/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();
|
||||
204
includes/admin/settings/options-player.php
Normal file
204
includes/admin/settings/options-player.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
class SportsPressPlayerSettingsPage {
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
add_action( 'admin_init', array( $this, 'page_init' ), 1 );
|
||||
}
|
||||
|
||||
function page_init() {
|
||||
register_setting(
|
||||
'sportspress_players',
|
||||
'sportspress',
|
||||
'sportspress_options_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'player',
|
||||
__( 'Players', 'sportspress' ),
|
||||
'',
|
||||
'sportspress_players'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'list',
|
||||
__( 'Player Lists', 'sportspress' ),
|
||||
'',
|
||||
'sportspress_players'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'nationality',
|
||||
__( 'Nationality', 'sportspress' ),
|
||||
array( $this, 'nationality_callback' ),
|
||||
'sportspress_players',
|
||||
'player'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'list',
|
||||
__( 'List', 'sportspress' ),
|
||||
array( $this, 'list_callback' ),
|
||||
'sportspress_players',
|
||||
'list'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'gallery',
|
||||
__( 'Gallery', 'sportspress' ),
|
||||
array( $this, 'gallery_callback' ),
|
||||
'sportspress_players',
|
||||
'list'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'metrics',
|
||||
__( 'Metrics', 'sportspress' ),
|
||||
array( $this, 'metrics_callback' ),
|
||||
'sportspress_players',
|
||||
'list'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'performance',
|
||||
__( 'Performance', 'sportspress' ),
|
||||
array( $this, 'performance_callback' ),
|
||||
'sportspress_players',
|
||||
'list'
|
||||
);
|
||||
}
|
||||
|
||||
function nationality_callback() {
|
||||
$show_nationality_flag = sportspress_array_value( $this->options, 'player_show_nationality_flag', true );
|
||||
?>
|
||||
<fieldset>
|
||||
<label for="sportspress_player_show_nationality_flag">
|
||||
<input id="sportspress_player_show_nationality_flag_default" name="sportspress[player_show_nationality_flag]" type="hidden" value="0">
|
||||
<input id="sportspress_player_show_nationality_flag" name="sportspress[player_show_nationality_flag]" type="checkbox" value="1" <?php checked( $show_nationality_flag ); ?>>
|
||||
<?php _e( 'Display national flags', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function list_callback() {
|
||||
$responsive = sportspress_array_value( $this->options, 'player_list_responsive', true );
|
||||
$sortable = sportspress_array_value( $this->options, 'player_list_sortable', true );
|
||||
$link_posts = sportspress_array_value( $this->options, 'player_list_link_posts', true );
|
||||
?>
|
||||
<fieldset>
|
||||
<label for="sportspress_player_list_responsive">
|
||||
<input id="sportspress_player_list_responsive_default" name="sportspress[player_list_responsive]" type="hidden" value="0">
|
||||
<input id="sportspress_player_list_responsive" name="sportspress[player_list_responsive]" type="checkbox" value="1" <?php checked( $responsive ); ?>>
|
||||
<?php _e( 'Responsive', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="sportspress_player_list_sortable">
|
||||
<input id="sportspress_player_list_sortable_default" name="sportspress[player_list_sortable]" type="hidden" value="0">
|
||||
<input id="sportspress_player_list_sortable" name="sportspress[player_list_sortable]" type="checkbox" value="1" <?php checked( $sortable ); ?>>
|
||||
<?php _e( 'Sortable', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="sportspress_player_list_link_posts">
|
||||
<input id="sportspress_player_list_link_posts_default" name="sportspress[player_list_link_posts]" type="hidden" value="0">
|
||||
<input id="sportspress_player_list_link_posts" name="sportspress[player_list_link_posts]" type="checkbox" value="1" <?php checked( $link_posts ); ?>>
|
||||
<?php _e( 'Link players', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function gallery_callback() {
|
||||
$show_names_on_hover = sportspress_array_value( $this->options, 'player_gallery_show_names_on_hover', true );
|
||||
?>
|
||||
<fieldset>
|
||||
<label for="sportspress_player_gallery_show_names_on_hover">
|
||||
<input id="sportspress_player_gallery_show_names_on_hover_default" name="sportspress[player_gallery_show_names_on_hover]" type="hidden" value="0">
|
||||
<input id="sportspress_player_gallery_show_names_on_hover" name="sportspress[player_gallery_show_names_on_hover]" type="checkbox" value="1" <?php checked( $show_names_on_hover ); ?>>
|
||||
<?php _e( 'Display player names on hover', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function metrics_callback() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_metric',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<fieldset>
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Positions', 'sportspress' ); ?></th>
|
||||
<th scope="col"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo get_the_terms ( $row->ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : '—'; ?></td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_metric' ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_metric' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</fieldset>
|
||||
<?
|
||||
}
|
||||
|
||||
function performance_callback() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_performance',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<fieldset>
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Positions', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Calculate', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo get_the_terms ( $row->ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : '—'; ?></td>
|
||||
<td><?php echo sportspress_get_post_calculate( $row->ID ); ?></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_performance' ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_performance' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_admin() )
|
||||
$sportspress_player_settings_page = new SportsPressPlayerSettingsPage();
|
||||
121
includes/admin/settings/options-team.php
Normal file
121
includes/admin/settings/options-team.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
class SportsPressTeamSettingsPage {
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
add_action( 'admin_init', array( $this, 'page_init' ), 1 );
|
||||
}
|
||||
|
||||
function page_init() {
|
||||
register_setting(
|
||||
'sportspress_teams',
|
||||
'sportspress',
|
||||
'sportspress_options_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'table',
|
||||
__( 'League Tables', 'sportspress' ),
|
||||
'',
|
||||
'sportspress_teams'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'table',
|
||||
__( 'Table', 'sportspress' ),
|
||||
array( $this, 'table_callback' ),
|
||||
'sportspress_teams',
|
||||
'table'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'columns',
|
||||
__( 'Columns', 'sportspress' ),
|
||||
array( $this, 'columns_callback' ),
|
||||
'sportspress_teams',
|
||||
'table'
|
||||
);
|
||||
}
|
||||
|
||||
function table_callback() {
|
||||
$responsive = sportspress_array_value( $this->options, 'league_table_responsive', true );
|
||||
$sortable = sportspress_array_value( $this->options, 'league_table_sortable', true );
|
||||
$show_team_logo = sportspress_array_value( $this->options, 'league_table_show_team_logo', false );
|
||||
$link_posts = sportspress_array_value( $this->options, 'league_table_link_posts', false );
|
||||
?>
|
||||
<fieldset>
|
||||
<label for="sportspress_league_table_responsive">
|
||||
<input id="sportspress_league_table_responsive_default" name="sportspress[league_table_responsive]" type="hidden" value="0">
|
||||
<input id="sportspress_league_table_responsive" name="sportspress[league_table_responsive]" type="checkbox" value="1" <?php checked( $responsive ); ?>>
|
||||
<?php _e( 'Responsive', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="sportspress_league_table_sortable">
|
||||
<input id="sportspress_league_table_sortable_default" name="sportspress[league_table_sortable]" type="hidden" value="0">
|
||||
<input id="sportspress_league_table_sortable" name="sportspress[league_table_sortable]" type="checkbox" value="1" <?php checked( $sortable ); ?>>
|
||||
<?php _e( 'Sortable', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="sportspress_league_table_show_team_logo">
|
||||
<input id="sportspress_league_table_show_team_logo_default" name="sportspress[league_table_show_team_logo]" type="hidden" value="0">
|
||||
<input id="sportspress_league_table_show_team_logo" name="sportspress[league_table_show_team_logo]" type="checkbox" value="1" <?php checked( $show_team_logo ); ?>>
|
||||
<?php _e( 'Display logos', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="sportspress_league_table_link_posts">
|
||||
<input id="sportspress_league_table_link_posts_default" name="sportspress[league_table_link_posts]" type="hidden" value="0">
|
||||
<input id="sportspress_league_table_link_posts" name="sportspress[league_table_link_posts]" type="checkbox" value="1" <?php checked( $link_posts ); ?>>
|
||||
<?php _e( 'Link teams', 'sportspress' ); ?>
|
||||
</label>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
function columns_callback() {
|
||||
$args = array(
|
||||
'post_type' => 'sp_column',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<fieldset>
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Equation', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Rounding', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Sort Order', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo $row->post_name; ?></td>
|
||||
<td><?php echo sportspress_get_post_equation( $row->ID, $row->post_name ); ?></td>
|
||||
<td><?php echo sportspress_get_post_precision( $row->ID ); ?></td>
|
||||
<td><?php echo sportspress_get_post_order( $row->ID ); ?></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
</table>
|
||||
<div class="tablenav bottom">
|
||||
<div class="alignleft actions">
|
||||
<a class="button" id="doaction" href="<?php echo admin_url( 'edit.php?post_type=sp_column' ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
|
||||
<a class="button" id="doaction2" href="<?php echo admin_url( 'post-new.php?post_type=sp_column' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
|
||||
</div>
|
||||
<br class="clear">
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_admin() )
|
||||
$sportspress_team_settings_page = new SportsPressTeamSettingsPage();
|
||||
46
includes/admin/settings/options-text.php
Normal file
46
includes/admin/settings/options-text.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
class SportsPressTextSettingsPage {
|
||||
private $strings = null;
|
||||
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
add_action( 'admin_init', array( $this, 'page_init' ), 1 );
|
||||
}
|
||||
|
||||
function page_init() {
|
||||
register_setting(
|
||||
'sportspress_text',
|
||||
'sportspress',
|
||||
'sportspress_options_validate'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'text',
|
||||
__( 'Text', 'sportspress' ),
|
||||
'',
|
||||
'sportspress_text'
|
||||
);
|
||||
|
||||
$this->strings =& SP()->text->strings;
|
||||
foreach ( $this->strings as $string ):
|
||||
add_settings_field(
|
||||
sanitize_title( $string ),
|
||||
$string,
|
||||
array( $this, 'text_callback' ),
|
||||
'sportspress_text',
|
||||
'text'
|
||||
);
|
||||
endforeach;
|
||||
}
|
||||
|
||||
public function text_callback( $test ) {
|
||||
$string = array_shift( $this->strings );
|
||||
$key = sanitize_title( $string );
|
||||
$text = sportspress_array_value( sportspress_array_value( $this->options, 'text', array() ), $string, null );
|
||||
?><fieldset><input id="sportspress_text_<?php echo $key; ?>" name="sportspress[text][<?php echo $string; ?>]" type="text" class="regular-text" value="<?php echo $text; ?>" placeholder="<?php echo $string; ?>"></fieldset><?php
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_admin() )
|
||||
$sportspress_text_settings_page = new SportsPressTextSettingsPage();
|
||||
173
includes/admin/settings/settings.php
Normal file
173
includes/admin/settings/settings.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
function sportspress_options() {
|
||||
|
||||
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general';
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<a href="<?php echo remove_query_arg( 'tab' ); ?>" class="nav-tab<?php echo $active_tab == 'general' ? ' nav-tab-active' : ''; ?>"><?php _e( 'SportsPress', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo add_query_arg( 'tab', 'events' ); ?>" class="nav-tab<?php echo $active_tab == 'events' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Schedule', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo add_query_arg( 'tab', 'teams' ); ?>" class="nav-tab<?php echo $active_tab == 'teams' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Teams', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo add_query_arg( 'tab', 'players' ); ?>" class="nav-tab<?php echo $active_tab == 'players' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Roster', 'sportspress' ); ?></a>
|
||||
<a href="<?php echo add_query_arg( 'tab', 'text' ); ?>" class="nav-tab<?php echo $active_tab == 'text' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Text', 'sportspress' ); ?></a>
|
||||
</h2>
|
||||
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
switch ( $active_tab ):
|
||||
case 'events':
|
||||
settings_fields( 'sportspress_events' );
|
||||
do_settings_sections( 'sportspress_events' );
|
||||
submit_button();
|
||||
break;
|
||||
case 'teams':
|
||||
settings_fields( 'sportspress_teams' );
|
||||
do_settings_sections( 'sportspress_teams' );
|
||||
submit_button();
|
||||
break;
|
||||
case 'players':
|
||||
settings_fields( 'sportspress_players' );
|
||||
do_settings_sections( 'sportspress_players' );
|
||||
submit_button();
|
||||
break;
|
||||
case 'text':
|
||||
settings_fields( 'sportspress_text' );
|
||||
do_settings_sections( 'sportspress_text' );
|
||||
submit_button();
|
||||
break;
|
||||
default:
|
||||
settings_fields( 'sportspress_general' );
|
||||
do_settings_sections( 'sportspress_general' );
|
||||
submit_button();
|
||||
break;
|
||||
endswitch;
|
||||
?>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function sportspress_options_validate( $input ) {
|
||||
|
||||
$options = (array)get_option( 'sportspress', array() );
|
||||
|
||||
if ( isset( $input['sport'] ) && sportspress_array_value( $options, 'sport', null ) != sportspress_array_value( $input, 'sport', null ) ):
|
||||
|
||||
// Get sports presets
|
||||
global $sportspress_sports;
|
||||
|
||||
// Get array of taxonomies to insert
|
||||
$term_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'terms', array() );
|
||||
|
||||
foreach( $term_groups as $taxonomy => $terms ):
|
||||
// Find empty terms and destroy
|
||||
$allterms = get_terms( $taxonomy, 'hide_empty=0' );
|
||||
|
||||
foreach( $allterms as $term ):
|
||||
if ( $term->count == 0 )
|
||||
wp_delete_term( $term->term_id, $taxonomy );
|
||||
endforeach;
|
||||
|
||||
// Insert terms
|
||||
foreach( $terms as $term ):
|
||||
wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
|
||||
endforeach;
|
||||
endforeach;
|
||||
|
||||
// Get array of post types to insert
|
||||
$post_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'posts', array() );
|
||||
|
||||
// Loop through each post type
|
||||
foreach( $post_groups as $post_type => $posts ):
|
||||
|
||||
$args = array(
|
||||
'post_type' => $post_type,
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => '_sp_preset',
|
||||
'value' => 1
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Delete posts
|
||||
$old_posts = get_posts( $args );
|
||||
|
||||
foreach( $old_posts as $post ):
|
||||
wp_delete_post( $post->ID, true);
|
||||
endforeach;
|
||||
|
||||
// Add posts
|
||||
foreach( $posts as $index => $post ):
|
||||
|
||||
// Make sure post doesn't overlap
|
||||
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
|
||||
|
||||
// Translate post title
|
||||
$post['post_title'] = __( $post['post_title'], 'sportspress' );
|
||||
|
||||
// Set post type
|
||||
$post['post_type'] = $post_type;
|
||||
|
||||
// Increment menu order by 2 and publish post
|
||||
$post['menu_order'] = $index * 2 + 2;
|
||||
$post['post_status'] = 'publish';
|
||||
$id = wp_insert_post( $post );
|
||||
|
||||
// Flag as preset
|
||||
update_post_meta( $id, '_sp_preset', 1 );
|
||||
|
||||
// Update meta
|
||||
if ( array_key_exists( 'meta', $post ) ):
|
||||
|
||||
foreach ( $post['meta'] as $key => $value ):
|
||||
|
||||
update_post_meta( $id, $key, $value );
|
||||
|
||||
endforeach;
|
||||
|
||||
endif;
|
||||
|
||||
// Update terms
|
||||
if ( array_key_exists( 'tax_input', $post ) ):
|
||||
|
||||
foreach ( $post['tax_input'] as $taxonomy => $terms ):
|
||||
|
||||
wp_set_object_terms( $id, $terms, $taxonomy, false );
|
||||
|
||||
endforeach;
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
|
||||
endforeach;
|
||||
|
||||
elseif ( isset( $input['text'] ) ):
|
||||
$input['text'] = array_filter( $input['text'] );
|
||||
endif;
|
||||
|
||||
if ( ! is_array( $input ) )
|
||||
$input = array();
|
||||
|
||||
// Merge with existing options
|
||||
return array_merge( $options, $input );
|
||||
}
|
||||
|
||||
function sportspress_add_menu_page() {
|
||||
add_options_page(
|
||||
__( 'SportsPress', 'sportspress' ),
|
||||
__( 'SportsPress', 'sportspress' ),
|
||||
'manage_options',
|
||||
'sportspress',
|
||||
'sportspress_options'
|
||||
);
|
||||
}
|
||||
add_action( 'admin_menu', 'sportspress_add_menu_page' );
|
||||
Reference in New Issue
Block a user