Save default variable name for config types

This commit is contained in:
Brian Miyaji
2014-04-25 01:06:35 +10:00
parent 88d43e0a4f
commit 727d7d3fe6
17 changed files with 227 additions and 108 deletions

View File

@@ -35,7 +35,7 @@ class SP_Admin_Post_Types {
include( 'post-types/class-sp-admin-cpt-performance.php' );
include( 'post-types/class-sp-admin-cpt-column.php' );
include( 'post-types/class-sp-admin-cpt-metric.php' );
//include( 'post-types/class-sp-admin-cpt-statistic.php' );
include( 'post-types/class-sp-admin-cpt-statistic.php' );
include( 'post-types/class-sp-admin-cpt-event.php' );
include( 'post-types/class-sp-admin-cpt-calendar.php' );
include( 'post-types/class-sp-admin-cpt-team.php' );

View File

@@ -41,7 +41,7 @@ class SP_Admin_CPT_Column extends SP_Admin_CPT {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_variable' => __( 'Variable', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'sp_precision' => __( 'Rounding', 'sportspress' ),
'sp_order' => __( 'Sort Order', 'sportspress' ),
@@ -55,7 +55,7 @@ class SP_Admin_CPT_Column extends SP_Admin_CPT {
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
case 'sp_variable':
global $post;
echo $post->post_name;
break;

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post Types
* @version 0.7
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -41,8 +41,7 @@ class SP_Admin_CPT_Metric extends SP_Admin_CPT {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_variable' => __( 'Variable', 'sportspress' ),
);
return $columns;
}
@@ -53,8 +52,9 @@ class SP_Admin_CPT_Metric extends SP_Admin_CPT {
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_position':
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
case 'sp_variable':
global $post;
echo $post->post_name;
break;
endswitch;
}

View File

@@ -41,7 +41,7 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_variable' => __( 'Variable', 'sportspress' ),
);
return $columns;
}
@@ -52,7 +52,7 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
case 'sp_variable':
global $post;
echo $post->post_name;
break;

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post Types
* @version 0.7
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -41,9 +41,7 @@ class SP_Admin_CPT_Performance extends SP_Admin_CPT {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_calculate' => __( 'Calculate', 'sportspress' ),
'sp_variable' => __( 'Variable', 'sportspress' ),
);
return $columns;
}
@@ -54,16 +52,10 @@ class SP_Admin_CPT_Performance extends SP_Admin_CPT {
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
case 'sp_variable':
global $post;
echo $post->post_name;
break;
case 'sp_position':
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
break;
case 'sp_calculate':
echo sp_get_post_calculate( $post_id );
break;
endswitch;
}
}

View File

