From 43776d25b90baae90fca967dbd294a1c8f1871b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Wed, 19 Jan 2022 22:48:47 +0100 Subject: [PATCH 1/5] Renaming to tec-labs --- plugin.php | 6 +++--- src/Tec/Hooks.php | 2 +- src/Tec/Plugin.php | 2 +- src/Tec/Settings.php | 10 +++++----- src/Tec/Settings_Helper.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin.php b/plugin.php index e83662a..26601a2 100644 --- a/plugin.php +++ b/plugin.php @@ -3,13 +3,13 @@ * Plugin Name: The Events Calendar Extension: Remove Past Events Plus * Plugin URI: * GitHub Plugin URI: https://github.com/mt-support/tec-labs-remove-past-events-plus - * Description: + * Description: More times to remove past events. * Version: 1.0.0 * Author: The Events Calendar * Author URI: https://evnt.is/1971 * License: GPL version 3 or any later version * License URI: https://www.gnu.org/licenses/gpl-3.0.html - * Text Domain: __TRIBE_DOMAIN__ + * Text Domain: tec-labs-remove-past-events-plus * * This plugin is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,7 +53,7 @@ function tribe_extension_remove_past_events_plus() { if ( ! class_exists( '\Tribe\Extensions\Remove_Past_Events_Plus\Plugin' ) ) { tribe_transient_notice( 'remove-past-events-plus', - '

' . esc_html__( 'Couldn\'t properly load "The Events Calendar Extension: Remove Past Events Plus" the extension was deactivated.', '__TRIBE_DOMAIN__' ) . '

', + '

' . esc_html__( 'Couldn\'t properly load "The Events Calendar Extension: Remove Past Events Plus" the extension was deactivated.', 'tec-labs-remove-past-events-plus' ) . '

', [], // 1 second after that make sure the transient is removed. 1 diff --git a/src/Tec/Hooks.php b/src/Tec/Hooks.php index 5fc667a..da47a90 100644 --- a/src/Tec/Hooks.php +++ b/src/Tec/Hooks.php @@ -70,7 +70,7 @@ protected function add_filters() { */ public function load_text_domains() { $mopath = tribe( Plugin::class )->plugin_dir . 'lang/'; - $domain = '__TRIBE_DOMAIN__'; + $domain = 'tec-labs-remove-past-events-plus'; // This will load `wp-content/languages/plugins` files first. Common::instance()->load_text_domain( $domain, $mopath ); diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index 8f9931a..bd27496 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -150,7 +150,7 @@ protected function register_plugin_dependencies() { * TODO: Remove if not using settings */ private function get_options_prefix() { - return (string) str_replace( '-', '_', 'tribe-ext-remove-past-events-plus' ); + return (string) str_replace( '-', '_', 'tec-labs-remove-past-events-plus' ); } /** diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php index abbc0e2..f9cb86d 100644 --- a/src/Tec/Settings.php +++ b/src/Tec/Settings.php @@ -88,7 +88,7 @@ public function get_settings_helper() { */ private function set_options_prefix( $options_prefix = '' ) { if ( empty( $opts_prefix ) ) { - $opts_prefix = str_replace( '-', '_', '__TRIBE_DOMAIN__' ); // The text domain. + $opts_prefix = str_replace( '-', '_', 'tec-labs-remove-past-events-plus' ); // The text domain. } $opts_prefix = $opts_prefix . '_'; @@ -237,8 +237,8 @@ public function add_settings() { // TODO: Settings heading end. 'a_setting' => [ // TODO: Change setting. 'type' => 'text', - 'label' => esc_html__( 'Example setting', '__TRIBE_DOMAIN__' ), - 'tooltip' => sprintf( esc_html__( 'Example setting description. Enter your custom URL, including "http://" or "https://", for example %s.', '__TRIBE_DOMAIN__' ), 'https://demo.theeventscalendar.com/' ), + 'label' => esc_html__( 'Example setting', 'tec-labs-remove-past-events-plus' ), + 'tooltip' => sprintf( esc_html__( 'Example setting description. Enter your custom URL, including "http://" or "https://", for example %s.', 'tec-labs-remove-past-events-plus' ), 'https://demo.theeventscalendar.com/' ), 'validation_type' => 'html', ], ]; @@ -279,10 +279,10 @@ function ( $key ) { * @return string */ private function get_example_intro_text() { - $result = '

' . esc_html_x( 'Example Extension Setup', 'Settings header', '__TRIBE_DOMAIN__' ) . '

'; + $result = '

' . esc_html_x( 'Example Extension Setup', 'Settings header', 'tec-labs-remove-past-events-plus' ) . '

'; $result .= '
'; $result .= '

