diff --git a/admin/hooks/admin-init.php b/admin/hooks/admin-init.php
index 16233f59..5f39597e 100644
--- a/admin/hooks/admin-init.php
+++ b/admin/hooks/admin-init.php
@@ -11,24 +11,26 @@ function sportspress_admin_init() {
);
$caps = array(
- 'publish',
'read',
- 'delete',
- 'delete_others',
- 'delete_private',
- 'delete_published',
+ 'read_private',
'edit',
'edit_others',
'edit_private',
'edit_published',
- 'read_private',
+ 'publish',
+ 'delete',
+ 'delete_others',
+ 'delete_private',
+ 'delete_published',
);
// Site Admin
$administrator = get_role( 'administrator' );
foreach( $post_types as $post_type ):
+ $administrator->add_cap( 'read_' . $post_type );
$administrator->add_cap( 'edit_' . $post_type );
+ $administrator->add_cap( 'delete_' . $post_type );
foreach ( $caps as $cap ):
$administrator->add_cap( $cap . '_' . $post_type . 's' );
endforeach;
diff --git a/admin/hooks/manage-posts-columns.php b/admin/hooks/manage-posts-columns.php
index 1299775c..13a14fe4 100644
--- a/admin/hooks/manage-posts-columns.php
+++ b/admin/hooks/manage-posts-columns.php
@@ -34,6 +34,7 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
$team = get_post( $team_id );
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
+ echo $team->post_title;
if ( $outcome_slug && $outcome_slug != '-1' ):
$args=array(
'name' => $outcome_slug,
@@ -43,10 +44,12 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
);
$outcomes = get_posts( $args );
- echo $team->post_title . ( $outcomes ? ' — ' . $outcomes[0]->post_title : '' ) . '
';
- else:
- echo $team->post_title . '
';
+ if ( sizeof( $outcomes ) ):
+ $outcome = reset( $outcomes );
+ echo ' — ' . $outcome->post_title;
+ endif;
endif;
+ echo '
';
endforeach;
elseif ( $post_type == 'sp_player' ):
$results = get_post_meta( $post_id, 'sp_results', true );
diff --git a/admin/hooks/parse-query.php b/admin/hooks/parse-query.php
new file mode 100644
index 00000000..b2313a2f
--- /dev/null
+++ b/admin/hooks/parse-query.php
@@ -0,0 +1,13 @@
+query_vars['meta_key'] = 'sp_team';
+ $query->query_vars['meta_value'] = $_GET['team'];
+ endif;
+ endif;
+}
+add_filter('parse_query', 'sportspress_parse_query');
diff --git a/admin/hooks/pre-get-posts.php b/admin/hooks/pre-get-posts.php
index 5322c927..b90741c2 100644
--- a/admin/hooks/pre-get-posts.php
+++ b/admin/hooks/pre-get-posts.php
@@ -1,15 +1,18 @@
query['post_type'];
+function sportspress_pre_get_posts( $query ) {
+ if( !is_admin() )
+ return $query;
- if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
- $wp_query->set( 'orderby', 'menu_order' );
- $wp_query->set( 'order', 'ASC' );
- elseif ( $post_type == 'sp_event' ):
- $wp_query->set( 'orderby', 'post_date' );
- $wp_query->set( 'order', 'ASC' );
- endif;
+ $post_type = $query->query['post_type'];
+
+ if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
+ $query->set( 'orderby', 'menu_order' );
+ $query->set( 'order', 'ASC' );
+ elseif ( $post_type == 'sp_event' ):
+ $query->set( 'orderby', 'post_date' );
+ $query->set( 'order', 'ASC' );
endif;
+
+ return $query;
}
add_filter('pre_get_posts', 'sportspress_pre_get_posts');
diff --git a/admin/hooks/restrict-manage-posts.php b/admin/hooks/restrict-manage-posts.php
index 9a4fb640..37269768 100644
--- a/admin/hooks/restrict-manage-posts.php
+++ b/admin/hooks/restrict-manage-posts.php
@@ -32,5 +32,16 @@ function sportspress_restrict_manage_posts() {
);
sportspress_dropdown_taxonomies( $args );
endif;
+ if ( in_array( $typenow, array( 'sp_event', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' ) ) ):
+ $selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null;
+ $args = array(
+ 'post_type' => 'sp_team',
+ 'name' => 'team',
+ 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
+ 'selected' => $selected,
+ 'values' => 'ID',
+ );
+ sportspress_dropdown_pages( $args );
+ endif;
}
add_action( 'restrict_manage_posts', 'sportspress_restrict_manage_posts' );
diff --git a/admin/hooks/wp-enqueue-scripts.php b/admin/hooks/wp-enqueue-scripts.php
index dda69a01..2429b756 100644
--- a/admin/hooks/wp-enqueue-scripts.php
+++ b/admin/hooks/wp-enqueue-scripts.php
@@ -6,7 +6,7 @@ function sportspress_enqueue_scripts() {
// Scripts
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array(), '3.exp', true );
- wp_enqueue_script( 'jquery-datatables', SPORTSPRESS_PLUGIN_URL .'/assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.9.4', true );
- wp_enqueue_script( 'sportspress', SPORTSPRESS_PLUGIN_URL .'/assets/js/sportspress.js', array( 'jquery' ), time(), true );
+ wp_enqueue_script( 'jquery-datatables', SPORTSPRESS_PLUGIN_URL .'assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.9.4', true );
+ wp_enqueue_script( 'sportspress', SPORTSPRESS_PLUGIN_URL .'assets/js/sportspress.js', array( 'jquery' ), time(), true );
}
add_action( 'wp_enqueue_scripts', 'sportspress_enqueue_scripts' );
\ No newline at end of file
diff --git a/admin/post-types/player.php b/admin/post-types/player.php
index c5f81a4d..3c60bb53 100644
--- a/admin/post-types/player.php
+++ b/admin/post-types/player.php
@@ -47,7 +47,7 @@ function sportspress_player_meta_init( $post ) {
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_player_team_meta', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_metricsdiv', __( 'Metrics', 'sportspress' ), 'sportspress_player_metrics_meta', 'sp_player', 'normal', 'high' );
- if ( $leagues && ! empty( $leagues ) && $seasons && is_array( $seasons ) && is_object( $seasons[0] ) ):
+ if ( $leagues && ! empty( $leagues ) && $seasons && ! empty( $seasons ) ):
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sportspress_player_stats_meta', 'sp_player', 'normal', 'high' );
endif;
@@ -131,7 +131,7 @@ function sportspress_player_stats_meta( $post ) {
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = sportspress_get_player_statistics_data( $post->ID, $league->term_id, true );
- sportspress_edit_player_statistics_table( $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_teams' ) );
+ sportspress_edit_player_statistics_table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_teams' ) );
endforeach;
}
diff --git a/admin/presets/rugby.php b/admin/presets/rugby.php
index 95f6ee29..df79f6a6 100644
--- a/admin/presets/rugby.php
+++ b/admin/presets/rugby.php
@@ -4,6 +4,32 @@ global $sportspress_sports;
$sportspress_sports['rugby'] = array(
'name' => __( 'Rugby', 'sportspress' ),
'posts' => array(
+ // Results
+ 'sp_result' => array(
+ array(
+ 'post_title' => __( 'Points', 'sportspress' ),
+ 'post_name' => 'points',
+ ),
+ array(
+ 'post_title' => __( 'Bonus', 'sportspress' ),
+ 'post_name' => 'bonus',
+ ),
+ ),
+ // Outcomes
+ 'sp_outcome' => array(
+ array(
+ 'post_title' => 'W',
+ 'post_name' => 'w',
+ ),
+ array(
+ 'post_title' => 'D',
+ 'post_name' => 'd',
+ ),
+ array(
+ 'post_title' => 'L',
+ 'post_name' => 'l',
+ ),
+ ),
// Table Columns
'sp_column' => array(
array(
@@ -11,6 +37,7 @@ $sportspress_sports['rugby'] = array(
'post_name' => 'p',
'meta' => array(
'sp_equation' => '$eventsplayed',
+ 'sp_precision' => 1,
),
),
array(
@@ -18,6 +45,7 @@ $sportspress_sports['rugby'] = array(
'post_name' => 'w',
'meta' => array(
'sp_equation' => '$w',
+ 'sp_precision' => 1,
),
),
array(
@@ -25,6 +53,7 @@ $sportspress_sports['rugby'] = array(
'post_name' => 'd',
'meta' => array(
'sp_equation' => '$d',
+ 'sp_precision' => 1,
),
),
array(
@@ -32,54 +61,100 @@ $sportspress_sports['rugby'] = array(
'post_name' => 'l',
'meta' => array(
'sp_equation' => '$l',
+ 'sp_precision' => 1,
),
),
array(
'post_title' => 'B',
'post_name' => 'b',
'meta' => array(
- 'sp_equation' => '$b',
+ 'sp_equation' => '$bonus',
+ 'sp_precision' => 1,
),
),
array(
'post_title' => 'F',
'post_name' => 'f',
'meta' => array(
- 'sp_equation' => '$ptsfor',
+ 'sp_equation' => '$pointsfor',
+ 'sp_precision' => 1,
),
),
array(
'post_title' => 'A',
'post_name' => 'a',
'meta' => array(
- 'sp_equation' => '$ptsagainst',
+ 'sp_equation' => '$pointsagainst',
+ 'sp_precision' => 1,
),
),
array(
'post_title' => '+/-',
'post_name' => 'pd',
'meta' => array(
- 'sp_equation' => '$ptsfor - $ptsagainst',
+ 'sp_equation' => '$pointsfor - $pointsagainst',
+ 'sp_precision' => 1,
),
),
array(
'post_title' => 'Pts',
'post_name' => 'pts',
'meta' => array(
- 'sp_equation' => '( $w + $b ) * 2 + $d',
+ 'sp_equation' => '( $w + $bonus ) * 2 + $d',
+ 'sp_precision' => 1,
'sp_priority' => '1',
'sp_order' => 'DESC',
),
),
),
- // Statistics
+ // Player Metrics
+ 'sp_metric' => array(
+ array(
+ 'post_title' => __( 'Height', 'sportspress' ),
+ 'post_name' => 'height',
+ ),
+ array(
+ 'post_title' => __( 'Weight', 'sportspress' ),
+ 'post_name' => 'weight',
+ ),
+ ),
+ // Player Statistics
'sp_statistic' => array(
- ),
- // Results
- 'sp_result' => array(
- ),
- // Outcomes
- 'sp_outcome' => array(
+ array(
+ 'post_title' => __( 'Points', 'sportspress' ),
+ 'post_name' => 'points',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ array(
+ 'post_title' => __( 'Tries', 'sportspress' ),
+ 'post_name' => 'tries',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ array(
+ 'post_title' => __( 'Conversions', 'sportspress' ),
+ 'post_name' => 'conversions',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ array(
+ 'post_title' => __( 'Penalty Goals', 'sportspress' ),
+ 'post_name' => 'penaltygoals',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ array(
+ 'post_title' => __( 'Drop Goals', 'sportspress' ),
+ 'post_name' => 'dropgoals',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
),
),
);
diff --git a/admin/presets/soccer.php b/admin/presets/soccer.php
index 21c76be8..4bad7c64 100644
--- a/admin/presets/soccer.php
+++ b/admin/presets/soccer.php
@@ -4,166 +4,11 @@ global $sportspress_sports;
$sportspress_sports['soccer'] = array(
'name' => __( 'Association Football (Soccer)', 'sportspress' ),
'posts' => array(
- // Table Columns
- 'sp_column' => array(
- array(
- 'post_title' => 'P',
- 'post_name' => 'p',
- 'meta' => array(
- 'sp_equation' => '$eventsplayed',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'W',
- 'post_name' => 'w',
- 'meta' => array(
- 'sp_equation' => '$w',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'D',
- 'post_name' => 'd',
- 'meta' => array(
- 'sp_equation' => '$d',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'L',
- 'post_name' => 'l',
- 'meta' => array(
- 'sp_equation' => '$l',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'F',
- 'post_name' => 'f',
- 'meta' => array(
- 'sp_equation' => '$goalsfor',
- 'sp_priority' => '3',
- 'sp_order' => 'DESC',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'A',
- 'post_name' => 'a',
- 'meta' => array(
- 'sp_equation' => '$goalsagainst',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'GD',
- 'post_name' => 'gd',
- 'meta' => array(
- 'sp_equation' => '$goalsfor - $goalsagainst',
- 'sp_priority' => '2',
- 'sp_order' => 'DESC',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'Pts',
- 'post_name' => 'pts',
- 'meta' => array(
- 'sp_equation' => '$w * 3 + $d',
- 'sp_priority' => '1',
- 'sp_order' => 'DESC',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- ),
- // Player Statistics
- 'sp_statistic' => array(
- array(
- 'post_title' => 'Goals',
- 'post_name' => 'goals',
- 'meta' => array(
- 'sp_equation' => '',
- 'sp_priority' => '1',
- 'sp_order' => 'DESC',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'Assists',
- 'post_name' => 'assists',
- 'meta' => array(
- 'sp_equation' => '',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'Yellow Cards',
- 'post_name' => 'yellowcards',
- 'meta' => array(
- 'sp_equation' => '',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'Red Cards',
- 'post_name' => 'redcards',
- 'meta' => array(
- 'sp_equation' => '',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- ),
- // Player Metrics
- 'sp_metric' => array(
- array(
- 'post_title' => 'Appearances',
- 'post_name' => 'appearances',
- 'meta' => array(
- 'sp_equation' => '$eventsplayed',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'Height',
- 'post_name' => 'height',
- 'meta' => array(
- 'sp_equation' => '',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- array(
- 'post_title' => 'Weight',
- 'post_name' => 'weight',
- 'meta' => array(
- 'sp_equation' => '',
- 'sp_format' => 'integer',
- 'sp_precision' => 1,
- ),
- ),
- ),
// Results
'sp_result' => array(
array(
- 'post_title' => 'Goals',
+ 'post_title' => __( 'Goals', 'sportspress' ),
'post_name' => 'goals',
- 'meta' => array(
- 'sp_format' => 'integer',
- ),
),
),
// Outcomes
@@ -181,5 +26,120 @@ $sportspress_sports['soccer'] = array(
'post_name' => 'l',
),
),
+ // Table Columns
+ 'sp_column' => array(
+ array(
+ 'post_title' => 'P',
+ 'post_name' => 'p',
+ 'meta' => array(
+ 'sp_equation' => '$eventsplayed',
+ 'sp_precision' => 1,
+ ),
+ ),
+ array(
+ 'post_title' => 'W',
+ 'post_name' => 'w',
+ 'meta' => array(
+ 'sp_equation' => '$w',
+ 'sp_precision' => 1,
+ ),
+ ),
+ array(
+ 'post_title' => 'D',
+ 'post_name' => 'd',
+ 'meta' => array(
+ 'sp_equation' => '$d',
+ 'sp_precision' => 1,
+ ),
+ ),
+ array(
+ 'post_title' => 'L',
+ 'post_name' => 'l',
+ 'meta' => array(
+ 'sp_equation' => '$l',
+ 'sp_precision' => 1,
+ ),
+ ),
+ array(
+ 'post_title' => 'F',
+ 'post_name' => 'f',
+ 'meta' => array(
+ 'sp_equation' => '$goalsfor',
+ 'sp_precision' => 1,
+ 'sp_priority' => '3',
+ 'sp_order' => 'DESC',
+ ),
+ ),
+ array(
+ 'post_title' => 'A',
+ 'post_name' => 'a',
+ 'meta' => array(
+ 'sp_equation' => '$goalsagainst',
+ 'sp_precision' => 1,
+ ),
+ ),
+ array(
+ 'post_title' => 'GD',
+ 'post_name' => 'gd',
+ 'meta' => array(
+ 'sp_equation' => '$goalsfor - $goalsagainst',
+ 'sp_precision' => 1,
+ 'sp_priority' => '2',
+ 'sp_order' => 'DESC',
+ ),
+ ),
+ array(
+ 'post_title' => 'Pts',
+ 'post_name' => 'pts',
+ 'meta' => array(
+ 'sp_equation' => '$w * 3 + $d',
+ 'sp_precision' => 1,
+ 'sp_priority' => '1',
+ 'sp_order' => 'DESC',
+ ),
+ ),
+ ),
+ // Player Metrics
+ 'sp_metric' => array(
+ array(
+ 'post_title' => __( 'Height', 'sportspress' ),
+ 'post_name' => 'height',
+ ),
+ array(
+ 'post_title' => __( 'Weight', 'sportspress' ),
+ 'post_name' => 'weight',
+ ),
+ ),
+ // Player Statistics
+ 'sp_statistic' => array(
+ array(
+ 'post_title' => __( 'Goals', 'sportspress' ),
+ 'post_name' => 'goals',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ array(
+ 'post_title' => __( 'Assists', 'sportspress' ),
+ 'post_name' => 'assists',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ array(
+ 'post_title' => __( 'Yellow Cards', 'sportspress' ),
+ 'post_name' => 'yellowcards',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ array(
+ 'post_title' => __( 'Red Cards', 'sportspress' ),
+ 'post_name' => 'redcards',
+ 'meta' => array(
+ 'sp_calculate' => 'sum',
+ ),
+ ),
+ ),
),
);
diff --git a/admin/templates/league-table.php b/admin/templates/league-table.php
index 86709501..7f84b3c1 100644
--- a/admin/templates/league-table.php
+++ b/admin/templates/league-table.php
@@ -17,10 +17,14 @@ if ( !function_exists( 'sportspress_league_table' ) ) {
$seasons = get_the_terms( $id, 'sp_season' );
$terms = array();
- if ( isset( $leagues[0] ) )
- $terms[] = $leagues[0]->name;
- if ( isset( $seasons[0] ) )
- $terms[] = $seasons[0]->name;
+ if ( sizeof( $leagues ) ):
+ $league = reset( $leagues );
+ $terms[] = $league->name;
+ endif;
+ if ( sizeof( $seasons ) ):
+ $season = reset( $seasons );
+ $terms[] = $season->name;
+ endif;
$title = sizeof( $terms ) ? implode( ' — ', $terms ) : get_the_title( $id );
diff --git a/admin/terms/venue.php b/admin/terms/venue.php
index 3b2adec8..72f4714e 100644
--- a/admin/terms/venue.php
+++ b/admin/terms/venue.php
@@ -57,8 +57,9 @@ add_action( 'sp_venue_edit_form_fields', 'sportspress_venue_edit_form_fields', 1
// Get latitude and longitude from the last added venue
$terms = get_terms( 'sp_venue', $args );
- if ( $terms && array_key_exists( 0, $terms) && is_object( $terms[0] ) ):
- $t_id = $terms[0]->term_id;
+ if ( $terms && array_key_exists( 0, $terms) && is_object( reset( $terms ) ) ):
+ $term = reset( $terms );
+ $t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = sportspress_array_value( $term_meta, 'sp_latitude', '40.7324319' );
$longitude = sportspress_array_value( $term_meta, 'sp_longitude', '-73.82480799999996' );
diff --git a/assets/css/sportspress.css b/assets/css/sportspress.css
index e0fb7b15..adc4f341 100644
--- a/assets/css/sportspress.css
+++ b/assets/css/sportspress.css
@@ -49,6 +49,7 @@
width: 50%;
overflow: hidden;
overflow-x: scroll;
+ box-shadow: 0 0 1em rgba(0,0,0,0.5);
}
.sp-pinned-table table {
border-right: none;
diff --git a/functions.php b/functions.php
index f69ec236..6c442985 100644
--- a/functions.php
+++ b/functions.php
@@ -122,6 +122,9 @@ if ( !function_exists( 'sportspress_get_post_views' ) ) {
if ( !function_exists( 'sportspress_set_post_views' ) ) {
function sportspress_set_post_views( $post_id ) {
+ if ( is_preview() )
+ return;
+
$count_key = 'sp_views';
$count = get_post_meta( $post_id, $count_key, true );
if ( $count == '' ):
@@ -766,7 +769,11 @@ if ( !function_exists( 'sportspress_edit_team_columns_table' ) ) {
}
if ( !function_exists( 'sportspress_edit_player_statistics_table' ) ) {
- function sportspress_edit_player_statistics_table( $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $seasons_teams = array(), $readonly = true ) {
+ function sportspress_edit_player_statistics_table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $seasons_teams = array(), $readonly = true ) {
+ if ( ! $id )
+ $id = get_the_ID();
+
+ $teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
?>