From 94ac918e0ce096ee33169ea323eb460ff7a9a4fe Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Tue, 18 Feb 2014 13:22:51 +1100 Subject: [PATCH] Add chosen selectors to player edit screen, style installation notice --- admin/includes/notice-install.php | 4 +- admin/post-types/event.php | 1 + admin/post-types/player.php | 205 +++++++++++++++++++----------- assets/css/admin.css | 49 ++++++- assets/js/admin.js | 11 +- functions.php | 134 ++++++++++++++----- readme.txt | 13 -- 7 files changed, 286 insertions(+), 131 deletions(-) diff --git a/admin/includes/notice-install.php b/admin/includes/notice-install.php index 241ad248..1dfb64ef 100644 --- a/admin/includes/notice-install.php +++ b/admin/includes/notice-install.php @@ -4,7 +4,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

Welcome to SportsPress – Get Started', 'sportspress' ); ?>

- - + +

\ No newline at end of file diff --git a/admin/post-types/event.php b/admin/post-types/event.php index a5546497..e41b60c5 100644 --- a/admin/post-types/event.php +++ b/admin/post-types/event.php @@ -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, diff --git a/admin/post-types/player.php b/admin/post-types/player.php index 0a51aea1..ad38d66b 100644 --- a/admin/post-types/player.php +++ b/admin/post-types/player.php @@ -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 ); ?> -

- -

-

- -

-

- -

-

- -

- -

- -

-

- -

- -

+

-function sportspress_player_team_meta( $post ) { - sportspress_post_checklist( $post->ID, 'sp_team' ); - sportspress_post_adder( 'sp_team' ); +

+

+ +

+

'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 ); + ?>

+ +

+

'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 ); + ?>

+ +

+

'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 ); + ?>

+ +

+

'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 ); + ?>

+ +

+

'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 ); + ?>

+ -
- - - - - - - - - - - - post_name, '' ); - ?> - - - - -
- post_title; ?> -
-
- +

post_title; ?>

+

+ 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( '', $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( '', $args['show_option_all'] ); + endif; + if ( $args['show_option_none'] ): + printf( '', $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( '', $this_value, $selected_prop, $term->name ); + endforeach; print( '' ); 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( '', $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( '' ); + endif; + if ( $args['show_option_all'] ): + printf( '', $args['option_all_value'], selected( $selected, $args['option_all_value'], false ), $args['show_option_all'] ); + endif; + if ( $args['show_option_none'] ): + printf( '', $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( '', $slug, selected( $selected, $slug, false ), $label ); + endforeach; + endif; endif; + foreach ( $posts as $post ): setup_postdata( $post ); + if ( $values == 'ID' ): - printf( '', $post->ID, selected( $selected, $post->ID, false ), $post->post_title . ( $args['show_dates'] ? ' (' . $post->post_date . ')' : '' ) ); + $this_value = $post->ID; else: - printf( '', $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( '', $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( '', $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( '', $slug, selected( $selected, $slug, false ), $label ); + endforeach; + endif; endif; print( '' ); return true; diff --git a/readme.txt b/readme.txt index f81db732..72a28c49 100644 --- a/readme.txt +++ b/readme.txt @@ -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.