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; + } + ?> +
+
+ + +
++ + +
+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() { + ?> +