Add settings tabs and config page

This commit is contained in:
Brian Miyaji
2013-12-31 03:52:09 +11:00
parent ed352f8e2d
commit 6d40c687ea
5 changed files with 213 additions and 17 deletions

175
admin/options/config.php Normal file
View File

@@ -0,0 +1,175 @@
<?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>
</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>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th colspan="3"><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>
</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>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th colspan="3"><a href="<?php echo admin_url( 'edit.php?post_type=sp_column' ); ?>"><?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>
</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>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th><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>
</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>
</tr>
<?php $i++; endforeach; ?>
<tfoot>
<tr>
<th><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();
?>

View File

@@ -2,7 +2,7 @@
function sportspress_admin_menu() {
add_options_page(
__( 'SportsPress Settings', 'sportspress' ),
__( 'SportsPress', 'sportspress' ),
__( 'SportsPress', 'sportspress' ),
'manage_options',
'sportspress',
@@ -13,17 +13,26 @@ function sportspress_admin_menu() {
add_action( 'admin_menu', 'sportspress_admin_menu' );
function sportspress_settings() {
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general';
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"></div>
<h2><?php _e( 'SportsPress Settings', 'sportspress' ); ?></h2>
<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
settings_fields( 'sportspress' );
do_settings_sections( 'sportspress' );
submit_button();
switch ( $active_tab ):
case 'config':
include 'config.php';
break;
default:
include 'general.php';
endswitch;
?>
</form>
@@ -74,7 +83,7 @@ function sportspress_validate( $input ) {
function sportspress_register_settings() {
register_setting(
'sportspress',
'sportspress_general',
'sportspress',
'sportspress_validate'
);
@@ -83,14 +92,14 @@ function sportspress_register_settings() {
'general',
'',
'',
'sportspress'
'sportspress_general'
);
add_settings_field(
'sport',
'sport',
__( 'Sport', 'sportspress' ),
'sportspress_sport_callback',
'sportspress',
'sportspress_general',
'general'
);

View File

@@ -55,11 +55,16 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
echo get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '<br />', $result, ( empty( $result ) ? ' — ' : ' ' ) ) : '—';
break;
case 'sp_equation':
echo str_replace(
array( '$', '+', '-', '*', '/' ),
array( '', '&plus;', '&minus;', '&times;', '&divide' ),
get_post_meta ( $post_id, 'sp_equation', true )
);
$equation = get_post_meta ( $post_id, 'sp_equation', true );
if ( $equation ):
echo str_replace(
array( '$', '+', '-', '*', '/' ),
array( '', '&plus;', '&minus;', '&times;', '&divide' ),
$equation
);
else:
echo '—';
endif;
break;
case 'sp_order':
$priority = get_post_meta ( $post_id, 'sp_priority', true );

View File

@@ -31,7 +31,7 @@ include dirname( __FILE__ ) . '/sportspress-globals.php' ;
require_once dirname( __FILE__ ) . '/sportspress-functions.php';
// Settings
include dirname( __FILE__ ) . '/sportspress-settings.php' ;
include dirname( __FILE__ ) . '/admin/options/options.php' ;
// Custom Post Types
require_once dirname( __FILE__ ) . '/admin/post-types/separator.php';