Apply players (individual sport) mode throughout

This commit is contained in:
Brian Miyaji
2015-01-25 16:45:21 +11:00
parent 352c6632da
commit 5d5368d1bf
19 changed files with 656 additions and 559 deletions

View File

@@ -28,8 +28,10 @@ class SP_Admin_Importers {
* Add menu items
*/
public function register_importers() {
register_importer( 'sp_event_csv', __( 'SportsPress Events (CSV)', 'sportspress' ), __( 'Import <strong>events</strong> from a csv file.', 'sportspress'), array( $this, 'events_importer' ) );
register_importer( 'sp_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'), array( $this, 'teams_importer' ) );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
register_importer( 'sp_event_csv', __( 'SportsPress Events (CSV)', 'sportspress' ), __( 'Import <strong>events</strong> from a csv file.', 'sportspress'), array( $this, 'events_importer' ) );
register_importer( 'sp_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'), array( $this, 'teams_importer' ) );
}
register_importer( 'sp_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import <strong>players</strong> from a csv file.', 'sportspress'), array( $this, 'players_importer' ) );
register_importer( 'sp_staff_csv', __( 'SportsPress Staff (CSV)', 'sportspress' ), __( 'Import <strong>staff</strong> from a csv file.', 'sportspress'), array( $this, 'staff_importer' ) );
}

View File

