diff --git a/includes/admin/post-types/class-sp-admin-cpt-team-metric.php b/includes/admin/post-types/class-sp-admin-cpt-team-metric.php new file mode 100644 index 00000000..1978a82f --- /dev/null +++ b/includes/admin/post-types/class-sp-admin-cpt-team-metric.php @@ -0,0 +1,74 @@ +type = 'sp_team_metric'; + + // Admin Columns + add_filter( 'manage_edit-sp_team_metric_columns', array( $this, 'edit_columns' ) ); + add_action( 'manage_sp_team_metric_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' => esc_attr__( 'Label', 'sportspress' ), + 'sp_key' => esc_attr__( 'Variable', 'sportspress' ), + 'sp_description' => esc_attr__( 'Description', 'sportspress' ), + ); + return apply_filters( 'sportspress_team_metric_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 esc_html( $post->post_name ); + break; + case 'sp_description': + global $post; + echo '' . wp_kses_post( $post->post_excerpt ) . ''; + break; + endswitch; + } + } + +endif; + +return new SP_Admin_CPT_Team_Metric(); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-metrics-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-metrics-details.php new file mode 100644 index 00000000..f3acc9e9 --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-team-metrics-details.php @@ -0,0 +1,67 @@ +ID, 'sp_visible', true ); + if ( '' === $visible ) { + $visible = 1; + } + ?> +

+

+ + +

+

+ + +

+ + ID, 'sp_team_metrics', true ); + + $args = array( + 'post_type' => 'sp_team_metric', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + + $vars = get_posts( $args ); + + if ( $vars ) : + foreach ( $vars as $var ) : + ?> +

post_title ); ?>

+

+ define_constants(); + + // Actions + add_action( 'init', array( $this, 'register_post_type' ) ); + add_action( 'sportspress_config_page', array( $this, 'sp_team_metrics_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' ) ); + add_filter( 'sportspress_config_types', array( $this, 'add_post_type' ) ); + add_filter( 'sportspress_team_details', array( $this, 'team_details' ), 10, 2 ); + } + + /** + * Define constants. + */ + private function define_constants() { + if ( ! defined( 'SP_TEAM_METRICS_VERSION' ) ) { + define( 'SP_TEAM_METRICS_VERSION', '2.7.30' ); + } + + if ( ! defined( 'SP_TEAM_METRICS_URL' ) ) { + define( 'SP_TEAM_METRICS_URL', plugin_dir_url( __FILE__ ) ); + } + + if ( ! defined( 'SP_TEAM_METRICS_DIR' ) ) { + define( 'SP_TEAM_METRICS_DIR', plugin_dir_path( __FILE__ ) ); + } + } + + /** + * Register event specs post type + */ + public static function register_post_type() { + register_post_type( + 'sp_team_metric', + apply_filters( + 'sportspress_register_post_type_team_metric', + array( + 'labels' => array( + 'name' => esc_attr__( 'Team Metrics', 'sportspress' ), + 'singular_name' => esc_attr__( 'Team Metric', 'sportspress' ), + 'add_new_item' => esc_attr__( 'Add New Team Metric', 'sportspress' ), + 'edit_item' => esc_attr__( 'Edit Team Metric', 'sportspress' ), + 'new_item' => esc_attr__( 'New', 'sportspress' ), + 'view_item' => esc_attr__( 'View', 'sportspress' ), + 'search_items' => esc_attr__( 'Search', 'sportspress' ), + 'not_found' => esc_attr__( 'No results found.', 'sportspress' ), + 'not_found_in_trash' => esc_attr__( '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_team_metric', + 'sp_team_metric', + ) + ); + } + + public static function add_post_type( $post_types = array() ) { + $post_types[] = 'sp_team_metric'; + return $post_types; + } + + /** + * 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-team-metric.php'; + } + + /** + * Display Team Metrics Table at Config Page + * + * @return null + */ + public function sp_team_metrics_config() { + ?> + + + 'sp_team_metric', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + $data = get_posts( $args ); + ?> + + + + + +
+ +

+
+ + + + + + + + + + + + + > + + + + + + + + + + + +
post_title ); ?>post_name ); ?> + ID, 'sp_visible', true ) ) { + echo ''; + } else { + echo ' '; + } + ?> +

post_excerpt ); ?>

+
+ + +
+
+
+ array( + 'title' => esc_attr__( 'Team Metrics', 'sportspress' ), + 'save' => 'SP_Meta_Box_Team_Metrics_Details::save', + 'output' => 'SP_Meta_Box_Team_Metrics_Details::output', + 'context' => 'normal', + 'priority' => 'high', + ), + ); + $meta_boxes['sp_team']['metrics'] = array( + 'title' => esc_attr__( 'Team Metrics', 'sportspress' ), + 'save' => 'SP_Meta_Box_Team_Metrics::save', + 'output' => 'SP_Meta_Box_Team_Metrics::output', + 'context' => 'side', + 'priority' => 'default', + ); + return $meta_boxes; + } + + /** + * Add team details. + * + * @return array + */ + public function team_details( $data, $id ) { + $metrics = $this->team_metrics( $id ); + return array_merge( $data, $metrics ); + } + + /** + * Returns formatted team metrics + * + * @access public + * @return array + */ + public function team_metrics( $id, $neg = null ) { + $metrics = (array) get_post_meta( $id, 'sp_team_metrics', true ); + $metric_labels = (array) sp_get_var_labels( 'sp_team_metric', $neg, false ); + $data = array(); + + foreach ( $metric_labels as $key => $value ) : + $metric = sp_array_value( $metrics, $key, null ); + if ( $metric == null ) { + continue; + } + $data[ $value ] = sp_array_value( $metrics, $key, ' ' ); + endforeach; + return $data; + } + + } + +endif; + +new SportsPress_Team_Metrics(); \ No newline at end of file diff --git a/templates/team-details.php b/templates/team-details.php index f2dd088c..e0785695 100644 --- a/templates/team-details.php +++ b/templates/team-details.php @@ -4,7 +4,7 @@ * * @author ThemeBoy * @package SportsPress/Templates - * @version 2.7.1 + * @version 2.7.30 */ if ( ! defined( 'ABSPATH' ) ) { @@ -51,6 +51,9 @@ endif; endif; +// Give the option to add more details to the team details. +$data = apply_filters( 'sportspress_team_details', $data, $id ); + $output = '
' . '
';