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' );
|
add_filter( 'the_posts', 'sp_event_display_scheduled' );
|
||||||
|
|
||||||
function sp_event_meta_init( $post ) {
|
function sp_event_meta_init( $post ) {
|
||||||
$limit = get_option( 'sp_event_team_count' );
|
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
|
|
||||||
|
|
||||||
remove_meta_box( 'submitdiv', 'sp_event', 'side' );
|
remove_meta_box( 'submitdiv', 'sp_event', 'side' );
|
||||||
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
|
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' );
|
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_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' );
|
add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sp_event_results_meta', 'sp_event', 'normal', 'high' );
|
||||||
endif;
|
endif;
|
||||||
@@ -43,20 +42,20 @@ function sp_event_meta_init( $post ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sp_event_team_meta( $post ) {
|
function sp_event_team_meta( $post ) {
|
||||||
$limit = get_option( 'sp_event_team_count' );
|
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
|
|
||||||
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
|
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
|
||||||
for ( $i = 0; $i < $limit; $i++ ):
|
foreach ( $teams as $key => $value ):
|
||||||
?>
|
?>
|
||||||
<div>
|
<div class="sp-clone">
|
||||||
<p class="sp-tab-select sp-title-generator">
|
<p class="sp-tab-select sp-title-generator">
|
||||||
<?php
|
<?php
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'sp_team',
|
'post_type' => 'sp_team',
|
||||||
'name' => 'sp_team[]',
|
'name' => 'sp_team[]',
|
||||||
'class' => 'sportspress-pages',
|
'class' => 'sportspress-pages',
|
||||||
'show_option_none' => sprintf( __( 'Select %s' ), 'Team' ),
|
'show_option_none' => sprintf( __( 'Remove', 'sportspress' ), 'Team' ),
|
||||||
'selected' => $teams[ $i ]
|
'option_none_value' => '0',
|
||||||
|
'selected' => $value
|
||||||
);
|
);
|
||||||
wp_dropdown_pages( $args );
|
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>
|
<li class="wp-tab"><a href="#sp_staff-all"><?php _e( 'Staff', 'sportspress' ); ?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<?php
|
<?php
|
||||||
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team', $i );
|
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team', $key );
|
||||||
sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_team', $i );
|
sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_team', $key );
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
<?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
|
<?php
|
||||||
endfor;
|
|
||||||
sp_post_adder( 'sp_team' );
|
sp_post_adder( 'sp_team' );
|
||||||
sp_nonce();
|
sp_nonce();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_event_players_meta( $post ) {
|
function sp_event_players_meta( $post ) {
|
||||||
$limit = get_option( 'sp_event_team_count' );
|
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
|
|
||||||
|
|
||||||
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
|
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
|
||||||
|
|
||||||
// Get columns from result variables
|
// Get columns from result variables
|
||||||
@@ -104,17 +115,7 @@ function sp_event_players_meta( $post ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sp_event_results_meta( $post ) {
|
function sp_event_results_meta( $post ) {
|
||||||
$limit = get_option( 'sp_event_team_count' );
|
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$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 ) ):
|
|
||||||
|
|
||||||
?>
|
|
||||||
<p><strong><?php echo $team_id ? get_the_title( $team_id ) : sprintf( __( 'Select %s' ), 'Teams' ); ?></strong></p>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
$results = (array)get_post_meta( $post->ID, 'sp_results', true );
|
$results = (array)get_post_meta( $post->ID, 'sp_results', true );
|
||||||
|
|
||||||
@@ -129,8 +130,6 @@ function sp_event_results_meta( $post ) {
|
|||||||
<?php sp_event_results_table( $columns, $data ); ?>
|
<?php sp_event_results_table( $columns, $data ); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
endif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_event_article_meta( $post ) {
|
function sp_event_article_meta( $post ) {
|
||||||
|
|||||||
@@ -27,18 +27,19 @@ jQuery(document).ready(function($){
|
|||||||
// Trigger tab filter
|
// Trigger tab filter
|
||||||
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change();
|
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change();
|
||||||
|
|
||||||
// Title changer
|
// Self-cloning
|
||||||
$('input[name=post_title]').on('updateTitle', function() {
|
$('.sp-clone:last').find('select').change(function() {
|
||||||
title = $('.sp-title-generator select[value!=0]').map(function(){
|
$(this).closest('.sp-clone').siblings().find('select').change(function() {
|
||||||
return $(this).find(':selected').html().replace(/&[^;]+;/g, '');
|
if($(this).val() == '0') $(this).closest('.sp-clone').remove();
|
||||||
}).get().join(' vs ');
|
}).find('option:first').text($(this).closest('.sp-clone').attr('data-remove-text'));
|
||||||
$(this).val(title);
|
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
|
// Activate self-cloning
|
||||||
$('.sp-title-generator select').change(function() {
|
$('.sp-clone:last').find('select').change();
|
||||||
$('input[name=post_title]').trigger('updateTitle');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Total stats calculator
|
// Total stats calculator
|
||||||
$('.sp-data-table .sp-total input').on('updateTotal', function() {
|
$('.sp-data-table .sp-total input').on('updateTotal', function() {
|
||||||
|
|||||||
@@ -74,7 +74,20 @@ function sp_sanitize_title( $title ) {
|
|||||||
$title = preg_replace( "/[^a-z]/", '', $title );
|
$title = preg_replace( "/[^a-z]/", '', $title );
|
||||||
|
|
||||||
// Convert post ID to words if title is empty
|
// 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;
|
endif;
|
||||||
|
|
||||||
@@ -82,6 +95,25 @@ function sp_sanitize_title( $title ) {
|
|||||||
}
|
}
|
||||||
add_filter( 'sanitize_title', 'sp_sanitize_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 ) {
|
function sp_pre_get_posts( $wp_query ) {
|
||||||
if ( is_admin() ):
|
if ( is_admin() ):
|
||||||
$post_type = $wp_query->query['post_type'];
|
$post_type = $wp_query->query['post_type'];
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ $sportspress_texts = array(
|
|||||||
'Remove featured image' => sprintf( __( 'Remove %s', 'sportspress' ), __( 'Logo', 'sportspress' ) )
|
'Remove featured image' => sprintf( __( 'Remove %s', 'sportspress' ), __( 'Logo', 'sportspress' ) )
|
||||||
),
|
),
|
||||||
'sp_event' => array(
|
'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>',
|
'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>',
|
'Published on: <b>%1$s</b>' => __( 'Kick-off', 'sportspress' ) . ': <b>%1$s</b>',
|
||||||
'Publish <b>immediately</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' ) )
|
'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