Add details section to player edit page showing number and custom fields

This commit is contained in:
Brian Miyaji
2014-01-06 15:26:25 +11:00
parent 5b0e30221f
commit 2ededfdfe5
5 changed files with 86 additions and 17 deletions

View File

@@ -19,6 +19,18 @@ function sp_player_cpt_init() {
}
add_action( 'init', 'sp_player_cpt_init' );
function sp_player_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Name', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' )
);
return $columns;
}
add_filter( 'manage_edit-sp_player_columns', 'sp_player_edit_columns' );
function sp_player_meta_init( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
$leagues = (array)get_the_terms( $post->ID, 'sp_season' );
@@ -33,13 +45,14 @@ function sp_player_meta_init( $post ) {
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
endif;
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sp_player_details_meta', 'sp_player', 'normal', 'high' );
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' );
}
function sp_player_team_meta( $post ) {
sp_post_checklist( $post->ID, 'sp_team' );
sp_post_adder( 'sp_team' );
sp_nonce();
}
function sp_player_stats_meta( $post ) {
@@ -176,15 +189,43 @@ function sp_player_profile_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}
function sp_player_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Name', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' )
function sp_player_details_meta( $post ) {
$number = get_post_meta( $post->ID, 'sp_number', true );
$details = get_post_meta( $post->ID, 'sp_details', true );
?>
<p><strong><?php _e( 'Player Number', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_number" type="text" size="4" id="sp_number" value="<?php echo $number; ?>">
</p>
<?php
$args = array(
'post_type' => 'sp_statistic',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'sp_format',
'value' => 'custom',
),
),
);
return $columns;
$vars = get_posts( $args );
$custom = array();
foreach ( $vars as $var ):
?>
<p><strong><?php echo $var->post_title; ?></strong></p>
<p>
<input name="sp_details[<?php echo $var->post_name; ?>]" type="text" value="<?php echo sp_array_value( $details, $var->post_name, ''); ?>">
</p>
<?php
endforeach;
sp_nonce();
}
add_filter( 'manage_edit-sp_player_columns', 'sp_player_edit_columns' );
?>

View File

@@ -126,11 +126,20 @@ $sportspress_sports['soccer'] = array(
),
),
array(
'post_title' => __( 'Red Cards', 'sportspress' ),
'post_name' => 'redcards',
'post_title' => __( 'Height', 'sportspress' ),
'post_name' => 'height',
'meta' => array(
'sp_equation' => '',
'sp_format' => 'integer',
'sp_format' => 'custom',
'sp_precision' => 1,
),
),
array(
'post_title' => __( 'Weight', 'sportspress' ),
'post_name' => 'weight',
'meta' => array(
'sp_equation' => '',
'sp_format' => 'custom',
'sp_precision' => 1,
),
),

View File

@@ -235,6 +235,12 @@ function sp_save_post( $post_id ) {
// Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
// Update player number
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', '' ) );
// Update player details array
update_post_meta( $post_id, 'sp_details', sp_array_value( $_POST, 'sp_details', array() ) );
break;
case ( 'sp_staff' ):

View File

@@ -444,7 +444,14 @@ if ( !function_exists( 'sp_get_var_labels' ) ) {
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'sp_format',
'value' => 'custom',
'compare' => '!=',
),
),
);
$vars = get_posts( $args );
@@ -1260,7 +1267,14 @@ if ( !function_exists( 'sp_get_list' ) ) {
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'sp_format',
'value' => 'custom',
'compare' => '!=',
),
),
);
$statistics = get_posts( $args );
@@ -1280,7 +1294,7 @@ if ( !function_exists( 'sp_get_list' ) ) {
// Add order to priorities if priority is set and does not exist in array already
$priority = sp_array_value( sp_array_value( $meta, 'sp_priority', array() ), 0, 0 );
if ( $priority && ! array_key_exists( $priorities, $priority ) ):
if ( $priority && ! array_key_exists( $priority, $priorities ) ):
$priorities[ $priority ] = array(
'column' => $statistic->post_name,
'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )

View File

@@ -1,5 +1,4 @@
<?php
// Sports array to be populated with presets
$sportspress_sports = array();