From 9db32d4d3d6e74e47dc947021686cd7eed72be21 Mon Sep 17 00:00:00 2001 From: savvasha Date: Tue, 27 Feb 2018 21:28:37 +0200 Subject: [PATCH] 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();