From d62b37d749f56db0c2534b2003f6b1153f323e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 10:19:01 +0100 Subject: [PATCH 01/21] Set dependency --- src/Tec/Plugin_Register.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tec/Plugin_Register.php b/src/Tec/Plugin_Register.php index 662ad0c..5d6db46 100644 --- a/src/Tec/Plugin_Register.php +++ b/src/Tec/Plugin_Register.php @@ -26,7 +26,7 @@ class Plugin_Register extends Abstract_Plugin_Register { protected $main_class = Plugin::class; protected $dependencies = [ 'parent-dependencies' => [ - 'Tribe__Events__Main' => '6.1.2.2-dev', + 'Tribe__Events__Community__Main' => '4.10.0-dev', ], ]; } From 9e82a54ffafa8e76776283bdf29de8dab552f47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 10:31:58 +0100 Subject: [PATCH 02/21] Add setting --- src/Tec/Settings.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php index 4464302..2fcd067 100644 --- a/src/Tec/Settings.php +++ b/src/Tec/Settings.php @@ -232,22 +232,26 @@ public function add_settings() { // 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(), + 'html' => $this->recaptcha_v3_settings_intro_text(), ], // TODO: Settings heading end. - 'a_setting' => [ // TODO: Change setting. + 'recaptcha_v3_site_key' => [ // TODO: Change setting. 'type' => 'text', - 'label' => esc_html__( 'Example setting', 'tec-labs-ce-recaptcha-v3' ), - 'tooltip' => sprintf( esc_html__( 'Example setting description. Enter your custom URL, including "http://" or "https://", for example %s.', 'tec-labs-ce-recaptcha-v3' ), 'https://demo.theeventscalendar.com/' ), + 'label' => esc_html__( 'Site Key', 'tec-labs-ce-recaptcha-v3' ), + 'tooltip' => sprintf( esc_html__( 'Get your Site Key at %s.', 'tec-labs-ce-recaptcha-v3' ), 'https://www.google.com/recaptcha/admin/create' ), 'validation_type' => 'html', + 'default' => '', + 'can_be_empty' => true, + 'parent_option' => \Tribe__Events__Community__Main::OPTIONNAME, + 'size' => 'large', ], ]; $this->settings_helper->add_fields( $this->prefix_settings_field_keys( $fields ), - 'general', - 'tribeEventsMiscellaneousTitle', - true + 'addons', + 'recaptchaPrivateKey', + false ); } @@ -278,11 +282,11 @@ function ( $key ) { * * @return string */ - private function get_example_intro_text() { - $result = '

' . esc_html_x( 'Example Extension Setup', 'Settings header', 'tec-labs-ce-recaptcha-v3' ) . '

'; + private function recaptcha_v3_settings_intro_text() { + $result = '

' . esc_html_x( 'reCAPTCHA v3 API Key', 'Settings header', 'tec-labs-ce-recaptcha-v3' ) . '

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

'; - $result .= esc_html_x( 'Some text here about this settings section.', 'Setting section description', 'tec-labs-ce-recaptcha-v3' ); + $result .= esc_html_x( 'Provide reCAPTCHA v3 API key to enable reCAPTCHA on your Community Events form.', 'Setting section description', 'tec-labs-ce-recaptcha-v3' ); $result .= '

'; $result .= '
'; From 4594ddb43f7ec97d3ab8a0e7649f48851d987832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 10:39:11 +0100 Subject: [PATCH 03/21] Rearrange settings. Reuse reCAPTCHA v2 setting Here we are re-using the reCAPTCHA v2 site key setting so we don't need to superfluously remove a setting and add a new one. --- src/Tec/Settings.php | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php index 2fcd067..6bf95bd 100644 --- a/src/Tec/Settings.php +++ b/src/Tec/Settings.php @@ -211,14 +211,11 @@ public function delete_option( $key = '' ) { * 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 reCAPTCHA v2 info + $this->settings_helper->remove_field( 'recaptcha-info', 'addons' ); - // 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' ); + // Remove reCAPTCHA v2 Secret Key + $this->settings_helper->remove_field( 'recaptchaPrivateKey', 'addons' ); } /** @@ -234,24 +231,13 @@ public function add_settings() { 'type' => 'html', 'html' => $this->recaptcha_v3_settings_intro_text(), ], - // TODO: Settings heading end. - 'recaptcha_v3_site_key' => [ // TODO: Change setting. - 'type' => 'text', - 'label' => esc_html__( 'Site Key', 'tec-labs-ce-recaptcha-v3' ), - 'tooltip' => sprintf( esc_html__( 'Get your Site Key at %s.', 'tec-labs-ce-recaptcha-v3' ), 'https://www.google.com/recaptcha/admin/create' ), - 'validation_type' => 'html', - 'default' => '', - 'can_be_empty' => true, - 'parent_option' => \Tribe__Events__Community__Main::OPTIONNAME, - 'size' => 'large', - ], ]; $this->settings_helper->add_fields( $this->prefix_settings_field_keys( $fields ), 'addons', - 'recaptchaPrivateKey', - false + 'recaptchaPublicKey', + true ); } @@ -283,8 +269,7 @@ function ( $key ) { * @return string */ private function recaptcha_v3_settings_intro_text() { - $result = '

' . esc_html_x( 'reCAPTCHA v3 API Key', 'Settings header', 'tec-labs-ce-recaptcha-v3' ) . '

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

'; $result .= esc_html_x( 'Provide reCAPTCHA v3 API key to enable reCAPTCHA on your Community Events form.', 'Setting section description', 'tec-labs-ce-recaptcha-v3' ); $result .= '

'; From ea6eac4a57d7ff6ff8bf18c57f2aa768a95d4f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:08:29 +0100 Subject: [PATCH 04/21] Set up template overrides and handling --- src/Tec/Plugin.php | 47 ++++++++++ src/views/community/edit-event.php | 113 ++++++++++++++++++++++++ src/views/community/modules/captcha.php | 14 +++ src/views/community/modules/submit.php | 61 +++++++++++++ 4 files changed, 235 insertions(+) create mode 100644 src/views/community/edit-event.php create mode 100644 src/views/community/modules/captcha.php create mode 100644 src/views/community/modules/submit.php diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index 76e352c..a68bd31 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -105,7 +105,11 @@ public function register() { // Start binds. + // Template override for the main templates (in src/views/community). + add_filter( 'tribe_events_template_paths', [ $this, 'template_base_paths' ] ); + // Template override for module templates (under src/views/community). + add_filter( 'tribe_get_template_part_path', [ $this, 'custom_templates' ], 10, 4 ); // End binds. @@ -113,6 +117,49 @@ public function register() { $this->container->register( Assets::class ); } + /** + * Add template override location for the main template files. + * (Files in src/views/community.) + * + * @param array $paths The template paths. + * + * @return array The new template paths. + */ + function template_base_paths( array $paths ): array { + $slug = "tec-labs-" . PUE::get_slug(); + $paths[$slug] = trailingslashit( plugin_dir_path( TRIBE_EXTENSION_CE_RECAPTCHA_V3_FILE ) ); + + return $paths; + } + + /** + * Add template override location for template parts. + * (Files under src/views/community.) + * + * @param string $file The template file name with full server path. + * @param string $template The template file name with the default override path. (E.g. community/modules/template.php) + * @param string $slug The template slug. (Same as file name but without extension.) + * @param string|null $name + * + * @return string + */ + function custom_templates( string $file, string $template, string $slug, ?string $name ): string { + $custom_folder = "src/views"; + + $plugin_path = implode( "", array_merge( + (array) trailingslashit( plugin_dir_path( TRIBE_EXTENSION_CE_RECAPTCHA_V3_FILE ) ), + (array) $custom_folder, + ) ); + + $new_file = $plugin_path . "/" . $template; + + if ( file_exists( $new_file ) ) { + return $new_file; + } + + return $file; + } + /** * Checks whether the plugin dependency manifest is satisfied or not. * diff --git a/src/views/community/edit-event.php b/src/views/community/edit-event.php new file mode 100644 index 0000000..3dee281 --- /dev/null +++ b/src/views/community/edit-event.php @@ -0,0 +1,113 @@ +getOption( 'termsEnabled' ); + +$terms_description = $main->getOption( 'termsDescription' ); + +// Variables for the Website view. +$event_url = $_POST['EventURL'] ?? tribe_get_event_website_url(); +$event_url = esc_attr( $event_url ); + + +?> + + + + + +
+ + + + $events_label_singular ] ); ?> + + + + + + + + Tribe__Events__Main::TAXONOMY ] ); ?> + + 'post_tag' ] ); ?> + + + + + + + + + + $event_url ] ); ?> + + + + + + + + + + $terms_enabled, 'terms_description' => $terms_description ] ); ?> + + +
+ + diff --git a/src/views/community/modules/captcha.php b/src/views/community/modules/captcha.php new file mode 100644 index 0000000..3044bee --- /dev/null +++ b/src/views/community/modules/captcha.php @@ -0,0 +1,14 @@ + diff --git a/src/views/community/modules/submit.php b/src/views/community/modules/submit.php new file mode 100644 index 0000000..36af5f3 --- /dev/null +++ b/src/views/community/modules/submit.php @@ -0,0 +1,61 @@ +getOption( 'recaptchaPublicKey', '' ); + +if ( tribe_is_event( $post_id ) ) { + $button_label = sprintf( __( 'Update %s', 'tribe-events-community' ), $events_label_singular ); +} else { + $button_label = sprintf( __( 'Submit %s', 'tribe-events-community' ), $events_label_singular ); +} +$button_label = apply_filters( 'tribe_community_event_edit_button_label', $button_label ); +?> + + + + From 8fc7bd6bc747a21dcc306d9fca71d17612683b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:11:33 +0100 Subject: [PATCH 05/21] Only do overrides if there is a recaptcha key --- src/Tec/Plugin.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index a68bd31..ef4defb 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -105,11 +105,7 @@ public function register() { // Start binds. - // Template override for the main templates (in src/views/community). - add_filter( 'tribe_events_template_paths', [ $this, 'template_base_paths' ] ); - - // Template override for module templates (under src/views/community). - add_filter( 'tribe_get_template_part_path', [ $this, 'custom_templates' ], 10, 4 ); + $this->maybe_do_recaptcha_v3(); // End binds. @@ -117,6 +113,22 @@ public function register() { $this->container->register( Assets::class ); } + /** + * Replace reCAPTCHA v2 with v3 if there is a license key set. + * @return void + */ + function maybe_do_recaptcha_v3() { + $recaptcha_key = tribe( 'community.main' )->getOption( 'recaptchaPublicKey', '' ); + + if ( $recaptcha_key != '' ) { + // Template override for the main templates (in src/views/community). + add_filter( 'tribe_events_template_paths', [ $this, 'template_base_paths' ] ); + + // Template override for module templates (under src/views/community). + add_filter( 'tribe_get_template_part_path', [ $this, 'custom_templates' ], 10, 4 ); + } + } + /** * Add template override location for the main template files. * (Files in src/views/community.) From 23e664e364e7b2dfe8794baeb3dcc9e261fe110c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:22:13 +0100 Subject: [PATCH 06/21] Implement using the recaptcha setting --- src/Tec/Plugin.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index ef4defb..401c3d1 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -118,7 +118,9 @@ public function register() { * @return void */ function maybe_do_recaptcha_v3() { - $recaptcha_key = tribe( 'community.main' )->getOption( 'recaptchaPublicKey', '' ); + //$recaptcha_key = new tribe( 'community.main' )->getOption( 'recaptchaPublicKey', '' ); + $ce_options = \Tribe__Events__Community__Main::getOptions(); + $recaptcha_key = $ce_options['recaptchaPublicKey']; if ( $recaptcha_key != '' ) { // Template override for the main templates (in src/views/community). @@ -128,7 +130,7 @@ function maybe_do_recaptcha_v3() { add_filter( 'tribe_get_template_part_path', [ $this, 'custom_templates' ], 10, 4 ); } } - + /** * Add template override location for the main template files. * (Files in src/views/community.) From c28cd2d792835793aae4e854f3f00d3d460203df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:26:23 +0100 Subject: [PATCH 07/21] Format docblocks --- src/Tec/Plugin.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index 401c3d1..d8bbde5 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -115,7 +115,10 @@ public function register() { /** * Replace reCAPTCHA v2 with v3 if there is a license key set. + * * @return void + * + * @since 1.0.0 */ function maybe_do_recaptcha_v3() { //$recaptcha_key = new tribe( 'community.main' )->getOption( 'recaptchaPublicKey', '' ); @@ -138,6 +141,8 @@ function maybe_do_recaptcha_v3() { * @param array $paths The template paths. * * @return array The new template paths. + * + * @since 1.0.0 */ function template_base_paths( array $paths ): array { $slug = "tec-labs-" . PUE::get_slug(); @@ -156,6 +161,8 @@ function template_base_paths( array $paths ): array { * @param string|null $name * * @return string + * + * @since 1.0.0 */ function custom_templates( string $file, string $template, string $slug, ?string $name ): string { $custom_folder = "src/views"; From 49108b2dadbe3bbefb551da113868a91a3c07683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:26:41 +0100 Subject: [PATCH 08/21] Add method to handle scripts --- src/Tec/Plugin.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index d8bbde5..df7c272 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -131,6 +131,8 @@ function maybe_do_recaptcha_v3() { // Template override for module templates (under src/views/community). add_filter( 'tribe_get_template_part_path', [ $this, 'custom_templates' ], 10, 4 ); + + add_action( 'wp_head', [ $this, 'add_recaptcha_scripts' ] ); } } @@ -181,6 +183,22 @@ function custom_templates( string $file, string $template, string $slug, ?string return $file; } + /** + * Add recaptcha scripts to the head. + * + * @return void + * + * @since 1.0.0 + * + * @see https://developers.google.com/recaptcha/docs/v3 + */ + function add_recaptcha_scripts() { + if ( tribe_context()->get('view') == "community_event_page" ) { + echo ''; + echo ''; + } + } + /** * Checks whether the plugin dependency manifest is satisfied or not. * From fc86e9bb1e6412d16286d9d4327be8194951cdd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:33:04 +0100 Subject: [PATCH 09/21] Housekeeping --- src/Tec/Plugin.php | 14 +------------- src/Tec/Settings.php | 13 +------------ src/Tec/Settings_Helper.php | 2 -- 3 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index df7c272..e659c84 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -70,13 +70,11 @@ class Plugin extends Service_Provider { * @since 1.0.0 * * @var Settings - * - * TODO: Remove if not using settings */ private $settings; /** - * Setup the Extension's properties. + * Set up the Extension's properties. * * This always executes even if the required plugins are not present. * @@ -100,7 +98,6 @@ public function register() { } // Do the settings. - // TODO: Remove if not using settings $this->get_settings(); // Start binds. @@ -121,7 +118,6 @@ public function register() { * @since 1.0.0 */ function maybe_do_recaptcha_v3() { - //$recaptcha_key = new tribe( 'community.main' )->getOption( 'recaptchaPublicKey', '' ); $ce_options = \Tribe__Events__Community__Main::getOptions(); $recaptcha_key = $ce_options['recaptchaPublicKey']; @@ -233,8 +229,6 @@ protected function register_plugin_dependencies() { * @return string * * @see \Tribe\Extensions\CeRecaptchaV3\Settings::set_options_prefix() - * - * TODO: Remove if not using settings */ private function get_options_prefix() { return (string) str_replace( '-', '_', 'tec-labs-ce-recaptcha-v3' ); @@ -244,8 +238,6 @@ private function get_options_prefix() { * Get Settings instance. * * @return Settings - * - * TODO: Remove if not using settings */ private function get_settings() { if ( empty( $this->settings ) ) { @@ -259,8 +251,6 @@ private function get_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(); @@ -275,8 +265,6 @@ public function get_all_options() { * @param string $default * * @return array - * - * TODO: Remove if not using settings */ public function get_option( $option, $default = '' ) { $settings = $this->get_settings(); diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php index 6bf95bd..67776d5 100644 --- a/src/Tec/Settings.php +++ b/src/Tec/Settings.php @@ -12,8 +12,6 @@ /** * Do the Settings. - * - * TODO: Delete file if not using settings */ class Settings { @@ -36,8 +34,6 @@ class Settings { /** * Settings constructor. * - * TODO: Update this entire class for your needs, or remove the entire `src` directory this file is in and do not load it in the main plugin file. - * * @param string $options_prefix Recommended: the plugin text domain, with hyphens converted to underscores. */ public function __construct( $options_prefix ) { @@ -207,8 +203,6 @@ public function delete_option( $key = '' ) { /** * 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 reCAPTCHA v2 info @@ -221,13 +215,10 @@ public function remove_settings() { /** * 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' => [ + 'Intro' => [ 'type' => 'html', 'html' => $this->recaptcha_v3_settings_intro_text(), ], @@ -264,8 +255,6 @@ function ( $key ) { /** * 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 recaptcha_v3_settings_intro_text() { diff --git a/src/Tec/Settings_Helper.php b/src/Tec/Settings_Helper.php index 2db93b2..afe8f0d 100644 --- a/src/Tec/Settings_Helper.php +++ b/src/Tec/Settings_Helper.php @@ -13,8 +13,6 @@ /** * Helper for inserting/removing fields on the WP Admin TEC Settings pages - * - * @TODO Delete file if not using settings */ class Settings_Helper { From dd51c947b6104b19e0b8771b9e62bc1be44b9690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:40:53 +0100 Subject: [PATCH 10/21] Housekeeping --- plugin.php | 4 ++-- readme.txt | 20 +++++++------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/plugin.php b/plugin.php index f655bb6..d4a61c5 100644 --- a/plugin.php +++ b/plugin.php @@ -3,8 +3,8 @@ * Plugin Name: The Events Calendar: Community Events Extension: reCAPTCHA v3 * Plugin URI: https://theeventscalendar.com/extensions/recaptcha-v3-for-community-events * GitHub Plugin URI: https://github.com/mt-support/tec-labs-ce-recaptcha-v3 - * Description: Add reCAPTCHA v3 support for Community Events - * Version: 1.0.0 + * Description: Add reCAPTCHA v3 support for Community Events. + * Version: 1.0.0-dev * Author: The Events Calendar * Author URI: https://evnt.is/1971 * License: GPL version 3 or any later version diff --git a/readme.txt b/readme.txt index f80d19a..8918be8 100644 --- a/readme.txt +++ b/readme.txt @@ -2,20 +2,14 @@ Contributors: theeventscalendar Donate link: https://evnt.is/29 Tags: events, calendar -Requires at least: 4.9 -Tested up to: 5.7 -Requires PHP: 5.6 -Stable tag: 1.0.0 +Requires at least: 6.1.0 +Tested up to: 6.4.1 +Requires PHP: 7.4 +Stable tag: 1.0.0-dev License: GPL version 3 or any later version License URI: https://www.gnu.org/licenses/gpl-3.0.html -Add reCAPTCHA v3 support for Community Events - -== Description == - -This is the long description. No limit, and you can use Markdown (as well as in the following sections). - -For backwards compatibility, if this section is missing, the full length of the short description will be used, and Markdown parsed. +Add reCAPTCHA v3 support for Community Events. == Installation == @@ -37,6 +31,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-dev] 2023-11-16 = -* Initial release \ No newline at end of file +* Beta release \ No newline at end of file From fbbaddc0cc30a0e4bd3aa88f463802e4c69d1de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Thu, 16 Nov 2023 13:48:31 +0100 Subject: [PATCH 11/21] Set initial release --- plugin.php | 2 +- readme.txt | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin.php b/plugin.php index d4a61c5..1a72588 100644 --- a/plugin.php +++ b/plugin.php @@ -4,7 +4,7 @@ * Plugin URI: https://theeventscalendar.com/extensions/recaptcha-v3-for-community-events * GitHub Plugin URI: https://github.com/mt-support/tec-labs-ce-recaptcha-v3 * Description: Add reCAPTCHA v3 support for Community Events. - * Version: 1.0.0-dev + * Version: 1.0.0 * Author: The Events Calendar * Author URI: https://evnt.is/1971 * License: GPL version 3 or any later version diff --git a/readme.txt b/readme.txt index 8918be8..08229fc 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: events, calendar Requires at least: 6.1.0 Tested up to: 6.4.1 Requires PHP: 7.4 -Stable tag: 1.0.0-dev +Stable tag: 1.0.0 License: GPL version 3 or any later version License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -31,6 +31,10 @@ We're always interested in your feedback and our [Help Desk](https://support.the == Changelog == += [1.0.0] 2023-11-20 = + +* Initial release + = [1.0.0-dev] 2023-11-16 = * Beta release \ No newline at end of file From 4861f4742ee0b931f40ed32a5d9881678e093a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Tue, 21 Nov 2023 11:50:09 +0100 Subject: [PATCH 12/21] Add filter to remove captcha v2 --- src/Tec/Plugin.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index e659c84..1511f5f 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -122,6 +122,9 @@ function maybe_do_recaptcha_v3() { $recaptcha_key = $ce_options['recaptchaPublicKey']; if ( $recaptcha_key != '' ) { + // Remove reCAPTCHA v2 + add_filter('tribe_community_events_captcha_plugin', '__return_null' ); + // Template override for the main templates (in src/views/community). add_filter( 'tribe_events_template_paths', [ $this, 'template_base_paths' ] ); From 6c6d2c70f228a80f7bec98fa005b7380be8403a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Tue, 21 Nov 2023 12:13:45 +0100 Subject: [PATCH 13/21] Re-add separate v3 settings --- src/Tec/Settings.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php index 67776d5..68060fc 100644 --- a/src/Tec/Settings.php +++ b/src/Tec/Settings.php @@ -206,10 +206,10 @@ public function delete_option( $key = '' ) { */ public function remove_settings() { // Remove reCAPTCHA v2 info - $this->settings_helper->remove_field( 'recaptcha-info', 'addons' ); + //$this->settings_helper->remove_field( 'recaptcha-info', 'addons' ); // Remove reCAPTCHA v2 Secret Key - $this->settings_helper->remove_field( 'recaptchaPrivateKey', 'addons' ); + //$this->settings_helper->remove_field( 'recaptchaPrivateKey', 'addons' ); } /** @@ -222,13 +222,23 @@ public function add_settings() { 'type' => 'html', 'html' => $this->recaptcha_v3_settings_intro_text(), ], + 'site_key' => [ // TODO: Change setting. + 'type' => 'text', + 'label' => esc_html__( 'Site Key', 'tec-labs-ce-recaptcha-v3' ), + 'tooltip' => sprintf( esc_html__( 'Get your Site Key at %s.', 'tec-labs-ce-recaptcha-v3' ), 'https://www.google.com/recaptcha/admin/create' ), + 'validation_type' => 'html', + 'default' => '', + 'can_be_empty' => true, + 'parent_option' => \Tribe__Events__Community__Main::OPTIONNAME, + 'size' => 'large', + ], ]; $this->settings_helper->add_fields( $this->prefix_settings_field_keys( $fields ), 'addons', - 'recaptchaPublicKey', - true + 'google_maps_js_api_key', + false ); } @@ -258,7 +268,8 @@ function ( $key ) { * @return string */ private function recaptcha_v3_settings_intro_text() { - $result = '
'; + $result = '

' . esc_html_x( 'reCAPTCHA v3 API Key', 'Settings header', 'tec-labs-ce-recaptcha-v3' ) . '

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

'; $result .= esc_html_x( 'Provide reCAPTCHA v3 API key to enable reCAPTCHA on your Community Events form.', 'Setting section description', 'tec-labs-ce-recaptcha-v3' ); $result .= '

'; From b717953e8cd66f1c4e881dd7af7621f674d23eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Tue, 21 Nov 2023 12:30:41 +0100 Subject: [PATCH 14/21] Move the removal of v2 earlier. --- src/Tec/Plugin.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index 1511f5f..7c0c1c5 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -102,6 +102,9 @@ public function register() { // Start binds. + // Remove reCAPTCHA v2 + add_filter('tribe_community_events_captcha_plugin', '__return_null' ); + $this->maybe_do_recaptcha_v3(); // End binds. @@ -122,15 +125,13 @@ function maybe_do_recaptcha_v3() { $recaptcha_key = $ce_options['recaptchaPublicKey']; if ( $recaptcha_key != '' ) { - // Remove reCAPTCHA v2 - add_filter('tribe_community_events_captcha_plugin', '__return_null' ); - // Template override for the main templates (in src/views/community). add_filter( 'tribe_events_template_paths', [ $this, 'template_base_paths' ] ); // Template override for module templates (under src/views/community). add_filter( 'tribe_get_template_part_path', [ $this, 'custom_templates' ], 10, 4 ); + // Add scripts needed for v3. add_action( 'wp_head', [ $this, 'add_recaptcha_scripts' ] ); } } From 77939510e43191e1891c007a4fa99ece3f7766d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Tue, 21 Nov 2023 12:30:59 +0100 Subject: [PATCH 15/21] Make sure the right option is used --- src/Tec/Plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index 7c0c1c5..919df87 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -122,7 +122,7 @@ public function register() { */ function maybe_do_recaptcha_v3() { $ce_options = \Tribe__Events__Community__Main::getOptions(); - $recaptcha_key = $ce_options['recaptchaPublicKey']; + $recaptcha_key = $ce_options['tec_labs_ce_recaptcha_v3_site_key']; if ( $recaptcha_key != '' ) { // Template override for the main templates (in src/views/community). From 5ce18de13f3d55980fc3bedd0e45c4dc5372ab9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Tue, 21 Nov 2023 12:40:52 +0100 Subject: [PATCH 16/21] Remove unused methods --- src/Tec/Plugin.php | 27 ++------------------------- src/Tec/Settings.php | 21 +++------------------ 2 files changed, 5 insertions(+), 43 deletions(-) diff --git a/src/Tec/Plugin.php b/src/Tec/Plugin.php index 919df87..53935be 100644 --- a/src/Tec/Plugin.php +++ b/src/Tec/Plugin.php @@ -122,7 +122,8 @@ public function register() { */ function maybe_do_recaptcha_v3() { $ce_options = \Tribe__Events__Community__Main::getOptions(); - $recaptcha_key = $ce_options['tec_labs_ce_recaptcha_v3_site_key']; + $option_key = $this->get_options_prefix() . '_site_key'; + $recaptcha_key = $ce_options[$option_key]; if ( $recaptcha_key != '' ) { // Template override for the main templates (in src/views/community). @@ -251,28 +252,4 @@ private function get_settings() { return $this->settings; } - /** - * Get all of this extension's options. - * - * @return array - */ - 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 - */ - public function get_option( $option, $default = '' ) { - $settings = $this->get_settings(); - - return $settings->get_option( $option, $default ); - } } diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php index 68060fc..aba8a26 100644 --- a/src/Tec/Settings.php +++ b/src/Tec/Settings.php @@ -41,10 +41,7 @@ public function __construct( $options_prefix ) { $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 settings specific to the extension add_action( 'admin_init', [ $this, 'add_settings' ] ); } @@ -200,18 +197,6 @@ public function delete_option( $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. - */ - public function remove_settings() { - // Remove reCAPTCHA v2 info - //$this->settings_helper->remove_field( 'recaptcha-info', 'addons' ); - - // Remove reCAPTCHA v2 Secret Key - //$this->settings_helper->remove_field( 'recaptchaPrivateKey', 'addons' ); - } - /** * Adds a new section of fields to Events > Settings > General tab, appearing after the "Map Settings" section * and before the "Miscellaneous Settings" section. @@ -229,7 +214,7 @@ public function add_settings() { 'validation_type' => 'html', 'default' => '', 'can_be_empty' => true, - 'parent_option' => \Tribe__Events__Community__Main::OPTIONNAME, + 'parent_option' => \Tribe__Events__Community__Main::OPTIONNAME, // We're using the Community Events entry, instead of the default TEC. 'size' => 'large', ], ]; @@ -263,7 +248,7 @@ function ( $key ) { } /** - * Here is an example of getting some HTML for the Settings Header. + * HTML for the Settings Header. * * @return string */ From 33c38bb630bc1b6c67b21b1db48ec5b6f2f06605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Guseo?= Date: Tue, 21 Nov 2023 13:07:05 +0100 Subject: [PATCH 17/21] Add setting for widget theme (light or dark) --- src/Tec/Settings.php | 14 ++++++++++++++ src/views/community/modules/submit.php | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/Tec/Settings.php b/src/Tec/Settings.php index aba8a26..a3cdf99 100644 --- a/src/Tec/Settings.php +++ b/src/Tec/Settings.php @@ -217,6 +217,20 @@ public function add_settings() { 'parent_option' => \Tribe__Events__Community__Main::OPTIONNAME, // We're using the Community Events entry, instead of the default TEC. 'size' => 'large', ], + 'theme' => [ + 'type' => 'dropdown', + 'label' => esc_html__( 'Theme', 'tec-labs-ce-recaptcha-v3' ), + 'tooltip' => esc_html__( 'The color theme of the widget.', 'tec-labs-ce-recaptcha-v3' ), + 'default' => 'light', + 'validation_type' => 'options', + 'size' => 'small', + 'parent_option' => \Tribe__Events__Community__Main::OPTIONNAME, // We're using the Community Events entry, instead of the default TEC. + 'options' => [ + 'light' => esc_html__( 'Light', 'tec-labs-ce-recaptcha-v3' ), + 'dark' => esc_html__( 'Dark', 'tec-labs-ce-recaptcha-v3' ), + ], + ], + ]; $this->settings_helper->add_fields( diff --git a/src/views/community/modules/submit.php b/src/views/community/modules/submit.php index 36af5f3..43ae053 100644 --- a/src/views/community/modules/submit.php +++ b/src/views/community/modules/submit.php @@ -29,6 +29,8 @@ $button_label = sprintf( __( 'Submit %s', 'tribe-events-community' ), $events_label_singular ); } $button_label = apply_filters( 'tribe_community_event_edit_button_label', $button_label ); + +$recaptcha_theme = tribe( 'community.main' )->getOption( 'tec_labs_ce_recaptcha_v3_theme', 'light' ); ?>