diff --git a/admin/post-types/metric.php b/admin/post-types/metric.php index ad969bed..3fe48761 100644 --- a/admin/post-types/metric.php +++ b/admin/post-types/metric.php @@ -7,18 +7,29 @@ function sp_metric_cpt_init() { $args = array( 'label' => $name, 'labels' => $labels, - 'public' => true, + 'public' => false, + 'show_ui' => true, 'show_in_nav_menus' => false, 'hierarchical' => false, 'supports' => array( 'title', 'page-attributes' ), 'register_meta_box_cb' => 'sp_metric_meta_init', - 'rewrite' => array( 'slug' => 'metric' ), 'show_in_menu' => 'edit.php?post_type=sp_player' ); register_post_type( 'sp_metric', $args ); } add_action( 'init', 'sp_metric_cpt_init' ); +function sp_metric_edit_columns() { + $columns = array( + 'cb' => '', + 'title' => __( 'Label', 'sportspress' ), + 'sp_sport' => __( 'Sports', 'sportspress' ), + 'sp_equation' => __( 'Equation', 'sportspress' ), + ); + return $columns; +} +add_filter( 'manage_edit-sp_metric_columns', 'sp_metric_edit_columns' ); + function sp_metric_meta_init() { } ?> \ No newline at end of file diff --git a/admin/post-types/outcome.php b/admin/post-types/outcome.php new file mode 100644 index 00000000..2e291761 --- /dev/null +++ b/admin/post-types/outcome.php @@ -0,0 +1,35 @@ + $name, + 'labels' => $labels, + 'public' => false, + 'show_ui' => true, + 'show_in_nav_menus' => false, + 'hierarchical' => false, + 'supports' => array( 'title', 'page-attributes' ), + 'register_meta_box_cb' => 'sp_outcome_meta_init', + 'show_in_menu' => 'edit.php?post_type=sp_event' + ); + register_post_type( 'sp_outcome', $args ); +} +add_action( 'init', 'sp_outcome_cpt_init' ); + +function sp_outcome_edit_columns() { + $columns = array( + 'cb' => '', + 'title' => __( 'Label', 'sportspress' ), + 'sp_sport' => __( 'Sports', 'sportspress' ), + 'sp_equation' => __( 'Conditions', 'sportspress' ), + ); + return $columns; +} +add_filter( 'manage_edit-sp_outcome_columns', 'sp_outcome_edit_columns' ); + +function sp_outcome_meta_init() { +} +?> \ No newline at end of file diff --git a/admin/post-types/result.php b/admin/post-types/result.php new file mode 100644 index 00000000..4b1a28f0 --- /dev/null +++ b/admin/post-types/result.php @@ -0,0 +1,35 @@ + $name, + 'labels' => $labels, + 'public' => true, + 'show_ui' => true, + '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 ); +} +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' ), + ); + 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 d3d93a6e..d7b5e1f0 100644 --- a/admin/post-types/stat.php +++ b/admin/post-types/stat.php @@ -7,7 +7,8 @@ function sp_stat_cpt_init() { $args = array( 'label' => $name, 'labels' => $labels, - 'public' => true, + 'public' => false, + 'show_ui' => true, 'show_in_nav_menus' => false, 'hierarchical' => false, 'supports' => array( 'title', 'page-attributes' ), @@ -23,7 +24,7 @@ function sp_stat_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Label', 'sportspress' ), - 'sp_sport' => __( 'Sport', 'sportspress' ), + 'sp_sport' => __( 'Sports', 'sportspress' ), 'sp_equation' => __( 'Equation', 'sportspress' ), ); return $columns; @@ -41,7 +42,7 @@ function sp_stat_equation_meta( $post ) {
ID, 'stat', $piece ); endforeach; ?>
diff --git a/admin/terms/div.php b/admin/terms/div.php index 5ae38446..c658f673 100644 --- a/admin/terms/div.php +++ b/admin/terms/div.php @@ -10,7 +10,7 @@ function sp_div_term_init() { 'labels' => $labels, 'public' => true, 'hierarchical' => true, - 'rewrite' => array( 'slug' => 'division' ), + 'rewrite' => array( 'slug' => 'division' ) ); register_taxonomy( 'sp_div', $object_type, $args ); } diff --git a/admin/terms/sport.php b/admin/terms/sport.php index ff2c0f5a..08ee2deb 100644 --- a/admin/terms/sport.php +++ b/admin/terms/sport.php @@ -3,12 +3,14 @@ function sp_sport_term_init() { $name = __( 'Sports', 'sportspress' ); $singular_name = __( 'Sport', 'sportspress' ); $lowercase_name = __( 'sport', 'sportspress' ); - $object_type = array( 'sp_stat', 'sp_metric' ); + $object_type = array( 'sp_result', 'sp_outcome', 'sp_stat', 'sp_metric' ); $labels = sp_tax_labels( $name, $singular_name, $lowercase_name ); $args = array( 'label' => $name, 'labels' => $labels, - 'public' => true, + 'public' => false, + 'show_ui' => true, + 'show_in_nav_menus' => false, 'hierarchical' => true, 'rewrite' => array( 'slug' => 'sport' ) ); diff --git a/sportspress-actions.php b/sportspress-actions.php index 2738c869..63a3d444 100644 --- a/sportspress-actions.php +++ b/sportspress-actions.php @@ -10,13 +10,28 @@ function sp_after_theme_setup() { } add_action( 'after_theme_setup', 'sp_after_theme_setup' ); -function sp_admin_menu_separator() { +function sp_admin_menu() { if ( ! current_user_can( 'manage_options' ) ) return; - global $menu; + + global $menu, $submenu; + + // Add separator $menu[41] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' ); + + // Remove "Add Event" link under Events + unset( $submenu['edit.php?post_type=sp_event'][10] ); + + // Remove "Divisions" link under Events + unset( $submenu['edit.php?post_type=sp_event'][15] ); + + // Remove "Divisions" link under Players + unset( $submenu['edit.php?post_type=sp_player'][15] ); + + // Remove "Divisions" link under Staff + unset( $submenu['edit.php?post_type=sp_staff'][15] ); } -add_action( 'admin_menu', 'sp_admin_menu_separator' ); +add_action( 'admin_menu', 'sp_admin_menu' ); function sp_manage_posts_custom_column( $column, $post_id ) { global $post; diff --git a/sportspress-filters.php b/sportspress-filters.php index 9f06c331..d319ed4f 100644 --- a/sportspress-filters.php +++ b/sportspress-filters.php @@ -42,4 +42,26 @@ function sportspress_the_content( $content ) { return $content; } add_filter('the_content', 'sportspress_the_content'); + +function sp_sanitize_title( $title ) { + + if ( in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_stat', 'sp_metric' ) ) ): + + // Get post title + $title = $_POST['post_title']; + + // String to lowercase + $title = strtolower( $title ); + + // Replace all numbers with words + $title = sp_numbers_to_words( $title ); + + // Remove all other non-alphabet characters + $title = preg_replace( "/[^a-z]/", '', $title ); + + endif; + + return $title; +} +add_filter( 'sanitize_title', 'sp_sanitize_title' ); ?> \ No newline at end of file diff --git a/sportspress-helpers.php b/sportspress-helpers.php index f85d1da2..ecc6d94d 100644 --- a/sportspress-helpers.php +++ b/sportspress-helpers.php @@ -55,13 +55,11 @@ if ( !function_exists( 'sp_array_combine' ) ) { } } -if ( !function_exists( 'sp_num_to_letter' ) ) { - function sp_num_to_letter( $num, $uppercase = false ) { - $num -= 0; - $letter = chr( ( $num % 26 ) + 97 ); - $letter .= ( floor( $num / 26 ) > 0 ) ? str_repeat( $letter, floor( $num / 26 ) ) : ''; - return ( $uppercase ? strtoupper( $letter ) : $letter ); - } +if ( !function_exists( 'sp_numbers_to_words' ) ) { + function sp_numbers_to_words( $str ) { + $output = str_replace( array( '1st', '2nd', '3rd', '5th', '8th', '9th', '10', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ), array( 'first', 'second', 'third', 'fifth', 'eight', 'ninth', 'ten', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ), $str ); + return $output; + } } if ( !function_exists( 'sp_cpt_labels' ) ) { @@ -71,6 +69,7 @@ if ( !function_exists( 'sp_cpt_labels' ) ) { 'name' => $name, 'singular_name' => $singular_name, 'all_items' => $name, + 'add_new' => sprintf( __( 'Add %s', 'sportspress' ), $singular_name ), 'add_new_item' => sprintf( __( 'Add New %s', 'sportspress' ), $singular_name ), 'edit_item' => sprintf( __( 'Edit %s', 'sportspress' ), $singular_name ), 'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ), @@ -257,9 +256,62 @@ 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 ) { + $arr = array(); + + // Get stats within the sports that the current stat is in ### TODO: should be for sport selected + $args = array( + 'post_type' => $type, + '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; + $vars = get_posts( $args ); + + // Add extra vars to the array + if ( isset( $defaults ) && is_array( $defaults ) ): + foreach ( $defaults as $key => $value ): + $arr[ $key ] = $value; + endforeach; + endif; + + // Add vars to the array + if ( isset( $variations ) && is_array( $variations ) ): + foreach ( $vars as $var ): + foreach ( $variations as $key => $value ): + $arr[ $var->post_name . '_' . $key ] = $var->post_title . ' ' . $value; + endforeach; + endforeach; + else: + foreach ( $vars as $var ): + $arr[ $var->post_name ] = $var->post_title; + endforeach; + endif; + + return (array) $arr; + } +} if ( !function_exists( 'sp_get_equation_selector' ) ) { - function sp_get_equation_selector( $type = null, $selected = null ) { + function sp_get_equation_selector( $postid, $type = null, $selected = null ) { + + if ( ! isset( $postid ) ) + return; // Initialize options array $options = array(); @@ -268,57 +320,27 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) { if ( $type == 'stat' ): - // Create array of events ## TODO: should be a custom post under events called outcomes - $events = array( 'wins' => __( 'Wins', 'sportspress' ), 'draws' => __( 'Draws', 'sportspress' ), 'ties' => __( 'Ties', 'sportspres' ), 'losses' => __( 'Losses', 'sportspress' ) ); + // Add events to options + $options[ __( 'Results', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_result', array( 'for' => '→', 'against' => '←' ) ); // Add events to options - $options[ __( 'Events', 'sportspress' ) ] = (array) $events; - - $vars = array(); - - // Get stats within the sports that the current stat is in ### TODO: should be for sport selected - $args = array( - 'post_type' => 'sp_stat', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'exclude' => $post->ID - ); - $sports = get_the_terms( $post->ID, '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; - $stats = get_posts( $args ); - - // Add vars to the array - foreach ( $stats as $stat ): - $vars[ $stat->post_name ] = $stat->post_title; - endforeach; + $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' ) ] = (array) $vars; + $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 ### TODO: should be for sport selected + // Get metrics within the sports that the current metric is in $args = array( 'post_type' => 'sp_metric', 'numberposts' => -1, 'posts_per_page' => -1, - 'exclude' => $post->ID + 'exclude' => $postid ); - $sports = get_the_terms( $post->ID, 'sp_sport' ); + $sports = get_the_terms( $postid, 'sp_sport' ); if ( ! empty( $sports ) ): $terms = array(); foreach ( $sports as $sport ): @@ -362,7 +384,7 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) { ?>