Ability to add more than 2 teams to an event
This commit is contained in:
@@ -29,13 +29,12 @@ function sp_event_display_scheduled( $posts ) {
|
||||
add_filter( 'the_posts', 'sp_event_display_scheduled' );
|
||||
|
||||
function sp_event_meta_init( $post ) {
|
||||
$limit = get_option( 'sp_event_team_count' );
|
||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
|
||||
remove_meta_box( 'submitdiv', 'sp_event', 'side' );
|
||||
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'side', 'high' );
|
||||
if ( $teams != array_pad( array_slice( array(), 0, $limit ), $limit, 0 ) ):
|
||||
if ( sizeof( $teams ) > 0 ):
|
||||
add_meta_box( 'sp_playersdiv', __( 'Players', 'sportspress' ), 'sp_event_players_meta', 'sp_event', 'normal', 'high' );
|
||||
add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sp_event_results_meta', 'sp_event', 'normal', 'high' );
|
||||
endif;
|
||||
@@ -43,20 +42,20 @@ function sp_event_meta_init( $post ) {
|
||||
}
|
||||
|
||||
function sp_event_team_meta( $post ) {
|
||||
$limit = get_option( 'sp_event_team_count' );
|
||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
|
||||
for ( $i = 0; $i < $limit; $i++ ):
|
||||
?>
|
||||
<div>
|
||||
foreach ( $teams as $key => $value ):
|
||||
?>
|
||||
<div class="sp-clone">
|
||||
<p class="sp-tab-select sp-title-generator">
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team[]',
|
||||
'class' => 'sportspress-pages',
|
||||
'show_option_none' => sprintf( __( 'Select %s' ), 'Team' ),
|
||||
'selected' => $teams[ $i ]
|
||||
'show_option_none' => sprintf( __( 'Remove', 'sportspress' ), 'Team' ),
|
||||
'option_none_value' => '0',
|
||||
'selected' => $value
|
||||
);
|
||||
wp_dropdown_pages( $args );
|
||||
?>
|
||||
@@ -66,20 +65,32 @@ function sp_event_team_meta( $post ) {
|
||||
<li class="wp-tab"><a href="#sp_staff-all"><?php _e( 'Staff', 'sportspress' ); ?></a></li>
|
||||
</ul>
|
||||
<?php
|
||||
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team', $i );
|
||||
sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_team', $i );
|
||||
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team', $key );
|
||||
sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_team', $key );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
endfor;
|
||||
<?php endforeach; ?>
|
||||
<div class="sp-clone" data-remove-text="<?php _e( 'Remove', 'sportspress' ); ?>" data-clone-name="sp_team">
|
||||
<p class="sp-tab-select sp-title-generator">
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team_selector',
|
||||
'class' => 'sportspress-pages',
|
||||
'show_option_none' => sprintf( __( 'Select %s', 'sportspress' ), 'Team' ),
|
||||
'option_none_value' => '0'
|
||||
);
|
||||
wp_dropdown_pages( $args );
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
sp_post_adder( 'sp_team' );
|
||||
sp_nonce();
|
||||
}
|
||||
|
||||
function sp_event_players_meta( $post ) {
|
||||
$limit = get_option( 'sp_event_team_count' );
|
||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
|
||||
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
|
||||
|
||||
// Get columns from result variables
|
||||
@@ -104,33 +115,21 @@ function sp_event_players_meta( $post ) {
|
||||
}
|
||||
|
||||
function sp_event_results_meta( $post ) {
|
||||
$limit = get_option( 'sp_event_team_count' );
|
||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
|
||||
|
||||
// Teams
|
||||
if ( $teams == array_pad( array_slice( array(), 0, $limit ), $limit, 0 ) ):
|
||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||
|
||||
?>
|
||||
<p><strong><?php echo $team_id ? get_the_title( $team_id ) : sprintf( __( 'Select %s' ), 'Teams' ); ?></strong></p>
|
||||
<?php
|
||||
$results = (array)get_post_meta( $post->ID, 'sp_results', true );
|
||||
|
||||
else:
|
||||
// Get columns from result variables
|
||||
$columns = sp_get_var_labels( 'sp_result' );
|
||||
|
||||
$results = (array)get_post_meta( $post->ID, 'sp_results', true );
|
||||
// Get results for all teams
|
||||
$data = sp_array_combine( $teams, $results );
|
||||
|
||||
// Get columns from result variables
|
||||
$columns = sp_get_var_labels( 'sp_result' );
|
||||
|
||||
// Get results for all teams
|
||||
$data = sp_array_combine( $teams, $results );
|
||||
|
||||
?>
|
||||
<div>
|
||||
<?php sp_event_results_table( $columns, $data ); ?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
endif;
|
||||
?>
|
||||
<div>
|
||||
<?php sp_event_results_table( $columns, $data ); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function sp_event_article_meta( $post ) {
|
||||
|
||||
@@ -27,18 +27,19 @@ jQuery(document).ready(function($){
|
||||
// Trigger tab filter
|
||||
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change();
|
||||
|
||||
// Title changer
|
||||
$('input[name=post_title]').on('updateTitle', function() {
|
||||
title = $('.sp-title-generator select[value!=0]').map(function(){
|
||||
return $(this).find(':selected').html().replace(/&[^;]+;/g, '');
|
||||
}).get().join(' vs ');
|
||||
$(this).val(title);
|
||||
// Self-cloning
|
||||
$('.sp-clone:last').find('select').change(function() {
|
||||
$(this).closest('.sp-clone').siblings().find('select').change(function() {
|
||||
if($(this).val() == '0') $(this).closest('.sp-clone').remove();
|
||||
}).find('option:first').text($(this).closest('.sp-clone').attr('data-remove-text'));
|
||||
if($(this).val() != '0') {
|
||||
$original = $(this).closest('.sp-clone');
|
||||
$original.before($original.clone().find('select').attr('name', $original.attr('data-clone-name') + '[]').val($(this).val()).closest('.sp-clone')).attr('data-clone-num', parseInt($original.attr('data-clone-num')) + 1).find('select').val('0').change();
|
||||
}
|
||||
});
|
||||
|
||||
// Activate title changer
|
||||
$('.sp-title-generator select').change(function() {
|
||||
$('input[name=post_title]').trigger('updateTitle');
|
||||
});
|
||||
// Activate self-cloning
|
||||
$('.sp-clone:last').find('select').change();
|
||||
|
||||
// Total stats calculator
|
||||
$('.sp-data-table .sp-total input').on('updateTotal', function() {
|
||||
|
||||
@@ -74,7 +74,20 @@ function sp_sanitize_title( $title ) {
|
||||
$title = preg_replace( "/[^a-z]/", '', $title );
|
||||
|
||||
// Convert post ID to words if title is empty
|
||||
if ( $title == '' ) $title = sp_numbers_to_words( $_POST['ID'] );
|
||||
if ( $title == '' ):
|
||||
|
||||
$title = sp_numbers_to_words( $_POST['ID'] );
|
||||
|
||||
endif;
|
||||
|
||||
elseif ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && $_POST['post_type'] == 'sp_event' ):
|
||||
|
||||
// Auto slug generation
|
||||
if ( $_POST['post_title'] == '' && ( $_POST['post_name'] == '' || is_int( $_POST['post_name'] ) ) ):
|
||||
|
||||
$title = '';
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
||||
@@ -82,6 +95,25 @@ function sp_sanitize_title( $title ) {
|
||||
}
|
||||
add_filter( 'sanitize_title', 'sp_sanitize_title' );
|
||||
|
||||
function sp_insert_post_data( $data, $postarr ) {
|
||||
|
||||
if( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ):
|
||||
|
||||
$teams = (array)$postarr['sp_team'];
|
||||
|
||||
$team_names = array();
|
||||
foreach( $teams as $team ):
|
||||
$team_names[] = get_the_title( $team );
|
||||
endforeach;
|
||||
|
||||
$data['post_title'] = implode( ' ' . __( 'vs', 'sportspress' ) . ' ', $team_names );
|
||||
|
||||
endif;
|
||||
|
||||
return $data;
|
||||
}
|
||||
add_filter( 'wp_insert_post_data' , 'sp_insert_post_data' , '99', 2 );
|
||||
|
||||
function sp_pre_get_posts( $wp_query ) {
|
||||
if ( is_admin() ):
|
||||
$post_type = $wp_query->query['post_type'];
|
||||
|
||||
@@ -25,7 +25,7 @@ $sportspress_texts = array(
|
||||
'Remove featured image' => sprintf( __( 'Remove %s', 'sportspress' ), __( 'Logo', 'sportspress' ) )
|
||||
),
|
||||
'sp_event' => array(
|
||||
'Enter title here' => '',
|
||||
'Enter title here' => __( '(no title)', 'sportspress' ),
|
||||
'Scheduled for: <b>%1$s</b>' => __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>',
|
||||
'Published on: <b>%1$s</b>' => __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>',
|
||||
'Publish <b>immediately</b>' => __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>'
|
||||
@@ -67,6 +67,4 @@ $sportspress_thumbnail_texts = array(
|
||||
'Remove featured image' => sprintf( __( 'Remove %s', 'sportspress' ), __( 'Photo', 'sportspress' ) )
|
||||
)
|
||||
);
|
||||
|
||||
add_option( 'sp_event_team_count', 2 ); // TODO: dynamic team appending
|
||||
?>
|
||||
Reference in New Issue
Block a user