'; - $result .= esc_html_x( 'Some text here about this settings section.', 'Setting section description', '__TRIBE_DOMAIN__' ); + $result .= esc_html_x( 'Some text here about this settings section.', 'Setting section description', 'tec-labs-remove-past-events-plus' ); $result .= '

'; $result .= '
'; diff --git a/src/Tec/Settings_Helper.php b/src/Tec/Settings_Helper.php index 788f59e..18e248b 100644 --- a/src/Tec/Settings_Helper.php +++ b/src/Tec/Settings_Helper.php @@ -135,7 +135,7 @@ public function filter_options( $fields, $tab ) { $misc_heading = [ 'tribeMiscSettings' => [ 'type' => 'html', - 'html' => '

' . esc_html__( 'Miscellaneous Settings', '__TRIBE_DOMAIN__' ) . '

', + 'html' => '

' . esc_html__( 'Miscellaneous Settings', 'tec-labs-remove-past-events-plus' ) . '

', ], ]; $fields = Tribe__Main::array_insert_before_key( 'tribe-form-content-end', $fields, $misc_heading ); From 41b24035aa9e8672fee7caae310e1d9b4d2d53f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Wed, 19 Jan 2022 23:26:53 +0100 Subject: [PATCH 2/5] Added code --- src/Tec/Plugin.php | 129 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 128 insertions(+), 1 deletion(-) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index bd27496..d802dd5 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -104,7 +104,9 @@ public function register() { // Start binds. - + add_filter( 'tribe_events_delete_old_events_sql', [ $this, 'cleanup_query' ] ); + add_filter( 'tribe-event-general-settings-fields', [ $this, 'option_filter' ] ); + add_action( 'plugins_loaded', [ $this, 'reschedule_crons' ], 99 ); // End binds. @@ -196,4 +198,129 @@ public function get_option( $option, $default = '' ) { return $settings->get_option( $option, $default ); } + + /** + * Adjusting the cleanup query to use minutes instead of months + * + * @param string $sql The cleanup query in SQL format. + * + * @return string The modified cleanup query in SQL format. + */ + public function cleanup_query( $sql ) { + global $wpdb; + + $posts_with_parents_sql = " +SELECT DISTINCT post_parent +FROM {$wpdb->posts} +WHERE +post_type= '$event_post_type' +AND post_parent <> 0 +"; + + $sql = " +SELECT post_id +FROM {$wpdb->posts} AS t1 +INNER JOIN {$wpdb->postmeta} AS t2 ON t1.ID = t2.post_id +WHERE +t1.post_type = %s +AND t2.meta_key = '_EventEndDate' +AND t2.meta_value <= DATE_SUB( CURRENT_TIMESTAMP(), INTERVAL %d MINUTE ) +AND t2.meta_value != 0 +AND t2.meta_value != '' +AND t2.meta_value IS NOT NULL +AND t1.post_parent = 0 +AND t1.ID NOT IN ( $posts_with_parents_sql ) +"; + + return $sql; + } + + /** + * Adjusting the dropdown options for trashing and deleting past events. + * + * @param array $fields The array of option values. + * + * @return array The modified option values. + */ + function option_filter( $fields ) { + $new_values = [ + null => esc_html__( 'Disabled', 'the-events-calendar' ), + 1 => esc_html__( '1 minute', 'the-events-calendar' ), + 15 => esc_html__( '15 minutes', 'the-events-calendar' ), + 60 => esc_html__( '1 hour', 'the-events-calendar' ), + 720 => esc_html__( '12 hours', 'the-events-calendar' ), + 1440 => esc_html__( '1 day', 'the-events-calendar' ), + 4320 => esc_html__( '3 days', 'the-events-calendar' ), + 10080 => esc_html__( '1 week', 'the-events-calendar' ), + 20160 => esc_html__( '2 weeks', 'the-events-calendar' ), + 43200 => esc_html__( '1 month', 'the-events-calendar' ), + 129600 => esc_html__( '3 months', 'the-events-calendar' ), + 259200 => esc_html__( '6 months', 'the-events-calendar' ), + 388800 => esc_html__( '9 months', 'the-events-calendar' ), + 525600 => esc_html__( '1 year', 'the-events-calendar' ), + 1051200 => esc_html__( '2 years', 'the-events-calendar' ), + 1576800 => 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' ); + } + + /** + * Recheduling the crons handling the trashing and deleting. + * + * @param string $cron The slug of the cron. + * + * @return void + */ + 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 ); + } + /** + * The frequency we want to run the cron on. + * + * Possible values: + * - tribe-every15mins (recommended for removing "immediately") + * - hourly + * - twicedaily + * - daily (recommended for removing day-old and older) + * - weekly + * - fifteendays + * - monthly + */ + + // For 1 minute and 15 minutes + if ( $time < 60 ) { + $frequency = 'tribe-every15mins'; + } + // For 1 hour and 12 hours + elseif ( $time < 1440 ) { + $frequency = 'hourly'; + } + // For 1 day and longer + else { + $frequency = 'daily'; + } + + $scheduled = wp_next_scheduled( $cron ); + + if ( $scheduled && $frequency !== wp_get_schedule( $cron ) ) { + wp_unschedule_event( $scheduled, $cron ); + wp_schedule_event( time(), $frequency, $cron ); + } + } } From c114afa25461e007748f5d4bfd4cd6d8e79202bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 20 Jan 2022 10:40:59 +0100 Subject: [PATCH 3/5] Resolved TODOs --- src/Tec/Plugin.php | 72 --------- src/Tec/Settings.php | 292 ------------------------------------ src/Tec/Settings_Helper.php | 176 ---------------------- 3 files changed, 540 deletions(-) delete mode 100644 src/Tec/Settings.php delete mode 100644 src/Tec/Settings_Helper.php diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index d802dd5..68d7e0c 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -65,15 +65,6 @@ class Plugin extends \tad_DI52_ServiceProvider { */ public $plugin_url; - /** - * @since 1.0.0 - * - * @var Settings - * - * TODO: Remove if not using settings - */ - private $settings; - /** * Setup the Extension's properties. * @@ -98,10 +89,6 @@ public function register() { return; } - // Do the settings. - // TODO: Remove if not using settings - $this->get_settings(); - // Start binds. add_filter( 'tribe_events_delete_old_events_sql', [ $this, 'cleanup_query' ] ); @@ -140,65 +127,6 @@ protected function register_plugin_dependencies() { $this->container->singleton( 'extension.remove_past_events_plus', $plugin_register ); } - /** - * Get this plugin's options prefix. - * - * Settings_Helper will append a trailing underscore before each option. - * - * @return string - * - * @see \Tribe\Extensions\Remove_Past_Events_Plus\Settings::set_options_prefix() - * - * TODO: Remove if not using settings - */ - private function get_options_prefix() { - return (string) str_replace( '-', '_', 'tec-labs-remove-past-events-plus' ); - } - - /** - * Get Settings instance. - * - * @return Settings - * - * TODO: Remove if not using settings - */ - private function get_settings() { - if ( empty( $this->settings ) ) { - $this->settings = new Settings( $this->get_options_prefix() ); - } - - return $this->settings; - } - - /** - * Get all of this extension's options. - * - * @return array - * - * TODO: Remove if not using settings - */ - public function get_all_options() { - $settings = $this->get_settings(); - - return $settings->get_all_options(); - } - - /** - * Get a specific extension option. - * - * @param $option - * @param string $default - * - * @return array - * - * TODO: Remove if not using settings - */ - public function get_option( $option, $default = '' ) { - $settings = $this->get_settings(); - - return $settings->get_option( $option, $default ); - } - /** * Adjusting the cleanup query to use minutes instead of months * diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php deleted file mode 100644 index f9cb86d..0000000 --- a/src/Tec/Settings.php +++ /dev/null @@ -1,292 +0,0 @@ -settings_helper = new Settings_Helper(); - - $this->set_options_prefix( $options_prefix ); - - // Remove settings specific to Google Maps - add_action( 'admin_init', [ $this, 'remove_settings' ] ); - - // Add settings specific to OSM - add_action( 'admin_init', [ $this, 'add_settings' ] ); - } - - /** - * Allow access to set the Settings Helper property. - * - * @see get_settings_helper() - * - * @param Settings_Helper $helper - * - * @return Settings_Helper - */ - public function set_settings_helper( Settings_Helper $helper ) { - $this->settings_helper = $helper; - - return $this->get_settings_helper(); - } - - /** - * Allow access to get the Settings Helper property. - * - * @see set_settings_helper() - */ - public function get_settings_helper() { - return $this->settings_helper; - } - - /** - * Set the options prefix to be used for this extension's settings. - * - * Recommended: the plugin text domain, with hyphens converted to underscores. - * Is forced to end with a single underscore. All double-underscores are converted to single. - * - * @see get_options_prefix() - * - * @param string $options_prefix - */ - private function set_options_prefix( $options_prefix = '' ) { - if ( empty( $opts_prefix ) ) { - $opts_prefix = str_replace( '-', '_', 'tec-labs-remove-past-events-plus' ); // The text domain. - } - - $opts_prefix = $opts_prefix . '_'; - - $this->options_prefix = str_replace( '__', '_', $opts_prefix ); - } - - /** - * Get this extension's options prefix. - * - * @see set_options_prefix() - * - * @return string - */ - public function get_options_prefix() { - return $this->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' )`. - * - * @see tribe_get_option() - * - * @param string $key - * @param string $default - * - * @return mixed - */ - public function get_option( $key = '', $default = '' ) { - $key = $this->sanitize_option_key( $key ); - - return tribe_get_option( $key, $default ); - } - - /** - * Get an option key after ensuring it is appropriately prefixed. - * - * @param string $key - * - * @return string - */ - private function sanitize_option_key( $key = '' ) { - $prefix = $this->get_options_prefix(); - - if ( 0 === strpos( $key, $prefix ) ) { - $prefix = ''; - } - - return $prefix . $key; - } - - /** - * Get an array of all of this extension's options without array keys having the redundant prefix. - * - * @return array - */ - public function get_all_options() { - $raw_options = $this->get_all_raw_options(); - - $result = []; - - $prefix = $this->get_options_prefix(); - - foreach ( $raw_options as $key => $value ) { - $abbr_key = str_replace( $prefix, '', $key ); - $result[ $abbr_key ] = $value; - } - - return $result; - } - - /** - * Get an array of all of this extension's raw options (i.e. the ones starting with its prefix). - * - * @return array - */ - public function get_all_raw_options() { - $tribe_options = Tribe__Settings_Manager::get_options(); - - if ( ! is_array( $tribe_options ) ) { - return []; - } - - $result = []; - - foreach ( $tribe_options as $key => $value ) { - if ( 0 === strpos( $key, $this->get_options_prefix() ) ) { - $result[ $key ] = $value; - } - } - - return $result; - } - - /** - * 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' )`. - * - * @param string $key - * - * @return mixed - */ - public function delete_option( $key = '' ) { - $key = $this->sanitize_option_key( $key ); - - $options = Tribe__Settings_Manager::get_options(); - - unset( $options[ $key ] ); - - return Tribe__Settings_Manager::set_options( $options ); - } - - /** - * Here is an example of removing settings from Events > Settings > General tab > "Map Settings" section - * that are specific to Google Maps. - * - * TODO: Remove this method and the corresponding hook in `__construct()` if you don't want to remove any settings. - */ - public function remove_settings() { - // Remove "Enable Google Maps" checkbox - $this->settings_helper->remove_field( 'embedGoogleMaps', 'general' ); - - // Remove "Map view search distance limit" (default of 25) - $this->settings_helper->remove_field( 'geoloc_default_geofence', 'general' ); - - // Remove "Google Maps default zoom level" (0-21, default of 10) - $this->settings_helper->remove_field( 'embedGoogleMapsZoom', 'general' ); - } - - /** - * Adds a new section of fields to Events > Settings > General tab, appearing after the "Map Settings" section - * and before the "Miscellaneous Settings" section. - * - * TODO: Move the setting to where you want and update this docblock. If you like it here, just delete this TODO. - */ - public function add_settings() { - $fields = [ - // TODO: Settings heading start. Remove this element if not needed. Also remove the corresponding `get_example_intro_text()` method below. - 'Example' => [ - 'type' => 'html', - 'html' => $this->get_example_intro_text(), - ], - // TODO: Settings heading end. - 'a_setting' => [ // TODO: Change setting. - 'type' => 'text', - 'label' => esc_html__( 'Example setting', 'tec-labs-remove-past-events-plus' ), - 'tooltip' => sprintf( esc_html__( 'Example setting description. Enter your custom URL, including "http://" or "https://", for example %s.', 'tec-labs-remove-past-events-plus' ), 'https://demo.theeventscalendar.com/' ), - 'validation_type' => 'html', - ], - ]; - - $this->settings_helper->add_fields( - $this->prefix_settings_field_keys( $fields ), - 'general', - 'tribeEventsMiscellaneousTitle', - true - ); - } - - /** - * Add the options prefix to each of the array keys. - * - * @param array $fields - * - * @return array - */ - private function prefix_settings_field_keys( array $fields ) { - $prefixed_fields = array_combine( - array_map( - function ( $key ) { - return $this->get_options_prefix() . $key; - }, array_keys( $fields ) - ), - $fields - ); - - return (array) $prefixed_fields; - } - - /** - * Here is an example of getting some HTML for the Settings Header. - * - * TODO: Delete this method if you do not need a heading for your settings. Also remove the corresponding element in the the $fields array in the `add_settings()` method above. - * - * @return string - */ - private function get_example_intro_text() { - $result = '

