Skip to content

Commit

Permalink
Merge pull request #9 from mt-support/1.2.0-fix-settings-display
Browse files Browse the repository at this point in the history
1.2.0 fix settings display
  • Loading branch information
andrasguseo authored Oct 16, 2024
2 parents f698eae + 7741fee commit 11614c2
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 131 deletions.
17 changes: 11 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
=== The Events Calendar Extension: Relabeler ===
Contributors: ModernTribe
Donate link: http://m.tri.be/29
Contributors: theeventscalendar, aguseo
Donate link: https://evnt.is/29
Tags: events, calendar
Requires at least: 4.9
Tested up to: 5.3.2
Requires PHP: 5.6
Stable tag: 1.1.0
Requires at least: 6.3
Tested up to: 6.6.2
Requires PHP: 7.4
Stable tag: 1.2.0
License: GPL version 3 or any later version
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -36,6 +36,11 @@ We're always interested in your feedback and our [premium forums](https://theeve

== Changelog ==

= [1.2.0] 2024-10-09 =

* Fix - Make sure the settings are visible and work with the new TEC admin interface. [TECEXT-334]
* Tweak - Move settings to their separate sub-tab under Events > Settings > Display > Labels.

= [1.1.0] 2020-05-01 =

* Tweak - Rework the extension based on the new template for better compatibility.
Expand Down
303 changes: 185 additions & 118 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
namespace Tribe\Extensions\Relabeler;

use Tribe__Settings_Manager;
use TEC\Common\Admin\Entities\Div;
use TEC\Common\Admin\Entities\Link;
use TEC\Common\Admin\Entities\Heading;
use TEC\Common\Admin\Entities\Paragraph;
use TEC\Common\Admin\Entities\Plain_Text;
use Tribe\Utils\Element_Classes as Classes;