@@ -131,33 +131,35 @@ class SP_Admin_Sample_Data {
/*
* Insert teams
*/
foreach ( $teams as $index => $team ) {
$post['post_title'] = $team['name'];
$post['post_type'] = 'sp_team';
$post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), admin_url() );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
foreach ( $teams as $index => $team ) {
$post['post_title'] = $team['name'];
$post['post_type'] = 'sp_team';
$post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), admin_url() );
// Terms
$post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) );
};
// Terms
$post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) );
};
$post['tax_input']['sp_venue'] = get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $index ) );
$post['tax_input']['sp_venue'] = get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $index ) );
// Insert post
$id = wp_insert_post( $post );
// Insert post
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_team'][] = $id;
// Add to inserted ids array
$inserted_ids['sp_team'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Update meta
update_post_meta( $id, 'sp_abbreviation', $team['abbreviation'] );
update_post_meta( $id, 'sp_url', $team['url'] );
// Update meta
update_post_meta( $id, 'sp_abbreviation', $team['abbreviation'] );
update_post_meta( $id, 'sp_url', $team['url'] );
}
}
// Define players
@@ -345,31 +347,175 @@ class SP_Admin_Sample_Data {
/*
* Insert events
*/
for ( $index = 0; $index < 6; $index ++ ) {
// Determine team index and post status
$i = $index % 3;
if ( $index < 3 ) {
$post_status = 'publish';
$post_year = $current_year - 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
} else {
$post_status = 'future';
$post_year = $current_year + 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'DESC', 'number' => 1 ) );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
for ( $index = 0; $index < 6; $index ++ ) {
// Determine team index and post status
$i = $index % 3;
if ( $index < 3 ) {
$post_status = 'publish';
$post_year = $current_year - 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
} else {
$post_status = 'future';
$post_year = $current_year + 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'DESC', 'number' => 1 ) );
}
// The away team should be the next inserted team, or the first if this is the last event
if ( $i == 2 ) $away_index = 0;
else $away_index = $i + 1;
$post = array(
'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'],
'post_type' => 'sp_event',
'post_status' => $post_status,
'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), admin_url() ),
'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00',
'tax_input' => array(
'sp_league' => get_terms( 'sp_league', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ),
'sp_season' => $event_season,
'sp_venue' => get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $i ) ),
),
);
// Insert post
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_event'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Calculate home and away team ids
$home_team_index = ( $i ) % 3;
$away_team_index = ( $i + 1 ) % 3;
$home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 );
$away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 );
$event_teams = array(
$home_team_id,
$away_team_id,
);
// Initialize meta
$event_players = array( 0 );
$performance = $results = array();
if ( $home_team_id ) {
// Add home team player performance
$performance[ $home_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j );
$event_players[] = $player_id;
$player_performance = array();
foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 );
}
$performance[ $home_team_id ][ $player_id ] = $player_performance;
}
// Add home team results
$results[ $home_team_id ] = array();
foreach ( $result_posts as $result_post_index => $result_post ) {
$results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index;
}
$outcome = reset( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $home_team_id ]['outcome'] = array( $outcome->post_name );
}
// Separate teams with zero
$event_players[] = 0;
if ( $away_team_id ) {
$performance[ $away_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j );
$event_players[] = $player_id;
$player_performance = array();
foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 );
}
$performance[ $away_team_id ][ $player_id ] = $player_performance;
}
// Add away team results
$results[ $away_team_id ] = array();
foreach ( $result_posts as $result_post ) {
$results[ $away_team_id ][ $result_post->post_name ] = '0';
}
$outcome = next( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $away_team_id ]['outcome'] = array( $outcome->post_name );
}
if ( 'publish' === $post_status ) {
// Swap results for last event only
if ( $i == 2 ) {
$k = array_keys( $results );
$v = array_values( $results );
$rv = array_reverse( $v );
$results = array_combine( $k, $rv );
}
// Update future post meta
update_post_meta( $id, 'sp_players', $performance );
update_post_meta( $id, 'sp_results', $results );
}
// Update general meta
sp_update_post_meta_recursive( $id, 'sp_team', $event_teams );
sp_update_post_meta_recursive( $id, 'sp_player', $event_players );
update_post_meta( $id, 'sp_columns', $columns );
update_post_meta( $id, 'sp_format', 'league' );
update_post_meta( $id, 'sp_video', $event_videos[ $i ] );
}
// The away team should be the next inserted team, or the first if this is the last event
if ( $i == 2 ) $away_index = 0;
else $away_index = $i + 1;
}
/*
* Insert calendar
*/
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
$post = array(
'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'],
'post_type' => 'sp_event',
'post_status' => $post_status,
'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), admin_url() ),
'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00',
'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ),
'post_type' => 'sp_calendar',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), admin_url() )
);
// Insert post
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_calendar'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Define columns
$columns = array( 'event', 'time', 'article' );
// Update meta
update_post_meta( $id, 'sp_format', 'list' );
update_post_meta( $id, 'sp_status', 'any' );
update_post_meta( $id, 'sp_date', 0 );
update_post_meta( $id, 'sp_team', 0 );
update_post_meta( $id, 'sp_order', 'ASC' );
update_post_meta( $id, 'sp_columns', $columns );
}
/*
* Insert league table
*/
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
$leagues = get_terms( 'sp_league', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
$league = reset( $leagues );
$seasons = get_terms( 'sp_season', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
$season = reset( $seasons );
$post = array(
'post_title' => $league->name . ' ' . $season->name,
'post_type' => 'sp_table',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), admin_url() ),
'tax_input' => array(
'sp_league' => get_terms( 'sp_league', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ),
'sp_season' => $event_season,
'sp_venue' => get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $i ) ),
'sp_league' => $league->term_id,
'sp_season' => $season->term_id,
),
);
@@ -377,196 +523,16 @@ class SP_Admin_Sample_Data {
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_event'][] = $id;
$inserted_ids['sp_table'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Calculate home and away team ids
$home_team_index = ( $i ) % 3;
$away_team_index = ( $i + 1 ) % 3;
$home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 );
$away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 );
$event_teams = array(
$home_team_id,
$away_team_id,
);
// Initialize meta
$event_players = array( 0 );
$performance = $results = array();
if ( $home_team_id ) {
// Add home team player performance
$performance[ $home_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j );
$event_players[] = $player_id;
$player_performance = array();
foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 );
}
$performance[ $home_team_id ][ $player_id ] = $player_performance;
}
// Add home team results
$results[ $home_team_id ] = array();
foreach ( $result_posts as $result_post_index => $result_post ) {
$results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index;
}
$outcome = reset( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $home_team_id ]['outcome'] = array( $outcome->post_name );
}
// Separate teams with zero
$event_players[] = 0;
if ( $away_team_id ) {
$performance[ $away_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j );
$event_players[] = $player_id;
$player_performance = array();
foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 );
}
$performance[ $away_team_id ][ $player_id ] = $player_performance;
}
// Add away team results
$results[ $away_team_id ] = array();
foreach ( $result_posts as $result_post ) {
$results[ $away_team_id ][ $result_post->post_name ] = '0';
}
$outcome = next( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $away_team_id ]['outcome'] = array( $outcome->post_name );
}
if ( 'publish' === $post_status ) {
// Swap results for last event only
if ( $i == 2 ) {
$k = array_keys( $results );
$v = array_values( $results );
$rv = array_reverse( $v );
$results = array_combine( $k, $rv );
}
// Update future post meta
update_post_meta( $id, 'sp_players', $performance );
update_post_meta( $id, 'sp_results', $results );
}
// Update general meta
sp_update_post_meta_recursive( $id, 'sp_team', $event_teams );
sp_update_post_meta_recursive( $id, 'sp_player', $event_players );
update_post_meta( $id, 'sp_columns', $columns );
update_post_meta( $id, 'sp_format', 'league' );
update_post_meta( $id, 'sp_video', $event_videos[ $i ] );
}
/*
* Insert calendar
*/
$post = array(
'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ),
'post_type' => 'sp_calendar',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), admin_url() )
);
// Insert post
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_calendar'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Define columns
$columns = array( 'event', 'time', 'article' );
// Update meta
update_post_meta( $id, 'sp_format', 'list' );
update_post_meta( $id, 'sp_status', 'any' );
update_post_meta( $id, 'sp_date', 0 );
update_post_meta( $id, 'sp_team', 0 );
update_post_meta( $id, 'sp_order', 'ASC' );
update_post_meta( $id, 'sp_columns', $columns );
/*
* Insert league table
*/
$leagues = get_terms( 'sp_league', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
$league = reset( $leagues );
$seasons = get_terms( 'sp_season', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
$season = reset( $seasons );
$post = array(
'post_title' => $league->name . ' ' . $season->name,
'post_type' => 'sp_table',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), admin_url() ),
'tax_input' => array(
'sp_league' => $league->term_id,
'sp_season' => $season->term_id,
),
);
// Insert post
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_table'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Get columns
$columns = array();
$args = array(
'post_type' => 'sp_column',
'posts_per_page' => 8,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$column_posts = get_posts( $args );
foreach ( $column_posts as $column_post ) {
$columns[] = $column_post->post_name;
}
// Update meta
sp_update_post_meta_recursive( $id, 'sp_team', $inserted_ids['sp_team'] );
update_post_meta( $id, 'sp_columns', $columns );
update_post_meta( $id, 'sp_highlight', reset( $inserted_ids['sp_team'] ) );
/*
* Insert player list for each team
*/
foreach ( $inserted_ids['sp_team'] as $index => $team_id ) {
$post = array(
'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ),
'post_type' => 'sp_list',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), admin_url() ),
);
// Insert post
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_list'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Get players from team
$list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 );
// Get columns
$columns = array();
$args = array(
'post_type' => array( 'sp_metric' ),
'posts_per_page' => 2,
'post_type' => 'sp_column',
'posts_per_page' => 8,
'orderby' => 'menu_order',
'order' => 'ASC',
);
@@ -576,13 +542,57 @@ class SP_Admin_Sample_Data {
}
// Update meta
update_post_meta( $id, 'sp_format', 'list' );
sp_update_post_meta_recursive( $id, 'sp_player', $list_players );
sp_update_post_meta_recursive( $id, 'sp_team', $inserted_ids['sp_team'] );
update_post_meta( $id, 'sp_columns', $columns );
update_post_meta( $id, 'sp_grouping', 'position' );
update_post_meta( $id, 'sp_orderby', 'name' );
update_post_meta( $id, 'sp_order', 'ASC' );
update_post_meta( $id, 'sp_team', $team_id );
update_post_meta( $id, 'sp_highlight', reset( $inserted_ids['sp_team'] ) );
}
/*
* Insert player list for each team
*/
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
foreach ( $inserted_ids['sp_team'] as $index => $team_id ) {
$post = array(
'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ),
'post_type' => 'sp_list',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), admin_url() ),
);
// Insert post
$id = wp_insert_post( $post );
// Add to inserted ids array
$inserted_ids['sp_list'][] = $id;
// Flag as sample
update_post_meta( $id, '_sp_sample', 1 );
// Get players from team
$list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 );
// Get columns
$columns = array();
$args = array(
'post_type' => array( 'sp_metric' ),
'posts_per_page' => 2,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$column_posts = get_posts( $args );
foreach ( $column_posts as $column_post ) {
$columns[] = $column_post->post_name;
}
// Update meta
update_post_meta( $id, 'sp_format', 'list' );
sp_update_post_meta_recursive( $id, 'sp_player', $list_players );
update_post_meta( $id, 'sp_columns', $columns );
update_post_meta( $id, 'sp_grouping', 'position' );
update_post_meta( $id, 'sp_orderby', 'name' );
update_post_meta( $id, 'sp_order', 'ASC' );
update_post_meta( $id, 'sp_team', $team_id );
}
}
/*
@@ -620,9 +630,11 @@ class SP_Admin_Sample_Data {
/*
* Update player list and league table per team
*/
foreach ( $inserted_ids['sp_team'] as $index => $team_id ) {
update_post_meta( $team_id, 'sp_list', sp_array_value( $inserted_ids['sp_list'], $index, 0 ) );
update_post_meta( $team_id, 'sp_table', sp_array_value( $inserted_ids['sp_table'], 0 ) );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
foreach ( $inserted_ids['sp_team'] as $index => $team_id ) {
update_post_meta( $team_id, 'sp_list', sp_array_value( $inserted_ids['sp_list'], $index, 0 ) );
update_post_meta( $team_id, 'sp_table', sp_array_value( $inserted_ids['sp_table'], 0 ) );
}
}
}

