Add visibility option to player metrics

This commit is contained in:
Brian Miyaji
2017-06-25 09:41:55 +10:00
parent 83ebb9e81b
commit 8317be9c60
3 changed files with 45 additions and 2 deletions

View File

@@ -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;
?>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
</p>
<p>
<strong><?php _e( 'Visible', 'sportspress' ); ?></strong>
<i class="dashicons dashicons-editor-help sp-desc-tip" title="<?php _e( 'Display in player profile?', 'sportspress' ); ?>"></i>
</p>
<ul class="sp-visible-selector">
<li>
<label class="selectit">
<input name="sp_visible" id="sp_visible_yes" type="radio" value="1" <?php checked( $visible ); ?>>
<?php _e( 'Yes', 'sportspress' ); ?>
</label>
</li>
<li>
<label class="selectit">
<input name="sp_visible" id="sp_visible_no" type="radio" value="0" <?php checked( ! $visible ); ?>>
<?php _e( 'No', 'sportspress' ); ?>
</label>
</li>
</ul>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1 ) );
}
}

View File

@@ -89,7 +89,7 @@ class SP_Player extends SP_Custom_Post {
*/
public function metrics( $neg = null ) {
$metrics = (array)get_post_meta( $this->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 ):

View File

@@ -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();