@@ -41,7 +41,7 @@ class SP_Admin_CPT_Result extends SP_Admin_CPT {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_variable' => __( 'Variable', 'sportspress' ),
);
return $columns;
}
@@ -52,7 +52,7 @@ class SP_Admin_CPT_Result extends SP_Admin_CPT {
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
case 'sp_variable':
global $post;
echo $post->post_name;
break;

View File

@@ -0,0 +1,73 @@
<?php
/**
* Admin functions for the statistics post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post Types
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_CPT' ) )
include( 'class-sp-admin-cpt.php' );
if ( ! class_exists( 'SP_Admin_CPT_Statistic' ) ) :
/**
* SP_Admin_CPT_Statistic Class
*/
class SP_Admin_CPT_Statistic extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_statistic';
// Admin Columns
add_filter( 'manage_edit-sp_statistic_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_statistic_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_variable' => __( 'Variable', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'sp_precision' => __( 'Rounding', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_variable':
global $post;
echo $post->post_name;
break;
case 'sp_equation':
echo sp_get_post_equation( $post_id );
break;
case 'sp_precision':
echo sp_get_post_precision( $post_id );
break;
endswitch;
}
}
endif;
return new SP_Admin_CPT_Statistic();

View File

@@ -38,6 +38,9 @@ class SP_Admin_Meta_Boxes {
// Save Performance Meta Boxes
add_action( 'sportspress_process_sp_performance_meta', 'SP_Meta_Box_Performance_Details::save', 10, 2 );
// Save Statistic Meta Boxes
add_action( 'sportspress_process_sp_statistic_meta', 'SP_Meta_Box_Statistic_Details::save', 10, 2 );
// Save Column Meta Boxes
add_action( 'sportspress_process_sp_column_meta', 'SP_Meta_Box_Column_Details::save', 10, 2 );
@@ -95,6 +98,9 @@ class SP_Admin_Meta_Boxes {
// Performance
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Performance_Details::output', 'sp_performance', 'normal', 'high' );
// Metrics
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Statistic_Details::output', 'sp_statistic', 'normal', 'high' );
// Events
add_meta_box( 'sp_shortcodediv', __( 'Shortcodes', 'sportspress' ), 'SP_Meta_Box_Event_Shortcode::output', 'sp_event', 'side', 'default' );
add_meta_box( 'sp_formatdiv', __( 'Format', 'sportspress' ), 'SP_Meta_Box_Event_Format::output', 'sp_event', 'side', 'default' );
@@ -200,7 +206,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_column', 'sp_metric', 'sp_statistic', 'sp_event', 'sp_calendar', 'sp_team', 'sp_table', 'sp_player', 'sp_list', 'sp_staff' ) ) ) 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;
do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post );
}

View File

@@ -28,15 +28,16 @@ class SP_Meta_Box_Column_Details {
// Defaults
if ( $precision == '' ) $precision = 0;
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
<input name="sp_default_variable" type="hidden" id="sp_default_variable" value="<?php echo $post->post_name; ?>">
<input name="sp_variable" type="text" id="sp_variable" value="<?php echo $post->post_name; ?>">
</p>
<p><strong><?php _e( 'Equation', 'sportspress' ); ?></strong></p>
<p class="sp-equation-selector">
<?php
foreach ( $equation as $piece ):
sp_equation_selector( $post->ID, $piece, array( 'team_event', 'result', 'outcome' ) );
sp_equation_selector( $post->ID, $piece, array( 'team_event', 'outcome', 'result' ) );
endforeach;
?>
</p>

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7.3
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -22,9 +22,10 @@ class SP_Meta_Box_Metric_Details {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$calculate = get_post_meta( $post->ID, 'sp_calculate', true );
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
<input name="sp_default_variable" type="hidden" id="sp_default_variable" value="<?php echo $post->post_name; ?>">
<input name="sp_variable" type="text" id="sp_variable" value="<?php echo $post->post_name; ?>">
</p>
<?php
}

View File

@@ -21,9 +21,10 @@ class SP_Meta_Box_Outcome_Details {
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
<input name="sp_default_variable" type="hidden" id="sp_default_variable" value="<?php echo $post->post_name; ?>">
<input name="sp_variable" type="text" id="sp_variable" value="<?php echo $post->post_name; ?>">
</p>
<?php
}

View File

@@ -5,7 +5,7 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.7.3
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -22,13 +22,10 @@ class SP_Meta_Box_Performance_Details {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$calculate = get_post_meta( $post->ID, 'sp_calculate', true );
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
</p>
<p><strong><?php _e( 'Calculate', 'sportspress' ); ?></strong></p>
<p class="sp-calculate-selector">
<?php sp_calculate_selector( $post->ID, $calculate ); ?>
<input name="sp_default_variable" type="hidden" id="sp_default_variable" value="<?php echo $post->post_name; ?>">
<input name="sp_variable" type="text" id="sp_variable" value="<?php echo $post->post_name; ?>">
</p>
<?php
}
@@ -38,6 +35,5 @@ class SP_Meta_Box_Performance_Details {
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
update_post_meta( $post_id, 'sp_calculate', sp_array_value( $_POST, 'sp_calculate', 'DESC' ) );
}
}

View File

@@ -21,9 +21,10 @@ class SP_Meta_Box_Result_Details {
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
<input name="sp_default_variable" type="hidden" id="sp_default_variable" value="<?php echo $post->post_name; ?>">
<input name="sp_variable" type="text" id="sp_variable" value="<?php echo $post->post_name; ?>">
</p>
<?php
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* Statistic Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta Boxes
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Statistic_Details
*/
class SP_Meta_Box_Statistic_Details {
/**
* Output the metabox
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$precision = get_post_meta( $post->ID, 'sp_precision', true );
// Defaults
if ( $precision == '' ) $precision = 0;
?>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_default_variable" type="hidden" id="sp_default_variable" value="<?php echo $post->post_name; ?>">
<input name="sp_variable" type="text" id="sp_variable" value="<?php echo $post->post_name; ?>">
</p>
<p><strong><?php _e( 'Equation', 'sportspress' ); ?></strong></p>
<p class="sp-equation-selector">
<?php
foreach ( $equation as $piece ):
sp_equation_selector( $post->ID, $piece, array( 'player_event', 'outcome', 'performance', 'metric' ) );
endforeach;
?>
</p>
<p><strong><?php _e( 'Rounding', 'sportspress' ); ?></strong></p>
<p class="sp-precision-selector">
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="0">
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
sp_delete_duplicate_post( $_POST );
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1 ) );
}
}