Add settings tabs and config page
This commit is contained in:
175
admin/options/config.php
Normal file
175
admin/options/config.php
Normal 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( '', '+', '−', '×', '÷' ),
|
||||||
|
$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( '↓', '↑' ),
|
||||||
|
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( '', '+', '−', '×', '÷' ),
|
||||||
|
$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( '↓', '↑' ),
|
||||||
|
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>
|
||||||
7
admin/options/general.php
Normal file
7
admin/options/general.php
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
settings_fields( 'sportspress_general' );
|
||||||
|
do_settings_sections( 'sportspress_general' );
|
||||||
|
submit_button();
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
function sportspress_admin_menu() {
|
function sportspress_admin_menu() {
|
||||||
|
|
||||||
add_options_page(
|
add_options_page(
|
||||||
__( 'SportsPress Settings', 'sportspress' ),
|
__( 'SportsPress', 'sportspress' ),
|
||||||
__( 'SportsPress', 'sportspress' ),
|
__( 'SportsPress', 'sportspress' ),
|
||||||
'manage_options',
|
'manage_options',
|
||||||
'sportspress',
|
'sportspress',
|
||||||
@@ -13,17 +13,26 @@ function sportspress_admin_menu() {
|
|||||||
add_action( 'admin_menu', 'sportspress_admin_menu' );
|
add_action( 'admin_menu', 'sportspress_admin_menu' );
|
||||||
|
|
||||||
function sportspress_settings() {
|
function sportspress_settings() {
|
||||||
|
|
||||||
|
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'general';
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
|
|
||||||
<div id="icon-options-general" class="icon32"></div>
|
<h2 class="nav-tab-wrapper">
|
||||||
<h2><?php _e( 'SportsPress Settings', 'sportspress' ); ?></h2>
|
<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">
|
<form method="post" action="options.php">
|
||||||
<?php
|
<?php
|
||||||
settings_fields( 'sportspress' );
|
switch ( $active_tab ):
|
||||||
do_settings_sections( 'sportspress' );
|
case 'config':
|
||||||
submit_button();
|
include 'config.php';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
include 'general.php';
|
||||||
|
endswitch;
|
||||||
?>
|
?>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
@@ -74,7 +83,7 @@ function sportspress_validate( $input ) {
|
|||||||
function sportspress_register_settings() {
|
function sportspress_register_settings() {
|
||||||
|
|
||||||
register_setting(
|
register_setting(
|
||||||
'sportspress',
|
'sportspress_general',
|
||||||
'sportspress',
|
'sportspress',
|
||||||
'sportspress_validate'
|
'sportspress_validate'
|
||||||
);
|
);
|
||||||
@@ -83,14 +92,14 @@ function sportspress_register_settings() {
|
|||||||
'general',
|
'general',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'sportspress'
|
'sportspress_general'
|
||||||
);
|
);
|
||||||
|
|
||||||
add_settings_field(
|
add_settings_field(
|
||||||
'sport',
|
'sport',
|
||||||
__( 'Sport', 'sportspress' ),
|
__( 'Sport', 'sportspress' ),
|
||||||
'sportspress_sport_callback',
|
'sportspress_sport_callback',
|
||||||
'sportspress',
|
'sportspress_general',
|
||||||
'general'
|
'general'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -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 ) ? ' — ' : ' ' ) ) : '—';
|
echo get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '<br />', $result, ( empty( $result ) ? ' — ' : ' ' ) ) : '—';
|
||||||
break;
|
break;
|
||||||
case 'sp_equation':
|
case 'sp_equation':
|
||||||
|
$equation = get_post_meta ( $post_id, 'sp_equation', true );
|
||||||
|
if ( $equation ):
|
||||||
echo str_replace(
|
echo str_replace(
|
||||||
array( '$', '+', '-', '*', '/' ),
|
array( '$', '+', '-', '*', '/' ),
|
||||||
array( '', '+', '−', '×', '÷' ),
|
array( '', '+', '−', '×', '÷' ),
|
||||||
get_post_meta ( $post_id, 'sp_equation', true )
|
$equation
|
||||||
);
|
);
|
||||||
|
else:
|
||||||
|
echo '—';
|
||||||
|
endif;
|
||||||
break;
|
break;
|
||||||
case 'sp_order':
|
case 'sp_order':
|
||||||
$priority = get_post_meta ( $post_id, 'sp_priority', true );
|
$priority = get_post_meta ( $post_id, 'sp_priority', true );
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ include dirname( __FILE__ ) . '/sportspress-globals.php' ;
|
|||||||
require_once dirname( __FILE__ ) . '/sportspress-functions.php';
|
require_once dirname( __FILE__ ) . '/sportspress-functions.php';
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
include dirname( __FILE__ ) . '/sportspress-settings.php' ;
|
include dirname( __FILE__ ) . '/admin/options/options.php' ;
|
||||||
|
|
||||||
// Custom Post Types
|
// Custom Post Types
|
||||||
require_once dirname( __FILE__ ) . '/admin/post-types/separator.php';
|
require_once dirname( __FILE__ ) . '/admin/post-types/separator.php';
|
||||||
|
|||||||
Reference in New Issue
Block a user