From 388e5283b44f124f4d832d6f89049f4186c060dd Mon Sep 17 00:00:00 2001 From: ThemeBoy Date: Wed, 27 Nov 2013 17:31:35 +1100 Subject: [PATCH] Remove sport taxonomy and improve equation selectors --- admin/post-types/metric.php | 18 +++++- admin/post-types/outcome.php | 20 ++++++- admin/post-types/result.php | 8 +-- admin/post-types/stat.php | 3 +- admin/terms/sport.php | 20 ------- assets/js/admin.js | 5 +- sportspress-actions.php | 34 ++++++----- sportspress-filters.php | 15 +++++ sportspress-helpers.php | 106 +++++++++-------------------------- sportspress.php | 1 - 10 files changed, 105 insertions(+), 125 deletions(-) delete mode 100644 admin/terms/sport.php diff --git a/admin/post-types/metric.php b/admin/post-types/metric.php index 3fe48761..17baf1ec 100644 --- a/admin/post-types/metric.php +++ b/admin/post-types/metric.php @@ -23,7 +23,6 @@ function sp_metric_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Label', 'sportspress' ), - 'sp_sport' => __( 'Sports', 'sportspress' ), 'sp_equation' => __( 'Equation', 'sportspress' ), ); return $columns; @@ -31,5 +30,22 @@ function sp_metric_edit_columns() { add_filter( 'manage_edit-sp_metric_columns', 'sp_metric_edit_columns' ); function sp_metric_meta_init() { + add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_metric_equation_meta', 'sp_metric', 'normal', 'high' ); +} + +function sp_metric_equation_meta( $post ) { + $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); + ?> +
+

+ ID, $piece, array( 'event' ) ); + endforeach; + ?> +

+
+ \ No newline at end of file diff --git a/admin/post-types/outcome.php b/admin/post-types/outcome.php index 2e291761..39f808e9 100644 --- a/admin/post-types/outcome.php +++ b/admin/post-types/outcome.php @@ -23,13 +23,29 @@ function sp_outcome_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Label', 'sportspress' ), - 'sp_sport' => __( 'Sports', 'sportspress' ), - 'sp_equation' => __( 'Conditions', 'sportspress' ), + 'sp_equation' => __( 'Equation', 'sportspress' ), ); return $columns; } add_filter( 'manage_edit-sp_outcome_columns', 'sp_outcome_edit_columns' ); function sp_outcome_meta_init() { + add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_outcome_equation_meta', 'sp_outcome', 'normal', 'high' ); +} + +function sp_outcome_equation_meta( $post ) { + $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); + ?> +
+

+ ID, $piece, array( 'result' ) ); + endforeach; + ?> +

+
+ \ No newline at end of file diff --git a/admin/post-types/result.php b/admin/post-types/result.php index 4b1a28f0..7ea1b422 100644 --- a/admin/post-types/result.php +++ b/admin/post-types/result.php @@ -12,7 +12,6 @@ function sp_result_cpt_init() { 'show_in_nav_menus' => false, 'hierarchical' => false, 'supports' => array( 'title', 'page-attributes' ), - 'register_meta_box_cb' => 'sp_result_meta_init', 'show_in_menu' => 'edit.php?post_type=sp_event' ); register_post_type( 'sp_result', $args ); @@ -22,14 +21,9 @@ add_action( 'init', 'sp_result_cpt_init' ); function sp_result_edit_columns() { $columns = array( 'cb' => '', - 'title' => __( 'Label', 'sportspress' ), - 'sp_sport' => __( 'Sports', 'sportspress' ), - 'sp_equation' => __( 'Equation', 'sportspress' ), + 'title' => __( 'Label', 'sportspress' ) ); return $columns; } add_filter( 'manage_edit-sp_result_columns', 'sp_result_edit_columns' ); - -function sp_result_meta_init() { -} ?> \ No newline at end of file diff --git a/admin/post-types/stat.php b/admin/post-types/stat.php index d7b5e1f0..08db5a91 100644 --- a/admin/post-types/stat.php +++ b/admin/post-types/stat.php @@ -24,7 +24,6 @@ function sp_stat_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Label', 'sportspress' ), - 'sp_sport' => __( 'Sports', 'sportspress' ), 'sp_equation' => __( 'Equation', 'sportspress' ), ); return $columns; @@ -42,7 +41,7 @@ function sp_stat_equation_meta( $post ) {

ID, 'stat', $piece ); + sp_get_equation_selector( $post->ID, $piece, array( 'event', 'result', 'outcome' ) ); endforeach; ?>