' . esc_html_x( 'Example Extension Setup', 'Settings header', 'tec-labs-remove-past-events-plus' ) . '

'; - $result .= '
'; - $result .= '

'; - $result .= esc_html_x( 'Some text here about this settings section.', 'Setting section description', 'tec-labs-remove-past-events-plus' ); - $result .= '

'; - $result .= '
'; - - return $result; - } - -} diff --git a/src/Tec/Settings_Helper.php b/src/Tec/Settings_Helper.php deleted file mode 100644 index 18e248b..0000000 --- a/src/Tec/Settings_Helper.php +++ /dev/null @@ -1,176 +0,0 @@ - 'checkbox_bool, 'label' => ... ] - * @param string $setting_tab Settings tab where this will be added. Example: 'display'. - * @param string $neighboring_field (optional) The field key/HTML name="" attribute to insert this under. - * @param bool $above (optional) Insert above or below its neighbor. - */ - public function add_field( $field_key, $field_args, $setting_tab, $neighboring_field = null, $above = true ) { - // Our settings walker needs 'key' => arg pairs. - $field = [ $field_key => $field_args ]; - - $this->add_fields( $field, $setting_tab, $neighboring_field, $above ); - } - - /** - * Add multiple fields to a TEC Settings tab - * - * @param array $fields Fields that will be added, expects 'fieldname' => (array) args. - * @param string $setting_tab Settings tab where this will be added. Example: 'display'. - * @param string $neighboring_field (optional) The field key/HTML name="" attribute to insert this under. - * @param bool $above (optional) Insert above or below its neighbor. - */ - public function add_fields( $fields, $setting_tab, $neighboring_field = null, $above = false ) { - if ( ! is_string( $neighboring_field ) ) { - // If neighbor is not specified, add this to misc section. - $this->insert_fields_misc = array_replace_recursive( - $this->insert_fields_misc, - [ $setting_tab => $fields ] - ); - } elseif ( true === $above ) { - // Add to above fields list with neighbor specified. - $this->insert_fields_above = array_replace_recursive( - $this->insert_fields_above, - [ $setting_tab => [ $neighboring_field => $fields ] ] - ); - } else { - // Add to below fields list with neighbor specified. - $this->insert_fields_below = array_replace_recursive( - $this->insert_fields_below, - [ $setting_tab => [ $neighboring_field => $fields ] ] - ); - } - - } - - - /** - * Remove a field from one of the tabs in WP Admin > Events > Settings - * - * @param string $field_key Option key for your setting. Example: 'fancyOptionName'. - * @param string $setting_tab Settings tab from where this will be removed. Example: 'display'. - */ - public function remove_field( $field_key, $setting_tab ) { - $this->remove_fields[ $setting_tab ][] = $field_key; - } - - - /** - * Attached to 'tribe_settings_tab_fields' to add/remove this class' fields on TEC Settings pages. - * - * @param array $fields The fields within tribe settings page. - * @param string $tab The settings tab key. - * - * @return array $fields The fields within tribe settings page - */ - public function filter_options( $fields, $tab ) { - - // Fields appended to misc section. - if ( array_key_exists( $tab, $this->insert_fields_misc ) ) { - - // Add a misc heading if none exists. - if ( ! array_key_exists( 'tribeMiscSettings', $fields ) ) { - $misc_heading = [ - 'tribeMiscSettings' => [ - 'type' => 'html', - 'html' => '

' . esc_html__( 'Miscellaneous Settings', 'tec-labs-remove-past-events-plus' ) . '

', - ], - ]; - $fields = Tribe__Main::array_insert_before_key( 'tribe-form-content-end', $fields, $misc_heading ); - } - - // Insert these settings under misc heading. - $fields = Tribe__Main::array_insert_after_key( 'tribeMiscSettings', $fields, $this->insert_fields_misc[ $tab ] ); - } - - // Fields inserted above a neighboring field. - if ( array_key_exists( $tab, $this->insert_fields_above ) ) { - - foreach ( $this->insert_fields_above[ $tab ] as $insert_after => $new_field ) { - $fields = Tribe__Main::array_insert_before_key( $insert_after, $fields, $new_field ); - } - } - - // Fields inserted below a neighboring field. - if ( array_key_exists( $tab, $this->insert_fields_below ) ) { - - foreach ( $this->insert_fields_below[ $tab ] as $insert_after => $new_field ) { - $fields = Tribe__Main::array_insert_after_key( $insert_after, $fields, $new_field ); - } - } - - // Fields that will be removed. - if ( array_key_exists( $tab, $this->remove_fields ) ) { - - foreach ( $this->remove_fields[ $tab ] as $remove_field ) { - if ( array_key_exists( $remove_field, $fields ) ) { - unset( $fields[ $remove_field ] ); - } - } - } - - return $fields; - } -} From 0a0c417a60af6213cf1bd349150c396f3508fe88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 20 Jan 2022 10:46:31 +0100 Subject: [PATCH 4/5] Remove 'plus' --- plugin.php | 24 ++++++++++++------------ src/Tec/Assets.php | 8 ++++---- src/Tec/Hooks.php | 18 +++++++++--------- src/Tec/PUE.php | 10 +++++----- src/Tec/Plugin.php | 17 ++++++++--------- src/Tec/Plugin_Register.php | 6 +++--- 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/plugin.php b/plugin.php index 26601a2..07080e6 100644 --- a/plugin.php +++ b/plugin.php @@ -1,15 +1,15 @@ register_prefix( - '\\Tribe\\Extensions\\Remove_Past_Events_Plus\\', + '\\Tribe\\Extensions\\Remove_Past_Events\\', __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Tec', - 'remove-past-events-plus' + 'remove-past-events' ); // Deactivates the plugin in case of the main class didn't autoload. - if ( ! class_exists( '\Tribe\Extensions\Remove_Past_Events_Plus\Plugin' ) ) { + if ( ! class_exists( '\Tribe\Extensions\Remove_Past_Events\Plugin' ) ) { tribe_transient_notice( - 'remove-past-events-plus', - '