View File

@@ -34,7 +34,10 @@ class SP_Admin_Settings {
$settings[] = include( 'settings/class-sp-settings-modules.php' );
$settings[] = include( 'settings/class-sp-settings-general.php' );
$settings[] = include( 'settings/class-sp-settings-events.php' );
$settings[] = include( 'settings/class-sp-settings-teams.php' );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) )
$settings[] = include( 'settings/class-sp-settings-teams.php' );
$settings[] = include( 'settings/class-sp-settings-players.php' );
$settings[] = include( 'settings/class-sp-settings-staff.php' );

View File

@@ -194,14 +194,16 @@ class SP_Admin_Welcome {
<a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sportspress', 'tab' => 'general' ), 'admin.php' ) ) ); ?>"><i class="dashicons dashicons-edit"></i> <?php _e( 'Change', 'sportspress' ); ?></a>
<h4><?php _e( 'Mode', 'sportspress' ); ?></h4>
<?php echo ( 'team' == get_option( 'sportspress_mode', 'team' ) ? __( 'Teams', 'sportspress' ) : __( 'Players', 'sportspress' ) ); ?>
<?php echo ( 'team' == get_option( 'sportspress_mode', 'team' ) ? __( 'Teams', 'sportspress' ) : __( 'Players', 'sportspress' ) . ' ' . __( '(Beta)', 'sportspress' ) ); ?>
<a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sportspress', 'tab' => 'general' ), 'admin.php' ) ) ); ?>"><i class="dashicons dashicons-edit"></i> <?php _e( 'Change', 'sportspress' ); ?></a>
<h4><?php _e( 'Next Steps', 'sportspress' ); ?></h4>
<p><?php _e( 'We&#8217;ve assembled some links to get you started:', 'sportspress' ); ?></p>
<div class="sportspress-steps">
<ul>
<li><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'post_type' => 'sp_team' ), 'edit.php' ) ) ); ?>" class="welcome-icon sp-welcome-icon dashicons-shield-alt"><?php _e( 'Add New Team', 'sportspress' ); ?></a></li>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<li><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'post_type' => 'sp_team' ), 'edit.php' ) ) ); ?>" class="welcome-icon sp-welcome-icon dashicons-shield-alt"><?php _e( 'Add New Team', 'sportspress' ); ?></a></li>
<?php } ?>
<li><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'post_type' => 'sp_player' ), 'edit.php' ) ) ); ?>" class="welcome-icon sp-welcome-icon dashicons-groups"><?php _e( 'Add New Player', 'sportspress' ); ?></a></li>
<li><a href="<?php echo esc_url( admin_url( add_query_arg( array( 'post_type' => 'sp_event' ), 'edit.php' ) ) ); ?>" class="welcome-icon sp-welcome-icon dashicons-calendar"><?php _e( 'Add New Event', 'sportspress' ); ?></a></li>
</ul>
@@ -265,7 +267,7 @@ class SP_Admin_Welcome {
'type' => 'radio',
'options' => array(
'team' => __( 'Teams', 'sportspress' ),
'player' => __( 'Players', 'sportspress' ),
'player' => __( 'Players', 'sportspress' ) . ' ' . __( '(Beta)', 'sportspress' ),
),
'desc_tip' => _x( 'Who competes in events?', 'mode setting description', 'sportspress' ),
),

