diff --git a/admin/post-types/event.php b/admin/post-types/event.php
index 5c7c4657..51228f3f 100644
--- a/admin/post-types/event.php
+++ b/admin/post-types/event.php
@@ -28,12 +28,17 @@ function sp_event_display_scheduled( $posts ) {
}
add_filter( 'the_posts', 'sp_event_display_scheduled' );
-function sp_event_meta_init() {
+function sp_event_meta_init( $post ) {
+ $limit = get_option( 'sp_event_team_count' );
+ $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' );
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_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' );
+ if ( $teams != array_pad( array_slice( array(), 0, $limit ), $limit, 0 ) ):
+ 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' );
+ endif;
add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' );
}
@@ -75,35 +80,26 @@ function sp_event_players_meta( $post ) {
$limit = get_option( 'sp_event_team_count' );
$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 ) ):
+ $stats = (array)get_post_meta( $post->ID, 'sp_players', true );
+
+ // Get columns from result variables
+ $columns = sp_get_var_labels( 'sp_metric', true );
+
+ foreach ( $teams as $key => $team_id ):
+ if ( ! $team_id ) continue;
+
+ // Get results for players in the team
+ $players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
+ $data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
?>
-
+
ID, 'sp_players', true );
-
- // Get columns from result variables
- $columns = sp_get_var_labels( 'sp_metric', true );
-
- foreach ( $teams as $key => $team_id ):
-
- // Get results for players in the team
- $players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
- $data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
-
- ?>
-
- ID, 'sp_player', false );
+
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' );
+
+ if ( $players && $players != array(0) ):
+ add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sp_list_stats_meta', 'sp_list', 'normal', 'high' );
+ endif;
}
function sp_list_player_meta( $post ) {
diff --git a/admin/post-types/player.php b/admin/post-types/player.php
index 0beb4899..88efc356 100644
--- a/admin/post-types/player.php
+++ b/admin/post-types/player.php
@@ -18,13 +18,20 @@ function sp_player_cpt_init() {
}
add_action( 'init', 'sp_player_cpt_init' );
-function sp_player_meta_init() {
+function sp_player_meta_init( $post ) {
+ $teams = (array)get_post_meta( $post->ID, 'sp_team', false );
+ $divisions = (array)get_the_terms( $post->ID, 'sp_div' );
+
remove_meta_box( 'submitdiv', 'sp_player', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_player', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_player', 'side' );
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_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
+
+ if ( $teams && $teams != array(0) && $divisions && $divisions != array(0) ):
+ add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
+ endif;
+
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' );
}
diff --git a/admin/post-types/table.php b/admin/post-types/table.php
index d4227987..e8b313e3 100644
--- a/admin/post-types/table.php
+++ b/admin/post-types/table.php
@@ -29,12 +29,17 @@ function sp_table_edit_columns() {
}
add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' );
-function sp_table_meta_init() {
+function sp_table_meta_init( $post ) {
+ $teams = (array)get_post_meta( $post->ID, 'sp_team', false );
+
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' );
+
+ if ( $teams && $teams != array(0) ):
+ add_meta_box( 'sp_statsdiv', __( 'League Table', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' );
+ endif;
}
-function sp_table_team_meta( $post ) {
+function sp_table_team_meta( $post, $test ) {
$division_id = sp_get_the_term_id( $post->ID, 'sp_div', 0 );
?>
diff --git a/admin/post-types/team.php b/admin/post-types/team.php
index ea19eed6..61fcbd8e 100644
--- a/admin/post-types/team.php
+++ b/admin/post-types/team.php
@@ -18,12 +18,17 @@ function sp_team_cpt_init() {
}
add_action( 'init', 'sp_team_cpt_init' );
-function sp_team_meta_init() {
+function sp_team_meta_init( $post ) {
+ $divisions = (array)get_the_terms( $post->ID, 'sp_div' );
+
remove_meta_box( 'submitdiv', 'sp_team', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
- add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_team_stats_meta', 'sp_team', 'normal', 'high' );
+
+ if ( $divisions && $divisions != array(0) ):
+ add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_team_stats_meta', 'sp_team', 'normal', 'high' );
+ endif;
}
function sp_team_edit_columns() {