define_constants(); // Actions add_action( 'sportspress_after_register_taxonomy', array( $this, 'register_taxonomy' ) ); add_action( 'sportspress_after_register_post_type', array( $this, 'register_post_type' ) ); add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) ); add_action( 'sportspress_create_rest_routes', array( $this, 'create_rest_routes' ) ); add_action( 'sportspress_register_rest_fields', array( $this, 'register_rest_fields' ) ); add_action( 'sportspress_event_list_head_row', array( $this, 'event_list_head_row' ) ); add_action( 'sportspress_event_list_row', array( $this, 'event_list_row' ), 10, 2 ); add_action( 'sportspress_calendar_data_meta_box_table_head_row', array( $this, 'calendar_meta_head_row' ) ); add_action( 'sportspress_calendar_data_meta_box_table_row', array( $this, 'calendar_meta_row' ), 10, 2 ); add_action( 'sp_duty_edit_form_fields', array( $this, 'edit_taxonomy_fields' ), 10, 1 ); add_action( 'edited_sp_duty', array( $this, 'save_taxonomy_fields' ), 10, 1 ); add_action( 'admin_menu', array( $this, 'duties_menu' ) ); add_action( 'parent_file', array( $this, 'parent_file' ) ); // Filters add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_filter( 'sportspress_calendar_columns', array( $this, 'calendar_columns' ) ); add_filter( 'sportspress_after_event_template', array( $this, 'add_event_template' ), 30 ); add_filter( 'sportspress_event_options', array( $this, 'add_event_options' ) ); add_filter( 'sportspress_text', array( $this, 'add_text_options' ) ); add_filter( 'sportspress_menu_items', array( $this, 'add_menu_item' ) ); add_filter( 'sportspress_glance_items', array( $this, 'add_glance_item' ) ); add_filter( 'sportspress_importers', array( $this, 'register_importer' ) ); add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) ); add_filter( 'sportspress_post_types', array( $this, 'add_post_type' ) ); add_filter( 'sportspress_primary_post_types', array( $this, 'add_post_type' ) ); add_filter( 'sportspress_importable_post_types', array( $this, 'add_post_type' ) ); add_filter( 'sportspress_post_type_hierarchy', array( $this, 'add_to_hierarchy' ) ); add_filter( 'manage_edit-sp_duty_columns', array( $this, 'taxonomy_columns' ) ); add_filter( 'manage_sp_duty_custom_column', array( $this, 'taxonomy_column_value' ), 10, 3 ); } /** * Define constants. */ private function define_constants() { if ( ! defined( 'SP_OFFICIALS_VERSION' ) ) { define( 'SP_OFFICIALS_VERSION', '2.7.9' ); } if ( ! defined( 'SP_OFFICIALS_URL' ) ) { define( 'SP_OFFICIALS_URL', plugin_dir_url( __FILE__ ) ); } if ( ! defined( 'SP_OFFICIALS_DIR' ) ) { define( 'SP_OFFICIALS_DIR', plugin_dir_path( __FILE__ ) ); } } /** * Register officials taxonomy */ public static function register_taxonomy() { $labels = array( 'name' => esc_attr__( 'Duties', 'sportspress' ), 'singular_name' => esc_attr__( 'Duty', 'sportspress' ), 'all_items' => esc_attr__( 'All', 'sportspress' ), 'edit_item' => esc_attr__( 'Edit Duty', 'sportspress' ), 'view_item' => esc_attr__( 'View', 'sportspress' ), 'update_item' => esc_attr__( 'Update', 'sportspress' ), 'add_new_item' => esc_attr__( 'Add New', 'sportspress' ), 'new_item_name' => esc_attr__( 'Name', 'sportspress' ), 'parent_item' => esc_attr__( 'Parent', 'sportspress' ), 'parent_item_colon' => esc_attr__( 'Parent:', 'sportspress' ), 'search_items' => esc_attr__( 'Search', 'sportspress' ), 'not_found' => esc_attr__( 'No results found.', 'sportspress' ), ); $args = apply_filters( 'sportspress_register_taxonomy_duty', array( 'label' => esc_attr__( 'Duties', 'sportspress' ), 'labels' => $labels, 'public' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'show_tagcloud' => false, 'hierarchical' => true, 'rewrite' => array( 'slug' => get_option( 'sportspress_duty_slug', 'duty' ) ), 'capabilities' => array( 'manage_terms' => 'manage_sp_event_terms', 'edit_terms' => 'edit_sp_event_terms', 'delete_terms' => 'delete_sp_event_terms', 'assign_terms' => 'assign_sp_event_terms', ), 'show_in_rest' => true, 'rest_controller_class' => 'SP_REST_Terms_Controller', 'rest_base' => 'duties', ) ); $object_types = apply_filters( 'sportspress_duty_object_types', array() ); register_taxonomy( 'sp_duty', $object_types, $args ); foreach ( $object_types as $object_type ) : register_taxonomy_for_object_type( 'sp_duty', $object_type ); endforeach; } /** * Register officials post type */ public static function register_post_type() { register_post_type( 'sp_official', apply_filters( 'sportspress_register_post_type_official', array( 'labels' => array( 'name' => esc_attr__( 'Officials', 'sportspress' ), 'singular_name' => esc_attr__( 'Official', 'sportspress' ), 'add_new_item' => esc_attr__( 'Add New Official', 'sportspress' ), 'edit_item' => esc_attr__( 'Edit Official', 'sportspress' ), 'new_item' => esc_attr__( 'New', 'sportspress' ), 'view_item' => esc_attr__( 'View Official', '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' ), 'featured_image' => esc_attr__( 'Photo', 'sportspress' ), 'set_featured_image' => esc_attr__( 'Select Photo', 'sportspress' ), 'remove_featured_image' => esc_attr__( 'Remove Photo', 'sportspress' ), 'use_featured_image' => esc_attr__( 'Select Photo', 'sportspress' ), ), 'public' => true, 'show_ui' => true, 'capability_type' => 'sp_event', 'map_meta_cap' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'hierarchical' => false, 'rewrite' => array( 'slug' => get_option( 'sportspress_official_slug', 'official' ) ), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'page-attributes' ), 'has_archive' => false, 'show_in_nav_menus' => true, 'menu_icon' => 'dashicons-flag', 'show_in_rest' => true, 'rest_controller_class' => 'SP_REST_Posts_Controller', 'rest_base' => 'officials', ) ) ); } /** * 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-official.php'; } /** * Create REST API routes. */ public function create_rest_routes() { $controller = new SP_REST_Posts_Controller( 'sp_official' ); $controller->register_routes(); } /** * Register REST API fields. */ public function register_rest_fields() { register_rest_field( 'sp_official', 'data', array( 'get_callback' => 'SP_REST_API::get_post_data', 'update_callback' => 'SP_REST_API::update_post_meta_arrays', 'schema' => array( 'description' => esc_attr__( 'Official', 'sportspress' ), 'type' => 'array', 'context' => array( 'view', 'edit' ), 'arg_options' => array( 'sanitize_callback' => 'rest_sanitize_request_arg', ), ), ) ); } /** * Event list head row. */ public function event_list_head_row( $usecolumns = array() ) { if ( is_array( $usecolumns ) && in_array( 'officials', $usecolumns ) ) { $duties = get_terms( array( 'taxonomy' => 'sp_duty', 'hide_empty' => false, 'orderby' => 'meta_value_num', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'sp_order', 'compare' => 'NOT EXISTS', ), array( 'key' => 'sp_order', 'compare' => 'EXISTS', ), ), ) ); if ( empty( $duties ) ) { return; } foreach ( $duties as $duty ) { ?>