if ( ! class_exists( Settings::class ) ) {
/**
Expand Down Expand Up @@ -36,10 +42,186 @@ public function __construct( $options_prefix ) {

$this->set_options_prefix( $options_prefix );

add_action( 'tec_events_settings_tab_display', [ $this, 'add_settings_tab' ] );

// Add settings specific to OSM
add_action( 'admin_init', [ $this, 'add_settings' ] );
}

/**
* Add a tab to the Display settings.
*
* @since 1.2.0
*
* @param \Tribe__Settings_Tab $display_tab Object containing the data for the settings tab.
*
* @return void
*/
public function add_settings_tab( $display_tab ) {
$labels_tab = new \Tribe__Settings_Tab(
'display-labels-tab',
esc_html_x( 'Labels', 'Settings tab label', 'tribe-ext-relabeler' ),
[
'priority' => 20,
'fields' => $this->add_settings(),
]
);

$display_tab->add_child( $labels_tab );
}

/**
* Add the settings to the settings tab.
*
* @since 1.2.0
*
* @return array
*/
public function add_settings() {
$settings = [
'tec-settings-form__header-block' => ( new Div( new Classes( [ 'tec-settings-form__header-block', 'tec-settings-form__header-block--horizontal' ] ) ) )->add_children(
[
new Heading(
_x( 'Labels', 'Labels settings header', 'tribe-ext-relabeler' ),
2,
new Classes( [ 'tec-settings-form__section-header' ] )
),
( new Paragraph( new Classes( [ 'tec-settings-form__section-description' ] ) ) )->add_children(
[
new Plain_Text(
__(
"The following fields allow you to change the default labels. Inputting something other than the default will change that word everywhere it appears. ",
'tribe-ext-relabeler'
)
),
new Plain_Text(
// Translators: Beginning of the sentence "Remember to resave the permalinks after doing any changes.
__( 'Remember to ', 'tribe-ext-relabeler' ),
),
new Link(
admin_url( 'options-permalink.php' ),
// Translators: Middle of the sentence "Remember to resave the permalinks after doing any changes.
__( 'resave the permalinks', 'tribe-ext-relabeler' ),
),
new Plain_Text(
// Translators: End of the sentence "Remember to resave the permalinks after doing any changes.
__( ' after doing any changes.', 'tribe-ext-relabeler' ),
),
]
),
]
),
];

$fields_setup = [
'labels_heading' => [
'type' => 'html',
'html' => '<h3 class="tec-settings-form__section-header tec-settings-form__section-header--sub">' . esc_html__( 'Labels', 'tribe-ext-relabeler' ) . '</h3>',
],
'label_event_single' => [
'type' => 'text',
'label' => esc_html__( 'Event', 'the-events-calendar' ),
'default' => esc_attr__( 'Event', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Singular label for Events.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_event_single_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'event', 'the-events-calendar' ),
'default' => esc_attr__( 'event', 'the-events-calendar' ),
'tooltip' => sprintf(
esc_html__( 'Lowercase singular label for Events. You might wish to also modify the "Events URL Slug" found in the %s events settings tab.', 'tribe-ext-relabeler' ),
$this->general_settings_tab_link()
),
'validation_type' => 'html',
],
'label_event_plural' => [
'type' => 'text',
'label' => esc_html__( 'Events', 'the-events-calendar' ),
'default' => esc_attr__( 'Events', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Plural label for Events.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_event_plural_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'events', 'the-events-calendar' ),
'default' => esc_attr__( 'events', 'the-events-calendar' ),
'tooltip' => sprintf(
esc_html__( 'Lowercase plural label for Events. You might wish to also modify the "Single Event URL Slug" found in the %s events settings tab.', 'tribe-ext-relabeler' ),
$this->general_settings_tab_link()
),
'validation_type' => 'html',
],
'label_venue_single' => [
'type' => 'text',
'label' => esc_html__( 'Venue', 'the-events-calendar' ),
'default' => esc_attr__( 'Venue', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Singular label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_venue_single_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'venue', 'the-events-calendar' ),
'default' => esc_attr__( 'venue', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase singular label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_venue_plural' => [
'type' => 'text',
'label' => esc_html__( 'Venues', 'the-events-calendar' ),
'default' => esc_attr__( 'Venues', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Plural label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_venue_plural_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'venues', 'the-events-calendar' ),
'default' => esc_attr__( 'venues', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase plural label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_single' => [
'type' => 'text',
'label' => esc_html__( 'Organizer', 'the-events-calendar' ),
'default' => esc_attr__( 'Organizer', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Singular label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_single_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'organizer', 'the-events-calendar' ),
'default' => esc_attr__( 'organizer', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase singular label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_plural' => [
'type' => 'text',
'label' => esc_html__( 'Organizers', 'the-events-calendar' ),
'default' => esc_attr__( 'Organizers', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Plural label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_plural_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'organizers', 'the-events-calendar' ),
'default' => esc_attr__( 'organizers', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase plural label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
];

$fields = [];
foreach( $fields_setup as $key => $value ) {
$fields[ $this->get_options_prefix() . $key ] = $value;
}

$fields = tribe( 'settings' )->wrap_section_content( 'tec-events-settings-calendar-template', $fields );

$settings += $fields;

return $settings;
}

/**
* Allow access to set the Settings Helper property.
*
Expand Down Expand Up @@ -94,7 +276,7 @@ public function get_options_prefix() {
/**
* Given an option key, get this extension's option value.
*
* This automatically prepends this extension's option prefix so you can just do `$this->get_option( 'a_setting' )`.
* This automatically prepends this extension's option prefix, so you can just do `$this->get_option( 'a_setting' )`.
*
* @see tribe_get_option()
*
Expand Down Expand Up @@ -171,7 +353,7 @@ public function get_all_raw_options() {
/**
* Given an option key, delete this extension's option value.
*
* This automatically prepends this extension's option prefix so you can just do `$this->delete_option( 'a_setting' )`.
* This automatically prepends this extension's option prefix, so you can just do `$this->delete_option( 'a_setting' )`.
*
* @param string $key
*
Expand All @@ -187,121 +369,6 @@ public function delete_option( $key = '' ) {
return Tribe__Settings_Manager::set_options( $options );
}

/**
* Adds a new section of fields to Events > Settings > Display tab, appearing after the "Basic Template" section
* and before the "Date Format Settings" section.
*/
public function add_settings() {

$fields = [
'labels_heading' => [
'type' => 'html',
'html' => '<h3>' . esc_html__( 'Labels', 'tribe-ext-relabeler' ) . '</h3>',
],
'labels_helper_text' => [
'type' => 'html',
'html' => '<p>' . esc_html__( 'The following fields allow you to change the default labels. Inputting something other than the default will change that word everywhere it appears.', 'tribe-ext-relabeler' ) . '</p>',
],
'label_event_single' => [
'type' => 'text',
'label' => esc_html__( 'Event', 'the-events-calendar' ),
'default' => esc_attr__( 'Event', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Singular label for Events.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_event_single_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'event', 'the-events-calendar' ),
'default' => esc_attr__( 'event', 'the-events-calendar' ),
'tooltip' => sprintf(
esc_html__( 'Lowercase singular label for Events. You might wish to also modify the "Events URL Slug" found in the %s events settings tab.', 'tribe-ext-relabeler' ),
$this->general_settings_tab_link()
),
'validation_type' => 'html',
],
'label_event_plural' => [
'type' => 'text',
'label' => esc_html__( 'Events', 'the-events-calendar' ),
'default' => esc_attr__( 'Events', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Plural label for Events.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_event_plural_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'events', 'the-events-calendar' ),
'default' => esc_attr__( 'events', 'the-events-calendar' ),
'tooltip' => sprintf(
esc_html__( 'Lowercase plural label for Events. You might wish to also modify the "Single Event URL Slug" found in the %s events settings tab.', 'tribe-ext-relabeler' ),
$this->general_settings_tab_link()
),
'validation_type' => 'html',
],
'label_venue_single' => [
'type' => 'text',
'label' => esc_html__( 'Venue', 'the-events-calendar' ),
'default' => esc_attr__( 'Venue', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Singular label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_venue_single_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'venue', 'the-events-calendar' ),
'default' => esc_attr__( 'venue', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase singular label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_venue_plural' => [
'type' => 'text',
'label' => esc_html__( 'Venues', 'the-events-calendar' ),
'default' => esc_attr__( 'Venues', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Plural label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_venue_plural_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'venues', 'the-events-calendar' ),
'default' => esc_attr__( 'venues', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase plural label for Venues.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_single' => [
'type' => 'text',
'label' => esc_html__( 'Organizer', 'the-events-calendar' ),
'default' => esc_attr__( 'Organizer', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Singular label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_single_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'organizer', 'the-events-calendar' ),
'default' => esc_attr__( 'organizer', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase singular label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_plural' => [
'type' => 'text',
'label' => esc_html__( 'Organizers', 'the-events-calendar' ),
'default' => esc_attr__( 'Organizers', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Plural label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
'label_organizer_plural_lowercase' => [
'type' => 'text',
'label' => esc_html__( 'organizers', 'the-events-calendar' ),
'default' => esc_attr__( 'organizers', 'the-events-calendar' ),
'tooltip' => esc_html__( 'Lowercase plural label for Organizers.', 'tribe-ext-relabeler' ),
'validation_type' => 'html',
],
];

$this->settings_helper->add_fields(
$this->prefix_settings_field_keys( $fields ),
'display',
'tribeEventsDateFormatSettingsTitle',
true
);
}

/**
* Add the options prefix to each of the array keys.
*
Expand All @@ -328,7 +395,7 @@ function ( $key ) {
* @return string HTML link element to the general settings tab
*/
protected function general_settings_tab_link() {
$url = \Tribe__Settings::instance()->get_url( [ 'tab' => 'general' ] );
$url = tribe( 'settings' )->get_tab_url( 'general-viewing-tab' );

return sprintf(
'<a href="%2$s">%1$s</a>',
Expand Down
Loading

0 comments on commit 11614c2

Please sign in to comment.