From fa1877747c820a825bfc7c685e8a32ace5182aad Mon Sep 17 00:00:00 2001 From: savvasha Date: Fri, 16 Feb 2018 13:53:56 +0200 Subject: [PATCH 1/6] Add sp_spec CPT for Event Specs a) Create sp_spec b) Add it to Config Page c) Add Admin Meta-Box d) Add Event Meta-Box --- includes/admin/class-sp-admin-sports.php | 13 +++- .../post-types/class-sp-admin-cpt-spec.php | 70 +++++++++++++++++++ .../post-types/class-sp-admin-meta-boxes.php | 16 +++++ .../class-sp-meta-box-event-specs.php | 53 ++++++++++++++ .../class-sp-meta-box-spec-details.php | 62 ++++++++++++++++ includes/admin/sp-admin-functions.php | 2 + includes/admin/views/html-admin-config.php | 49 +++++++++++++ includes/class-sp-event.php | 20 ++++++ includes/class-sp-post-types.php | 30 ++++++++ includes/sp-conditional-functions.php | 2 +- includes/sp-template-hooks.php | 2 +- templates/event-details.php | 7 ++ 12 files changed, 323 insertions(+), 3 deletions(-) create mode 100644 includes/admin/post-types/class-sp-admin-cpt-spec.php create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-event-specs.php create mode 100644 includes/admin/post-types/meta-boxes/class-sp-meta-box-spec-details.php 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; ?>
From 9db32d4d3d6e74e47dc947021686cd7eed72be21 Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 27 Feb 2018 21:28:37 +0200 Subject: [PATCH 2/6] Create module for Event Specs Convert most of the previous changes to the module for easier maintenance --- .../post-types/class-sp-admin-meta-boxes.php | 16 -- includes/admin/sp-admin-functions.php | 2 - includes/admin/views/html-admin-config.php | 49 ----- includes/class-sp-post-types.php | 30 --- modules/sportspress-event-specs.php | 195 ++++++++++++++++++ 5 files changed, 195 insertions(+), 97 deletions(-) create mode 100644 modules/sportspress-event-specs.php 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 6b434360..56bb893b 100644 --- a/includes/admin/post-types/class-sp-admin-meta-boxes.php +++ b/includes/admin/post-types/class-sp-admin-meta-boxes.php @@ -93,15 +93,6 @@ 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' ), @@ -167,13 +158,6 @@ 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/sp-admin-functions.php b/includes/admin/sp-admin-functions.php index 006082d7..490a3683 100755 --- a/includes/admin/sp-admin-functions.php +++ b/includes/admin/sp-admin-functions.php @@ -34,8 +34,6 @@ function sp_get_screen_ids() { 'sp_column', 'edit-sp_metric', 'sp_metric', - 'edit-sp_spec', - 'sp_spec', 'edit-sp_statistic', 'sp_statistic', 'edit-sp_event', diff --git a/includes/admin/views/html-admin-config.php b/includes/admin/views/html-admin-config.php index 66780491..8b90f05a 100644 --- a/includes/admin/views/html-admin-config.php +++ b/includes/admin/views/html-admin-config.php @@ -295,55 +295,6 @@ $columns = get_option( 'sportspress_player_columns', 'auto' );
-
- - - 'sp_spec', - 'numberposts' => -1, - 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC' - ); - $data = get_posts( $args ); - ?> - - - - -
- -

-
- - - - - - - - - - - > - - - - - - - - - - -
post_title; ?>post_name; ?>

post_excerpt; ?>

