Tidy up player edit screen and add custom menu icons

This commit is contained in:
Brian Miyaji
2014-02-18 19:33:06 +11:00
parent f07f60d593
commit 1b30d3a4ce
19 changed files with 293 additions and 209 deletions

View File

@@ -1,38 +1,4 @@
<?php
function sportspress_team_importer() {
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
require $class_wp_importer;
}
// includes
require dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/importers/team-importer.php';
// Dispatch
$importer = new SP_Team_Importer();
$importer->dispatch();
}
function sportspress_player_importer() {
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
require $class_wp_importer;
}
// includes
require dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/importers/player-importer.php';
// Dispatch
$importer = new SP_Player_Importer();
$importer->dispatch();
}
function sportspress_admin_init() {
$post_types = array(
'sp_event',
@@ -69,9 +35,5 @@ function sportspress_admin_init() {
$administrator->add_cap( $cap . '_' . $post_type . 's' );
endforeach;
endforeach;
// Importers
register_importer( 'sportspress_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'), 'sportspress_team_importer' );
register_importer( 'sportspress_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import <strong>players</strong> from a csv file.', 'sportspress'), 'sportspress_player_importer' );
}
add_action( 'admin_init', 'sportspress_admin_init' );

View File

@@ -3,15 +3,15 @@ function sportspress_admin_menu( $position ) {
global $menu, $submenu;
// Find where our placeholder is in the menu
// Find where our separator is in the menu
foreach( $menu as $key => $data ):
if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' )
$seperator_position = $key;
$separator_position = $key;
endforeach;
// Swap our placeholder post type with a menu separator
if ( $seperator_position ):
$menu[ $seperator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
// Swap our separator post type with a menu separator
if ( isset( $separator_position ) ):
$menu[ $separator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
endif;
// Remove "Venues" and "Positions" links from Media submenu
@@ -41,6 +41,12 @@ function sportspress_admin_menu( $position ) {
}
add_action( 'admin_menu', 'sportspress_admin_menu' );
if ( ! function_exists( 'sportspress_admin_menu_remove_add_new' ) ) {
function sportspress_admin_menu_remove_add_new( $arr = array() ) {
return $arr[0] != __( 'Add New', 'sportspress' );
}
}
if ( ! function_exists( 'sportspress_admin_menu_remove_leagues' ) ) {
function sportspress_admin_menu_remove_leagues( $arr = array() ) {
return $arr[0] != __( 'Leagues', 'sportspress' );

View File

@@ -1,10 +1,8 @@
<?php
function sportspress_admin_notices_styles() {
$screen = get_current_screen();
if ( $screen->id != 'settings_page_sportspress' ):
if ( isset( $_REQUEST['sportspress_installed'] ) ):
update_option( 'sportspress_installed', $_REQUEST['sportspress_installed'] );
endif;
@@ -12,13 +10,11 @@ function sportspress_admin_notices_styles() {
if ( ! get_option( 'sportspress_installed' ) ):
add_action( 'admin_notices', 'sportspress_admin_install_notices' );
endif;
endif;
$template = get_option( 'template' );
if ( ! current_theme_supports( 'sportspress' ) && ! in_array( $template, array( 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ):
if ( ! empty( $_GET['hide_sportspress_theme_support_check'] ) ):
update_option( 'sportspress_theme_support_check', $template );
return;
@@ -27,9 +23,7 @@ function sportspress_admin_notices_styles() {
if ( get_option( 'sportspress_theme_support_check' ) !== $template ):
add_action( 'admin_notices', 'sportspress_theme_check_notice' );
endif;
endif;
}
add_action( 'admin_print_styles', 'sportspress_admin_notices_styles' );
@@ -50,5 +44,5 @@ function sportspress_admin_install_notices() {
* @return void
*/
function sportspress_theme_check_notice() {
include( dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/includes/notice-theme-support.php' );
// include( dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/includes/notice-theme-support.php' );
}

View File

@@ -95,15 +95,18 @@ function sportspress_save_post( $post_id ) {
// Update seasons teams to show
update_post_meta( $post_id, 'sp_leagues', sportspress_array_value( $_POST, 'sp_leagues', array() ) );
// Update current team
update_post_meta( $post_id, 'sp_current_team', sportspress_array_value( $_POST, 'sp_current_team', null ) );
// Update past team array
sportspress_update_post_meta_recursive( $post_id, 'sp_past_team', sportspress_array_value( $_POST, 'sp_past_team', array() ) );
// Update team array
sportspress_update_post_meta_recursive( $post_id, 'sp_team', sportspress_array_value( $_POST, 'sp_team', array() ) );
sportspress_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sportspress_array_value( $_POST, 'sp_current_team', null ) ), sportspress_array_value( $_POST, 'sp_past_team', array() ) ) );
// Update player number
update_post_meta( $post_id, 'sp_number', sportspress_array_value( $_POST, 'sp_number', '' ) );
// Update current team
update_post_meta( $post_id, 'sp_current_team', sportspress_array_value( $_POST, 'sp_current_team', '' ) );
// Update nationality
update_post_meta( $post_id, 'sp_nationality', sportspress_array_value( $_POST, 'sp_nationality', '' ) );

View File

@@ -1,12 +1,10 @@
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>
<?php if ( false ): ?>
<div id="message" class="error sportspress-message">
<h4><?php _e( '<strong>Your theme does not declare SportsPress support</strong> &#8211; if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?></h4>
<p><?php _e( '<strong>Your theme does not declare SportsPress support</strong> &#8211; if you encounter layout issues please read our integration guide or choose a SportsPress theme :)', 'sportspress' ); ?></p>
<p class="submit">
<a class="button-primary" href="http://docs.themeboy.com/sportspress/compatibility/"><?php _e( 'Theme Integration Guide', 'sportspress' ); ?></a>
<a class="button-secondary" href="<?php echo add_query_arg( 'hide_sportspress_theme_support_check', 'true' ); ?>"><?php _e( 'Hide this notice', 'sportspress' ); ?></a>
</p>
</div>
<?php endif;
</div>

View File

@@ -96,7 +96,7 @@ function sportspress_player_details_meta( $post ) {
endif;
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
$the_teams = array_filter( get_post_meta( $post->ID, 'sp_team', false ) );
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$current_team = get_post_meta( $post->ID, 'sp_current_team', true );
?>
<p><strong><?php _e( 'Number', 'sportspress' ); ?></strong></p>
@@ -114,6 +114,51 @@ function sportspress_player_details_meta( $post ) {
<?php endforeach; ?>
</select></p>
<p><strong><?php _e( 'Positions', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_position',
'name' => 'tax_input[sp_position][]',
'selected' => $position_ids,
'values' => 'term_id',
'placeholder' => __( 'Select Positions', 'sportspress' ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Current Team', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team',
'show_option_blank' => true,
'selected' => $current_team,
'values' => 'ID',
'placeholder' => __( 'Select Team', 'sportspress' ),
'class' => 'sp-current-team widefat',
'chosen' => true,
);
sportspress_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => __( 'Select Teams', 'sportspress' ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Leagues', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
@@ -143,51 +188,6 @@ function sportspress_player_details_meta( $post ) {
);
sportspress_dropdown_taxonomies( $args );
?></p>
<p><strong><?php _e( 'Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team[]',
'selected' => $the_teams,
'values' => 'ID',
'placeholder' => __( 'Select Teams', 'sportspress' ),
'class' => 'sp-team widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Current Team', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team',
'show_option_blank' => true,
'selected' => $current_team,
'values' => 'ID',
'placeholder' => __( 'Select Team', 'sportspress' ),
'class' => 'sp-current-team widefat',
'chosen' => true,
);
sportspress_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Positions', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_position',
'name' => 'tax_input[sp_position][]',
'selected' => $position_ids,
'values' => 'term_id',
'placeholder' => __( 'Select Positions', 'sportspress' ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sportspress_dropdown_taxonomies( $args );
?></p>
<?php
}

View File

@@ -7,10 +7,10 @@ function sportspress_settings() {
<div class="wrap">
<h2 class="nav-tab-wrapper">
<a href="?page=sportspress" class="nav-tab<?php echo $active_tab == 'general' ? ' nav-tab-active' : ''; ?>"><?php _e( 'SportsPress', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=events" class="nav-tab<?php echo $active_tab == 'events' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Events', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=tables" class="nav-tab<?php echo $active_tab == 'tables' ? ' nav-tab-active' : ''; ?>"><?php _e( 'League Tables', 'sportspress' ); ?></a>
<a href="?page=sportspress&tab=players" class="nav-tab<?php echo $active_tab == 'players' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Players', 'sportspress' ); ?></a>
<a href="<?php echo remove_query_arg( 'tab' ); ?>" class="nav-tab<?php echo $active_tab == 'general' ? ' nav-tab-active' : ''; ?>"><?php _e( 'General', 'sportspress' ); ?></a>
<a href="<?php echo add_query_arg( 'tab', 'events' ); ?>" class="nav-tab<?php echo $active_tab == 'events' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Events', 'sportspress' ); ?></a>
<a href="<?php echo add_query_arg( 'tab', 'tables' ); ?>" class="nav-tab<?php echo $active_tab == 'tables' ? ' nav-tab-active' : ''; ?>"><?php _e( 'League Tables', 'sportspress' ); ?></a>
<a href="<?php echo add_query_arg( 'tab', 'players' ); ?>" class="nav-tab<?php echo $active_tab == 'players' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Players', 'sportspress' ); ?></a>
</h2>
<form method="post" action="options.php">
@@ -43,13 +43,13 @@ function sportspress_sport_callback() {
$custom_sport_name = sportspress_array_value( $options, 'custom_sport_name', null );
?>
<select id="sportspress_sport" name="sportspress[sport]">
<option value><?php _e( '-- Select --', 'sportspress' ); ?></option>
<option value><?php _e( '&mdash; Select &mdash;', 'sportspress' ); ?></option>
<?php foreach( $sportspress_sports as $slug => $sport ): ?>
<option value="<?php echo $slug; ?>" <?php selected( $selected, $slug ); ?>><?php echo $sport['name']; ?></option>
<?php endforeach; ?>
<option value="custom" <?php selected( $selected, 'custom' ); ?>><?php _e( 'Custom', 'sportspress' ); ?></option>
</select>
<input id="sportspress_custom_sport_name" name="sportspress[custom_sport_name]" type="text" placeholder="<?php _e( 'Sport', 'sportspress' ); ?>" value="<?php echo $custom_sport_name; ?>"<?php if ( $selected != 'custom' ): ?> class="hidden"<?php endif; ?>></p>
<input id="sportspress_custom_sport_name" name="sportspress[custom_sport_name]" type="text" placeholder="<?php _e( 'Sport', 'sportspress' ); ?>" value="<?php echo $custom_sport_name; ?>"<?php if ( $selected != 'custom' ): ?> class="hidden"<?php endif; ?>>
<?php
}
@@ -87,7 +87,7 @@ function sportspress_settings_init() {
register_setting(
'sportspress_general',
'sportspress',
'sportspress_sport_validate'
'sportspress_options_validate'
);
add_settings_section(
@@ -108,7 +108,8 @@ function sportspress_settings_init() {
// Event Settings
register_setting(
'sportspress_events',
'sportspress'
'sportspress',
'sportspress_options_validate'
);
add_settings_section(
@@ -129,113 +130,113 @@ function sportspress_settings_init() {
}
add_action( 'admin_init', 'sportspress_settings_init', 1 );
function sportspress_sport_validate( $input ) {
function sportspress_options_validate( $input ) {
$options = get_option( 'sportspress' );
// Do nothing if sport is the same as currently selected
if ( sportspress_array_value( $options, 'sport', null ) == sportspress_array_value( $input, 'sport', null ) )
if ( isset( $input['sport'] ) && sportspress_array_value( $options, 'sport', null ) != sportspress_array_value( $input, 'sport', null ) ):
return $input;
// Get sports presets
global $sportspress_sports;
// Get sports presets
global $sportspress_sports;
// Get array of taxonomies to insert
$term_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'terms', array() );
// Get array of taxonomies to insert
$term_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'terms', array() );
foreach( $term_groups as $taxonomy => $terms ):
// Find empty terms and destroy
$allterms = get_terms( $taxonomy, 'hide_empty=0' );
foreach( $term_groups as $taxonomy => $terms ):
// Find empty terms and destroy
$allterms = get_terms( $taxonomy, 'hide_empty=0' );
foreach( $allterms as $term ):
if ( $term->count == 0 )
wp_delete_term( $term->term_id, $taxonomy );
endforeach;
foreach( $allterms as $term ):
if ( $term->count == 0 )
wp_delete_term( $term->term_id, $taxonomy );
// Insert terms
foreach( $terms as $term ):
wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
endforeach;
endforeach;
// Insert terms
foreach( $terms as $term ):
wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
endforeach;
endforeach;
// Get array of post types to insert
$post_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'posts', array() );
// Get array of post types to insert
$post_groups = sportspress_array_value( sportspress_array_value( $sportspress_sports, sportspress_array_value( $input, 'sport', null ), array() ), 'posts', array() );
// Loop through each post type
foreach( $post_groups as $post_type => $posts ):
// Loop through each post type
foreach( $post_groups as $post_type => $posts ):
$args = array(
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_sp_preset',
'value' => 1
$args = array(
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => '_sp_preset',
'value' => 1
)
)
)
);
);
// Delete posts
$old_posts = get_posts( $args );
// Delete posts
$old_posts = get_posts( $args );
foreach( $old_posts as $post ):
wp_delete_post( $post->ID, true);
endforeach;
foreach( $old_posts as $post ):
wp_delete_post( $post->ID, true);
endforeach;
// Add posts
foreach( $posts as $index => $post ):
// Add posts
foreach( $posts as $index => $post ):
// Make sure post doesn't overlap
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
// Make sure post doesn't overlap
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post_type ) ):
// Translate post title
$post['post_title'] = __( $post['post_title'], 'sportspress' );
// Translate post title
$post['post_title'] = __( $post['post_title'], 'sportspress' );
// Set post type
$post['post_type'] = $post_type;
// Set post type
$post['post_type'] = $post_type;
// Increment menu order by 2 and publish post
$post['menu_order'] = $index * 2 + 2;
$post['post_status'] = 'publish';
$id = wp_insert_post( $post );
// Increment menu order by 2 and publish post
$post['menu_order'] = $index * 2 + 2;
$post['post_status'] = 'publish';
$id = wp_insert_post( $post );
// Flag as preset
update_post_meta( $id, '_sp_preset', 1 );
// Flag as preset
update_post_meta( $id, '_sp_preset', 1 );
// Update meta
if ( array_key_exists( 'meta', $post ) ):
// Update meta
if ( array_key_exists( 'meta', $post ) ):
foreach ( $post['meta'] as $key => $value ):
foreach ( $post['meta'] as $key => $value ):
update_post_meta( $id, $key, $value );
update_post_meta( $id, $key, $value );
endforeach;
endforeach;
endif;
// Update terms
if ( array_key_exists( 'tax_input', $post ) ):
foreach ( $post['tax_input'] as $taxonomy => $terms ):
wp_set_object_terms( $id, $terms, $taxonomy, false );
endforeach;
endif;
endif;
// Update terms
if ( array_key_exists( 'tax_input', $post ) ):
foreach ( $post['tax_input'] as $taxonomy => $terms ):
wp_set_object_terms( $id, $terms, $taxonomy, false );
endforeach;
endif;
endif;
endforeach;
endforeach;
endforeach;
endif;
return $input;
// Merge with existing options
return array_merge( $options, $input );
}
function sportspress_add_options_page() {
function sportspress_add_menu_page() {
add_options_page(
__( 'SportsPress', 'sportspress' ),
__( 'SportsPress', 'sportspress' ),
@@ -244,4 +245,4 @@ function sportspress_add_options_page() {
'sportspress_settings'
);
}
add_action( 'admin_menu', 'sportspress_add_options_page' );
add_action( 'admin_menu', 'sportspress_add_menu_page' );

View File

@@ -9,15 +9,30 @@ if ( !function_exists( 'sportspress_player_metrics' ) ) {
$number = get_post_meta( $id, 'sp_number', true );
$nationality = get_post_meta( $id, 'sp_nationality', true );
$current_team = get_post_meta( $id, 'sp_current_team', true );
$past_teams = get_post_meta( $id, 'sp_past_team', false );
$metrics = sportspress_get_player_metrics_data( $id );
$common = array(
__( 'Number', 'sportspress' ) => $number,
__( 'Nationality', 'sportspress' ) => sportspress_array_value( $sportspress_countries, $nationality, '&mdash;' ),
);
$common = array();
if ( $number != null )
$common[ __( 'Number', 'sportspress' ) ] = $number;
if ( $nationality )
$common[ __( 'Nationality', 'sportspress' ) ] = sportspress_array_value( $sportspress_countries, $nationality, '&mdash;' );
$data = array_merge( $common, $metrics );
if ( $current_team )
$data[ __( 'Current Team', 'sportspress' ) ] = '<a href="' . get_post_permalink( $current_team ) . '">' . get_the_title( $current_team ) . '</a>';
if ( $past_teams ):
$teams = array();
foreach ( $past_teams as $team ):
$teams[] = '<a href="' . get_post_permalink( $team ) . '">' . get_the_title( $team ) . '</a>';
endforeach;
$data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams );
endif;
$output = '<div class="sp-table-wrapper">' .
'<table class="sp-player-metrics sp-data-table sp-responsive-table">' . '<tbody>';

40
admin/tools/importers.php Normal file
View File

@@ -0,0 +1,40 @@
<?php
function sportspress_team_importer() {
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
require $class_wp_importer;
}
// includes
require dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/tools/team-importer.php';
// Dispatch
$importer = new SP_Team_Importer();
$importer->dispatch();
}
function sportspress_player_importer() {
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
require $class_wp_importer;
}
// includes
require dirname( SPORTSPRESS_PLUGIN_FILE ) . '/admin/tools/player-importer.php';
// Dispatch
$importer = new SP_Player_Importer();
$importer->dispatch();
}
function sportspress_register_importers() {
register_importer( 'sportspress_team_csv', __( 'SportsPress Teams (CSV)', 'sportspress' ), __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'), 'sportspress_team_importer' );
register_importer( 'sportspress_player_csv', __( 'SportsPress Players (CSV)', 'sportspress' ), __( 'Import <strong>players</strong> from a csv file.', 'sportspress'), 'sportspress_player_importer' );
}
add_action( 'admin_init', 'sportspress_register_importers' );