diff --git a/admin/terms/sport.php b/admin/terms/sport.php deleted file mode 100644 index 08ee2deb..00000000 --- a/admin/terms/sport.php +++ /dev/null @@ -1,20 +0,0 @@ - $name, - 'labels' => $labels, - 'public' => false, - 'show_ui' => true, - 'show_in_nav_menus' => false, - 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'sport' ) - ); - register_taxonomy( 'sp_sport', $object_type, $args ); -} -add_action( 'init', 'sp_sport_term_init' ); -?> \ No newline at end of file diff --git a/assets/js/admin.js b/assets/js/admin.js index 9d8b9a21..4c53ac22 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -74,6 +74,9 @@ jQuery(document).ready(function($){ }); // Trigger equation selector - $('.sp-equation-selector select:last').change(); + $('.sp-equation-selector select:last').change().siblings().change(); + + // Remove slug editor in quick edit for slug-sensitive post types + $('.inline-edit-sp_result, .inline-edit-sp_outcome, .inline-edit-sp_stat, .inline-edit-sp_metric').find('input[name=post_name]').closest('label').remove(); }); \ No newline at end of file diff --git a/sportspress-actions.php b/sportspress-actions.php index 63a3d444..e7768b9f 100644 --- a/sportspress-actions.php +++ b/sportspress-actions.php @@ -46,9 +46,6 @@ function sp_manage_posts_custom_column( $column, $post_id ) { $result = get_post_meta( $post_id, 'sp_result', false ); echo get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '
', $result, ( empty( $result ) ? ' — ' : ' ' ) ) : '—'; break; - case 'sp_sport': - echo get_the_terms ( $post_id, 'sp_sport' ) ? preg_replace('#.*?#i', '', sp_the_plain_terms( $post_id, 'sp_sport' ) ) : '—'; - break; case 'sp_equation': echo get_post_meta ( $post_id, 'sp_equation', true ); break; @@ -107,16 +104,6 @@ function sp_restrict_manage_posts() { ); sp_dropdown_taxonomies( $args ); endif; - if ( in_array( $typenow, array( 'sp_stat', 'sp_metric' ) ) ): - $selected = isset( $_REQUEST['sp_sport'] ) ? $_REQUEST['sp_sport'] : null; - $args = array( - 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Sports', 'sportspress' ) ), - 'taxonomy' => 'sp_sport', - 'name' => 'sp_sport', - 'selected' => $selected - ); - sp_dropdown_taxonomies( $args ); - endif; } add_action( 'restrict_manage_posts', 'sp_restrict_manage_posts' ); @@ -161,6 +148,20 @@ function sp_save_post( $post_id ) { break; + case ( 'sp_result' ): + + // Update equation as string + update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) ); + + break; + + case ( 'sp_outcome' ): + + // Update equation as string + update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) ); + + break; + case ( 'sp_stat' ): // Update equation as string @@ -168,6 +169,13 @@ function sp_save_post( $post_id ) { break; + case ( 'sp_metric' ): + + // Update equation as string + update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) ); + + break; + case ( 'sp_player' ): update_post_meta( $post_id, 'sp_stats', sp_array_value( $_POST, 'sp_stats', array() ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); diff --git a/sportspress-filters.php b/sportspress-filters.php index d319ed4f..3394f7da 100644 --- a/sportspress-filters.php +++ b/sportspress-filters.php @@ -59,9 +59,24 @@ function sp_sanitize_title( $title ) { // Remove all other non-alphabet characters $title = preg_replace( "/[^a-z]/", '', $title ); + // Convert post ID to words if title is empty + if ( $title == '' ) $title = sp_numbers_to_words( $_POST['ID'] ); + endif; return $title; } add_filter( 'sanitize_title', 'sp_sanitize_title' ); + +function sp_pre_get_posts( $wp_query ) { + if ( is_admin() ): + $post_type = $wp_query->query['post_type']; + + if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_stat', 'sp_metric' ) ) ): + $wp_query->set( 'orderby', 'menu_order' ); + $wp_query->set( 'order', 'ASC' ); + endif; + endif; +} +add_filter('pre_get_posts', 'sp_pre_get_posts'); ?> \ No newline at end of file diff --git a/sportspress-helpers.php b/sportspress-helpers.php index ecc6d94d..23ebe26e 100644 --- a/sportspress-helpers.php +++ b/sportspress-helpers.php @@ -257,7 +257,7 @@ if ( !function_exists( 'sp_post_checklist' ) ) { } if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) { - function sp_get_equation_optgroup_array( $postid, $type = null, $variations = null, $defaults = null ) { + function sp_get_equation_optgroup_array( $postid, $type = null, $variations = null, $defaults = null, $plain = true ) { $arr = array(); // Get stats within the sports that the current stat is in ### TODO: should be for sport selected @@ -265,22 +265,10 @@ if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) { 'post_type' => $type, 'numberposts' => -1, 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', 'exclude' => $postid ); - $sports = get_the_terms( $postid, 'sp_sport' ); - if ( ! empty( $sports ) ): - $terms = array(); - foreach ( $sports as $sport ): - $terms[] = $sport->slug; - endforeach; - $args['tax_query'] = array( - array( - 'taxonomy' => 'sp_sport', - 'field' => 'slug', - 'terms' => $terms - ) - ); - endif; $vars = get_posts( $args ); // Add extra vars to the array @@ -293,6 +281,7 @@ if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) { // Add vars to the array if ( isset( $variations ) && is_array( $variations ) ): foreach ( $vars as $var ): + if ( $plain ) $arr[ $var->post_name ] = $var->post_title; foreach ( $variations as $key => $value ): $arr[ $var->post_name . '_' . $key ] = $var->post_title . ' ' . $value; endforeach; @@ -308,7 +297,7 @@ if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) { } if ( !function_exists( 'sp_get_equation_selector' ) ) { - function sp_get_equation_selector( $postid, $type = null, $selected = null ) { + function sp_get_equation_selector( $postid, $selected = null, $groups = array() ) { if ( ! isset( $postid ) ) return; @@ -316,66 +305,37 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) { // Initialize options array $options = array(); - // Create array of variables - - if ( $type == 'stat' ): - - // Add events to options - $options[ __( 'Results', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_result', array( 'for' => '→', 'against' => '←' ) ); - - // Add events to options - $options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( '' => '', 'max' => '↑', 'min' => '↓' ), array( 'played' => __( 'Played', 'sportspress' ) ) ); - - // Add stats to options - $options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_stat' ); - - elseif ( $type == 'metric' ): - - $vars = array(); - - // Get metrics within the sports that the current metric is in - $args = array( - 'post_type' => 'sp_metric', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'exclude' => $postid - ); - $sports = get_the_terms( $postid, 'sp_sport' ); - if ( ! empty( $sports ) ): - $terms = array(); - foreach ( $sports as $sport ): - $terms[] = $sport->slug; - endforeach; - $args['tax_query'] = array( - array( - 'taxonomy' => 'sp_sport', - 'field' => 'slug', - 'terms' => $terms - ) - ); - endif; - $metrics = get_posts( $args ); - - // Add vars to the array - foreach ( $metrics as $metric ): - $vars[ $metric->post_name ] = $metric->post_title; - endforeach; - - // Add metrics to options - $options[ __( 'Metrics', 'sportspress' ) ] = (array) $vars; - - endif; + // Add groups to options + foreach ( $groups as $group ): + switch ( $group ): + case 'event': + $options[ __( 'Events', 'sportspress' ) ] = array( 'events_scheduled' => __( 'Scheduled', 'sportspress' ), 'events_attended' => __( 'Attended', 'sportspress' ), 'events_played' => __( 'Played', 'sportspress' ) ); + break; + case 'result': + $options[ __( 'Results', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_result', array( 'for' => '→', 'against' => '←' ), null, false ); + break; + case 'outcome': + $options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) ); + break; + case 'stat': + $options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_stat' ); + break; + case 'metric': + $options[ __( 'Metrics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_metric' ); + break; + endswitch; + endforeach; // Create array of operators - $operators = array( '+' => '+', '-' => '−', '*' => '×', '/' => '÷', '(' => '(', ')' => ')' ); + $operators = array( '+' => '+', '-' => '−', '*' => '×', '/' => '÷', '==' => '=', '!=' => '≠', '<' => '<', '<=' => '≤', '>' => '>', '>=' => '≥', '(' => '(', ')' => ')' ); // Add operators to options - $options[ __( 'Operators', 'sportspress' ) ] = (array) $operators; + $options[ __( 'Operators', 'sportspress' ) ] = $operators; // Create array of constants $max = 10; $constants = array(); - for ( $i = 1; $i < $max; $i ++ ): + for ( $i = 1; $i <= $max; $i ++ ): $constants[$i] = $i; endfor; @@ -705,16 +665,6 @@ if ( !function_exists( 'sportspress_render_option_field' ) ) { case 'checkbox': echo ''; break; - case 'sport': - $terms = get_terms( 'sp_sport' ); - if ( $terms ) { - printf( '' ); - } - break; default: echo ''; break; diff --git a/sportspress.php b/sportspress.php index 79710e10..72f58156 100644 --- a/sportspress.php +++ b/sportspress.php @@ -48,7 +48,6 @@ require_once dirname( __FILE__ ) . '/admin/post-types/staff.php'; // Terms require_once dirname( __FILE__ ) . '/admin/terms/div.php'; require_once dirname( __FILE__ ) . '/admin/terms/pos.php'; -require_once dirname( __FILE__ ) . '/admin/terms/sport.php'; // Shortcodes // require_once dirname( __FILE__ ) . '/classes/shortcodes/table.php';