From 88d43e0a4f4726d9d8d88072eb94541f4d764f22 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Fri, 25 Apr 2014 01:06:14 +1000 Subject: [PATCH] Move text settings to dedicated tab --- includes/admin/class-sp-admin-settings.php | 1 + includes/admin/class-sp-admin-welcome.php | 2 +- .../settings/class-sp-settings-config.php | 29 +++------ .../settings/class-sp-settings-events.php | 26 ++------ .../settings/class-sp-settings-general.php | 36 ++++------ .../settings/class-sp-settings-players.php | 24 +------ .../settings/class-sp-settings-teams.php | 24 +------ .../admin/settings/class-sp-settings-text.php | 65 +++++++++++++++++++ includes/class-sp-text.php | 13 ++-- templates/event-calendar.php | 2 +- templates/event-details.php | 4 +- templates/event-list.php | 18 ++--- templates/event-performance.php | 4 +- templates/event-results.php | 4 +- templates/event-venue.php | 2 +- templates/league-table.php | 4 +- templates/player-details.php | 6 +- templates/player-gallery.php | 2 +- templates/player-list.php | 4 +- templates/player-roster.php | 2 +- 20 files changed, 129 insertions(+), 143 deletions(-) create mode 100644 includes/admin/settings/class-sp-settings-text.php diff --git a/includes/admin/class-sp-admin-settings.php b/includes/admin/class-sp-admin-settings.php index 2c671471..9b304c66 100644 --- a/includes/admin/class-sp-admin-settings.php +++ b/includes/admin/class-sp-admin-settings.php @@ -34,6 +34,7 @@ class SP_Admin_Settings { $settings[] = include( 'settings/class-sp-settings-events.php' ); $settings[] = include( 'settings/class-sp-settings-teams.php' ); $settings[] = include( 'settings/class-sp-settings-players.php' ); + $settings[] = include( 'settings/class-sp-settings-text.php' ); $settings[] = include( 'settings/class-sp-settings-config.php' ); self::$settings = apply_filters( 'sportspress_get_settings_pages', $settings ); diff --git a/includes/admin/class-sp-admin-welcome.php b/includes/admin/class-sp-admin-welcome.php index cd898497..131ff59a 100644 --- a/includes/admin/class-sp-admin-welcome.php +++ b/includes/admin/class-sp-admin-welcome.php @@ -220,7 +220,7 @@ class SP_Admin_Welcome { countries->country_dropdown_options( $selected ); ?>

-

+

__( 'Configure SportsPress', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'config_options' ), - - array( - 'title' => __( 'Sport', 'sportspress' ), - 'id' => 'sportspress_sport', - 'default' => 'soccer', - 'type' => 'select', - 'options' => $sports, - ), array( 'type' => 'outcomes' ), @@ -76,11 +67,7 @@ class SP_Settings_Config extends SP_Settings_Page { * Save settings */ public function save() { - if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) != $_POST['sportspress_sport'] ): - $sport = SP()->sports->$_POST['sportspress_sport']; - SP_Admin_Settings::configure_sport( $sport ); - update_option( '_sp_needs_welcome', 0 ); - elseif ( isset( $_POST['sportspress_primary_result'] ) ): + if ( isset( $_POST['sportspress_primary_result'] ) ): update_option( 'sportspress_primary_result', $_POST['sportspress_primary_result'] ); endif; @@ -114,7 +101,7 @@ class SP_Settings_Config extends SP_Settings_Page { - + @@ -169,7 +156,7 @@ class SP_Settings_Config extends SP_Settings_Page { - + @@ -237,7 +224,7 @@ class SP_Settings_Config extends SP_Settings_Page { - + @@ -287,7 +274,7 @@ class SP_Settings_Config extends SP_Settings_Page { - + @@ -344,7 +331,7 @@ class SP_Settings_Config extends SP_Settings_Page { - +   @@ -396,7 +383,7 @@ class SP_Settings_Config extends SP_Settings_Page { - + diff --git a/includes/admin/settings/class-sp-settings-events.php b/includes/admin/settings/class-sp-settings-events.php index d597ac1a..d6b977b1 100644 --- a/includes/admin/settings/class-sp-settings-events.php +++ b/includes/admin/settings/class-sp-settings-events.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 0.7 + * @version 0.8 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -37,9 +37,9 @@ class SP_Settings_Events extends SP_Settings_Page { */ public function get_settings() { - $settings = array( + return apply_filters( 'sportspress_event_settings', array( - array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'event_options' ), + array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'event_options' ), array( 'type' => 'delimiter' ), @@ -95,25 +95,7 @@ class SP_Settings_Events extends SP_Settings_Page { array( 'type' => 'sectionend', 'id' => 'calendar_options' ), - array( 'title' => __( 'Text', 'sportspress' ), 'type' => 'title', 'desc' => __( 'The following options affect how words are displayed on the frontend.', 'sportspress' ), 'id' => 'text_options' ), - - ); - - $strings = sp_get_text_options(); - - foreach ( sp_array_value( $strings, 'event', array() ) as $key => $value ): - $settings[] = array( - 'title' => $value, - 'id' => 'sportspress_event_' . $key . '_text', - 'default' => '', - 'placeholder' => $value, - 'type' => 'text', - ); - endforeach; - - $settings[] = array( 'type' => 'sectionend', 'id' => 'text_options' ); - - return apply_filters( 'sportspress_event_settings', $settings ); // End event settings + )); // End event settings } /** diff --git a/includes/admin/settings/class-sp-settings-general.php b/includes/admin/settings/class-sp-settings-general.php index 8db6438b..961eb62d 100644 --- a/includes/admin/settings/class-sp-settings-general.php +++ b/includes/admin/settings/class-sp-settings-general.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 0.7 + * @version 0.8 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -39,13 +39,22 @@ class SP_Settings_General extends SP_Settings_Page { * @return array */ public function get_settings() { + $sports = sp_get_sport_options(); - $settings = array( + return apply_filters( 'sportspress_general_settings', array( array( 'title' => __( 'General Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ), array( 'type' => 'country' ), + array( + 'title' => __( 'Sport', 'sportspress' ), + 'id' => 'sportspress_sport', + 'default' => 'soccer', + 'type' => 'select', + 'options' => $sports, + ), + array( 'type' => 'sectionend', 'id' => 'general_options' ), array( 'title' => __( 'Styles and Scripts', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'script_styling_options' ), @@ -89,25 +98,7 @@ class SP_Settings_General extends SP_Settings_Page { array( 'type' => 'sectionend', 'id' => 'script_styling_options' ), - array( 'title' => __( 'Text', 'sportspress' ), 'type' => 'title', 'desc' => __( 'The following options affect how words are displayed on the frontend.', 'sportspress' ), 'id' => 'text_options' ), - - ); - - $strings = sp_get_text_options(); - - foreach ( sp_array_value( $strings, 'general', array() ) as $key => $value ): - $settings[] = array( - 'title' => $value, - 'id' => 'sportspress_' . $key . '_text', - 'default' => '', - 'placeholder' => $value, - 'type' => 'text', - ); - endforeach; - - $settings[] = array( 'type' => 'sectionend', 'id' => 'text_options' ); - - return apply_filters( 'sportspress_general_settings', $settings ); // End general settings + )); // End general settings } /** @@ -117,9 +108,8 @@ class SP_Settings_General extends SP_Settings_Page { if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) != $_POST['sportspress_sport'] ): $sport = SP()->sports->$_POST['sportspress_sport']; SP_Admin_Settings::configure_sport( $sport ); - update_option( 'sportspress_sport', $_POST['sportspress_sport'] ); update_option( '_sp_needs_welcome', 0 ); - endif; + endif; $settings = $this->get_settings(); SP_Admin_Settings::save_fields( $settings ); diff --git a/includes/admin/settings/class-sp-settings-players.php b/includes/admin/settings/class-sp-settings-players.php index 2219fe2b..8d64e438 100644 --- a/includes/admin/settings/class-sp-settings-players.php +++ b/includes/admin/settings/class-sp-settings-players.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 0.7 + * @version 0.8 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -36,7 +36,7 @@ class SP_Settings_Players extends SP_Settings_Page { */ public function get_settings() { - $settings = array( + return apply_filters( 'sportspress_event_settings', array( array( 'title' => __( 'Player Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'player_options' ), @@ -83,25 +83,7 @@ class SP_Settings_Players extends SP_Settings_Page { array( 'type' => 'sectionend', 'id' => 'list_options' ), - array( 'title' => __( 'Text', 'sportspress' ), 'type' => 'title', 'desc' => __( 'The following options affect how words are displayed on the frontend.', 'sportspress' ), 'id' => 'text_options' ), - - ); - - $strings = sp_get_text_options(); - - foreach ( sp_array_value( $strings, 'player', array() ) as $key => $value ): - $settings[] = array( - 'title' => $value, - 'id' => 'sportspress_player_' . $key . '_text', - 'default' => '', - 'placeholder' => $value, - 'type' => 'text', - ); - endforeach; - - $settings[] = array( 'type' => 'sectionend', 'id' => 'text_options' ); - - return apply_filters( 'sportspress_event_settings', $settings ); // End player settings + )); // End player settings } } diff --git a/includes/admin/settings/class-sp-settings-teams.php b/includes/admin/settings/class-sp-settings-teams.php index 3b2cfc91..cd75a8fa 100644 --- a/includes/admin/settings/class-sp-settings-teams.php +++ b/includes/admin/settings/class-sp-settings-teams.php @@ -5,7 +5,7 @@ * @author ThemeBoy * @category Admin * @package SportsPress/Admin - * @version 0.7 + * @version 0.8 */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly @@ -36,7 +36,7 @@ class SP_Settings_Teams extends SP_Settings_Page { */ public function get_settings() { - $settings = array( + return apply_filters( 'sportspress_event_settings', array( array( 'title' => __( 'Team Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'team_options' ), @@ -84,25 +84,7 @@ class SP_Settings_Teams extends SP_Settings_Page { array( 'type' => 'sectionend', 'id' => 'table_options' ), - array( 'title' => __( 'Text', 'sportspress' ), 'type' => 'title', 'desc' => __( 'The following options affect how words are displayed on the frontend.', 'sportspress' ), 'id' => 'text_options' ), - - ); - - $strings = sp_get_text_options(); - - foreach ( sp_array_value( $strings, 'team', array() ) as $key => $value ): - $settings[] = array( - 'title' => $value, - 'id' => 'sportspress_team_' . $key . '_text', - 'default' => '', - 'placeholder' => $value, - 'type' => 'text', - ); - endforeach; - - $settings[] = array( 'type' => 'sectionend', 'id' => 'text_options' ); - - return apply_filters( 'sportspress_event_settings', $settings ); // End team settings + )); // End team settings } } diff --git a/includes/admin/settings/class-sp-settings-text.php b/includes/admin/settings/class-sp-settings-text.php new file mode 100644 index 00000000..e618d301 --- /dev/null +++ b/includes/admin/settings/class-sp-settings-text.php @@ -0,0 +1,65 @@ +id = 'text'; + $this->label = __( 'Text', 'sportspress' ); + + 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_save_' . $this->id, array( $this, 'save' ) ); + } + + /** + * Get settings array + * + * @return array + */ + public function get_settings() { + + $settings = array( + + array( 'title' => __( 'Text', 'sportspress' ), 'type' => 'title', 'desc' => __( 'The following options affect how words are displayed on the frontend.', 'sportspress' ), 'id' => 'text_options' ), + + ); + + $strings = sp_get_text_options(); + + foreach ( $strings as $key => $value ): + $settings[] = array( + 'title' => $value, + 'id' => 'sportspress_' . $key . '_text', + 'default' => '', + 'placeholder' => $value, + 'type' => 'text', + ); + endforeach; + + $settings[] = array( 'type' => 'sectionend', 'id' => 'text_options' ); + + return apply_filters( 'sportspress_event_settings', $settings ); // End event settings + } +} + +endif; + +return new SP_Settings_Text(); diff --git a/includes/class-sp-text.php b/includes/class-sp-text.php index c2978a09..a03039da 100644 --- a/includes/class-sp-text.php +++ b/includes/class-sp-text.php @@ -5,7 +5,7 @@ * The SportsPress text class stores editable strings. * * @class SP_Text - * @version 0.7 + * @version 0.8 * @package SportsPress/Classes * @category Class * @author ThemeBoy @@ -33,18 +33,15 @@ class SP_Text { $this->data[ $key ] = $value; } - public function string( $string, $context = null ){ + public function string( $string ){ if ( is_admin() ) return $string; $key = str_replace( '-', '_', sanitize_title( $string ) ); - if ( $context == null ) - $context = 'general'; - - if ( array_key_exists( $context, $this->data ) && array_key_exists( $key, $this->data[ $context ] ) ): - $string = get_option( 'sportspress_' . ( $context == 'general' ? '' : $context . '_' ) . $key . '_text' ); - return ( empty( $string ) ? $this->data[ $context ][ $key ] : $string ); + if ( array_key_exists( $key, $this->data ) ): + $string = get_option( 'sportspress_' . $key . '_text' ); + return ( empty( $string ) ? $this->data[ $key ] : $string ); else: return $string; endif; diff --git a/templates/event-calendar.php b/templates/event-calendar.php index 0e9b1bad..f63f8532 100644 --- a/templates/event-calendar.php +++ b/templates/event-calendar.php @@ -205,6 +205,6 @@ if ( $pad != 0 && $pad != 7 ) $calendar_output .= "\n\t\n\t\n\t\n\t"; if ( $id && $show_all_events_link ) - $calendar_output .= '' . SP()->text->string('View all events', 'event') . ''; + $calendar_output .= '' . SP()->text->string('View all events') . ''; echo apply_filters( 'sportspress_event_calendar', $calendar_output ); diff --git a/templates/event-details.php b/templates/event-details.php index 7157173a..2cc562b1 100644 --- a/templates/event-details.php +++ b/templates/event-details.php @@ -17,7 +17,7 @@ $time = get_the_time( get_option('time_format'), $id ); $leagues = get_the_terms( $id, 'sp_league' ); $seasons = get_the_terms( $id, 'sp_season' ); -$data = array( SP()->text->string('Date', 'event') => $date, SP()->text->string('Time', 'event') => $time ); +$data = array( SP()->text->string('Date') => $date, SP()->text->string('Time') => $time ); if ( $leagues ): $league = array_pop( $leagues ); @@ -29,7 +29,7 @@ if ( $seasons ): $data[ SP()->text->string('Season') ] = $season->name; endif; ?> -

text->string('Details', 'event'); ?>

+

text->string('Details'); ?>

diff --git a/templates/event-list.php b/templates/event-list.php index 241190d9..07f5fe12 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -32,22 +32,22 @@ extract( $defaults, EXTR_SKIP ); if ( isset( $columns ) ) $usecolumns = $columns; - echo ''; + echo ''; if ( $usecolumns == null || in_array( 'event', $usecolumns ) ) - echo ''; + echo ''; if ( $usecolumns == null || in_array( 'teams', $usecolumns ) ) - echo ''; + echo ''; if ( $usecolumns == null || in_array( 'time', $usecolumns ) ) - echo ''; + echo ''; if ( $usecolumns == null || in_array( 'venue', $usecolumns ) ) - echo ''; + echo ''; if ( $usecolumns == null || in_array( 'article', $usecolumns ) ) - echo ''; + echo ''; ?> @@ -129,9 +129,9 @@ extract( $defaults, EXTR_SKIP ); endif; if ( $event->post_content !== null ): if ( $event->post_status == 'publish' ): - echo SP()->text->string('Recap', 'event'); + echo SP()->text->string('Recap'); else: - echo SP()->text->string('Preview', 'event'); + echo SP()->text->string('Preview'); endif; endif; @@ -148,6 +148,6 @@ extract( $defaults, EXTR_SKIP );
' . SP()->text->string('Date', 'event') . '' . SP()->text->string('Date') . '' . SP()->text->string('Event', 'event') . '' . SP()->text->string('Event') . '' . SP()->text->string('Teams', 'event') . '' . SP()->text->string('Teams') . '' . SP()->text->string('Time', 'event') . '' . SP()->text->string('Time') . '' . SP()->text->string('Venue', 'event') . '' . SP()->text->string('Venue') . '' . SP()->text->string('Article', 'event') . '' . SP()->text->string('Article') . '
' . SP()->text->string('View all events', 'event') . ''; + echo '' . SP()->text->string('View all events') . ''; ?>
\ No newline at end of file diff --git a/templates/event-performance.php b/templates/event-performance.php index 0022c09c..cd48ec65 100644 --- a/templates/event-performance.php +++ b/templates/event-performance.php @@ -38,7 +38,7 @@ foreach( $teams as $key => $team_id ): # - text->string('Player', 'event'); ?> + text->string('Player'); ?> $label ): ?> @@ -102,7 +102,7 @@ foreach( $teams as $key => $team_id ):  '; - echo '' . SP()->text->string('Total', 'event') . ''; + echo '' . SP()->text->string('Total') . ''; endif; $row = $data[0]; diff --git a/templates/event-results.php b/templates/event-results.php index c8b8bf48..ac29810c 100644 --- a/templates/event-results.php +++ b/templates/event-results.php @@ -59,11 +59,11 @@ if ( empty( $table_rows ) ): else: - $output .= '

' . SP()->text->string('Team Results', 'event') . '

'; + $output .= '

' . SP()->text->string('Team Results') . '

'; $output .= '
' . '' . - ''; + ''; foreach( $result_labels as $key => $label ): $output .= ''; endforeach; diff --git a/templates/event-venue.php b/templates/event-venue.php index bd4ccba6..da29792f 100644 --- a/templates/event-venue.php +++ b/templates/event-venue.php @@ -32,7 +32,7 @@ foreach( $venues as $venue ): $latitude = sp_array_value( $meta, 'sp_latitude', 0 ); $longitude = sp_array_value( $meta, 'sp_longitude', 0 ); ?> -

text->string('Venue', 'event'); ?>

+

text->string('Venue'); ?>

' . SP()->text->string('Team', 'event') . '' . SP()->text->string('Team') . '' . $label . '
diff --git a/templates/league-table.php b/templates/league-table.php index 4e93d534..4e76913a 100644 --- a/templates/league-table.php +++ b/templates/league-table.php @@ -41,7 +41,7 @@ if ( ! $columns ) if ( ! is_array( $columns ) ) $columns = explode( ',', $columns ); -$output .= ''; +$output .= ''; foreach( $labels as $key => $label ): if ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) @@ -93,7 +93,7 @@ endforeach; $output .= '' . '
' . SP()->text->string('Pos', 'team') . '' . SP()->text->string('Pos') . '
'; if ( $show_full_table_link ) - $output .= '' . SP()->text->string('View full table', 'team') . ''; + $output .= '' . SP()->text->string('View full table') . ''; $output .= '
'; diff --git a/templates/player-details.php b/templates/player-details.php index dd99216f..43b463e7 100644 --- a/templates/player-details.php +++ b/templates/player-details.php @@ -28,20 +28,20 @@ $metrics = sp_get_player_metrics_data( $id ); $common = array(); if ( $nationality ): $country_name = sp_array_value( $countries, $nationality, null ); - $common[ SP()->text->string('Nationality', 'player') ] = $country_name ? ( $show_nationality_flags ? '' . $nationality . ' ' : '' ) . $country_name : '—'; + $common[ SP()->text->string('Nationality') ] = $country_name ? ( $show_nationality_flags ? '' . $nationality . ' ' : '' ) . $country_name : '—'; endif; $data = array_merge( $common, $metrics ); if ( $current_team ) - $data[ SP()->text->string('Current Team', 'player') ] = '' . get_the_title( $current_team ) . ''; + $data[ SP()->text->string('Current Team') ] = '' . get_the_title( $current_team ) . ''; if ( $past_teams ): $teams = array(); foreach ( $past_teams as $team ): $teams[] = '' . get_the_title( $team ) . ''; endforeach; - $data[ SP()->text->string('Past Teams', 'player') ] = implode( ', ', $teams ); + $data[ SP()->text->string('Past Teams') ] = implode( ', ', $teams ); endif; $output = '
' . diff --git a/templates/player-gallery.php b/templates/player-gallery.php index 29cf8fba..12d59bb8 100644 --- a/templates/player-gallery.php +++ b/templates/player-gallery.php @@ -136,6 +136,6 @@ $output .= "
\n"; if ( $show_all_players_link ) - $output .= '' . SP()->text->string('View all players', 'player') . ''; + $output .= '' . SP()->text->string('View all players') . ''; echo apply_filters( 'sportspress_player_gallery', $output ); diff --git a/templates/player-list.php b/templates/player-list.php index 72b7e96c..fb7cb14f 100644 --- a/templates/player-list.php +++ b/templates/player-list.php @@ -53,7 +53,7 @@ endif; if ( in_array( $orderby, array( 'number', 'name' ) ) ): $output .= '#'; else: - $output .= '' . SP()->text->string('Rank', 'player') . ''; + $output .= '' . SP()->text->string('Rank') . ''; endif; foreach( $labels as $key => $label ): @@ -106,6 +106,6 @@ endforeach; $output .= '' . '' . ''; if ( $show_all_players_link ) - $output .= '' . SP()->text->string('View all players', 'player') . ''; + $output .= '' . SP()->text->string('View all players') . ''; echo apply_filters( 'sportspress_player_list', $output ); diff --git a/templates/player-roster.php b/templates/player-roster.php index 95e19769..d02f83c5 100644 --- a/templates/player-roster.php +++ b/templates/player-roster.php @@ -92,7 +92,7 @@ foreach ( $positions as $position ): if ( in_array( $r['orderby'], array( 'number', 'name' ) ) ): $output .= '#'; else: - $output .= '' . SP()->text->string('Rank', 'player') . ''; + $output .= '' . SP()->text->string('Rank') . ''; endif; foreach( $labels as $key => $label ):