Add player stats meta box

This commit is contained in:
Takumi
2013-07-30 00:33:12 +10:00
parent 87a6a334d1
commit a7873b7673
2 changed files with 16 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ function sp_player_meta_init() {
remove_meta_box( 'postimagediv', 'sp_player', 'side' ); remove_meta_box( 'postimagediv', 'sp_player', 'side' );
add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_player', 'side', 'high' ); add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_player_team_meta', 'sp_player', 'side', 'high' ); add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_player_team_meta', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' ); add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' );
} }
@@ -31,6 +32,20 @@ function sp_player_team_meta( $post ) {
sp_nonce(); sp_nonce();
} }
function sp_player_stats_meta( $post ) {
$ids = (array)get_post_meta( $post->ID, 'sp_team', false );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
$stats = $stats[0];
$data = array();
foreach ( $ids as $id ):
if ( is_array( $stats ) && array_key_exists( $id, $stats ) )
$data[ $id ] = $stats[ $id ];
else
$data[ $id ] = array();
endforeach;
sp_data_table( $data, 0, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), false );
}
function sp_player_profile_meta( $post ) { function sp_player_profile_meta( $post ) {
wp_editor( $post->post_content, 'content' ); wp_editor( $post->post_content, 'content' );
} }

View File

@@ -46,7 +46,7 @@ function sp_table_stats_meta( $post ) {
$stats = $stats[0]; $stats = $stats[0];
$data = array(); $data = array();
foreach ( $ids as $id ): foreach ( $ids as $id ):
if ( array_key_exists( $id, $stats ) ) if ( is_array( $stats ) && array_key_exists( $id, $stats ) )
$data[ $id ] = $stats[ $id ]; $data[ $id ] = $stats[ $id ];
else else
$data[ $id ] = array(); $data[ $id ] = array();