Apply text settings via gettext
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
global $typenow;
|
||||
if ( $domain != 'sportspress' )
|
||||
return $translated_text;
|
||||
|
||||
global $typenow, $sportspress_options;
|
||||
|
||||
if ( is_admin() ):
|
||||
if ( in_array( $typenow, array( 'sp_team' ) ) ):
|
||||
@@ -68,6 +71,14 @@ function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( isset( $sportspress_options['text'] ) ):
|
||||
foreach( $sportspress_options['text'] as $key => $value ):
|
||||
if ( $untranslated_text == $key ):
|
||||
$translated_text = $value;
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
return $translated_text;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,45 @@ function sportspress_define_globals() {
|
||||
|
||||
$sportspress_options = (array)get_option( 'sportspress', array() );
|
||||
|
||||
// Text
|
||||
global $sportspress_text_options;
|
||||
|
||||
$sportspress_text_options = array(
|
||||
'Calendar',
|
||||
'Calendars',
|
||||
'Current Team',
|
||||
'Event',
|
||||
'Events',
|
||||
'Friendly',
|
||||
'League',
|
||||
'Leagues',
|
||||
'League Table',
|
||||
'League Tables',
|
||||
'Nationality',
|
||||
'Number',
|
||||
'Past Teams',
|
||||
'Played',
|
||||
'Player',
|
||||
'Players',
|
||||
'Player List',
|
||||
'Player Lists',
|
||||
'Position',
|
||||
'Positions',
|
||||
'Pos',
|
||||
'Rank',
|
||||
'Roster',
|
||||
'Schedule',
|
||||
'Season',
|
||||
'Seasons',
|
||||
'Staff',
|
||||
'Team',
|
||||
'Teams',
|
||||
'Venue',
|
||||
'Venues',
|
||||
);
|
||||
|
||||
sort( $sportspress_text_options );
|
||||
|
||||
// Continents
|
||||
global $sportspress_continents;
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
class SportsPressEventSettingsPage {
|
||||
private $options;
|
||||
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
class SportsPressGeneralSettingsPage {
|
||||
private $options;
|
||||
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
class SportsPressPlayerSettingsPage {
|
||||
private $options;
|
||||
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
class SportsPressTeamSettingsPage {
|
||||
private $options;
|
||||
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
$this->options =& $sportspress_options;
|
||||
|
||||
@@ -1,30 +1,12 @@
|
||||
<?php
|
||||
class SportsPressTextSettingsPage {
|
||||
public function __construct() {
|
||||
global $sportspress_options;
|
||||
global $sportspress_options, $sportspress_text_options;
|
||||
$this->options =& $sportspress_options;
|
||||
|
||||
$this->strings = array(
|
||||
array( 'league', __( 'League', 'sportspress' ) ),
|
||||
array( 'season', __( 'Season', 'sportspress' ) ),
|
||||
array( 'venue', __( 'Venue', 'sportspress' ) ),
|
||||
array( 'rank', __( 'Rank', 'sportspress' ) ),
|
||||
array( 'hash', '#' ),
|
||||
array( 'player', __( 'Player', 'sportspress' ) ),
|
||||
array( 'team', __( 'Team', 'sportspress' ) ),
|
||||
array( 'pos', __( 'Pos', 'sportspress' ) ),
|
||||
array( 'current_team', __( 'Current Team', 'sportspress' ) ),
|
||||
);
|
||||
usort( $this->strings, array( $this, 'compare_label' ) );
|
||||
|
||||
$this->strings =& $sportspress_text_options;
|
||||
add_action( 'admin_init', array( $this, 'page_init' ), 1 );
|
||||
}
|
||||
|
||||
private function compare_label( $a, $b ) {
|
||||
return strcmp( $a[1], $b[1] );
|
||||
}
|
||||
|
||||
|
||||
function page_init() {
|
||||
register_setting(
|
||||
'sportspress_text',
|
||||
@@ -41,8 +23,8 @@ class SportsPressTextSettingsPage {
|
||||
|
||||
foreach ( $this->strings as $string ):
|
||||
add_settings_field(
|
||||
$string[0],
|
||||
$string[1],
|
||||
sanitize_title( $string ),
|
||||
__( $string, 'sportspress' ),
|
||||
array( $this, 'text_callback' ),
|
||||
'sportspress_text',
|
||||
'text'
|
||||
@@ -52,10 +34,10 @@ class SportsPressTextSettingsPage {
|
||||
|
||||
public function text_callback( $test ) {
|
||||
$string = array_shift( $this->strings );
|
||||
$key = $string[0];
|
||||
$placeholder = $string[1];
|
||||
$text = sportspress_array_value( $this->options, $key . '_string', null );
|
||||
?><fieldset><input id="sportspress_<?php echo $key; ?>_string" name="sportspress[<?php echo $key; ?>_string]" type="text" value="<?php echo $text; ?>" placeholder="<?php echo $placeholder; ?>"></fieldset><?php
|
||||
$key = sanitize_title( $string );
|
||||
$localized = $string;
|
||||
$text = sportspress_array_value( sportspress_array_value( $this->options, 'text', array() ), $string, null );
|
||||
?><fieldset><input id="sportspress_text_<?php echo $key; ?>" name="sportspress[text][<?php echo $string; ?>]" type="text" class="regular-text code" value="<?php echo $text; ?>" placeholder="<?php echo $localized; ?>"></fieldset><?php
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,8 @@ function sportspress_options_validate( $input ) {
|
||||
|
||||
endforeach;
|
||||
|
||||
elseif ( isset( $input['text'] ) ):
|
||||
$input['text'] = array_filter( $input['text'] );
|
||||
endif;
|
||||
|
||||
if ( ! is_array( $input ) )
|
||||
|
||||
Reference in New Issue
Block a user