From 7395e6656140956c909ff601b39855e1e25e33c8 Mon Sep 17 00:00:00 2001 From: Glauber Silva Date: Thu, 19 Oct 2023 18:32:24 -0300 Subject: [PATCH 1/2] Hot Fix: Prevent fatal errors on legacy forms (v2) when it has 'post_content' populated --- src/DonationForms/FormPage/TemplateHandler.php | 15 +++++++++++++-- .../Repositories/DonationFormRepository.php | 6 +++--- src/FormBuilder/Routes/EditFormRoute.php | 4 +++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/DonationForms/FormPage/TemplateHandler.php b/src/DonationForms/FormPage/TemplateHandler.php index c809e30105..6c5ae01d45 100644 --- a/src/DonationForms/FormPage/TemplateHandler.php +++ b/src/DonationForms/FormPage/TemplateHandler.php @@ -2,8 +2,12 @@ namespace Give\DonationForms\FormPage; +use Give\Helpers\Form\Utils; use WP_Post as Post; +/** + * @since 3.0.0 + */ class TemplateHandler { /** @@ -22,6 +26,9 @@ public function __construct( $post, string $formPageTemplatePath ) $this->formPageTemplatePath = $formPageTemplatePath; } + /** + * @since 3.0.0 + */ public function handle($template) { return $this->isNextGenForm() @@ -29,10 +36,14 @@ public function handle($template) : $template; } + /** + * @unreleased Use isV3Form() method instead of 'post_content' to check if the form is built with Visual Builder + * @since 3.0.0 + */ protected function isNextGenForm(): bool { return $this->post - && $this->post->post_content - &&'give_forms' === $this->post->post_type; + && Utils::isV3Form($this->post->ID) + && 'give_forms' === $this->post->post_type; } } diff --git a/src/DonationForms/Repositories/DonationFormRepository.php b/src/DonationForms/Repositories/DonationFormRepository.php index 35d1d606e6..c7db596e27 100644 --- a/src/DonationForms/Repositories/DonationFormRepository.php +++ b/src/DonationForms/Repositories/DonationFormRepository.php @@ -19,6 +19,7 @@ use Give\Framework\PaymentGateways\PaymentGateway; use Give\Framework\PaymentGateways\PaymentGatewayRegister; use Give\Framework\Support\Facades\DateTime\Temporal; +use Give\Helpers\Form\Utils; use Give\Helpers\Hooks; use Give\Log\Log; @@ -477,13 +478,12 @@ function ($value, Closure $fail, string $key, array $values) use ($formId) { } /** + * @unreleased Use isV3Form() method instead of 'post_content' to check if it's a legacy form * @since 3.0.0 */ public function isLegacyForm(int $formId): bool { - $form = DB::table('posts')->select(['post_content', 'data'])->where('ID', $formId)->get(); - - return empty($form->data); + return ! Utils::isV3Form($formId); } /** diff --git a/src/FormBuilder/Routes/EditFormRoute.php b/src/FormBuilder/Routes/EditFormRoute.php index 9122287d43..5050b99eca 100644 --- a/src/FormBuilder/Routes/EditFormRoute.php +++ b/src/FormBuilder/Routes/EditFormRoute.php @@ -3,6 +3,7 @@ namespace Give\FormBuilder\Routes; use Give\FormBuilder\FormBuilderRouteBuilder; +use Give\Helpers\Form\Utils; /** * Route to edit an existing form @@ -10,6 +11,7 @@ class EditFormRoute { /** + * @unreleased Use isV3Form() method instead of 'post_content' to check if the form is built with Visual Builder * @since 3.0.0 * * @return void @@ -18,7 +20,7 @@ public function __invoke() { if (isset($_GET['post'], $_GET['action']) && 'edit' === $_GET['action']) { $post = get_post(abs($_GET['post'])); - if ('give_forms' === $post->post_type && $post->post_content) { + if ('give_forms' === $post->post_type && Utils::isV3Form($post->ID)) { wp_redirect(FormBuilderRouteBuilder::makeEditFormRoute($post->ID)); exit(); } From a2bc9af1f1d326c2d518c563aba22d7f6eb767eb Mon Sep 17 00:00:00 2001 From: Angela Blake <35241639+angelablake@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:01:08 -0500 Subject: [PATCH 2/2] chore: prepare for 3.0.3 release --- give.php | 4 ++-- readme.txt | 5 ++++- src/DonationForms/FormPage/TemplateHandler.php | 2 +- src/DonationForms/Repositories/DonationFormRepository.php | 2 +- src/FormBuilder/Routes/EditFormRoute.php | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/give.php b/give.php index 90819819a0..8cc9b7f5e1 100644 --- a/give.php +++ b/give.php @@ -6,7 +6,7 @@ * Description: The most robust, flexible, and intuitive way to accept donations on WordPress. * Author: GiveWP * Author URI: https://givewp.com/ - * Version: 3.0.1 + * Version: 3.0.3 * Requires at least: 6.0 * Requires PHP: 7.2 * Text Domain: give @@ -391,7 +391,7 @@ private function setup_constants() { // Plugin version. if (!defined('GIVE_VERSION')) { - define('GIVE_VERSION', '3.0.1'); + define('GIVE_VERSION', '3.0.3'); } // Plugin Root File. diff --git a/readme.txt b/readme.txt index ec928249bc..05f66ff0de 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: donation, donate, recurring donations, fundraising, crowdfunding Requires at least: 6.0 Tested up to: 6.4 Requires PHP: 7.2 -Stable tag: 3.0.1 +Stable tag: 3.0.3 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -262,6 +262,9 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri 10. Use almost any payment gateway integration with GiveWP through our add-ons or by creating your own add-on. == Changelog == += 3.0.3: October 20th, 2023 = +* Fix: Forms no longer have fatal errors on Elementor websites when the Display Content option is enabled + = 3.0.1: October 17th, 2023 = * Fix: Resolved a conflict with Matomo plugin that was causing a fatal error diff --git a/src/DonationForms/FormPage/TemplateHandler.php b/src/DonationForms/FormPage/TemplateHandler.php index 6c5ae01d45..8f286371d1 100644 --- a/src/DonationForms/FormPage/TemplateHandler.php +++ b/src/DonationForms/FormPage/TemplateHandler.php @@ -37,7 +37,7 @@ public function handle($template) } /** - * @unreleased Use isV3Form() method instead of 'post_content' to check if the form is built with Visual Builder + * @since 3.0.3 Use isV3Form() method instead of 'post_content' to check if the form is built with Visual Builder * @since 3.0.0 */ protected function isNextGenForm(): bool diff --git a/src/DonationForms/Repositories/DonationFormRepository.php b/src/DonationForms/Repositories/DonationFormRepository.php index c7db596e27..4e2dc185d5 100644 --- a/src/DonationForms/Repositories/DonationFormRepository.php +++ b/src/DonationForms/Repositories/DonationFormRepository.php @@ -478,7 +478,7 @@ function ($value, Closure $fail, string $key, array $values) use ($formId) { } /** - * @unreleased Use isV3Form() method instead of 'post_content' to check if it's a legacy form + * @since 3.0.3 Use isV3Form() method instead of 'post_content' to check if it's a legacy form * @since 3.0.0 */ public function isLegacyForm(int $formId): bool diff --git a/src/FormBuilder/Routes/EditFormRoute.php b/src/FormBuilder/Routes/EditFormRoute.php index 5050b99eca..a72aaff071 100644 --- a/src/FormBuilder/Routes/EditFormRoute.php +++ b/src/FormBuilder/Routes/EditFormRoute.php @@ -11,7 +11,7 @@ class EditFormRoute { /** - * @unreleased Use isV3Form() method instead of 'post_content' to check if the form is built with Visual Builder + * @since 3.0.3 Use isV3Form() method instead of 'post_content' to check if the form is built with Visual Builder * @since 3.0.0 * * @return void