Add player lists
This commit is contained in:
@@ -23,6 +23,9 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
|
||||
$result = get_post_meta( $post_id, 'sp_result', false );
|
||||
echo get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '<br />', $result, ( empty( $result ) ? ' — ' : ' ' ) ) : '—';
|
||||
break;
|
||||
case 'sp_player':
|
||||
echo sp_the_posts( $post_id, 'sp_player' );
|
||||
break;
|
||||
case 'sp_event':
|
||||
echo get_post_meta ( $post_id, 'sp_event' ) ? sizeof( get_post_meta ( $post_id, 'sp_event' ) ) : '—';
|
||||
break;
|
||||
@@ -124,6 +127,12 @@ function sp_save_post( $post_id ) {
|
||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_league', 0 ), 'sp_league' );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||
break;
|
||||
case ( 'sp_list' ):
|
||||
update_post_meta( $post_id, 'sp_stats', sp_array_value( $_POST, 'sp_stats', array() ) );
|
||||
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' );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
|
||||
break;
|
||||
endswitch;
|
||||
|
||||
/*
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
function sp_event_cpt_init() {
|
||||
$name = __( 'Events', 'sportspress' );
|
||||
$singular_name = __( 'Event', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'events', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
16
helpers.php
16
helpers.php
@@ -65,7 +65,8 @@ if ( !function_exists( 'sp_num_to_letter' ) ) {
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_cpt_labels' ) ) {
|
||||
function sp_cpt_labels( $name, $singular_name ) {
|
||||
function sp_cpt_labels( $name, $singular_name, $lowercase_name = null ) {
|
||||
if ( !$lowercase_name ) $lowercase_name = $name;
|
||||
$labels = array(
|
||||
'name' => $name,
|
||||
'singular_name' => $singular_name,
|
||||
@@ -75,8 +76,8 @@ if ( !function_exists( 'sp_cpt_labels' ) ) {
|
||||
'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ),
|
||||
'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ),
|
||||
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
|
||||
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $name ),
|
||||
'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $name ),
|
||||
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ),
|
||||
'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $lowercase_name ),
|
||||
'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':'
|
||||
);
|
||||
return $labels;
|
||||
@@ -84,7 +85,8 @@ if ( !function_exists( 'sp_cpt_labels' ) ) {
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_tax_labels' ) ) {
|
||||
function sp_tax_labels( $name, $singular_name ) {
|
||||
function sp_tax_labels( $name, $singular_name, $lowercase_name = null ) {
|
||||
if ( !$lowercase_name ) $lowercase_name = $name;
|
||||
$labels = array(
|
||||
'name' => $name,
|
||||
'singular_name' => $singular_name,
|
||||
@@ -97,7 +99,7 @@ if ( !function_exists( 'sp_tax_labels' ) ) {
|
||||
'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ),
|
||||
'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':',
|
||||
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
|
||||
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $name )
|
||||
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name )
|
||||
);
|
||||
return $labels;
|
||||
}
|
||||
@@ -125,7 +127,7 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
||||
'show_option_none' => false,
|
||||
'taxonomy' => null,
|
||||
'name' => null,
|
||||
'selected' => null,
|
||||
'selected' => null
|
||||
);
|
||||
$args = array_merge( $defaults, $args );
|
||||
$terms = get_terms( $args['taxonomy'] );
|
||||
@@ -354,7 +356,7 @@ if ( !function_exists( 'sp_get_stats_row' ) ) {
|
||||
else:
|
||||
|
||||
$output = $dynamic;
|
||||
|
||||
|
||||
endif;
|
||||
|
||||
return $output;
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
function sp_league_tax_init() {
|
||||
$name = __( 'Leagues', 'sportspress' );
|
||||
$singular_name = __( 'League', 'sportspress' );
|
||||
$object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff', 'sp_list' );
|
||||
$labels = sp_tax_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'leagues', 'sportspress' );
|
||||
$object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_staff' );
|
||||
$labels = sp_tax_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
81
list.php
81
list.php
@@ -2,13 +2,15 @@
|
||||
function sp_list_cpt_init() {
|
||||
$name = __( 'Player Lists', 'sportspress' );
|
||||
$singular_name = __( 'Player List', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'player lists', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
|
||||
'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes' ),
|
||||
'register_meta_box_cb' => 'sp_list_meta_init',
|
||||
'rewrite' => array( 'slug' => 'list' )
|
||||
);
|
||||
register_post_type( 'sp_list', $args );
|
||||
@@ -19,10 +21,85 @@ function sp_list_edit_columns() {
|
||||
$columns = array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Title' ),
|
||||
'sp_player' => __( 'Players', 'sportspress' ),
|
||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
||||
'sp_league' => __( 'Leagues', 'sportspress' )
|
||||
);
|
||||
return $columns;
|
||||
}
|
||||
add_filter( 'manage_edit-sp_list_columns', 'sp_list_edit_columns' );
|
||||
|
||||
function sp_list_meta_init() {
|
||||
add_meta_box( 'sp_playerdiv', __( 'Players', 'sportspress' ), 'sp_list_player_meta', 'sp_list', 'side', 'high' );
|
||||
add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sp_list_stats_meta', 'sp_list', 'normal', 'high' );
|
||||
}
|
||||
|
||||
function sp_list_player_meta( $post ) {
|
||||
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
||||
?>
|
||||
<div>
|
||||
<p class="sp-tab-select">
|
||||
<?php
|
||||
$args = array(
|
||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
|
||||
'taxonomy' => 'sp_league',
|
||||
'name' => 'sp_league',
|
||||
'selected' => $league_id
|
||||
);
|
||||
sp_dropdown_taxonomies( $args );
|
||||
?>
|
||||
</p>
|
||||
<p class="sp-tab-select">
|
||||
<?php
|
||||
$args = array(
|
||||
'show_option_none' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
|
||||
'option_none_value' => '0',
|
||||
'post_type' => 'sp_team',
|
||||
'name' => 'sp_team',
|
||||
'selected' => $team_id
|
||||
);
|
||||
wp_dropdown_pages( $args );
|
||||
?>
|
||||
</p>
|
||||
<?php
|
||||
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team' );
|
||||
sp_post_adder( 'sp_player' );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
sp_nonce();
|
||||
}
|
||||
|
||||
function sp_list_stats_meta( $post ) {
|
||||
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
|
||||
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
||||
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$team_id = get_post_meta( $post->ID, 'sp_team', true );
|
||||
$data = sp_array_combine( $players, sp_array_value( $stats, $league_id, array() ) );
|
||||
|
||||
// Generate array of placeholder values for each player
|
||||
$placeholders = array();
|
||||
foreach ( $players as $player ):
|
||||
$args = array(
|
||||
'post_type' => 'sp_event',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'sp_player',
|
||||
'value' => $player
|
||||
)
|
||||
),
|
||||
'tax_query' => array(
|
||||
array(
|
||||
'taxonomy' => 'sp_league',
|
||||
'field' => 'id',
|
||||
'terms' => $league_id
|
||||
)
|
||||
)
|
||||
);
|
||||
$placeholders[ $player ] = sp_get_stats_row( 'sp_player', $args, true );
|
||||
endforeach;
|
||||
|
||||
sp_stats_table( $data, $placeholders, $league_id, array( 'Player', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), false );
|
||||
}
|
||||
?>
|
||||
@@ -2,7 +2,8 @@
|
||||
function sp_player_cpt_init() {
|
||||
$name = __( 'Players', 'sportspress' );
|
||||
$singular_name = __( 'Player', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'players', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
function sp_position_tax_init() {
|
||||
$name = __( 'Positions', 'sportspress' );
|
||||
$singular_name = __( 'Position', 'sportspress' );
|
||||
$lowercase_name = __( 'position', 'sportspress' );
|
||||
$object_type = array( 'sp_player', 'sp_staff' );
|
||||
$labels = sp_tax_labels( $name, $singular_name );
|
||||
$labels = sp_tax_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
function sp_sponsor_tax_init() {
|
||||
$name = __( 'Sponsors', 'sportspress' );
|
||||
$singular_name = __( 'Sponsor', 'sportspress' );
|
||||
$lowercase_name = __( 'sponsors', 'sportspress' );
|
||||
$object_type = array( 'sp_team', 'sp_event', 'sp_player', 'sp_tournament', 'sp_venue' );
|
||||
$labels = sp_tax_labels( $name, $singular_name );
|
||||
$labels = sp_tax_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
@@ -9,9 +9,16 @@ jQuery(document).ready(function($){
|
||||
// Tab filter
|
||||
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(function() {
|
||||
var val = $(this).val();
|
||||
var filter = '.sp-filter-'+val;
|
||||
var $filters = $(this).closest('.sp-tab-select').siblings('.sp-tab-select');
|
||||
if($filters.length) {
|
||||
$filters.each(function() {
|
||||
filter += '.sp-filter-'+$(this).find('select').val();
|
||||
});
|
||||
}
|
||||
$(this).closest('.sp-tab-select').siblings('.sp-tab-panel').find('.sp-post').hide(0, function() {
|
||||
$(this).find('input').prop('disabled', true);
|
||||
$(this).filter('.sp-filter-'+val).show(0, function() {
|
||||
$(this).filter(filter).show(0, function() {
|
||||
$(this).find('input').prop('disabled', false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
function sp_staff_cpt_init() {
|
||||
$name = __( 'Staff', 'sportspress' );
|
||||
$singular_name = __( 'Staff', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'staff', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
function sp_table_cpt_init() {
|
||||
$name = __( 'League Tables', 'sportspress' );
|
||||
$singular_name = __( 'League Table', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'league tables', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
@@ -28,8 +29,6 @@ function sp_table_edit_columns() {
|
||||
add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' );
|
||||
|
||||
function sp_table_meta_init() {
|
||||
remove_meta_box( 'submitdiv', 'sp_table', 'side' );
|
||||
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_table', 'side', 'high' );
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_table_team_meta', 'sp_table', 'side', 'high' );
|
||||
add_meta_box( 'sp_statsdiv', __( 'League Table', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' );
|
||||
}
|
||||
|
||||
3
team.php
3
team.php
@@ -2,7 +2,8 @@
|
||||
function sp_team_cpt_init() {
|
||||
$name = __( 'Teams', 'sportspress' );
|
||||
$singular_name = __( 'Team', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'teams', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
function sp_tournament_cpt_init() {
|
||||
$name = __( 'Tournaments', 'sportspress' );
|
||||
$singular_name = __( 'Tournament', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'tournaments', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
function sp_venue_cpt_init() {
|
||||
$name = __( 'Venues', 'sportspress' );
|
||||
$singular_name = __( 'Venue', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name );
|
||||
$lowercase_name = __( 'venues', 'sportspress' );
|
||||
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
'labels' => $labels,
|
||||
|
||||
Reference in New Issue
Block a user