diff --git a/includes/admin/class-sp-admin-sports.php b/includes/admin/class-sp-admin-sports.php index 4609853a..33576416 100644 --- a/includes/admin/class-sp-admin-sports.php +++ b/includes/admin/class-sp-admin-sports.php @@ -143,7 +143,7 @@ class SP_Admin_Sports { update_post_meta( $id, 'sp_equation', sp_array_value( $result, 'equation', null ) ); } - // Make sure statistics and metrics have greater menu order than performance + // Make sure statistics, metrics and specs have greater menu order than performance $i = 0; // Performance @@ -192,6 +192,17 @@ class SP_Admin_Sports { $id = self::insert_preset_post( $post, $i + $index ); $i ++; } + + // Event Specs + $post_type = 'sp_spec'; + $specs = sp_array_value( $preset, 'specs', array() ); + self::delete_preset_posts( $post_type ); + foreach ( $specs as $index => $spec ) { + $post = self::get_post_array( $spec, $post_type ); + if ( empty( $post ) ) continue; + $id = self::insert_preset_post( $post, $i + $index ); + $i ++; + } // Statistics $post_type = 'sp_statistic'; diff --git a/includes/admin/post-types/class-sp-admin-cpt-spec.php b/includes/admin/post-types/class-sp-admin-cpt-spec.php new file mode 100644 index 00000000..8318949d --- /dev/null +++ b/includes/admin/post-types/class-sp-admin-cpt-spec.php @@ -0,0 +1,70 @@ +type = 'sp_spec'; + + // Admin Columns + add_filter( 'manage_edit-sp_spec_columns', array( $this, 'edit_columns' ) ); + add_action( 'manage_sp_spec_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); + + // Call SP_Admin_CPT constructor + parent::__construct(); + } + + /** + * Change the columns shown in admin. + */ + public function edit_columns( $existing_columns ) { + $columns = array( + 'cb' => '', + 'title' => __( 'Label', 'sportspress' ), + 'sp_key' => __( 'Variable', 'sportspress' ), + 'sp_description' => __( 'Description', 'sportspress' ), + ); + return apply_filters( 'sportspress_spec_admin_columns', $columns ); + } + + /** + * Define our custom columns shown in admin. + * @param string $column + */ + public function custom_columns( $column, $post_id ) { + switch ( $column ): + case 'sp_key': + global $post; + echo $post->post_name; + break; + case 'sp_description': + global $post; + echo '' . $post->post_excerpt . ''; + break; + endswitch; + } +} + +endif; + +return new SP_Admin_CPT_Spec(); diff --git a/includes/admin/post-types/class-sp-admin-meta-boxes.php b/includes/admin/post-types/class-sp-admin-meta-boxes.php index 56bb893b..6b434360 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -93,6 +93,15 @@ class SP_Admin_Meta_Boxes { 'priority' => 'high', ), ), + 'sp_spec' => array( + 'details' => array( + 'title' => __( 'Specs', 'sportspress' ), + 'save' => 'SP_Meta_Box_Spec_Details::save', + 'output' => 'SP_Meta_Box_Spec_Details::output', + 'context' => 'normal', + 'priority' => 'high', + ), + ), 'sp_statistic' => array( 'details' => array( 'title' => __( 'Details', 'sportspress' ), @@ -158,6 +167,13 @@ class SP_Admin_Meta_Boxes { 'context' => 'normal', 'priority' => 'high', ), + 'specs' => array( + 'title' => __( 'Specs', 'sportspress' ), + 'save' => 'SP_Meta_Box_Event_Specs::save', + 'output' => 'SP_Meta_Box_Event_Specs::output', + 'context' => 'side', + 'priority' => 'default', + ), ), 'sp_team' => array( 'details' => array( diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-specs.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-specs.php new file mode 100644 index 00000000..1e4e17c2 --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-specs.php @@ -0,0 +1,53 @@ +ID, 'sp_specs', true ); + + $args = array( + 'post_type' => 'sp_spec', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + + $vars = get_posts( $args ); + + if ( $vars ): + foreach ( $vars as $var ): + ?> +

post_title; ?>

+

+ ID, 'sp_visible', true ); + if ( '' === $visible ) $visible = 1; + ?> +

