Skip to content

Commit

Permalink
Merge pull request #9 from mt-support/fix/1.3.0-new-admin-ui
Browse files Browse the repository at this point in the history
Compatibility with new admin UI
  • Loading branch information
andrasguseo authored Oct 16, 2024
2 parents 24d3d2e + 77ebaf9 commit 9621d5f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 59 deletions.
67 changes: 67 additions & 0 deletions languages/tec-labs-remove-past-events.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (C) 2024 The Events Calendar
# This file is distributed under the GPL version 3 or any later version.
msgid ""
msgstr ""
"Project-Id-Version: The Events Calendar Extension: Remove Past Events 1.2.2\n"
"Report-Msgid-Bugs-To: The Events Calendar <https://support.theeventscalendar.com/>\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-10-16T14:56:04+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.9.0\n"
"X-Domain: tec-labs-remove-past-events\n"

#. Plugin Name of the plugin
msgid "The Events Calendar Extension: Remove Past Events"
msgstr ""

#. Plugin URI of the plugin
msgid "https://theeventscalendar.com/extensions/remove-past-events"
msgstr ""

#. Description of the plugin
msgid "Additional frequencies to remove past events."
msgstr ""

#. Author of the plugin
msgid "The Events Calendar"
msgstr ""

#. Author URI of the plugin
msgid "https://evnt.is/1971"
msgstr ""

#: plugin.php:56
msgid "Couldn't properly load \"The Events Calendar Extension: Remove Past Events\" the extension was deactivated."
msgstr ""

#: src/Tec/Plugin.php:144
msgid "15 minutes"
msgstr ""

#: src/Tec/Plugin.php:145
msgid "1 hour"
msgstr ""

#: src/Tec/Plugin.php:146
msgid "12 hours"
msgstr ""

#: src/Tec/Plugin.php:147
msgid "1 day"
msgstr ""

#: src/Tec/Plugin.php:148
msgid "3 days"
msgstr ""

#: src/Tec/Plugin.php:149
msgid "1 week"
msgstr ""

#: src/Tec/Plugin.php:150
msgid "2 weeks"
msgstr ""
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://theeventscalendar.com/extensions/remove-past-events
* GitHub Plugin URI: https://github.com/mt-support/tec-labs-remove-past-events
* Description: Additional frequencies to remove past events.
* Version: 1.2.1
* Version: 1.2.2
* Author: The Events Calendar
* Author URI: https://evnt.is/1971
* License: GPL version 3 or any later version
Expand Down
10 changes: 7 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Contributors: theeventscalendar
Donate link: https://evnt.is/29
Tags: events, calendar
Requires at least: 5.8.6
Tested up to: 6.2.0
Requires at least: 6.3.0
Tested up to: 6.6.2
Requires PHP: 7.4
Stable tag: 1.2.0
Stable tag: 1.2.2
License: GPL version 3 or any later version
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand All @@ -32,6 +32,10 @@ We're always interested in your feedback and our [Help Desk](https://support.the

== Changelog ==

= [1.2.2] 2024-10-11 =

* Fix - Added compatibility for the new admin UI. [TECEXT-335]

= [1.2.1] 2023-12-11 =

