Add column selector to player profiles
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @version 1.0
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 1.1
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
@@ -68,9 +68,10 @@ class SP_Admin_Meta_Boxes {
|
||||
add_action( 'sportspress_process_sp_table_meta', 'SP_Meta_Box_Table_Data::save', 20, 2 );
|
||||
|
||||
// Save Player Meta Boxes
|
||||
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Details::save', 10, 2 );
|
||||
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Metrics::save', 20, 2 );
|
||||
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Statistics::save', 30, 2 );
|
||||
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Columns::save', 10, 2 );
|
||||
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Details::save', 20, 2 );
|
||||
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Metrics::save', 30, 2 );
|
||||
add_action( 'sportspress_process_sp_player_meta', 'SP_Meta_Box_Player_Statistics::save', 40, 2 );
|
||||
|
||||
// Save List Meta Boxes
|
||||
add_action( 'sportspress_process_sp_list_meta', 'SP_Meta_Box_List_Format::save', 10, 2 );
|
||||
@@ -86,7 +87,6 @@ class SP_Admin_Meta_Boxes {
|
||||
* Add SP Meta boxes
|
||||
*/
|
||||
public function add_meta_boxes() {
|
||||
|
||||
// Results
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Result_Details::output', 'sp_result', 'normal', 'high' );
|
||||
|
||||
@@ -136,6 +136,7 @@ class SP_Admin_Meta_Boxes {
|
||||
add_meta_box( 'sp_editordiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_Table_Editor::output', 'sp_table', 'normal', 'high' );
|
||||
|
||||
// Players
|
||||
add_meta_box( 'sp_columnsdiv', __( 'Columns', 'sportspress' ), 'SP_Meta_Box_Player_Columns::output', 'sp_player', 'side', 'default' );
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Player_Details::output', 'sp_player', 'side', 'default' );
|
||||
add_meta_box( 'sp_metricsdiv', __( 'Metrics', 'sportspress' ), 'SP_Meta_Box_Player_Metrics::output', 'sp_player', 'side', 'default' );
|
||||
add_meta_box( 'sp_statisticsdiv', __( 'Statistics', 'sportspress' ), 'SP_Meta_Box_Player_Statistics::output', 'sp_player', 'normal', 'high' );
|
||||
@@ -214,7 +215,7 @@ class SP_Admin_Meta_Boxes {
|
||||
if ( is_int( wp_is_post_autosave( $post ) ) ) return;
|
||||
if ( empty( $_POST['sportspress_meta_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_meta_nonce'], 'sportspress_save_data' ) ) return;
|
||||
if ( ! current_user_can( 'edit_post', $post_id )) return;
|
||||
if ( ! in_array( $post->post_type, array( 'sp_result', 'sp_outcome', 'sp_performance', 'sp_statistic', 'sp_column', 'sp_metric', 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' ) ) ) return;
|
||||
if ( ! is_sp_post_type( $post->post_type ) && ! is_sp_config_type( $post->post_type ) ) return;
|
||||
|
||||
do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* Player Columns
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 1.1
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Player_Columns
|
||||
*/
|
||||
class SP_Meta_Box_Player_Columns {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
?>
|
||||
<div class="sp-instance">
|
||||
<ul id="sp_column-tabs" class="wp-tab-bar sp-tab-bar">
|
||||
<li class="wp-tab-active"><a href="#sp_performance-all"><?php _e( 'Performance', 'sportspress' ); ?></a></li>
|
||||
<li class="wp-tab"><a href="#sp_statistic-all"><?php _e( 'Statistics', 'sportspress' ); ?></a></li>
|
||||
</ul>
|
||||
<?php
|
||||
$selected = (array)get_post_meta( $post->ID, 'sp_columns', true );
|
||||
sp_column_checklist( $post->ID, 'sp_performance', 'block', $selected );
|
||||
sp_column_checklist( $post->ID, 'sp_statistic', 'none', $selected );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta Boxes
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 0.8
|
||||
*/
|
||||
|
||||
@@ -22,8 +22,6 @@ class SP_Meta_Box_Player_Statistics {
|
||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||
$league_num = sizeof( $leagues );
|
||||
|
||||
$usecolumns = get_post_meta( $post->ID, 'sp_columns', true );
|
||||
|
||||
// Loop through statistics for each league
|
||||
if ( $leagues ): foreach ( $leagues as $league ):
|
||||
|
||||
@@ -35,7 +33,7 @@ class SP_Meta_Box_Player_Statistics {
|
||||
|
||||
$player = new SP_Player( $post );
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
|
||||
self::table( $post->ID, $league->term_id, $columns, $usecolumns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) );
|
||||
|
||||
endforeach; else:
|
||||
|
||||
@@ -48,7 +46,6 @@ class SP_Meta_Box_Player_Statistics {
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||
update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) );
|
||||
if ( current_user_can( 'edit_sp_player_statistics' ) )
|
||||
update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
|
||||
@@ -57,20 +54,20 @@ class SP_Meta_Box_Player_Statistics {
|
||||
/**
|
||||
* Admin edit table
|
||||
*/
|
||||
public static function table( $id = null, $league_id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) {
|
||||
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) {
|
||||
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
|
||||
if ( is_array( $usecolumns ) )
|
||||
$usecolumns = array_filter( $usecolumns );
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<table class="widefat sp-data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Season', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||
<th><label for="sp_columns_team">
|
||||
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
|
||||
<?php _e( 'Team', 'sportspress' ); ?>
|
||||
</label></th>
|
||||
<?php foreach ( $columns as $key => $label ): ?>
|
||||
<th><label for="sp_columns_<?php echo $key; ?>">
|
||||
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
|
||||
<?php echo $label; ?>
|
||||
</label></th>
|
||||
<?php endforeach; ?>
|
||||
|
||||
Reference in New Issue
Block a user