Add details section to player edit page showing number and custom fields
This commit is contained in:
@@ -19,6 +19,18 @@ function sp_player_cpt_init() {
|
|||||||
}
|
}
|
||||||
add_action( 'init', '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 ) {
|
function sp_player_meta_init( $post ) {
|
||||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$leagues = (array)get_the_terms( $post->ID, 'sp_season' );
|
$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' );
|
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
|
||||||
endif;
|
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' );
|
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_player_team_meta( $post ) {
|
function sp_player_team_meta( $post ) {
|
||||||
sp_post_checklist( $post->ID, 'sp_team' );
|
sp_post_checklist( $post->ID, 'sp_team' );
|
||||||
sp_post_adder( 'sp_team' );
|
sp_post_adder( 'sp_team' );
|
||||||
sp_nonce();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_player_stats_meta( $post ) {
|
function sp_player_stats_meta( $post ) {
|
||||||
@@ -176,15 +189,43 @@ function sp_player_profile_meta( $post ) {
|
|||||||
wp_editor( $post->post_content, 'content' );
|
wp_editor( $post->post_content, 'content' );
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_player_edit_columns() {
|
function sp_player_details_meta( $post ) {
|
||||||
$columns = array(
|
|
||||||
'cb' => '<input type="checkbox" />',
|
$number = get_post_meta( $post->ID, 'sp_number', true );
|
||||||
'title' => __( 'Name', 'sportspress' ),
|
$details = get_post_meta( $post->ID, 'sp_details', true );
|
||||||
'sp_position' => __( 'Positions', 'sportspress' ),
|
|
||||||
'sp_team' => __( 'Teams', 'sportspress' ),
|
?>
|
||||||
'sp_season' => __( 'Seasons', 'sportspress' )
|
<p><strong><?php _e( 'Player Number', 'sportspress' ); ?></strong></p>
|
||||||
);
|
<p>
|
||||||
return $columns;
|
<input name="sp_number" type="text" size="4" id="sp_number" value="<?php echo $number; ?>">
|
||||||
}
|
</p>
|
||||||
add_filter( 'manage_edit-sp_player_columns', 'sp_player_edit_columns' );
|
<?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',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$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();
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
@@ -126,11 +126,20 @@ $sportspress_sports['soccer'] = array(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'post_title' => __( 'Red Cards', 'sportspress' ),
|
'post_title' => __( 'Height', 'sportspress' ),
|
||||||
'post_name' => 'redcards',
|
'post_name' => 'height',
|
||||||
'meta' => array(
|
'meta' => array(
|
||||||
'sp_equation' => '',
|
'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,
|
'sp_precision' => 1,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -235,6 +235,12 @@ function sp_save_post( $post_id ) {
|
|||||||
// Update team array
|
// Update team array
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_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;
|
break;
|
||||||
|
|
||||||
case ( 'sp_staff' ):
|
case ( 'sp_staff' ):
|
||||||
|
|||||||
@@ -444,7 +444,14 @@ if ( !function_exists( 'sp_get_var_labels' ) ) {
|
|||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'orderby' => 'menu_order',
|
'orderby' => 'menu_order',
|
||||||
'order' => 'ASC'
|
'order' => 'ASC',
|
||||||
|
'meta_query' => array(
|
||||||
|
array(
|
||||||
|
'key' => 'sp_format',
|
||||||
|
'value' => 'custom',
|
||||||
|
'compare' => '!=',
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$vars = get_posts( $args );
|
$vars = get_posts( $args );
|
||||||
@@ -1260,7 +1267,14 @@ if ( !function_exists( 'sp_get_list' ) ) {
|
|||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'orderby' => 'menu_order',
|
'orderby' => 'menu_order',
|
||||||
'order' => 'ASC'
|
'order' => 'ASC',
|
||||||
|
'meta_query' => array(
|
||||||
|
array(
|
||||||
|
'key' => 'sp_format',
|
||||||
|
'value' => 'custom',
|
||||||
|
'compare' => '!=',
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
$statistics = get_posts( $args );
|
$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
|
// 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 );
|
$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(
|
$priorities[ $priority ] = array(
|
||||||
'column' => $statistic->post_name,
|
'column' => $statistic->post_name,
|
||||||
'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
|
'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Sports array to be populated with presets
|
// Sports array to be populated with presets
|
||||||
$sportspress_sports = array();
|
$sportspress_sports = array();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user