diff --git a/assets/css/menu.css b/assets/css/menu.css index 67052db6..de2e0e63 100644 --- a/assets/css/menu.css +++ b/assets/css/menu.css @@ -194,6 +194,7 @@ #adminmenu #menu-posts-sp_team .menu-icon-sp_team div.wp-menu-image:before, #adminmenu #menu-posts-sp_player .menu-icon-sp_player div.wp-menu-image:before, #adminmenu #menu-posts-sp_staff .menu-icon-sp_staff div.wp-menu-image:before, +#adminmenu #menu-posts-sp_official .menu-icon-sp_official div.wp-menu-image:before, #sp_formatdiv #post-formats-select .post-format-icon:before, #sp_modediv #post-formats-select .post-format-icon:before { font-family: sportspress, dashicons; diff --git a/includes/admin/class-sp-admin-menus.php b/includes/admin/class-sp-admin-menus.php index d9fbb74a..1cbab568 100755 --- a/includes/admin/class-sp-admin-menus.php +++ b/includes/admin/class-sp-admin-menus.php @@ -26,7 +26,6 @@ class SP_Admin_Menus { add_action( 'admin_menu', array( $this, 'config_menu' ), 7 ); add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 ); add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 ); - add_action( 'admin_menu', array( $this, 'officials_menu' ), 22 ); add_action( 'admin_head', array( $this, 'menu_highlight' ) ); add_action( 'admin_head', array( $this, 'menu_rename' ) ); @@ -69,13 +68,6 @@ class SP_Admin_Menus { add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season'); } - /** - * Add menu item - */ - public function officials_menu() { - add_submenu_page( 'sportspress', __( 'Officials', 'sportspress' ), __( 'Officials', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_officials'); - } - /** * Highlights the correct top level admin menu item for post type add screens. * @@ -228,11 +220,6 @@ class SP_Admin_Menus { $submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) ); endif; - if ( isset( $submenu['edit.php?post_type=sp_official'] ) ): - $submenu['edit.php?post_type=sp_official'] = array_filter( $submenu['edit.php?post_type=sp_official'], array( $this, 'remove_leagues' ) ); - $submenu['edit.php?post_type=sp_official'] = array_filter( $submenu['edit.php?post_type=sp_official'], array( $this, 'remove_seasons' ) ); - endif; - $user_roles = $current_user->roles; $user_role = array_shift($user_roles); diff --git a/includes/admin/post-types/class-sp-admin-cpt-official.php b/includes/admin/post-types/class-sp-admin-cpt-official.php new file mode 100644 index 00000000..b0e6f0fe --- /dev/null +++ b/includes/admin/post-types/class-sp-admin-cpt-official.php @@ -0,0 +1,299 @@ +type = 'sp_official'; + + // Post title fields + add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 ); + + // Admin columns + add_filter( 'manage_edit-sp_official_columns', array( $this, 'edit_columns' ) ); + add_action( 'manage_sp_official_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); + + // Filtering + add_action( 'restrict_manage_posts', array( $this, 'filters' ) ); + add_filter( 'parse_query', array( $this, 'filters_query' ) ); + + // Quick edit + add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_teams' ), 10, 2 ); + add_action( 'save_post', array( $this, 'quick_save' ) ); + + // Bulk edit + add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit_teams' ), 10, 2 ); + add_action( 'wp_ajax_save_bulk_edit_sp_official', array( $this, 'bulk_save' ) ); + + // Call SP_Admin_CPT constructor + parent::__construct(); + } + + /** + * Change title boxes in admin. + * @param string $text + * @param object $post + * @return string + */ + public function enter_title_here( $text, $post ) { + if ( $post->post_type == 'sp_official' ) + return __( 'Name', 'sportspress' ); + + return $text; + } + + /** + * Change the columns shown in admin. + */ + public function edit_columns( $existing_columns ) { + unset( $existing_columns['author'], $existing_columns['date'] ); + $columns = array_merge( array( + 'cb' => '', + 'title' => null, + 'sp_duty' => __( 'Duties', 'sportspress' ), + 'sp_team' => __( 'Teams', 'sportspress' ), + ), $existing_columns, array( + 'title' => __( 'Name', 'sportspress' ) + ) ); + return apply_filters( 'sportspress_official_admin_columns', $columns ); + } + + /** + * Define our custom columns shown in admin. + * @param string $column + */ + public function custom_columns( $column, $post_id ) { + switch ( $column ): + case 'sp_duty': + echo get_the_terms( $post_id, 'sp_duty' ) ? the_terms( $post_id, 'sp_duty' ) : '—'; + break; + case 'sp_team': + $current_teams = get_post_meta( $post_id, 'sp_current_team', false ); + $past_teams = get_post_meta( $post_id, 'sp_past_team', false ); + $current_teams = array_filter( $current_teams ); + $past_teams = array_filter( $past_teams ); + echo ''; + $teams = (array)get_post_meta( $post_id, 'sp_team', false ); + $teams = array_filter( $teams ); + $teams = array_unique( $teams ); + if ( empty( $teams ) ): + echo '—'; + else: + foreach( $teams as $team_id ): + if ( ! $team_id ) continue; + $team = get_post( $team_id ); + if ( $team ): + echo $team->post_title; + if ( in_array( $team_id, $current_teams ) ): + echo ''; + endif; + echo '
'; + endif; + endforeach; + endif; + break; + endswitch; + } + + /** + * Show a category filter box + */ + public function filters() { + global $typenow, $wp_query; + + if ( $typenow != 'sp_official' ) + return; + + if ( taxonomy_exists( 'sp_duty' ) ): + $selected = isset( $_REQUEST['sp_duty'] ) ? $_REQUEST['sp_duty'] : null; + $args = array( + 'show_option_all' => __( 'Show all duties', 'sportspress' ), + 'taxonomy' => 'sp_duty', + 'name' => 'sp_duty', + 'selected' => $selected + ); + sp_dropdown_taxonomies( $args ); + endif; + + $selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null; + $args = array( + 'post_type' => 'sp_team', + 'name' => 'team', + 'show_option_none' => __( 'Show all teams', 'sportspress' ), + 'selected' => $selected, + 'values' => 'ID', + ); + wp_dropdown_pages( $args ); + } + + /** + * Filter in admin based on options + * + * @param mixed $query + */ + public function filters_query( $query ) { + global $typenow, $wp_query; + + if ( $typenow == 'sp_official' ) { + + if ( ! empty( $_GET['team'] ) ) { + $query->query_vars['meta_value'] = $_GET['team']; + $query->query_vars['meta_key'] = 'sp_team'; + } + } + } + + /** + * Quick edit teams + * + * @param string $column_name + * @param string $post_type + */ + public function quick_edit_teams( $column_name, $post_type ) { + if ( $this->type !== $post_type ) return; + if ( 'sp_team' !== $column_name ) return; + + $teams = get_posts( array( + 'post_type' => 'sp_team', + 'numberposts' => -1, + 'post_status' => 'publish', + ) ); + + if ( ! $teams ) return; + ?> +
+
+ + + + + + +
+
+ type}_edit_nonce" => '' ); + if ( ! wp_verify_nonce( $_POST["{$this->type}_edit_nonce"], plugin_basename( __FILE__ ) ) ) return $post_id;; + + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; + if ( isset( $post->post_type ) && $post->post_type == 'revision' ) return $post_id; + + sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) ); + sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) ); + sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) ); + } + + /** + * Bulk edit teams + * + * @param string $column_name + * @param string $post_type + */ + public function bulk_edit_teams( $column_name, $post_type ) { + if ( $this->type !== $post_type ) return; + if ( 'sp_team' !== $column_name ) return; + + static $print_nonce = true; + if ( $print_nonce ) { + $print_nonce = false; + wp_nonce_field( plugin_basename( __FILE__ ), 'sp_official_edit_nonce' ); + } + + $teams = get_posts( array( + 'post_type' => 'sp_team', + 'numberposts' => -1, + 'post_status' => 'publish', + ) ); + + if ( ! $teams ) return; + ?> +
+
+ + + + + + +
+
+ '' ); + if ( ! wp_verify_nonce( $_POST["nonce"], plugin_basename( __FILE__ ) ) ) return; + + $post_ids = ( ! empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : array(); + + $current_teams = sp_array_value( $_POST, 'current_teams', array() ); + $past_teams = sp_array_value( $_POST, 'past_teams', array() ); + $teams = array_merge( $current_teams, $past_teams ); + + if ( ! empty( $post_ids ) && is_array( $post_ids ) ) { + foreach ( $post_ids as $post_id ) { + if ( ! current_user_can( 'edit_post', $post_id ) ) continue; + + sp_add_post_meta_recursive( $post_id, 'sp_current_team', $current_teams ); + sp_add_post_meta_recursive( $post_id, 'sp_past_team', $past_teams ); + sp_add_post_meta_recursive( $post_id, 'sp_team', $teams ); + } + } + + die(); + } +} + +endif; + +return new SP_Admin_CPT_Official(); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php index 956ac305..4b8858ef 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php @@ -2,10 +2,11 @@ /** * Event Officials * - * @author Rob Tucker - * @category Admin + * @author Rob Tucker + * @author ThemeBoy + * @category Admin * @package SportsPress/Admin/Meta_Boxes - * @version 2.3 + * @version 2.5 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -19,43 +20,37 @@ class SP_Meta_Box_Event_Officials { * Output the metabox */ public static function output( $post ) { - wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' ); - $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); - $redirect = get_post_meta( $post->ID, 'sp_redirect', true ); - $url = get_post_meta( $post->ID, 'sp_url', true ); - if ( taxonomy_exists( 'sp_officials' ) ): - $officials = get_the_terms( $post->ID, 'sp_officials' ); - $official_ids = array(); - if ( $officials ): - foreach ( $officials as $official ): - $official_ids[] = $official->term_id; - endforeach; - endif; - endif; - ?> - -

-

'sp_officials', - 'name' => 'tax_input[sp_officials][]', - 'selected' => $official_ids, - 'values' => 'term_id', - 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ), - 'class' => 'widefat', - 'property' => 'multiple', - 'chosen' => true, - ); - sp_dropdown_taxonomies( $args ); - ?>

