Clean up config settings page tables

This commit is contained in:
Brian Miyaji
2014-01-04 13:19:42 +11:00
parent b5263009c1
commit 6cf7e5b77e
11 changed files with 55 additions and 25 deletions

223
admin/settings/config.php Normal file
View File

@@ -0,0 +1,223 @@
<?php
$args = array(
'post_type' => 'sp_column',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<h3 class="title"><?php _e( 'Table Columns', 'sportspress' ); ?></h3>
<table class="widefat">
<thead>
<tr>
<th><?php _e( 'Label', 'sportspress' ); ?></th>
<th><?php _e( 'Equation', 'sportspress' ); ?></th>
<th><?php _e( 'Sort Order', 'sportspress' ); ?></th>
<th><?php _e( 'Abbreviation', 'sportspress' ); ?></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td>
<?php
$equation = get_post_meta ( $row->ID, 'sp_equation', true );
if ( $equation ):
echo str_replace(
array( '$', '+', '-', '*', '/' ),
array( '', '&plus;', '&minus;', '&times;', '&divide' ),
$equation
);
else:
echo '—';
endif;
?>
</td>
<td>
<?php
$priority = get_post_meta ( $row->ID, 'sp_priority', true );
if ( $priority ):
echo $priority . ' ' . str_replace(
array( 'DESC', 'ASC' ),
array( '&darr;', '&uarr;' ),
get_post_meta ( $row->ID, 'sp_order', true )
);
else:
echo '—';
endif;
?>
</td>
<td>
<?php
$abbreviation = get_post_meta ( $row->ID, 'sp_abbreviation', true );
if ( $abbreviation ):
echo $abbreviation;
else:
echo $row->post_title;
endif;
?>
</td>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th colspan="4"><a href="<?php echo admin_url( 'edit.php?post_type=sp_column' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Table Columns', 'sportspress' ) ); ?></a></th>
</tr>
</tfoot>
</table>
<?php
$args = array(
'post_type' => 'sp_statistic',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<h3 class="title"><?php _e( 'Statistics', 'sportspress' ); ?></h3>
<table class="widefat">
<thead>
<tr>
<th><?php _e( 'Label', 'sportspress' ); ?></th>
<th><?php _e( 'Equation', 'sportspress' ); ?></th>
<th><?php _e( 'Sort Order', 'sportspress' ); ?></th>
<th><?php _e( 'Abbreviation', 'sportspress' ); ?></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td>
<?php
$equation = get_post_meta ( $row->ID, 'sp_equation', true );
if ( $equation ):
echo str_replace(
array( '$', '+', '-', '*', '/' ),
array( '', '&plus;', '&minus;', '&times;', '&divide' ),
$equation
);
else:
echo '—';
endif;
?>
</td>
<td>
<?php
$priority = get_post_meta ( $row->ID, 'sp_priority', true );
if ( $priority ):
echo $priority . ' ' . str_replace(
array( 'DESC', 'ASC' ),
array( '&darr;', '&uarr;' ),
get_post_meta ( $row->ID, 'sp_order', true )
);
else:
echo '—';
endif;
?>
</td>
<td>
<?php
$abbreviation = get_post_meta ( $row->ID, 'sp_abbreviation', true );
if ( $abbreviation ):
echo $abbreviation;
else:
echo $row->post_title;
endif;
?>
</td>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th colspan="4"><a href="<?php echo admin_url( 'edit.php?post_type=sp_statistic' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Statistics', 'sportspress' ) ); ?></a></th>
</tr>
</tfoot>
</table>
<?php
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<h3 class="title"><?php _e( 'Results', 'sportspress' ); ?></h3>
<table class="widefat">
<thead>
<tr>
<th><?php _e( 'Label', 'sportspress' ); ?></th>
<th><?php _e( 'Key', 'sportspress' ); ?></th>
<th><?php _e( 'Abbreviation', 'sportspress' ); ?></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 ) echo ' class="alternate"'; ?>>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo $row->post_name; ?></td>
<td>
<?php
$abbreviation = get_post_meta ( $row->ID, 'sp_abbreviation', true );
if ( $abbreviation ):
echo $abbreviation;
else:
echo $row->post_title;
endif;
?>
</td>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th colspan="3"><a href="<?php echo admin_url( 'edit.php?post_type=sp_result' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Results', 'sportspress' ) ); ?></a></th>
</tr>
</tfoot>
</table>
<?php
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$data = get_posts( $args );
?>
<h3 class="title"><?php _e( 'Outcomes', 'sportspress' ); ?></h3>
<table class="widefat">
<thead>
<tr>
<th><?php _e( 'Label', 'sportspress' ); ?></th>
<th><?php _e( 'Key', 'sportspress' ); ?></th>
<th><?php _e( 'Abbreviation', 'sportspress' ); ?></th>
</tr>
</thead>
<?php $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 ) echo ' class="alternate"'; ?>>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo $row->post_name; ?></td>
<td>
<?php
$abbreviation = get_post_meta ( $row->ID, 'sp_abbreviation', true );
if ( $abbreviation ):
echo $abbreviation;
else:
echo $row->post_title;
endif;
?>
</td>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th colspan="3"><a href="<?php echo admin_url( 'edit.php?post_type=sp_outcome' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Outcomes', 'sportspress' ) ); ?></a></th>
</tr>
</tfoot>
</table>

