From 8317be9c609d3de339ff6f3acfcc7c7c4dc4f2eb Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sun, 25 Jun 2017 09:41:55 +1000 Subject: [PATCH] Add visibility option to player metrics --- .../class-sp-meta-box-metric-details.php | 28 +++++++++++++++++++ includes/class-sp-player.php | 2 +- includes/sp-core-functions.php | 17 ++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-metric-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-metric-details.php index 6d1f4ee3..f3cd4a4c 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-metric-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-metric-details.php @@ -23,12 +23,40 @@ class SP_Meta_Box_Metric_Details extends SP_Meta_Box_Config { */ public static function output( $post ) { wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' ); + $visible = get_post_meta( $post->ID, 'sp_visible', true ); + if ( '' === $visible ) $visible = 1; ?>

+

+ + +

+ ID, 'sp_metrics', true ); - $metric_labels = (array)sp_get_var_labels( 'sp_metric', $neg ); + $metric_labels = (array)sp_get_var_labels( 'sp_metric', $neg, false ); $data = array(); foreach ( $metric_labels as $key => $value ): diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 2a354774..375b75ff 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -1067,7 +1067,7 @@ if ( !function_exists( 'sp_draft_or_post_title' ) ) { } if ( !function_exists( 'sp_get_var_labels' ) ) { - function sp_get_var_labels( $post_type, $neg = null ) { + function sp_get_var_labels( $post_type, $neg = null, $all = true ) { $args = array( 'post_type' => $post_type, 'numberposts' => -1, @@ -1076,6 +1076,21 @@ if ( !function_exists( 'sp_get_var_labels' ) ) { 'order' => 'ASC', ); + if ( ! $all ) { + $args['meta_query'] = array( + array( + 'key' => 'sp_visible', + 'value' => 1, + ), + array( + 'key' => 'sp_visible', + 'value' => 1, + 'compare' => 'NOT EXISTS', + ), + 'relation' => 'OR', + ); + } + $vars = get_posts( $args ); $output = array();