View File

@@ -129,8 +129,14 @@ class SP_Admin_Meta_Boxes {
if ( 'yes' == get_option( 'sportspress_load_videos_module', 'yes' ) ) {
add_meta_box( 'sp_videodiv', __( 'Video', 'sportspress' ), 'SP_Meta_Box_Event_Video::output', 'sp_event', 'side', 'low' );
}
add_meta_box( 'sp_resultsdiv', __( 'Team Results', 'sportspress' ), 'SP_Meta_Box_Event_Results::output', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Event_Performance::output', 'sp_event', 'normal', 'high' );
$teams = array_filter( sp_array_value( $post_meta, 'sp_team', array() ), array( $this, 'positive' ) );
if ( ! empty( $teams ) ) {
add_meta_box( 'sp_resultsdiv', __( 'Team Results', 'sportspress' ), 'SP_Meta_Box_Event_Results::output', 'sp_event', 'normal', 'high' );
}
$players = array_filter( sp_array_value( $post_meta, 'sp_player', array() ), array( $this, 'positive' ) );
if ( ! empty( $players ) ) {
add_meta_box( 'sp_performancediv', __( 'Player Performance', 'sportspress' ), 'SP_Meta_Box_Event_Performance::output', 'sp_event', 'normal', 'high' );
}
add_meta_box( 'sp_editordiv', __( 'Article', 'sportspress' ), 'SP_Meta_Box_Event_Editor::output', 'sp_event', 'normal', 'low' );
if ( 'yes' == get_option( 'sportspress_load_calendars_module', 'yes' ) ) {
@@ -263,6 +269,13 @@ class SP_Admin_Meta_Boxes {
do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post );
}
/*
* Array filter removes values that are not positive.
*/
public function positive( $var = 0 ) {
return $var > 0;
}
}
new SP_Admin_Meta_Boxes();

View File

@@ -104,21 +104,23 @@ class SP_Meta_Box_Calendar_Details {
endif;
?>
</p>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p>
<?php
$args = array(
'show_option_all' => __( 'All', 'sportspress' ),
'post_type' => 'sp_team',
'name' => 'sp_team',
'selected' => $team_id,
'values' => 'ID'
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p>
<?php
$args = array(
'show_option_all' => __( 'All', 'sportspress' ),
'post_type' => 'sp_team',
'name' => 'sp_team',
'selected' => $team_id,
'values' => 'ID'
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php } ?>
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_order">
@@ -141,7 +143,9 @@ class SP_Meta_Box_Calendar_Details {
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) );
update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) );
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', 0 ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', 0 ) );
}
}
}