-
- - -
-
-
diff --git a/includes/class-sp-post-types.php b/includes/class-sp-post-types.php index 222477d5..7a3a78e1 100644 --- a/includes/class-sp-post-types.php +++ b/includes/class-sp-post-types.php @@ -343,36 +343,6 @@ 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', array( diff --git a/modules/sportspress-event-specs.php b/modules/sportspress-event-specs.php new file mode 100644 index 00000000..4a4bd338 --- /dev/null +++ b/modules/sportspress-event-specs.php @@ -0,0 +1,195 @@ +define_constants(); + + // Actions + add_action( 'init', array( $this, 'register_post_type' ) ); + add_action( 'sportspress_config_page', array( $this, 'sp_specs_config' ), 9 ); + add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) ); + + // Filters + add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) ); + add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) ); + } + + /** + * Define constants. + */ + private function define_constants() { + if ( !defined( 'SP_EVENT_SPECS_VERSION' ) ) + define( 'SP_EVENT_SPECS_VERSION', '2.5.10' ); + + if ( !defined( 'SP_EVENT_SPECS_URL' ) ) + define( 'SP_EVENT_SPECS_URL', plugin_dir_url( __FILE__ ) ); + + if ( !defined( 'SP_EVENT_SPECS_DIR' ) ) + define( 'SP_EVENT_SPECS_DIR', plugin_dir_path( __FILE__ ) ); + } + + /** + * Register event specs post type + */ + public static function register_post_type() { + 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, + ) + ) + ); + } + + /** + * Add screen ids. + * + * @return array + */ + public function screen_ids( $ids ) { + return array_merge( $ids, array( + 'edit-sp_spec', + 'sp_spec', + ) ); + } + + /** + * Conditonally load the class and functions only needed when viewing this post type. + */ + public function include_post_type_handler() { + include_once( SP()->plugin_path() . '/includes/admin/post-types/class-sp-admin-cpt-spec.php' ); + } + + /** + * Display Event Specs Table at Config Page + * @return null + */ + public function sp_specs_config() { + ?> +
+ + 'sp_spec', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ); + $data = get_posts( $args ); + ?> + + + + + +
+ +

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

post_excerpt; ?>

