Change Base Location to Timezone

This commit is contained in:
Brian Miyaji
2014-07-16 15:06:27 +10:00
parent 68a49e7e5a
commit d6fbcba0c8
2 changed files with 64 additions and 32 deletions

View File

@@ -9,7 +9,7 @@
* @author ThemeBoy * @author ThemeBoy
* @category Admin * @category Admin
* @package SportsPress/Admin * @package SportsPress/Admin
* @version 0.9 * @version 1.2
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -167,6 +167,7 @@ class SP_Admin_Welcome {
*/ */
public function about_screen() { public function about_screen() {
include_once( 'class-sp-admin-settings.php' ); include_once( 'class-sp-admin-settings.php' );
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
?> ?>
<div class="wrap about-wrap about-sportspress-wrap"> <div class="wrap about-wrap about-sportspress-wrap">
@@ -178,17 +179,17 @@ class SP_Admin_Welcome {
<?php <?php
// Save settings // Save settings
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) != $_POST['sportspress_sport'] ): if ( isset( $_POST['timezone_string'] ) ):
$sport = $_POST['sportspress_sport']; update_option( 'timezone_string', $_POST['timezone_string'] );
SP_Admin_Sports::apply_preset( $sport );
update_option( 'sportspress_sport', $_POST['sportspress_sport'] );
endif; endif;
if ( isset( $_POST['sportspress_mode'] ) && ! empty( $_POST['sportspress_mode'] ) && get_option( 'sportspress_mode', null ) != $_POST['sportspress_mode'] ): if ( isset( $_POST['sportspress_mode'] ) && ! empty( $_POST['sportspress_mode'] ) && get_option( 'sportspress_mode', null ) != $_POST['sportspress_mode'] ):
$sport = $_POST['sportspress_mode']; $sport = $_POST['sportspress_mode'];
update_option( 'sportspress_mode', $_POST['sportspress_mode'] ); update_option( 'sportspress_mode', $_POST['sportspress_mode'] );
endif; endif;
if ( isset( $_POST['sportspress_default_country'] ) ): if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) != $_POST['sportspress_sport'] ):
update_option( 'sportspress_default_country', $_POST['sportspress_default_country'] ); $sport = $_POST['sportspress_sport'];
SP_Admin_Sports::apply_preset( $sport );
update_option( 'sportspress_sport', $_POST['sportspress_sport'] );
update_option( '_sportspress_needs_welcome', 1 ); update_option( '_sportspress_needs_welcome', 1 );
?> ?>
<div id="message" class="updated sportspress-message"> <div id="message" class="updated sportspress-message">
@@ -198,20 +199,33 @@ class SP_Admin_Welcome {
<div class="sp-feature feature-section col three-col"> <div class="sp-feature feature-section col three-col">
<div> <div>
<form method="post" id="mainform" action="" enctype="multipart/form-data"> <form method="post" id="mainform" action="" enctype="multipart/form-data">
<h4><?php _e( 'Base Location', 'sportspress' ); ?></h4> <h4><?php _e( 'Timezone', 'sportspress' ); ?></h4>
<select id="timezone_string" name="timezone_string" class="<?php echo $class; ?>">
<?php <?php
$selected = (string) get_option( 'sportspress_default_country', 'US' ); $current_offset = get_option('gmt_offset');
$continents = SP()->countries->continents; $tzstring = get_option('timezone_string');
$check_zone_info = true;
// Remove old Etc mappings. Fallback to gmt_offset.
if ( false !== strpos($tzstring,'Etc/GMT') )
$tzstring = '';
if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists
$check_zone_info = false;
if ( 0 == $current_offset )
$tzstring = 'UTC+0';
elseif ($current_offset < 0)
$tzstring = 'UTC' . $current_offset;
else
$tzstring = 'UTC+' . $current_offset;
}
echo wp_timezone_choice($tzstring);
?> ?>
<p>
<select name="sportspress_default_country" data-placeholder="<?php _e( 'Choose a country&hellip;', 'sportspress' ); ?>" title="Country" class="chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>">
<?php SP()->countries->country_dropdown_options( $selected ); ?>
</select> </select>
</p>
<h4><?php _e( 'Sport', 'sportspress' ); ?></h4> <h4><?php _e( 'Sport', 'sportspress' ); ?></h4>
<?php <?php
$sport_options = SP_Admin_Sports::get_preset_options(); $sport_options = SP_Admin_Sports::get_preset_options();
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
$settings = array( array( $settings = array( array(
'id' => 'sportspress_sport', 'id' => 'sportspress_sport',
'default' => 'soccer', 'default' => 'soccer',

View File

@@ -26,7 +26,7 @@ class SP_Settings_General extends SP_Settings_Page {
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) ); add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_country', array( $this, 'country_setting' ) ); add_action( 'sportspress_admin_field_timezone', array( $this, 'timezone_setting' ) );
add_action( 'sportspress_admin_field_frontend_styles', array( $this, 'frontend_styles_setting' ) ); add_action( 'sportspress_admin_field_frontend_styles', array( $this, 'frontend_styles_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) ); add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
} }
@@ -43,7 +43,7 @@ class SP_Settings_General extends SP_Settings_Page {
$settings = array( $settings = array(
array( 'title' => __( 'General Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), array( 'title' => __( 'General Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
array( 'type' => 'country' ), array( 'type' => 'timezone' ),
array( array(
'title' => __( 'Sport', 'sportspress' ), 'title' => __( 'Sport', 'sportspress' ),
@@ -52,6 +52,7 @@ class SP_Settings_General extends SP_Settings_Page {
'type' => 'select', 'type' => 'select',
'options' => $presets, 'options' => $presets,
), ),
array( array(
'title' => __( 'Mode', 'sportspress' ), 'title' => __( 'Mode', 'sportspress' ),
'id' => 'sportspress_mode', 'id' => 'sportspress_mode',
@@ -190,8 +191,8 @@ class SP_Settings_General extends SP_Settings_Page {
$settings = $this->get_settings(); $settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings ); SP_Admin_Settings::save_fields( $settings );
if ( isset( $_POST['sportspress_default_country'] ) ) if ( isset( $_POST['timezone_string'] ) )
update_option( 'sportspress_default_country', $_POST['sportspress_default_country'] ); update_option( 'timezone_string', $_POST['timezone_string'] );
update_option( 'sportspress_enable_frontend_css', isset( $_POST['sportspress_enable_frontend_css'] ) ? 'yes' : 'no' ); update_option( 'sportspress_enable_frontend_css', isset( $_POST['sportspress_enable_frontend_css'] ) ? 'yes' : 'no' );
@@ -217,23 +218,40 @@ class SP_Settings_General extends SP_Settings_Page {
} }
/** /**
* Country settings * Timezone settings
* *
* @access public * @access public
* @return void * @return void
*/ */
public function country_setting() { public function timezone_setting() {
$selected = (string) get_option( 'sportspress_default_country', 'US' ); $current_offset = get_option('gmt_offset');
$continents = SP()->countries->continents; $tzstring = get_option('timezone_string');
$check_zone_info = true;
// Remove old Etc mappings. Fallback to gmt_offset.
if ( false !== strpos($tzstring,'Etc/GMT') )
$tzstring = '';
if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists
$check_zone_info = false;
if ( 0 == $current_offset )
$tzstring = 'UTC+0';
elseif ($current_offset < 0)
$tzstring = 'UTC' . $current_offset;
else
$tzstring = 'UTC+' . $current_offset;
}
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
?> ?>
<tr valign="top"> <tr valign="top">
<th scope="row" class="titledesc"> <th scope="row" class="titledesc">
<label for="sportspress_default_country"><?php _e( 'Base Location', 'sportspress' ); ?></label> <label for="timezone_string"><?php _e( 'Timezone', 'sportspress' ); ?></label>
</th> </th>
<td class="forminp"> <td class="forminp">
<legend class="screen-reader-text"><span><?php _e( 'Base Location', 'sportspress' ); ?></span></legend> <legend class="screen-reader-text"><span><?php _e( 'Timezone', 'sportspress' ); ?></span></legend>
<select name="sportspress_default_country" data-placeholder="<?php _e( 'Choose a country&hellip;', 'sportspress' ); ?>" title="Country" class="chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>"> <select id="timezone_string" name="timezone_string" class="<?php echo $class; ?>">
<?php SP()->countries->country_dropdown_options( $selected ); ?> <?php echo wp_timezone_choice($tzstring); ?>
</select> </select>
</td> </td>
</tr> </tr>