Add chosen selectors to player edit screen, style installation notice

This commit is contained in:
Brian Miyaji
2014-02-18 13:22:51 +11:00
parent 3bfeaef612
commit 94ac918e0c
7 changed files with 286 additions and 131 deletions

View File

@@ -4,7 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<div id="message" class="updated sportspress-message">
<p><?php _e( '<strong>Welcome to SportsPress</strong> &#8211; Get Started', 'sportspress' ); ?></p>
<p class="submit">
<a class="button button-primary" href="<?php echo admin_url('options-general.php?page=sportspress'); ?>"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a>
<a class="button button-secondary" href="<?php echo add_query_arg('sportspress_installed', '1' ); ?>"><?php _e( 'Skip setup', 'sportspress' ); ?></a>
<a class="button-primary" href="<?php echo admin_url('options-general.php?page=sportspress'); ?>"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a>
<a class="button-secondary" href="<?php echo add_query_arg('sportspress_installed', '1' ); ?>"><?php _e( 'Skip setup', 'sportspress' ); ?></a>
</p>
</div>

View File

@@ -4,6 +4,7 @@ function sportspress_event_post_init() {
$singular_name = __( 'Event', 'sportspress' );
$lowercase_name = __( 'events', 'sportspress' );
$labels = sportspress_get_post_labels( $name, $singular_name, $lowercase_name );
//$labels['menu_name'] = __( 'SportsPress', 'sportspress' );
$args = array(
'label' => $name,
'labels' => $labels,

View File

@@ -40,12 +40,15 @@ function sportspress_player_meta_init( $post ) {
$seasons = (array)get_the_terms( $post->ID, 'sp_season' );
remove_meta_box( 'submitdiv', 'sp_player', 'side' );
add_meta_box( 'submitdiv', __( 'Publish', 'sportspress' ), 'post_submit_meta_box', 'sp_player', 'side', 'high' );
remove_meta_box( 'sp_seasondiv', 'sp_player', 'side' );
remove_meta_box( 'sp_leaguediv', 'sp_player', 'side' );
remove_meta_box( 'sp_positiondiv', 'sp_player', 'side' );
remove_meta_box( 'postimagediv', 'sp_player', 'side' );
add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_player', 'side', 'low' );
add_meta_box( 'submitdiv', __( 'Publish', 'sportspress' ), 'post_submit_meta_box', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_player_details_meta', 'sp_player', 'side', 'high' );
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' );
add_meta_box( 'sp_metricsdiv', __( 'Metrics', 'sportspress' ), 'sportspress_player_metrics_meta', 'sp_player', 'side', 'high' );
add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_player', 'side', 'low' );
if ( $leagues && ! empty( $leagues ) && $seasons && ! empty( $seasons ) ):
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sportspress_player_stats_meta', 'sp_player', 'normal', 'high' );
@@ -67,50 +70,125 @@ function sportspress_player_details_meta( $post ) {
$number = get_post_meta( $post->ID, 'sp_number', true );
$nationality = get_post_meta( $post->ID, 'sp_nationality', true );
$teams = array_filter( get_post_meta( $post->ID, 'sp_team', false ) );
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_ids = array();
if ( $leagues ):
foreach ( $leagues as $league ):
$league_ids[] = $league->term_id;
endforeach;
endif;
$seasons = get_the_terms( $post->ID, 'sp_season' );
$season_ids = array();
if ( $seasons ):
foreach ( $seasons as $season ):
$season_ids[] = $season->term_id;
endforeach;
endif;
$positions = get_the_terms( $post->ID, 'sp_position' );
$position_ids = array();
if ( $positions ):
foreach ( $positions as $position ):
$position_ids[] = $position->term_id;
endforeach;
endif;
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
$the_teams = array_filter( get_post_meta( $post->ID, 'sp_team', false ) );
$current_team = get_post_meta( $post->ID, 'sp_current_team', true );
?>
<p>
<strong><?php _e( 'Number', 'sportspress' ); ?></strong>
</p>
<p>
<input type="text" size="4" id="sp_number" name="sp_number" value="<?php echo $number; ?>">
</p>
<p>
<strong><?php _e( 'Nationality', 'sportspress' ); ?></strong>
</p>
<p>
<select id="sp_nationality" name="sp_nationality" class="chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>">
<option value=""><?php _e( '-- Not set --', 'sportspress' ); ?></option>
<?php foreach ( $continents as $continent => $countries ): ?>
<optgroup label="<?php echo $continent; ?>">
<?php foreach ( $countries as $code => $country ): ?>
<option value="<?php echo $code; ?>" <?php selected ( $nationality, $code ); ?>><?php echo $country; ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
</p>
<?php if ( $teams ): ?>
<p>
<strong><?php _e( 'Current Team', 'sportspress' ); ?></strong>
</p>
<p>
<select id="sp_current_team" name="sp_current_team">
<?php foreach ( $teams as $team ): ?>
<option value="<?php echo $team; ?>" <?php selected ( $current_team, $team ); ?>>
<?php echo get_the_title( $team ); ?>
</option>
<?php endforeach; ?>
</select>
</p>
<?php endif; ?>
<?php
}
<p><strong><?php _e( 'Number', 'sportspress' ); ?></strong></p>
<p><input type="text" size="4" id="sp_number" name="sp_number" value="<?php echo $number; ?>"></p>
function sportspress_player_team_meta( $post ) {
sportspress_post_checklist( $post->ID, 'sp_team' );
sportspress_post_adder( 'sp_team' );
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
<p><select id="sp_nationality" name="sp_nationality" data-placeholder="<?php _e( 'Select Nationality', 'sportspress' ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>">
<option value=""></option>
<?php foreach ( $continents as $continent => $countries ): ?>
<optgroup label="<?php echo $continent; ?>">
<?php foreach ( $countries as $code => $country ): ?>
<option value="<?php echo $code; ?>" <?php selected ( $nationality, $code ); ?>><?php echo $country; ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select></p>
<p><strong><?php _e( 'Leagues', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'placeholder' => __( 'Select Leagues', 'sportspress' ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'placeholder' => __( 'Select Seasons', 'sportspress' ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team[]',
'selected' => $the_teams,
'values' => 'ID',
'placeholder' => __( 'Select Teams', 'sportspress' ),
'class' => 'sp-team widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Current Team', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team',
'show_option_blank' => true,
'selected' => $current_team,
'values' => 'ID',
'placeholder' => __( 'Select Team', 'sportspress' ),
'class' => 'sp-current-team widefat',
'chosen' => true,
);
sportspress_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Positions', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_position',
'name' => 'tax_input[sp_position][]',
'selected' => $position_ids,
'values' => 'term_id',
'placeholder' => __( 'Select Positions', 'sportspress' ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_taxonomies( $args );
?></p>
<?php
}
function sportspress_player_metrics_meta( $post ) {
@@ -142,37 +220,12 @@ function sportspress_player_metrics_meta( $post ) {
$vars = get_posts( $args );
if ( $vars ):
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table">
<thead>
<tr>
<th><?php _e( 'Metric', 'sportspress' ); ?></th>
<th><?php _e( 'Value', 'sportspress' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( $vars as $var ):
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo $var->post_title; ?>
</td>
<?php
$value = sportspress_array_value( $metrics, $var->post_name, '' );
?>
<td><input type="text" name="sp_metrics[<?php echo $var->post_name; ?>]" value="<?php echo $value; ?>" /></td>
</tr>
<?php
$i++;
endforeach;
?>
</tbody>
</table>
</div>
<?php
foreach ( $vars as $var ):
?>
<p><strong><?php echo $var->post_title; ?></strong></p>
<p><input type="text" name="sp_metrics[<?php echo $var->post_name; ?>]" value="<?php echo sportspress_array_value( $metrics, $var->post_name, '' ); ?>" /></p>
<?php
endforeach;
else:
sportspress_post_adder( 'sp_metric' );
endif;

View File

@@ -1,13 +1,13 @@
/* SportsPress admin styles */
.sportspress-message {
border-left-color: #ff9900 !important;
border-left-color: #6bc2a5 !important;
}
.sportspress-message a.button-primary,
.sportspress-message a.button-secondary {
background: #ff9900;
border-color: #f48600;
background: #6bc2a5;
border-color: #3bad87;
-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.25),0 1px 0 rgba(0,0,0,.15);
box-shadow: inset 0 1px 0 rgba(255,255,255,.25),0 1px 0 rgba(0,0,0,.15);
color: #fff;
@@ -16,8 +16,8 @@
.sportspress-message a.button-primary:hover,
.sportspress-message a.button-secondary:hover {
background: #ff8800;
border-color: #f27000;
background: #3bad87;
border-color: #338a6d;
-webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.25),0 1px 0 rgba(0,0,0,.15);
box-shadow: inset 0 1px 0 rgba(255,255,255,.25),0 1px 0 rgba(0,0,0,.15);
color: #fff;
@@ -27,7 +27,7 @@
.sportspress-message a.button-secondary {
-moz-opacity: 0.7;
opacity: 0.7;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha"(Opacity=70);
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";
}
.widget[id*="sp_recent_events-"] .widget-title h4:before,
@@ -164,6 +164,43 @@ table.widefat td.column-sp_number .sp-flag {
color: #a00;
}
.chosen-container {
margin: 1px;
}
.chosen-container-multi .chosen-choices {
background: #fff;
color: #333;
padding: 3px 0;
border-color: #ddd;
box-shadow: inset 0 1px 2px rgba(0,0,0,.07);
line-height: 2;
}
.chosen-container-multi .chosen-choices li.search-field input[type="text"] {
color: #a9a9a9;
}
.chosen-container-multi .chosen-choices li.search-choice {
color: #555;
border-color: #ccc;
background: #f7f7f7;
-webkit-box-shadow: inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);
box-shadow: inset 0 1px 0 #fff,0 1px 0 rgba(0,0,0,.08);
vertical-align: top;
}
.chosen-container-multi .chosen-choices li.search-choice:hover {
background: #fafafa;
border-color: #999;
color: #222;
}
.chosen-container-multi .chosen-choices li.search-choice .search-choice-close {
transition: none;
-webkit-transition: none;
}
@media only screen and (max-width: 768px) {
.form-field .sp-location-picker {

View File

@@ -10,7 +10,16 @@ jQuery(document).ready(function($){
});
// Chosen select
$(".chosen-select").chosen();
$(".chosen-select").chosen({
allow_single_deselect: true,
single_backstroke_delete: false
});
$('#poststuff #sp_detailsdiv .sp-current-team').on('change', function(evt, params) {
$el = $(this).closest('#sp_detailsdiv').find('.sp-team');
$el.find('option[value='+$(this).val()+']').attr('selected', true);
$el.trigger('chosen:updated');
});
// Auto key placeholder
$("#poststuff #title").on("keyup", function() {

View File

@@ -227,30 +227,66 @@ if ( !function_exists( 'sportspress_dropdown_taxonomies' ) ) {
'show_option_none' => false,
'taxonomy' => null,
'name' => null,
'id' => null,
'selected' => null,
'hide_empty' => false,
'values' => 'slug',
'class' => null,
'property' => null,
'placeholder' => null,
'chosen' => false,
);
$args = array_merge( $defaults, $args );
$terms = get_terms( $args['taxonomy'], $args );
$name = ( $args['name'] ) ? $args['name'] : $args['taxonomy'];
$id = ( $args['id'] ) ? $args['id'] : $name;
unset( $args['name'] );
unset( $args['id'] );
$class = $args['class'];
unset( $args['class'] );
$property = $args['property'];
unset( $args['property'] );
$placeholder = $args['placeholder'];
unset( $args['placeholder'] );
$selected = $args['selected'];
unset( $args['selected'] );
$chosen = $args['chosen'];
unset( $args['chosen'] );
if ( $terms ):
printf( '<select name="%1$s" class="postform %2$s">', $name, $class );
if ( $args['show_option_all'] ) {
printf( '<option value="0">%s</option>', $args['show_option_all'] );
}
if ( $args['show_option_none'] ) {
printf( '<option value="-1">%s</option>', $args['show_option_none'] );
}
foreach ( $terms as $term ) {
if ( $args['values'] == 'term_id' )
printf( '<option value="%s" %s>%s</option>', $term->term_id, selected( true, $args['selected'] == $term->term_id, false ), $term->name );
else
printf( '<option value="%s" %s>%s</option>', $term->slug, selected( true, $args['selected'] == $term->slug, false ), $term->name );
}
printf( '<select name="%s" class="postform %s" %s>', $name, $class . ( $chosen ? ' chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ) : '' ), ( $placeholder != null ? 'data-placeholder="' . $placeholder . '" ' : '' ) . $property );
if ( strpos( $property, 'multiple' ) === false ):
if ( $args['show_option_all'] ):
printf( '<option value="0">%s</option>', $args['show_option_all'] );
endif;
if ( $args['show_option_none'] ):
printf( '<option value="-1">%s</option>', $args['show_option_none'] );
endif;
endif;
foreach ( $terms as $term ):
if ( $args['values'] == 'term_id' ):
$this_value = $term->term_id;
else:
$this_value = $term->slug;
endif;
if ( strpos( $property, 'multiple' ) !== false ):
$selected_prop = in_array( $this_value, $selected ) ? 'selected' : '';
else:
$selected_prop = selected( $this_value, $selected, false );
endif;
printf( '<option value="%s" %s>%s</option>', $this_value, $selected_prop, $term->name );
endforeach;
print( '</select>' );
return true;
else:
@@ -264,13 +300,14 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
$defaults = array(
'prepend_options' => null,
'append_options' => null,
'show_option_blank' => false,
'show_option_all' => false,
'show_option_none' => false,
'show_dates' => false,
'option_all_value' => 0,
'option_none_value' => -1,
'name' => 'page_id',
'id' => 'page_id',
'id' => null,
'selected' => null,
'numberposts' => -1,
'posts_per_page' => -1,
@@ -288,13 +325,16 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
'post_status' => 'publish',
'values' => 'post_name',
'class' => null,
'property' => null,
'placeholder' => null,
'chosen' => false,
);
$args = array_merge( $defaults, $args );
$name = $args['name'];
unset( $args['name'] );
$id = $args['id'];
$id = ( $args['id'] ) ? $args['id'] : $name;
unset( $args['id'] );
$values = $args['values'];
@@ -303,36 +343,64 @@ if ( !function_exists( 'sportspress_dropdown_pages' ) ) {
$class = $args['class'];
unset( $args['class'] );
$property = $args['property'];
unset( $args['property'] );
$placeholder = $args['placeholder'];
unset( $args['placeholder'] );
$selected = $args['selected'];
unset( $args['selected'] );
$chosen = $args['chosen'];
unset( $args['chosen'] );
$posts = get_posts( $args );
if ( $posts || $prepend || $append ):
printf( '<select name="%s" id="%s" class="postform %s">', $name, $id, $class );
if ( $args['show_option_all'] ):
printf( '<option value="%s" %s>%s</option>', $args['option_all_value'], selected( $selected, $args['option_all_value'], false ), $args['show_option_all'] );
endif;
if ( $args['show_option_none'] ):
printf( '<option value="%s" %s>%s</option>', $args['option_none_value'], selected( $selected, $args['option_none_value'], false ), $args['show_option_none'] );
endif;
if ( $args['prepend_options'] && is_array( $args['prepend_options'] ) ):
foreach( $args['prepend_options'] as $slug => $label ):
printf( '<option value="%s" %s>%s</option>', $slug, selected( $selected, $slug, false ), $label );
endforeach;
if ( $posts || $args['prepend_options'] || $args['append_options'] ):
printf( '<select name="%s" id="%s" class="postform %s" %s>', $name, $id, $class . ( $chosen ? ' chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' ) : '' ), ( $placeholder != null ? 'data-placeholder="' . $placeholder . '" ' : '' ) . $property );
if ( strpos( $property, 'multiple' ) === false ):
if ( $args['show_option_blank'] ):
printf( '<option value=""></option>' );
endif;
if ( $args['show_option_all'] ):
printf( '<option value="%s" %s>%s</option>', $args['option_all_value'], selected( $selected, $args['option_all_value'], false ), $args['show_option_all'] );
endif;
if ( $args['show_option_none'] ):
printf( '<option value="%s" %s>%s</option>', $args['option_none_value'], selected( $selected, $args['option_none_value'], false ), $args['show_option_none'] );
endif;
if ( $args['prepend_options'] && is_array( $args['prepend_options'] ) ):
foreach( $args['prepend_options'] as $slug => $label ):
printf( '<option value="%s" %s>%s</option>', $slug, selected( $selected, $slug, false ), $label );
endforeach;
endif;
endif;
foreach ( $posts as $post ):
setup_postdata( $post );
if ( $values == 'ID' ):
printf( '<option value="%s" %s>%s</option>', $post->ID, selected( $selected, $post->ID, false ), $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) );
$this_value = $post->ID;
else:
printf( '<option value="%s" %s>%s</option>', $post->post_name, selected( $selected, $post->post_name, false ), $post->post_title );
$this_value = $post->post_name;
endif;
if ( strpos( $property, 'multiple' ) !== false ):
$selected_prop = in_array( $this_value, $selected ) ? 'selected' : '';
else:
$selected_prop = selected( $this_value, $selected, false );
endif;
printf( '<option value="%s" %s>%s</option>', $this_value, $selected_prop, $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) );
endforeach;
wp_reset_postdata();
if ( $args['append_options'] && is_array( $args['append_options'] ) ):
foreach( $args['append_options'] as $slug => $label ):
printf( '<option value="%s" %s>%s</option>', $slug, selected( $selected, $slug, false ), $label );
endforeach;
if ( strpos( $property, 'multiple' ) === false ):
if ( $args['append_options'] && is_array( $args['append_options'] ) ):
foreach( $args['append_options'] as $slug => $label ):
printf( '<option value="%s" %s>%s</option>', $slug, selected( $selected, $slug, false ), $label );
endforeach;
endif;
endif;
print( '</select>' );
return true;

View File

@@ -85,10 +85,6 @@ Yes; SportsPress will work with any theme, but may require some styling to make
Bugs can be reported either in our support forum or preferably on the [SportsPress GitHub repository](https://github.com/ThemeBoy/SportsPress/issues).
= SportsPress is awesome! Can I contribute? =
Yes you can! Join in on our [GitHub repository](http://github.com/ThemeBoy/SportsPress/) :)
= Is this plugin ready for production? =
SportsPress is currently in beta and is undergoing testing. We are still actively making adjustments to the code, so we do not recommend installing it on a live server until we officially leave the beta phase.
@@ -188,15 +184,6 @@ SportsPress is currently in beta and is undergoing testing. We are still activel
* Tweak - Enable SportsPress content functions to be called without explicit ID.
* Tweak - Remove redundant admin menu links via filter.
= 0.1.10 =
* Documentation - Add Installation, FAQ and Screenshots to assets.
= 0.1.9 =
* Fix - Calculation dependencies.
= 0.1.8 =
* Tweak - Update subversion.
= 0.1.7 =
* Feature - Enable selecting venues to use uploaded images.