Add officials importer and improve admin placement
This commit is contained in:
@@ -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;
|
||||
|
||||
5
dummy-data/officials-sample.csv
Normal file
5
dummy-data/officials-sample.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
Name
|
||||
Marco Andrews
|
||||
Daniel Jacobs
|
||||
Erick Herbertson
|
||||
Rupert Abraham
|
||||
|
@@ -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() );
|
||||
|
||||
117
includes/admin/importers/class-sp-official-importer.php
Normal file
117
includes/admin/importers/class-sp-official-importer.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* Official importer - import officials into SportsPress.
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Importers
|
||||
* @version 1.9.10
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( class_exists( 'WP_Importer' ) ) {
|
||||
class SP_Official_Importer extends SP_Importer {
|
||||
|
||||
/**
|
||||
* __construct function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->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 '<div class="updated settings-error below-h2"><p>
|
||||
'.sprintf( __( 'Import complete - imported <strong>%s</strong> officials and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
|
||||
</p></div>';
|
||||
|
||||
$this->import_end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs post-import cleanup of files and the cache
|
||||
*/
|
||||
function import_end() {
|
||||
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_official') . '">' . __( 'View Officials', 'sportspress' ) . '</a>' . '</p>';
|
||||
|
||||
do_action( 'import_end' );
|
||||
}
|
||||
|
||||
/**
|
||||
* header function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function header() {
|
||||
echo '<div class="wrap"><h2>' . __( 'Import Officials', 'sportspress' ) . '</h2>';
|
||||
}
|
||||
|
||||
/**
|
||||
* greet function.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function greet() {
|
||||
echo '<div class="narrow">';
|
||||
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
|
||||
echo '<p>' . sprintf( __( 'Officials need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/officials-sample.csv' ) . '</p>';
|
||||
wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' );
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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' => '<input type="checkbox" />',
|
||||
'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 '<span class="hidden sp-official-teams" data-current-teams="' . implode( ',', $current_teams ) . '" data-past-teams="' . implode( ',', $past_teams ) . '"></span>';
|
||||
$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 '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
|
||||
endif;
|
||||
echo '<br>';
|
||||
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;
|
||||
?>
|
||||
<fieldset class="inline-edit-col-right">
|
||||
<div class="inline-edit-col">
|
||||
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
|
||||
<input type="hidden" name="sp_current_team[]" value="0">
|
||||
<ul class="cat-checklist">
|
||||
<?php foreach ( $teams as $team ) { ?>
|
||||
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_current_team[]"> <?php echo $team->post_title; ?></label></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<span class="title inline-edit-categories-label"><?php _e( 'Past Teams', 'sportspress' ); ?></span>
|
||||
<input type="hidden" name="sp_past_team[]" value="0">
|
||||
<ul class="cat-checklist">
|
||||
<?php foreach ( $teams as $team ) { ?>
|
||||
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_past_team[]"> <?php echo $team->post_title; ?></label></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save quick edit boxes
|
||||
*
|
||||
* @param int $post_id
|
||||
*/
|
||||
public function quick_save( $post_id ) {
|
||||
if ( empty( $_POST ) ) return $post_id;
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id;;
|
||||
|
||||
$_POST += array( "{$this->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;
|
||||
?>
|
||||
<fieldset class="inline-edit-col-right">
|
||||
<div class="inline-edit-col">
|
||||
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
|
||||
<input type="hidden" name="sp_current_team[]" value="0">
|
||||
<ul class="cat-checklist">
|
||||
<?php foreach ( $teams as $team ) { ?>
|
||||
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_current_team[]"> <?php echo $team->post_title; ?></label></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<span class="title inline-edit-categories-label"><?php _e( 'Past Teams', 'sportspress' ); ?></span>
|
||||
<input type="hidden" name="sp_past_team[]" value="0">
|
||||
<ul class="cat-checklist">
|
||||
<?php foreach ( $teams as $team ) { ?>
|
||||
<li><label class="selectit"><input value="<?php echo $team->ID; ?>" type="checkbox" name="sp_past_team[]"> <?php echo $team->post_title; ?></label></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
</fieldset>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save bulk edit boxes
|
||||
*/
|
||||
public function bulk_save() {
|
||||
$_POST += array( "nonce" => '' );
|
||||
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;
|
||||
|
||||
@@ -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 <strong>officials</strong> 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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user