View File

@@ -0,0 +1,7 @@
<?php
settings_fields( 'sportspress_general' );
do_settings_sections( 'sportspress_general' );
submit_button();
?>

133
admin/settings/settings.php Normal file
View File

@@ -0,0 +1,133 @@
<?php
function sportspress_admin_menu() {
add_options_page(
__( 'SportsPress', 'sportspress' ),
__( 'SportsPress', 'sportspress' ),
'manage_options',
'sportspress',
'sportspress_settings'
);
}
add_action( 'admin_menu', 'sportspress_admin_menu' );
function sportspress_settings() {
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general';
?>
<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=config" class="nav-tab<?php echo $active_tab == 'config' ? ' nav-tab-active' : ''; ?>"><?php _e( 'Configure', 'sportspress' ); ?></a>
</h2>
<form method="post" action="options.php">
<?php
switch ( $active_tab ):
case 'config':
include 'config.php';
break;
default:
include 'general.php';
endswitch;
?>
</form>
</div>
<?php
}
function sportspress_validate( $input ) {
$original = get_option( 'sportspress' );
if ( sp_array_value( $original, 'sport', null ) != sp_array_value( $input, 'sport', null ) ):
global $sportspress_sports;
$post_groups = sp_array_value( sp_array_value( $sportspress_sports, sp_array_value( $input, 'sport', null ), array() ), 'posts', array() );
foreach( $post_groups as $post_type => $posts ):
// Delete posts
$old_posts = get_posts( array( 'post_type' => $post_type, 'numberposts' => -1, 'posts_per_page' => -1 ) );
foreach( $old_posts as $post ):
wp_delete_post( $post->ID, true);
endforeach;
// Add posts
foreach( $posts as $index => $post ):
$post['post_type'] = $post_type;
if ( ! get_page_by_path( $post['post_name'], OBJECT, $post['post_type'] ) ):
$post['menu_order'] = $index;
$post['post_status'] = 'publish';
$id = wp_insert_post( $post );
if ( array_key_exists( 'meta', $post ) ):
foreach ( $post['meta'] as $key => $value ):
update_post_meta( $id, $key, $value );
endforeach;
endif;
endif;
endforeach;
endforeach;
endif;
return $input;
}
function sportspress_register_settings() {
register_setting(
'sportspress_general',
'sportspress',
'sportspress_validate'
);
add_settings_section(
'general',
'',
'',
'sportspress_general'
);
add_settings_field(
'sport',
__( 'Sport', 'sportspress' ),
'sportspress_sport_callback',
'sportspress_general',
'general'
);
}
add_action( 'admin_init', 'sportspress_register_settings' );
function sportspress_sport_callback() {
global $sportspress_sports;
$options = get_option( 'sportspress' );
?>
<select id="sportspress_sport" name="sportspress[sport]">
<?php foreach( $sportspress_sports as $slug => $sport ): ?>
<option value="<?php echo $slug; ?>" <?php selected( $options['sport'], $slug ); ?>><?php echo $sport['name']; ?></option>
<?php endforeach; ?>
</select>
<?
}
function sportspress_team_stats_callback() {
sportspress_render_option_field( 'sportspress_stats', 'team', 'textarea' );
}
function sportspress_event_stats_callback() {
sportspress_render_option_field( 'sportspress_stats', 'event', 'textarea' );
}
function sportspress_player_stats_callback() {
sportspress_render_option_field( 'sportspress_stats', 'player', 'textarea' );
}
?>