Apply players (individual sport) mode throughout
This commit is contained in:
@@ -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 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user