View File

@@ -87,9 +87,7 @@ class SP_Meta_Box_Event_Teams {
* Save meta box data
*/
public static function save( $post_id, $post ) {
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
}
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
}

View File

@@ -52,10 +52,12 @@ class SP_Meta_Box_List_Data {
<?php echo 'number' == $orderby ? '#' : __( 'Rank', 'sportspress' ); ?>
</label></th>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<th><label for="sp_columns_team">
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
<?php _e( 'Team', 'sportspress' ); ?>
</label></th>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<th><label for="sp_columns_team">
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
<?php _e( 'Team', 'sportspress' ); ?>
</label></th>
<?php } ?>
<?php foreach ( $columns as $key => $label ): ?>
<?php if ( in_array( $key, array( 'number', 'team' ) ) ) continue; ?>
<th><label for="sp_columns_<?php echo $key; ?>">
@@ -100,21 +102,23 @@ class SP_Meta_Box_List_Data {
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
</span>
</td>
<td>
<?php
$selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) );
if ( ! $selected ) $selected = get_post_meta( $player_id, 'sp_team', true );
$include = get_post_meta( $player_id, 'sp_team' );
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_players[' . $player_id . '][team]',
'include' => $include,
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
?>
</td>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<td>
<?php
$selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) );
if ( ! $selected ) $selected = get_post_meta( $player_id, 'sp_team', true );
$include = get_post_meta( $player_id, 'sp_team' );
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_players[' . $player_id . '][team]',
'include' => $include,
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
?>
</td>
<?php } ?>
<?php foreach( $columns as $column => $label ):
if ( in_array( $column, array( 'number', 'team' ) ) ) continue;
$value = sp_array_value( $player_stats, $column, '' );

View File

@@ -62,21 +62,23 @@ class SP_Meta_Box_List_Details {
endif;
?>
</p>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team',
'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $team_id,
'values' => 'ID',
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team',
'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $team_id,
'values' => 'ID',
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php } ?>
<p><strong><?php _e( 'Grouping', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_grouping">
@@ -126,7 +128,9 @@ class SP_Meta_Box_List_Details {
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
}
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );

View File

@@ -83,35 +83,37 @@ class SP_Meta_Box_Player_Details {
sp_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<?php } ?>
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>
<p><?php
@@ -151,8 +153,10 @@ class SP_Meta_Box_Player_Details {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', '' ) );
update_post_meta( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', '' ) );
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
}
}

View File

