Future-proof the event title generator

This commit is contained in:
Brian Miyaji
2015-01-21 23:46:27 +11:00
parent d4561e74be
commit 790789c6b6

View File

@@ -66,13 +66,22 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
public function wp_insert_post_data( $data, $postarr ) {
if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ):
$teams = sp_array_value( $postarr, 'sp_team', array() );
if ( 'teams' == get_option( 'sportspress_mode', 'teams' ) ) $post_type = 'sp_team';
else $post_type = 'sp_player';
$teams = sp_array_value( $postarr, $post_type, array() );
$teams = array_filter( $teams );
$team_names = array();
foreach( $teams as $team ):
$team_names[] = get_the_title( $team );
foreach ( $teams as $team ):
while ( is_array( $team ) ) {
$team = array_shift( array_filter( $team ) );
}
if ( $team ) $team_names[] = get_the_title( $team );
endforeach;
$team_names = array_unique( $team_names );
$data['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names );
endif;