* Fix - Added compatibility to The Events Calendar 6.0 data structure. [ECP-1604]
Expand Down
96 changes: 42 additions & 54 deletions src/Tec/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Plugin extends Service_Provider {
*
* @var string
*/
const VERSION = '1.2.1';
const VERSION = '1.2.2';

/**
* Stores the base slug for the plugin.
Expand Down Expand Up @@ -91,9 +91,9 @@ public function register() {
return;
}

add_filter( 'tribe-event-general-settings-fields', [ $this, 'option_filter' ] );
add_filter( 'tribe_general_settings_tab_fields', [ $this, 'option_filter' ] );
add_action( 'plugins_loaded', [ $this, 'reschedule_crons' ], 99 );
add_filter( 'tribe_general_settings_maintenance_section', [ $this, 'option_filter' ] );

add_filter( 'tec_events_event_cleaner_trash_cron_frequency', [ $this, 'reschedule_crons' ] );

$this->container->register( Hooks::class );
$this->container->register( Assets::class );
Expand Down Expand Up @@ -129,58 +129,51 @@ protected function register_plugin_dependencies() {
* Adjusting the dropdown options for trashing and deleting past events.
*
* @since 1.2.1 Changing option values to a 'frequency|interval' format.
* @since 1.2.2 Adjusting option values to keep the default values compatible.
* After enabling the extension, the setting dropdown will keep the current setting instead of
* reverting to 'Disabled' while the saved setting would still be something else due to the
* different option value (e.g. "9" vs. "9|month").
*
* @param array<string,string> $fields The array of option values.
*
* @return array The modified option values.
*/
function option_filter( $fields ) {
$new_values = [
$new_values = [
null => esc_html__( 'Disabled', 'the-events-calendar' ),
'15|minute' => esc_html__( '15 minutes', 'the-events-calendar' ),
'1|hour' => esc_html__( '1 hour', 'the-events-calendar' ),
'12|hours' => esc_html__( '12 hours', 'the-events-calendar' ),
'1|day' => esc_html__( '1 day', 'the-events-calendar' ),
'3|day' => esc_html__( '3 days', 'the-events-calendar' ),
'1|week' => esc_html__( '1 week', 'the-events-calendar' ),
'2|week' => esc_html__( '2 weeks', 'the-events-calendar' ),
'1|month' => esc_html__( '1 month', 'the-events-calendar' ),
'3|month' => esc_html__( '3 months', 'the-events-calendar' ),
'6|month' => esc_html__( '6 months', 'the-events-calendar' ),
'9|month' => esc_html__( '9 months', 'the-events-calendar' ),
'1|year' => esc_html__( '1 year', 'the-events-calendar' ),
'2|year' => esc_html__( '2 years', 'the-events-calendar' ),
'3|year' => esc_html__( '3 years', 'the-events-calendar' ),
'15|minute' => esc_html__( '15 minutes', 'tec-labs-remove-past-events' ),
'1|hour' => esc_html__( '1 hour', 'tec-labs-remove-past-events' ),
'12|hour' => esc_html__( '12 hours', 'tec-labs-remove-past-events' ),
'1|day' => esc_html__( '1 day', 'tec-labs-remove-past-events' ),
'3|day' => esc_html__( '3 days', 'tec-labs-remove-past-events' ),
'1|week' => esc_html__( '1 week', 'tec-labs-remove-past-events' ),
'2|week' => esc_html__( '2 weeks', 'tec-labs-remove-past-events' ),
'1' => esc_html__( '1 month', 'the-events-calendar' ),
'3' => esc_html__( '3 months', 'the-events-calendar' ),
'6' => esc_html__( '6 months', 'the-events-calendar' ),
'9' => esc_html__( '9 months', 'the-events-calendar' ),
'12' => esc_html__( '1 year', 'the-events-calendar' ),
'24' => esc_html__( '2 years', 'the-events-calendar' ),
'36' => esc_html__( '3 years', 'the-events-calendar' ),
];
$fields['delete-past-events']['options'] = $new_values;

$fields['trash-past-events']['options'] = $new_values;

return $fields;
}

/**
* Triggering the rescheduling of crons
*
* @return void
*/
function reschedule_crons() {
$this->reschedule_trash_or_del_event_cron( 'tribe_trash_event_cron' );
$this->reschedule_trash_or_del_event_cron( 'tribe_del_event_cron' );
}

/**
* Rescheduling the crons handling the trashing and deleting.
*
* @param string $cron The slug of the cron.
* @since 1.2.2 Adjust cron frequency calculation.
* Remove $cron parameter.
*
* @return void
* @return string The frequency string how often the cron should run.
*/
function reschedule_trash_or_del_event_cron( $cron ) {
if ( 'tribe_trash_event_cron' == $cron ) {
$time = tribe_get_option( 'trash-past-events', 43200 );
} else {
$time = tribe_get_option( 'delete-past-events', 43200 );
}
function reschedule_crons() {
// Get the setting, default to 1 month.
$time = tribe_get_option( 'trash-past-events', 1 );

/**
* The frequency we want to run the cron on.
*
Expand All @@ -193,25 +186,20 @@ function reschedule_trash_or_del_event_cron( $cron ) {
* - fifteendays
* - monthly
*/
$frequency_struct = explode( '|', $time );
$feq = $frequency_struct[0];
$interval = $frequency_struct[1] ?? 'month';

// For 1 minute and 15 minutes
if ( $time < 60 ) {
$frequency = 'tribe-every15mins';
}
// For 1 hour and 12 hours
elseif ( $time < 1440 ) {
$frequency = 'hourly';
// For 15 minutes (and other minutes)
if ( str_starts_with( $interval, 'minute' ) ) {
return 'tribe-every15mins';
}
// For 1 day and longer
else {
$frequency = 'daily';
// For 1 hour and 12 hours (and other hours)
elseif ( str_starts_with( $interval, 'hour' ) ) {
return 'hourly';
}

$scheduled = wp_next_scheduled( $cron );

if ( $scheduled && $frequency !== wp_get_schedule( $cron ) ) {
wp_unschedule_event( $scheduled, $cron );
wp_schedule_event( time(), $frequency, $cron );
}
// For 1 day and longer
return 'twicedaily';
}
}
2 changes: 1 addition & 1 deletion src/Tec/Plugin_Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Plugin_Register extends Abstract_Plugin_Register {
protected $main_class = Plugin::class;
protected $dependencies = [
'parent-dependencies' => [
'Tribe__Events__Main' => '6.3.1-dev',
'Tribe__Events__Main' => '6.7.0-dev',
],
];
}

0 comments on commit 9621d5f

Please sign in to comment.