Fix empty team checkboxes in player quick edit
This commit is contained in:
@@ -25,9 +25,17 @@
|
|||||||
|
|
||||||
// get the data
|
// get the data
|
||||||
var $number = $( '.column-sp_number', $post_row ).text();
|
var $number = $( '.column-sp_number', $post_row ).text();
|
||||||
|
var $current_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'current-teams' ) ).split(',');
|
||||||
|
var $past_teams = String( $( '.column-sp_team', $post_row ).find( '.sp-player-teams' ).data( 'past-teams' ) ).split(',');
|
||||||
|
|
||||||
// populate the data
|
// populate the data
|
||||||
$( ':input[name="sp_number"]', $edit_row ).val( $number );
|
$( ':input[name="sp_number"]', $edit_row ).val( $number );
|
||||||
|
$( ':input[name="sp_current_team[]"]', $edit_row ).each(function() {
|
||||||
|
$(this).prop("checked", ($.inArray($(this).val(), $current_teams ) != -1));
|
||||||
|
});
|
||||||
|
$( ':input[name="sp_past_team[]"]', $edit_row ).each(function() {
|
||||||
|
$(this).prop("checked", ($.inArray($(this).val(), $past_teams ) != -1));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -95,13 +95,17 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
|
|||||||
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '—';
|
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '—';
|
||||||
break;
|
break;
|
||||||
case 'sp_team':
|
case 'sp_team':
|
||||||
|
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
|
||||||
|
$past_teams = get_post_meta( $post_id, 'sp_past_team', false );
|
||||||
|
$current_teams = array_filter( $current_teams );
|
||||||
|
$past_teams = array_filter( $past_teams );
|
||||||
|
echo '<span class="hidden sp-player-teams" data-current-teams="' . implode( ',', $current_teams ) . '" data-past-teams="' . implode( ',', $past_teams ) . '"></span>';
|
||||||
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
|
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
|
||||||
$teams = array_filter( $teams );
|
$teams = array_filter( $teams );
|
||||||
$teams = array_unique( $teams );
|
$teams = array_unique( $teams );
|
||||||
if ( empty( $teams ) ):
|
if ( empty( $teams ) ):
|
||||||
echo '—';
|
echo '—';
|
||||||
else:
|
else:
|
||||||
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
|
|
||||||
foreach( $teams as $team_id ):
|
foreach( $teams as $team_id ):
|
||||||
if ( ! $team_id ) continue;
|
if ( ! $team_id ) continue;
|
||||||
$team = get_post( $team_id );
|
$team = get_post( $team_id );
|
||||||
@@ -212,14 +216,12 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
|
|||||||
$print_nonce = false;
|
$print_nonce = false;
|
||||||
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
|
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$number = get_post_meta( get_the_ID(), 'sp_number', true );
|
|
||||||
?>
|
?>
|
||||||
<fieldset class="inline-edit-col-right">
|
<fieldset class="inline-edit-col-right">
|
||||||
<div class="inline-edit-col">
|
<div class="inline-edit-col">
|
||||||
<label>
|
<label>
|
||||||
<span class="title"><?php _e( 'Squad Number', 'sportspress' ); ?></span>
|
<span class="title"><?php _e( 'Squad Number', 'sportspress' ); ?></span>
|
||||||
<span class="input-text-wrap"><input type="text" name="sp_number" class="inline-edit-menu-order-input" value="<?php echo $number; ?>"></span>
|
<span class="input-text-wrap"><input type="text" name="sp_number" class="inline-edit-menu-order-input"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@@ -243,11 +245,6 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
|
|||||||
) );
|
) );
|
||||||
|
|
||||||
if ( ! $teams ) return;
|
if ( ! $teams ) return;
|
||||||
|
|
||||||
$post_id = get_the_ID();
|
|
||||||
|
|
||||||
$current_teams = array_filter( get_post_meta( $post_id, 'sp_current_team', false ) );
|
|
||||||
$past_teams = array_filter( get_post_meta( $post_id, 'sp_past_team', false ) );
|
|
||||||
?>
|
?>
|
||||||
<fieldset class="inline-edit-col-right">
|
<fieldset class="inline-edit-col-right">
|
||||||
<div class="inline-edit-col">
|
<div class="inline-edit-col">
|
||||||
@@ -255,14 +252,14 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
|
|||||||
<input type="hidden" name="sp_current_team[]" value="0">
|
<input type="hidden" name="sp_current_team[]" value="0">
|
||||||
<ul class="cat-checklist">
|
<ul class="cat-checklist">
|
||||||
<?php foreach ( $teams as $team ) { ?>
|
<?php foreach ( $teams as $team ) { ?>
|
||||||
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_current_team[]" <?php checked( in_array( $team->ID, $current_teams ) ); ?>> <?php echo $team->post_title; ?></label></li>
|
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_current_team[]"> <?php echo $team->post_title; ?></label></li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
<span class="title inline-edit-categories-label"><?php _e( 'Past Teams', 'sportspress' ); ?></span>
|
<span class="title inline-edit-categories-label"><?php _e( 'Past Teams', 'sportspress' ); ?></span>
|
||||||
<input type="hidden" name="sp_past_team[]" value="0">
|
<input type="hidden" name="sp_past_team[]" value="0">
|
||||||
<ul class="cat-checklist">
|
<ul class="cat-checklist">
|
||||||
<?php foreach ( $teams as $team ) { ?>
|
<?php foreach ( $teams as $team ) { ?>
|
||||||
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_past_team[]" <?php checked( in_array( $team->ID, $past_teams ) ); ?>> <?php echo $team->post_title; ?></label></li>
|
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_past_team[]"> <?php echo $team->post_title; ?></label></li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user