diff --git a/assets/css/dashboard.css b/assets/css/dashboard.css
index e5134b9b..d992ca33 100644
--- a/assets/css/dashboard.css
+++ b/assets/css/dashboard.css
@@ -13,7 +13,9 @@
#dashboard_right_now .sp_player-count a:before,
#dashboard_right_now .sp_player-count span:before,
#dashboard_right_now .sp_staff-count a:before,
-#dashboard_right_now .sp_staff-count span:before {
+#dashboard_right_now .sp_staff-count span:before,
+#dashboard_right_now .sp_official-count a:before,
+#dashboard_right_now .sp_official-count span:before {
font-family: 'sportspress';
}
@@ -37,6 +39,11 @@
content: "\f338";
}
+#dashboard_right_now .sp_official-count a:before,
+#dashboard_right_now .sp_official-count span:before {
+ content: "\f227";
+}
+
#sportspress_dashboard_status .sp_status_list {
overflow: hidden;
margin: 0;
diff --git a/dummy-data/officials-sample.csv b/dummy-data/officials-sample.csv
new file mode 100644
index 00000000..2815ae7b
--- /dev/null
+++ b/dummy-data/officials-sample.csv
@@ -0,0 +1,5 @@
+Name
+Marco Andrews
+Daniel Jacobs
+Erick Herbertson
+Rupert Abraham
\ No newline at end of file
diff --git a/includes/admin/class-sp-admin-menus.php b/includes/admin/class-sp-admin-menus.php
index b5fb4324..142e5f48 100755
--- a/includes/admin/class-sp-admin-menus.php
+++ b/includes/admin/class-sp-admin-menus.php
@@ -130,7 +130,6 @@ class SP_Admin_Menus {
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order );
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order );
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order );
- $sportspress_official = array_search( 'edit.php?post_type=sp_official', $menu_order );
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ):
@@ -142,13 +141,11 @@ class SP_Admin_Menus {
$sportspress_menu_order[] = 'edit.php?post_type=sp_team';
$sportspress_menu_order[] = 'edit.php?post_type=sp_player';
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff';
- $sportspress_menu_order[] = 'edit.php?post_type=sp_official';
unset( $menu_order[ $sportspress_separator ] );
unset( $menu_order[ $sportspress_event ] );
unset( $menu_order[ $sportspress_team ] );
unset( $menu_order[ $sportspress_player ] );
unset( $menu_order[ $sportspress_staff ] );
- unset( $menu_order[ $sportspress_official ] );
// Apply to added menu items
$menu_items = apply_filters( 'sportspress_menu_items', array() );
diff --git a/includes/admin/importers/class-sp-official-importer.php b/includes/admin/importers/class-sp-official-importer.php
new file mode 100644
index 00000000..fefa7260
--- /dev/null
+++ b/includes/admin/importers/class-sp-official-importer.php
@@ -0,0 +1,117 @@
+import_page = 'sp_official_csv';
+ $this->import_label = __( 'Import Officials', 'sportspress' );
+ $this->columns = array(
+ 'post_title' => __( 'Name', 'sportspress' ),
+ );
+ parent::__construct();
+ }
+
+ /**
+ * import function.
+ *
+ * @access public
+ * @param array $array
+ * @param array $columns
+ * @return void
+ */
+ function import( $array = array(), $columns = array( 'post_title' ) ) {
+ $this->imported = $this->skipped = 0;
+
+ if ( ! is_array( $array ) || ! sizeof( $array ) ):
+ $this->footer();
+ die();
+ endif;
+
+ $rows = array_chunk( $array, sizeof( $columns ) );
+
+ foreach ( $rows as $row ):
+
+ $row = array_filter( $row );
+
+ if ( empty( $row ) ) continue;
+
+ $meta = array();
+
+ foreach ( $columns as $index => $key ):
+ $meta[ $key ] = sp_array_value( $row, $index );
+ endforeach;
+
+ $name = sp_array_value( $meta, 'post_title' );
+
+ if ( ! $name ):
+ $this->skipped++;
+ continue;
+ endif;
+
+ $args = array( 'post_type' => 'sp_official', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
+
+ $id = wp_insert_post( $args );
+
+ $this->imported++;
+
+ endforeach;
+
+ // Show Result
+ echo '
' . __( 'Import Officials', 'sportspress' ) . ' ';
+ }
+
+ /**
+ * greet function.
+ *
+ * @access public
+ * @return void
+ */
+ function greet() {
+ echo '
';
+ echo '
' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'
';
+ echo '
' . sprintf( __( 'Officials need to be defined with columns in a specific order. Click here to download a sample .', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/officials-sample.csv' ) . '
';
+ wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' );
+ echo '
';
+ }
+ }
+}
diff --git a/includes/admin/post-types/class-sp-admin-cpt-official.php b/includes/admin/post-types/class-sp-admin-cpt-official.php
index b0e6f0fe..5f0c6a9c 100644
--- a/includes/admin/post-types/class-sp-admin-cpt-official.php
+++ b/includes/admin/post-types/class-sp-admin-cpt-official.php
@@ -29,22 +29,6 @@ class SP_Admin_CPT_Official extends SP_Admin_CPT {
// 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();
}
@@ -61,237 +45,6 @@ class SP_Admin_CPT_Official extends SP_Admin_CPT {
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;
diff --git a/modules/sportspress-officials.php b/modules/sportspress-officials.php
index c21efceb..426d59bc 100644
--- a/modules/sportspress-officials.php
+++ b/modules/sportspress-officials.php
@@ -49,9 +49,13 @@ class SportsPress_Officials {
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 );
@@ -460,6 +464,47 @@ class SportsPress_Officials {
) );
}
+ /**
+ * Add menu item
+ */
+ public function add_menu_item( $items ) {
+ $items[] = 'edit.php?post_type=sp_official';
+ return $items;
+ }
+
+ /**
+ * Add glance item
+ */
+ public function add_glance_item( $items ) {
+ $items[] = 'sp_official';
+ return $items;
+ }
+
+ /**
+ * Register importer
+ */
+ public function register_importer( $importers = array() ) {
+ $importers['sp_official_csv'] = array(
+ 'name' => __( 'SportsPress Officials (CSV)', 'sportspress' ),
+ 'description' => __( 'Import
officials from a csv file.', 'sportspress'),
+ 'callback' => array( $this, 'officials_importer' ),
+ );
+ return $importers;
+ }
+
+ /**
+ * Officials importer
+ */
+ public function officials_importer() {
+ SP_Admin_Importers::includes();
+
+ require SP()->plugin_path() . '/includes/admin/importers/class-sp-official-importer.php';
+
+ // Dispatch
+ $importer = new SP_Official_Importer();
+ $importer->dispatch();
+ }
+
/**
* Add screen ids.
*