+
+ + +
+
+
+ array( + 'title' => __( 'Specs', 'sportspress' ), + 'save' => 'SP_Meta_Box_Spec_Details::save', + 'output' => 'SP_Meta_Box_Spec_Details::output', + 'context' => 'normal', + 'priority' => 'high', + ), + ); + $meta_boxes['sp_event']['specs'] = array( + 'title' => __( 'Specs', 'sportspress' ), + 'save' => 'SP_Meta_Box_Event_Specs::save', + 'output' => 'SP_Meta_Box_Event_Specs::output', + 'context' => 'side', + 'priority' => 'default', + ); + return $meta_boxes; + } +} + +endif; + +new SportsPress_Event_Specs(); From f447694a59dfe3b0b531010487f64edfe3ce3970 Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 27 Feb 2018 21:35:31 +0200 Subject: [PATCH 3/6] Conditional Functions Migration to module --- includes/sp-conditional-functions.php | 2 +- modules/sportspress-event-specs.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/sp-conditional-functions.php b/includes/sp-conditional-functions.php index ac475f54..8793c4c4 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_spec', 'sp_statistic' ) ); + return apply_filters( 'sportspress_config_types', array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_performance', 'sp_metric', 'sp_statistic' ) ); } } diff --git a/modules/sportspress-event-specs.php b/modules/sportspress-event-specs.php index 4a4bd338..66b18fec 100644 --- a/modules/sportspress-event-specs.php +++ b/modules/sportspress-event-specs.php @@ -36,6 +36,7 @@ class SportsPress_Event_Specs { // Filters add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) ); + add_filter( 'sportspress_config_types', array( $this, 'add_post_type' ) ); } /** @@ -98,6 +99,11 @@ class SportsPress_Event_Specs { 'sp_spec', ) ); } + + public static function add_post_type( $post_types = array() ) { + $post_types[] = 'sp_spec'; + return $post_types; + } /** * Conditonally load the class and functions only needed when viewing this post type. From 9b39b883f97da0dbe47ad1ad7b834833d703675c Mon Sep 17 00:00:00 2001 From: savvasha Date: Wed, 28 Feb 2018 21:17:27 +0200 Subject: [PATCH 4/6] Event details template Migrate to module code. --- modules/sportspress-event-specs.php | 18 ++++++++++++++++++ templates/event-details.php | 7 ------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/sportspress-event-specs.php b/modules/sportspress-event-specs.php index 66b18fec..509f2a17 100644 --- a/modules/sportspress-event-specs.php +++ b/modules/sportspress-event-specs.php @@ -37,6 +37,7 @@ class SportsPress_Event_Specs { add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) ); add_filter( 'sportspress_config_types', array( $this, 'add_post_type' ) ); + add_filter( 'sportspress_event_details', array( $this, 'event_details' ), 10, 2 ); } /** @@ -194,6 +195,23 @@ class SportsPress_Event_Specs { ); return $meta_boxes; } + + /** + * Add event details. + * + * @return array + */ + public function event_details ( $data, $id ) { + + $event = new SP_Event( $id ); + + $specs_before = $event->specs( true ); + $specs_after = $event->specs( false ); + + $data = array_merge( $specs_before, $data, $specs_after ); + + return $data; + } } endif; diff --git a/templates/event-details.php b/templates/event-details.php index ad898421..7d6dcbab 100644 --- a/templates/event-details.php +++ b/templates/event-details.php @@ -17,11 +17,6 @@ $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; @@ -60,8 +55,6 @@ 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; ?>
From 9ff1b105b2c1c4481d8c4152ef91ad7c8944c884 Mon Sep 17 00:00:00 2001 From: savvasha Date: Sat, 3 Mar 2018 12:21:59 +0200 Subject: [PATCH 5/6] Event List Template Add Event Specs to event-list template. --- modules/sportspress-event-specs.php | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/modules/sportspress-event-specs.php b/modules/sportspress-event-specs.php index 509f2a17..34eab80e 100644 --- a/modules/sportspress-event-specs.php +++ b/modules/sportspress-event-specs.php @@ -32,12 +32,15 @@ class SportsPress_Event_Specs { add_action( 'init', array( $this, 'register_post_type' ) ); add_action( 'sportspress_config_page', array( $this, 'sp_specs_config' ), 9 ); add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) ); + add_action( 'sportspress_event_list_head_row', array( $this, 'event_list_head_row' ), 11 ); + add_action( 'sportspress_event_list_row', array( $this, 'event_list_row' ), 11, 2 ); // Filters add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) ); add_filter( 'sportspress_config_types', array( $this, 'add_post_type' ) ); add_filter( 'sportspress_event_details', array( $this, 'event_details' ), 10, 2 ); + add_filter( 'sportspress_calendar_columns', array( $this, 'calendar_columns' ) ); } /** @@ -212,6 +215,58 @@ class SportsPress_Event_Specs { return $data; } + + /** + * Add calendar columns. + * + * @return array + */ + public function calendar_columns( $columns = array() ) { + $columns['event_specs'] = __( 'Event Specs', 'sportspress' ); + return $columns; + } + + /** + * Event list head row. + */ + public function event_list_head_row( $usecolumns = array() ) { + if ( is_array( $usecolumns ) && in_array( 'event_specs', $usecolumns ) ) { + $spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false ); + + if ( empty( $spec_labels ) ) return; + + foreach ( $spec_labels as $spec_label ) { + ?> + + + + specs( false ); + $spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false ); + + foreach ( $spec_labels as $spec_label ) { + ?> + + + + Date: Sun, 4 Mar 2018 09:49:36 +0200 Subject: [PATCH 6/6] 1st commit for "Integration Event-Specs to Equations" --- includes/sp-core-functions.php | 3 +++ modules/sportspress-event-specs.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index f4ed2378..b1e07140 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -1292,6 +1292,9 @@ if ( !function_exists( 'sp_get_eos_safe_slug' ) ) { if ( !function_exists( 'sp_solve' ) ) { function sp_solve( $equation, $vars, $precision = 0, $default = 0 ) { + // Add a hook to alter $equation + $equation = apply_filters( 'sportspress_equation_alter', $equation, $vars ); + if ( $equation == null ) return $default; diff --git a/modules/sportspress-event-specs.php b/modules/sportspress-event-specs.php index 34eab80e..56164b3d 100644 --- a/modules/sportspress-event-specs.php +++ b/modules/sportspress-event-specs.php @@ -41,6 +41,8 @@ class SportsPress_Event_Specs { add_filter( 'sportspress_config_types', array( $this, 'add_post_type' ) ); add_filter( 'sportspress_event_details', array( $this, 'event_details' ), 10, 2 ); add_filter( 'sportspress_calendar_columns', array( $this, 'calendar_columns' ) ); + add_filter( 'sportspress_equation_options', array( $this, 'add_options' ) ); + add_filter( 'sportspress_equation_alter', array( $this, 'alter_equation' ), 11, 2 ); } /** @@ -267,6 +269,33 @@ class SportsPress_Event_Specs { } } } + + /** + * Add additional options. + * + * @return array + */ + public function add_options( $options ) { + $spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false ); + foreach ( $spec_labels as $key => $value ) { + $options[ 'Event Specs' ]['$spec'.$key] = $value; + } + return $options; + } + + /** + * Alter. + * + * @return array + */ + public function alter_equation( $equation, $vars ) { + //var_dump($equation); + //var_dump($vars); + // Remove space between equation parts + $equation = str_replace( ' ', '', $equation ); + + return $equation; + } } endif;