' . esc_html__( 'Couldn\'t properly load "The Events Calendar Extension: Remove Past Events Plus" the extension was deactivated.', 'tec-labs-remove-past-events-plus' ) . '

', + 'remove-past-events', + '

' . esc_html__( 'Couldn\'t properly load "The Events Calendar Extension: Remove Past Events" the extension was deactivated.', 'tec-labs-remove-past-events' ) . '

', [], // 1 second after that make sure the transient is removed. 1 @@ -67,8 +67,8 @@ function tribe_extension_remove_past_events_plus() { return; } - tribe_register_provider( '\Tribe\Extensions\Remove_Past_Events_Plus\Plugin' ); + tribe_register_provider( '\Tribe\Extensions\Remove_Past_Events\Plugin' ); } // Loads after common is already properly loaded. -add_action( 'tribe_common_loaded', 'tribe_extension_remove_past_events_plus' ); +add_action( 'tribe_common_loaded', 'tribe_extension_remove_past_events' ); diff --git a/src/Tec/Assets.php b/src/Tec/Assets.php index 576921b..8acfca8 100644 --- a/src/Tec/Assets.php +++ b/src/Tec/Assets.php @@ -10,17 +10,17 @@ * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus + * @package Tribe\Extensions\Remove_Past_Events */ -namespace Tribe\Extensions\Remove_Past_Events_Plus; +namespace Tribe\Extensions\Remove_Past_Events; /** * Register Assets. * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus + * @package Tribe\Extensions\Remove_Past_Events */ class Assets extends \tad_DI52_ServiceProvider { /** @@ -30,7 +30,7 @@ class Assets extends \tad_DI52_ServiceProvider { */ public function register() { $this->container->singleton( static::class, $this ); - $this->container->singleton( 'extension.remove_past_events_plus.assets', $this ); + $this->container->singleton( 'extension.remove_past_events.assets', $this ); $plugin = tribe( Plugin::class ); diff --git a/src/Tec/Hooks.php b/src/Tec/Hooks.php index da47a90..1177142 100644 --- a/src/Tec/Hooks.php +++ b/src/Tec/Hooks.php @@ -4,22 +4,22 @@ * * To remove a filter: * ```php - * remove_filter( 'some_filter', [ tribe( Tribe\Extensions\Remove_Past_Events_Plus\Hooks::class ), 'some_filtering_method' ] ); - * remove_filter( 'some_filter', [ tribe( 'extension.remove_past_events_plus.hooks' ), 'some_filtering_method' ] ); + * remove_filter( 'some_filter', [ tribe( Tribe\Extensions\Remove_Past_Events\Hooks::class ), 'some_filtering_method' ] ); + * remove_filter( 'some_filter', [ tribe( 'extension.remove_past_events.hooks' ), 'some_filtering_method' ] ); * ``` * * To remove an action: * ```php - * remove_action( 'some_action', [ tribe( Tribe\Extensions\Remove_Past_Events_Plus\Hooks::class ), 'some_method' ] ); - * remove_action( 'some_action', [ tribe( 'extension.remove_past_events_plus.hooks' ), 'some_method' ] ); + * remove_action( 'some_action', [ tribe( Tribe\Extensions\Remove_Past_Events\Hooks::class ), 'some_method' ] ); + * remove_action( 'some_action', [ tribe( 'extension.remove_past_events.hooks' ), 'some_method' ] ); * ``` * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus; + * @package Tribe\Extensions\Remove_Past_Events; */ -namespace Tribe\Extensions\Remove_Past_Events_Plus; +namespace Tribe\Extensions\Remove_Past_Events; use Tribe__Main as Common; @@ -28,7 +28,7 @@ * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus; + * @package Tribe\Extensions\Remove_Past_Events; */ class Hooks extends \tad_DI52_ServiceProvider { @@ -39,7 +39,7 @@ class Hooks extends \tad_DI52_ServiceProvider { */ public function register() { $this->container->singleton( static::class, $this ); - $this->container->singleton( 'extension.remove_past_events_plus.hooks', $this ); + $this->container->singleton( 'extension.remove_past_events.hooks', $this ); $this->add_actions(); $this->add_filters(); @@ -70,7 +70,7 @@ protected function add_filters() { */ public function load_text_domains() { $mopath = tribe( Plugin::class )->plugin_dir . 'lang/'; - $domain = 'tec-labs-remove-past-events-plus'; + $domain = 'tec-labs-remove-past-events'; // This will load `wp-content/languages/plugins` files first. Common::instance()->load_text_domain( $domain, $mopath ); diff --git a/src/Tec/PUE.php b/src/Tec/PUE.php index da46b5c..ac44e04 100644 --- a/src/Tec/PUE.php +++ b/src/Tec/PUE.php @@ -4,10 +4,10 @@ * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus; + * @package Tribe\Extensions\Remove_Past_Events; */ -namespace Tribe\Extensions\Remove_Past_Events_Plus; +namespace Tribe\Extensions\Remove_Past_Events; use Tribe__PUE__Checker; @@ -16,7 +16,7 @@ * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus; + * @package Tribe\Extensions\Remove_Past_Events; */ class PUE extends \tad_DI52_ServiceProvider { @@ -27,7 +27,7 @@ class PUE extends \tad_DI52_ServiceProvider { * * @var string */ - private static $pue_slug = 'extension-remove-past-events-plus'; + private static $pue_slug = 'extension-remove-past-events'; /** * Whether to load PUE or not. @@ -63,7 +63,7 @@ class PUE extends \tad_DI52_ServiceProvider { */ public function register() { $this->container->singleton( static::class, $this ); - $this->container->singleton( 'extension.remove_past_events_plus.pue', $this ); + $this->container->singleton( 'extension.remove_past_events.pue', $this ); // Bail to avoid notice. if ( ! static:: $is_active ) { diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index 68d7e0c..f51c42b 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -4,17 +4,17 @@ * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus + * @package Tribe\Extensions\Remove_Past_Events */ -namespace Tribe\Extensions\Remove_Past_Events_Plus; +namespace Tribe\Extensions\Remove_Past_Events; /** * Class Plugin * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus + * @package Tribe\Extensions\Remove_Past_Events */ class Plugin extends \tad_DI52_ServiceProvider { /** @@ -33,7 +33,7 @@ class Plugin extends \tad_DI52_ServiceProvider { * * @var string */ - const SLUG = 'remove-past-events-plus'; + const SLUG = 'remove-past-events'; /** * Stores the base slug for the extension. @@ -42,7 +42,7 @@ class Plugin extends \tad_DI52_ServiceProvider { * * @var string */ - const FILE = TRIBE_EXTENSION_REMOVE_PAST_EVENTS_PLUS_FILE; + const FILE = TRIBE_EXTENSION_REMOVE_PAST_EVENTS_FILE; /** * @since 1.0.0 @@ -80,8 +80,8 @@ public function register() { // Register this provider as the main one and use a bunch of aliases. $this->container->singleton( static::class, $this ); - $this->container->singleton( 'extension.remove_past_events_plus', $this ); - $this->container->singleton( 'extension.remove_past_events_plus.plugin', $this ); + $this->container->singleton( 'extension.remove_past_events', $this ); + $this->container->singleton( 'extension.remove_past_events.plugin', $this ); $this->container->register( PUE::class ); if ( ! $this->check_plugin_dependencies() ) { @@ -124,7 +124,7 @@ protected function register_plugin_dependencies() { $plugin_register->register_plugin(); $this->container->singleton( Plugin_Register::class, $plugin_register ); - $this->container->singleton( 'extension.remove_past_events_plus', $plugin_register ); + $this->container->singleton( 'extension.remove_past_events', $plugin_register ); } /** @@ -173,7 +173,6 @@ public function cleanup_query( $sql ) { function option_filter( $fields ) { $new_values = [ null => esc_html__( 'Disabled', 'the-events-calendar' ), - 1 => esc_html__( '1 minute', 'the-events-calendar' ), 15 => esc_html__( '15 minutes', 'the-events-calendar' ), 60 => esc_html__( '1 hour', 'the-events-calendar' ), 720 => esc_html__( '12 hours', 'the-events-calendar' ), diff --git a/src/Tec/Plugin_Register.php b/src/Tec/Plugin_Register.php index 3f047ec..f6cd2e1 100644 --- a/src/Tec/Plugin_Register.php +++ b/src/Tec/Plugin_Register.php @@ -4,10 +4,10 @@ * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus + * @package Tribe\Extensions\Remove_Past_Events */ -namespace Tribe\Extensions\Remove_Past_Events_Plus; +namespace Tribe\Extensions\Remove_Past_Events; use Tribe__Abstract_Plugin_Register as Abstract_Plugin_Register; @@ -16,7 +16,7 @@ * * @since 1.0.0 * - * @package Tribe\Extensions\Remove_Past_Events_Plus + * @package Tribe\Extensions\Remove_Past_Events * * @see Tribe__Abstract_Plugin_Register For the plugin dependency manifest registration. */ From bb71f3f85f5899db1d3ec9e9f6b121306955df55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 20 Jan 2022 10:57:34 +0100 Subject: [PATCH 5/5] Updated readme --- README.md | 69 ------------------------------------------------------ plugin.php | 4 ++-- readme.txt | 17 +++++--------- 3 files changed, 8 insertions(+), 82 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index e6d3046..0000000 --- a/README.md +++ /dev/null @@ -1,69 +0,0 @@ -## What and Why? - -This is the TEC Labs Extension Template. It allows you to easily extend our plugins: The Events Calendar, Event Tickets, and their associated add-on plugins. - -The primary benefits of using this template is that it's gets you up-and-running quicker than building a custom plugin yourself, and it's best to extend one plugin via another plugin instead of adding custom code to your child theme's `functions.php` file. - -We ensure your new extension does not run if its required base plugin is not activated, which helps avoid fatal errors and means fewer `class_exists()` checks are applicable. - -Extensions have been available since The Events Calendar version 4.3.3 (November 16, 2016). If you try to get this template to work with versions before this date, your extension will not run at all. - -Newer extensions will only be compatible with the version of The Events Calendar 5.1.1 or newer. - -## Extension template Information - -If you have modifications you would like to suggest to our base template, here is the correct place to submit a Pull Request, but if you are looking for a specific extension you should take a look at our [GitHub profile](https://github.com/mt-support) or our [Extensions page on TheEventsCalendar.com](https://theeventscalendar.com/extensions/). - -#### If you want to make your own new extension: - -1. On Slack use `bot create (tec|et) extension named ` -1. Your Extension is currently a functional WordPress plugin at this point! Please refer to our [Good Practices](#good-practices) before the next step. -1. Zip and release your plugin! - -#### Good Practices - -* Verify if you need any dependencies to activate your plugin. If so, use the bot command to [set a dependency](#setting-a-dependency) -* Set the `== Changelog ==` section of `readme.txt`. -* Remove the unused classes from the `src/Tec` folder. -* Register any other classes you will need inside of `src/Tec/Plugin.php` on the method `register` after the line `// Start binds.` and before `// End binds.`. -* Sanitize all input and escape all output, as appropriate. -* Double-check your plugin's slug, name, and descriptions still apply to the end result of what your code actually accomplishes. -* Generate your *.pot* file by running this WP-CLI command: `wp i18n make-pot . languages/tec-labs-extension-template.pot --headers='{"Report-Msgid-Bugs-To":"The Events Calendar "}'` -* Remove this `README.md` file. - -#### Extension Template Variables - -By default, all of these variables will be replaced by the create method from the slack bot, but if you are creating your extension manually you will need to find/replace on all of the below. - -* `The Events Calendar` - "The Events Calendar" or "Event Tickets" -* `Remove Past Events Plus` - Plugin Human-readable name, e.g. "Sample Extension" -* `Remove_Past_Events_Plus` - Which namespace we will use for the plugin. Usually the plugin name or the slug in uppercase without spaces, e.g. "SampleExtension" -* `remove-past-events-plus` - Uses using dashes normally, e.g. "sample-extension" -* `__TRIBE_DOMAIN__` - Translation domain normally with "tribe-" prefix, e.g. "tec-labs-sample-extension" -* `remove_past_events_plus` - Uses underscores, so it's safe for variables, e.g. "sample_extension" -* `__TRIBE_SLUG_CLEAN_ALLCAPS__` - All-caps of clean slug, e.g. "SAMPLE_EXTENSION" -* `` - The URL of the extension page, by default empty. Usually "https://theeventscalendar.com/extensions/sample-extension/" -* `1.0.0` - Version number of the extension, by default empty. Follows the "1.0.0" format -* `` - The description of the extension, by default empty. - -#### Slack Bot commands related to Extensions - -##### Creating a new Extension - -Bot will determine the namespace based on the plugin name: -``` -bot create (tec|et) extension named -``` - -Specifically passing a namespace that is different from the plugin name: -``` -bot create (tec|et) extension named with a namespace of -``` - -##### Setting a dependency - -``` -bot add dependency version to extension -``` - -_More bot commands to come in the future._ diff --git a/plugin.php b/plugin.php index 07080e6..2bc5a29 100644 --- a/plugin.php +++ b/plugin.php @@ -1,9 +1,9 @@ Settings > General tab`. == Installation == @@ -37,6 +32,6 @@ We're always interested in your feedback and our [Help Desk](https://support.the == Changelog == -= [1.0.0] YYYY-MM-DD = += [1.0.0] 2022-01-20 = * Initial release \ No newline at end of file