@@ -61,17 +61,19 @@ class SP_Meta_Box_Player_Statistics {
<thead>
<tr>
<th><?php _e( 'Season', 'sportspress' ); ?></th>
<?php if ( $league_id ): ?>
<th>
<?php if ( $has_checkboxes ): ?>
<label for="sp_columns_team">
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ): ?>
<?php if ( $league_id ): ?>
<th>
<?php if ( $has_checkboxes ): ?>
<label for="sp_columns_team">
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
<?php _e( 'Team', 'sportspress' ); ?>
</label>
<?php else: ?>
<?php _e( 'Team', 'sportspress' ); ?>
</label>
<?php else: ?>
<?php _e( 'Team', 'sportspress' ); ?>
<?php endif; ?>
</th>
<?php endif; ?>
</th>
<?php endif; ?>
<?php endif; ?>
<?php foreach ( $columns as $key => $label ): if ( $key == 'team' ) continue; ?>
<th><?php echo $label; ?></th>
@@ -87,18 +89,29 @@ class SP_Meta_Box_Player_Statistics {
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php
if ( 'WP_Error' == get_class( $div ) ) _e( 'Total', 'sportspress' );
else echo $div->name;
?>
</td>
<?php if ( $league_id ): ?>
<?php if ( $div_id == 0 ): ?>
<td>&nbsp;</td>
<?php else: ?>
<td>
<?php if ( 'team' != get_option( 'sportspress_mode', 'team' ) && 0 !== $div_id ): ?>
<label>
<?php $value = sp_array_value( $leagues, $div_id, '-1' ); ?>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<input type="checkbox" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" value="1" <?php checked( $value ); ?>>
<?php
if ( 'WP_Error' == get_class( $div ) ) _e( 'Total', 'sportspress' );
else echo $div->name;
?>
</label>
<?php else: ?>
<?php
if ( 'WP_Error' == get_class( $div ) ) _e( 'Total', 'sportspress' );
else echo $div->name;
?>
<?php endif; ?>
</td>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ): ?>
<?php if ( $league_id ): ?>
<?php if ( $div_id == 0 ): ?>
<td>&nbsp;</td>
<?php else: ?>
<td>
<?php $value = sp_array_value( $leagues, $div_id, '-1' ); ?>
<?php
$args = array(
'post_type' => 'sp_team',
@@ -127,10 +140,8 @@ class SP_Meta_Box_Player_Statistics {
_e( '&mdash; None &mdash;', 'sportspress' );
endif;
?>
<?php } else { ?>
<input type="checkbox" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" value="0" <?php checked( 0, $value ); ?>>
<?php } ?>
</td>
</td>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php foreach ( $columns as $column => $label ): if ( $column == 'team' ) continue;

View File

@@ -81,35 +81,37 @@ class SP_Meta_Box_Staff_Details {
<?php endforeach; ?>
</select></p>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<?php } ?>
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>
<p><?php
@@ -149,8 +151,11 @@ class SP_Meta_Box_Staff_Details {
public static function save( $post_id, $post ) {
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_role', null ), 'sp_role', false );
update_post_meta( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', '' ) );
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
}
}

View File

@@ -28,6 +28,7 @@ class SP_Settings_General extends SP_Settings_Page {
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_timezone', array( $this, 'timezone_setting' ) );
add_action( 'sportspress_admin_field_frontend_styles', array( $this, 'frontend_styles_setting' ) );
add_action( 'sportspress_admin_field_current_mode', array( $this, 'current_mode_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
@@ -64,10 +65,12 @@ class SP_Settings_General extends SP_Settings_Page {
'type' => 'radio',
'options' => array(
'team' => __( 'Teams', 'sportspress' ),
'player' => __( 'Players', 'sportspress' ),
'player' => __( 'Players', 'sportspress' ) . ' ' . __( '(Beta)', 'sportspress' ),
),
'desc_tip' => _x( 'Who competes in events?', 'mode setting description', 'sportspress' ),
),
array( 'type' => 'current_mode' ),
)),
array(
@@ -335,6 +338,21 @@ class SP_Settings_General extends SP_Settings_Page {
<input name="' . esc_attr( $id ). '" id="' . esc_attr( $id ) . '" type="text" value="' . esc_attr( $value ) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr( $id ) . '" class="colorpickdiv"></div>
</div>';
}
/**
* Output script to refresh page when mode is changed.
*/
function current_mode_setting() {
?>
<input type="hidden" name="sportspress_current_mode" value="<?php echo get_option( 'sportspress_mode', 'team' ); ?>">
<?php if ( sp_array_value( $_POST, 'sportspress_mode', 'team' ) !== sp_array_value( $_POST, 'sportspress_current_mode', 'team' ) ) { ?>
<script type="text/javascript">
window.onload = function() {
window.location = window.location.href;
}
</script>
<?php }
}
}
endif;

View File

@@ -167,7 +167,8 @@ class SP_Settings_Modules extends SP_Settings_Page {
<img src="<?php echo $theme->get_screenshot(); ?>" class="sp-theme-screenshot">
<p><?php _e( '<strong>Your theme does not declare SportsPress support</strong> &#8211; if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?></p>
<p class="sp-module-actions">
<a class="button" href="http://themeboy.com/sportspress/themes/" target="_blank"><?php _e( 'Need a Better Theme?', 'sportspress' ); ?></a>
<span><?php _e( 'Free', 'sportspress' ); ?></span>
<a class="button" href="<?php echo add_query_arg( array( 'theme' => 'rookie' ), admin_url( 'theme-install.php' ) ); ?>" target="_blank"><?php _e( 'Install Rookie Theme', 'sportspress' ); ?></a>
</p>
</td></tr>
</tbody>
@@ -194,6 +195,7 @@ class SP_Settings_Modules extends SP_Settings_Page {
<div class="sp-modules-main">
<?php foreach ( SP()->modules->data as $section => $modules ) { ?>
<?php if ( 'team' == $section && 'team' != get_option( 'sportspress_mode', 'team' ) ) continue; ?>
<table class="sp-modules-table widefat" cellspacing="0">
<thead>
<tr><th>

View File

@@ -21,6 +21,8 @@ function sp_get_screen_ids() {
'widgets',
'dashboard',
'dashboard_page_sp-about',
'dashboard_page_sp-credits',
'dashboard_page_sp-translators',
'toplevel_page_sportspress',
'edit-sp_result',
'sp_result',

View File

@@ -55,79 +55,81 @@
</tr>
</tbody>
</table>
<table class="form-table">
<tbody>
<?php
$selection = get_option( 'sportspress_primary_result', 0 );
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<table class="form-table">
<tbody>
<?php
$selection = get_option( 'sportspress_primary_result', 0 );
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Team Results', 'sportspress' ) ?>
<p class="description"><?php _e( 'Used for events.', 'sportspress' ); ?></p>
</th>
<td class="forminp">
<legend class="screen-reader-text"><span><?php _e( 'Team Results', 'sportspress' ) ?></span></legend>
<form>
<?php wp_nonce_field( 'sp-save-primary-result', 'sp-config-nonce', false ); ?>
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th class="radio" scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Variables', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Team Results', 'sportspress' ) ?>
<p class="description"><?php _e( 'Used for events.', 'sportspress' ); ?></p>
</th>
<td class="forminp">
<legend class="screen-reader-text"><span><?php _e( 'Team Results', 'sportspress' ) ?></span></legend>
<form>
<?php wp_nonce_field( 'sp-save-primary-result', 'sp-config-nonce', false ); ?>
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th class="radio" scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Variables', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" class="sp-primary-result-option" id="sportspress_primary_result_0" name="sportspress_primary_result" value="0" <?php checked( $selection, 0 ); ?>></th>
<th colspan="4"><label for="sportspress_primary_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 if ( $data ): $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" class="sp-primary-result-option" id="sportspress_primary_result_<?php echo $row->post_name; ?>" name="sportspress_primary_result" value="<?php echo $row->post_name; ?>" <?php checked( $selection, $row->post_name ); ?>></td>
<td class="row-title"><label for="sportspress_primary_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>
<td><p class="description"><?php echo $row->post_excerpt; ?></p></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; else: ?>
<tr class="alternate">
<td colspan="5"><?php _e( 'No results found.', 'sportspress' ); ?></td>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" class="sp-primary-result-option" id="sportspress_primary_result_0" name="sportspress_primary_result" value="0" <?php checked( $selection, 0 ); ?>></th>
<th colspan="4"><label for="sportspress_primary_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 if ( $data ): $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" class="sp-primary-result-option" id="sportspress_primary_result_<?php echo $row->post_name; ?>" name="sportspress_primary_result" value="<?php echo $row->post_name; ?>" <?php checked( $selection, $row->post_name ); ?>></td>
<td class="row-title"><label for="sportspress_primary_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>
<td><p class="description"><?php echo $row->post_excerpt; ?></p></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; else: ?>
<tr class="alternate">
<td colspan="5"><?php _e( 'No results found.', 'sportspress' ); ?></td>
</tr>
<?php endif; ?>
</table>
</form>
<div class="tablenav bottom">
<a class="button alignleft" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button button-primary alignright" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
<br class="clear">
</div>
</td>
</tr>
</tbody>
</table>
<?php endif; ?>
</table>
</form>
<div class="tablenav bottom">
<a class="button alignleft" href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button button-primary alignright" href="<?php echo admin_url( 'post-new.php?post_type=sp_result' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
<br class="clear">
</div>
</td>
</tr>
</tbody>
</table>
<?php } ?>
<table class="form-table">
<tbody>
<?php
@@ -179,62 +181,64 @@
</tr>
</tbody>
</table>
<table class="form-table">
<tbody>
<?php
$args = array(
'post_type' => 'sp_column',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Table Columns', 'sportspress' ) ?>
<p class="description"><?php _e( 'Used for league tables.', 'sportspress' ); ?></p>
</th>
<td class="forminp">
<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>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<?php if ( $data ): $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 sp_get_post_equation( $row->ID ); ?></td>
<td><?php echo sp_get_post_precision( $row->ID ); ?></td>
<td><?php echo sp_get_post_order( $row->ID ); ?></td>
<td><p class="description"><?php echo $row->post_excerpt; ?></p></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; else: ?>
<tr class="alternate">
<td colspan="7"><?php _e( 'No results found.', 'sportspress' ); ?></td>
</tr>
<?php endif; ?>
</table>
<div class="tablenav bottom">
<a class="button alignleft" href="<?php echo admin_url( 'edit.php?post_type=sp_column' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button button-primary alignright" href="<?php echo admin_url( 'post-new.php?post_type=sp_column' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
<br class="clear">
</div>
</fieldset>
</td>
</tr>
</tbody>
</table>
<?php if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) { ?>
<table class="form-table">
<tbody>
<?php
$args = array(
'post_type' => 'sp_column',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php _e( 'Table Columns', 'sportspress' ) ?>
<p class="description"><?php _e( 'Used for league tables.', 'sportspress' ); ?></p>
</th>
<td class="forminp">
<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>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<?php if ( $data ): $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 sp_get_post_equation( $row->ID ); ?></td>
<td><?php echo sp_get_post_precision( $row->ID ); ?></td>
<td><?php echo sp_get_post_order( $row->ID ); ?></td>
<td><p class="description"><?php echo $row->post_excerpt; ?></p></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>
<?php $i++; endforeach; else: ?>
<tr class="alternate">
<td colspan="7"><?php _e( 'No results found.', 'sportspress' ); ?></td>
</tr>
<?php endif; ?>
</table>
<div class="tablenav bottom">
<a class="button alignleft" href="<?php echo admin_url( 'edit.php?post_type=sp_column' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button button-primary alignright" href="<?php echo admin_url( 'post-new.php?post_type=sp_column' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>
<br class="clear">
</div>
</fieldset>
</td>
</tr>
</tbody>
</table>
<?php } ?>
<table class="form-table">
<tbody>
<?php

View File

@@ -450,7 +450,7 @@ class SP_Player_List extends SP_Custom_Post {
foreach( $this->columns as $key ):
if ( $key == 'number' ):
$labels[ $key ] = '#';
elseif ( $key == 'team' ):
elseif ( $key == 'team' && 'team' == get_option( 'sportspress_mode', 'team' ) ):
$labels[ $key ] = __( 'Team', 'sportspress' );
elseif ( array_key_exists( $key, $columns ) ):
$labels[ $key ] = $columns[ $key ];
@@ -469,7 +469,7 @@ class SP_Player_List extends SP_Custom_Post {
$labels = array();
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
$labels['name'] = __( 'Player', 'sportspress' );
if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' );
if ( in_array( 'team', $this->columns ) && 'team' == get_option( 'sportspress_mode', 'team' ) ) $labels['team'] = __( 'Team', 'sportspress' );
$merged[0] = array_merge( $labels, $columns );
return $merged;

View File

@@ -429,67 +429,69 @@ class SP_Post_types {
);
}
register_post_type( 'sp_team',
apply_filters( 'sportspress_register_post_type_team',
array(
'labels' => array(
'name' => __( 'Teams', 'sportspress' ),
'singular_name' => __( 'Team', 'sportspress' ),
'add_new_item' => __( 'Add New Team', 'sportspress' ),
'edit_item' => __( 'Edit Team', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
'view_item' => __( 'View Team', 'sportspress' ),
'search_items' => __( 'Search', 'sportspress' ),
'not_found' => __( 'No results found.', 'sportspress' ),
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
),
'public' => true,
'show_ui' => true,
'capability_type' => 'sp_team',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => get_option( 'sportspress_team_slug', 'team' ) ),
'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => true,
'menu_icon' => 'dashicons-shield-alt',
)
)
);
if ( 'yes' == get_option( 'sportspress_load_league_tables_module', 'yes' ) ) {
register_post_type( 'sp_table',
apply_filters( 'sportspress_register_post_type_table',
if ( 'team' == get_option( 'sportspress_mode', 'team' ) ) {
register_post_type( 'sp_team',
apply_filters( 'sportspress_register_post_type_team',
array(
'labels' => array(
'name' => __( 'League Tables', 'sportspress' ),
'singular_name' => __( 'League Table', 'sportspress' ),
'add_new_item' => __( 'Add New League Table', 'sportspress' ),
'edit_item' => __( 'Edit League Table', 'sportspress' ),
'name' => __( 'Teams', 'sportspress' ),
'singular_name' => __( 'Team', 'sportspress' ),
'add_new_item' => __( 'Add New Team', 'sportspress' ),
'edit_item' => __( 'Edit Team', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
'view_item' => __( 'View League Table', 'sportspress' ),
'view_item' => __( 'View Team', 'sportspress' ),
'search_items' => __( 'Search', 'sportspress' ),
'not_found' => __( 'No results found.', 'sportspress' ),
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
),
'public' => true,
'show_ui' => true,
'capability_type' => 'sp_table',
'capability_type' => 'sp_team',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'rewrite' => array( 'slug' => get_option( 'sportspress_table_slug', 'table' ) ),
'supports' => array( 'title', 'page-attributes', 'thumbnail' ),
'hierarchical' => true,
'rewrite' => array( 'slug' => get_option( 'sportspress_team_slug', 'team' ) ),
'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes', 'excerpt' ),
'has_archive' => false,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_team',
'show_in_admin_bar' => true,
'menu_icon' => 'dashicons-shield-alt',
)
)
);
if ( 'yes' == get_option( 'sportspress_load_league_tables_module', 'yes' ) ) {
register_post_type( 'sp_table',
apply_filters( 'sportspress_register_post_type_table',
array(
'labels' => array(
'name' => __( 'League Tables', 'sportspress' ),
'singular_name' => __( 'League Table', 'sportspress' ),
'add_new_item' => __( 'Add New League Table', 'sportspress' ),
'edit_item' => __( 'Edit League Table', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
'view_item' => __( 'View League Table', 'sportspress' ),
'search_items' => __( 'Search', 'sportspress' ),
'not_found' => __( 'No results found.', 'sportspress' ),
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
),
'public' => true,
'show_ui' => true,
'capability_type' => 'sp_table',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'rewrite' => array( 'slug' => get_option( 'sportspress_table_slug', 'table' ) ),
'supports' => array( 'title', 'page-attributes', 'thumbnail' ),
'has_archive' => false,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_team',
'show_in_admin_bar' => true,
)
)
);
}
}
register_post_type( 'sp_player',

View File

@@ -61,8 +61,15 @@ if ( is_array( $teams ) ):
$totals = array();
if ( $team_id ) {
if ( 0 < $team_id ) {
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
} elseif ( 0 == $team_id ) {
$data = array();
foreach ( $players as $player_id ) {
if ( isset( $performance[ $player_id ][ $player_id ] ) ) {
$data[ $player_id ] = $performance[ $player_id ][ $player_id ];
}
}
} else {
$data = sp_array_value( array_values( $performance ), $index );
}