- - 'sp_duty', + 'hide_empty' => false, + ) ); + + $officials = (array) get_post_meta( $post->ID, 'sp_officials', true ); + + foreach ( $duties as $duty ) { + ?> +

name; ?>

+

'sp_official', + 'name' => 'sp_officials[' . $duty->term_id . '][]', + 'selected' => sp_array_value( $officials, $duty->term_id, array() ), + 'values' => 'ID', + 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ), + 'class' => 'widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sp_dropdown_pages( $args ); + ?>

+ countries->continents; + + $nationalities = get_post_meta( $post->ID, 'sp_nationality', false ); + foreach ( $nationalities as $index => $nationality ): + if ( 2 == strlen( $nationality ) ): + $legacy = SP()->countries->legacy; + $nationality = strtolower( $nationality ); + $nationality = sp_array_value( $legacy, $nationality, null ); + $nationalities[ $index ] = $nationality; + endif; + endforeach; + + if ( taxonomy_exists( 'sp_duty' ) ): + $positions = get_the_terms( $post->ID, 'sp_duty' ); + $position_ids = array(); + if ( $positions ): + foreach ( $positions as $position ): + $position_ids[] = $position->term_id; + endforeach; + endif; + endif; + + $teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) ); + $past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) ); + $current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) ); + ?> + +

+

+ + +

+

'sp_duty', + 'name' => 'tax_input[sp_duty][]', + 'selected' => $position_ids, + 'values' => 'term_id', + 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Duties', 'sportspress' ) ), + 'class' => 'widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sp_dropdown_taxonomies( $args ); + ?>

+ + +

+

'sp_team', + 'name' => 'sp_current_team[]', + 'selected' => $current_teams, + 'values' => 'ID', + 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), + 'class' => 'sp-current-teams widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sp_dropdown_pages( $args ); + ?>

+ +

+

'sp_team', + 'name' => 'sp_past_team[]', + 'selected' => $past_teams, + 'values' => 'ID', + 'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ), + 'class' => 'sp-past-teams widefat', + 'property' => 'multiple', + 'chosen' => true, + ); + sp_dropdown_pages( $args ); + ?>

+ - > + >