+

+ + +

+

+ + +

+ + + + + 'sp_spec', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ); + $data = get_posts( $args ); + ?> + + + + + +
+ +

+
+ + + + + + + + + + + > + + + + + + + + + + +
post_title; ?>post_name; ?>

post_excerpt; ?>

+
+ + +
+
+
ID, 'sp_specs', true ); + $spec_labels = (array)sp_get_var_labels( 'sp_spec', $neg, false ); + $data = array(); + + foreach ( $spec_labels as $key => $value ): + $spec = sp_array_value( $specs, $key, null ); + if ( $spec == null ) + continue; + $data[ $value ] = sp_array_value( $specs, $key, ' ' ); + endforeach; + return $data; + } } diff --git a/includes/class-sp-post-types.php b/includes/class-sp-post-types.php index f1d3c624..222477d5 100644 --- a/includes/class-sp-post-types.php +++ b/includes/class-sp-post-types.php @@ -342,6 +342,36 @@ class SP_Post_types { ) ) ); + + register_post_type( 'sp_spec', + apply_filters( 'sportspress_register_post_type_spec', + array( + 'labels' => array( + 'name' => __( 'Event Specs', 'sportspress' ), + 'singular_name' => __( 'Event Spec', 'sportspress' ), + 'add_new_item' => __( 'Add New Event Spec', 'sportspress' ), + 'edit_item' => __( 'Edit Event Spec', 'sportspress' ), + 'new_item' => __( 'New', 'sportspress' ), + 'view_item' => __( 'View', 'sportspress' ), + 'search_items' => __( 'Search', 'sportspress' ), + 'not_found' => __( 'No results found.', 'sportspress' ), + 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), + ), + 'public' => false, + 'show_ui' => true, + 'capability_type' => 'sp_config', + 'map_meta_cap' => true, + 'publicly_queryable' => false, + 'exclude_from_search' => true, + 'hierarchical' => false, + 'supports' => array( 'title', 'page-attributes', 'excerpt' ), + 'has_archive' => false, + 'show_in_nav_menus' => false, + 'can_export' => false, + 'show_in_menu' => false, + ) + ) + ); register_post_type( 'sp_performance', apply_filters( 'sportspress_register_post_type_performance', diff --git a/includes/sp-conditional-functions.php b/includes/sp-conditional-functions.php index 8793c4c4..ac475f54 100755 --- a/includes/sp-conditional-functions.php +++ b/includes/sp-conditional-functions.php @@ -78,7 +78,7 @@ if ( ! function_exists( 'sp_importable_post_types' ) ) { */ if ( ! function_exists( 'sp_config_types' ) ) { function sp_config_types() { - return apply_filters( 'sportspress_config_types', array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_performance', 'sp_metric', 'sp_statistic' ) ); + return apply_filters( 'sportspress_config_types', array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_performance', 'sp_metric', 'sp_spec', 'sp_statistic' ) ); } } diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index f64684a0..d8492594 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -253,7 +253,7 @@ function sportspress_post_updated_messages( $messages ) { global $typenow, $post; - if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric', 'sp_performance' ) ) ): + if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric', 'sp_spec', 'sp_performance' ) ) ): $obj = get_post_type_object( $typenow ); for ( $i = 0; $i <= 10; $i++ ): diff --git a/templates/event-details.php b/templates/event-details.php index 7d6dcbab..ad898421 100644 --- a/templates/event-details.php +++ b/templates/event-details.php @@ -17,6 +17,11 @@ $scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'ye $data = array(); +$event = new SP_Event( $id ); + +$specs_before = $event->specs( true ); +$specs_after = $event->specs( false ); + if ( 'yes' === get_option( 'sportspress_event_show_date', 'yes' ) ) { $date = get_the_time( get_option('date_format'), $id ); $data[ __( 'Date', 'sportspress' ) ] = $date; @@ -55,6 +60,8 @@ if ( 'yes' === get_option( 'sportspress_event_show_full_time', 'yes' ) ) { $data = apply_filters( 'sportspress_event_details', $data, $id ); +$data = array_merge( $specs_before, $data, $specs_after ); + if ( ! sizeof( $data ) ) return; ?>