Skip to content

Commit

Permalink
Merge branch 'develop' into fix/donor-wall-shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski committed Oct 25, 2023
2 parents 3964320 + 3e9a81f commit 7a560da
Show file tree
Hide file tree
Showing 27 changed files with 130 additions and 280 deletions.
4 changes: 2 additions & 2 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.2');
}

// Plugin Root File.
Expand Down
3 changes: 2 additions & 1 deletion includes/admin/settings/class-settings-gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ static function ($value, $key) {
$gateways,
give()->gateways->getPaymentGateways(2)
)
)
),
2
);

// v3 gateways are gateways that are registered with updated gateway registration API.
Expand Down
3 changes: 1 addition & 2 deletions includes/forms/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1703,8 +1703,7 @@ class="give-cancel-login give-checkout-register-cancel give-btn button" name="gi
* @since 1.0
*/
function give_payment_mode_select( $form_id, $args ) {

$gateways = give_get_enabled_payment_gateways( $form_id );
$gateways = give_get_enabled_payment_gateways($form_id, 2);
$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';

/**
Expand Down
60 changes: 43 additions & 17 deletions includes/gateways/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
* @param int|null $version
* @return array $gateways All the available gateways
*/
function give_get_payment_gateways($version = 2)
function give_get_payment_gateways($version = null)
{
$suffix = $version === 3 ? '_v3' : '';

// Default, built-in gateways
$gateways = apply_filters(
'give_payment_gateways',
Expand All @@ -43,7 +41,14 @@ function give_get_payment_gateways($version = 2)
}
});

$gatewayLabels = give_get_option('gateways_label' . $suffix, []);
$gatewayLabels = [];
if (!$version || $version === 2) {
$gatewayLabels = array_merge($gatewayLabels, (array)give_get_option('gateways_label', []));
}

if (!$version || $version === 3) {
$gatewayLabels = array_merge($gatewayLabels, (array)give_get_option('gateways_label_v3', []));
}

// Replace payment gateway checkout label with admin defined checkout label.
if ($gatewayLabels) {
Expand All @@ -67,12 +72,20 @@ function give_get_payment_gateways($version = 2)
* @param int|null $version
* @return array $gateway_list All the available gateways
*/
function give_get_enabled_payment_gateways($form_id = 0, $version = 2)
function give_get_enabled_payment_gateways($form_id = 0, $version = null)
{
$suffix = $version === 3 ? '_v3' : '';
$gateways = give_get_payment_gateways($version);

$enabled = $_POST['gateways' . $suffix] ?? give_get_option('gateways' . $suffix);
$enabled = [];
if (!$version || $version === 2) {
$gatewaysFromPostRequest = isset($_POST['gateways']) ? (array)$_POST['gateways'] : null;
$enabled = array_merge($enabled, $gatewaysFromPostRequest ?? (array)give_get_option('gateways', []));
}

if (!$version || $version === 3) {
$gatewaysFromPostRequest = isset($_POST['gateways_v3']) ? (array)$_POST['gateways_v3'] : null;
$enabled = array_merge($enabled, $gatewaysFromPostRequest ?? (array)give_get_option('gateways_v3', []));
}

$gateway_list = [];

Expand All @@ -91,7 +104,7 @@ function give_get_enabled_payment_gateways($form_id = 0, $version = 2)
/**
* Checks whether a specified gateway is activated.
*
* @unlreased add $version param
* @since 3.0.2 add $version param
* @since 1.0
*
* @param string $gateway Name of the gateway to check for
Expand All @@ -110,7 +123,7 @@ function give_is_gateway_active($gateway, $version = 2)
/**
* Gets the default payment gateway selected from the Give Settings
*
* @unlreased add $version param
* @since 3.0.2 add $version param
* @since 1.0
*
* @param int|null $form_id int ID of the Give Form
Expand Down Expand Up @@ -345,19 +358,32 @@ function give_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish
/**
* Returns a ordered list of all available gateways.
*
* @unlreased add $version param
* @since 3.0.2 add $version param
* @since 1.4.5
*
* @param array $gateways List of payment gateways
* @param int|null $version
* @return array $gateways All the available gateways
*/
function give_get_ordered_payment_gateways($gateways, $version = 2)
function give_get_ordered_payment_gateways($gateways, $version = null)
{
$suffix = $version === 3 ? '_v3' : '';

// Get gateways setting.
$gateways_setting = $_POST['gateways' . $suffix] ?? give_get_option('gateways' . $suffix);
$gateways_setting = [];
if (!$version || $version === 2) {
$gatewaysFromPostRequest = isset($_POST['gateways']) ? (array)$_POST['gateways'] : null;
$gateways_setting = array_merge(
$gateways_setting,
$gatewaysFromPostRequest ?? (array)give_get_option('gateways', [])
);
}

if (!$version || $version === 3) {
$gatewaysFromPostRequest = isset($_POST['gateways_v3']) ? (array)$_POST['gateways_v3'] : null;
$gateways_setting = array_merge(
$gateways_setting,
$gatewaysFromPostRequest ?? (array)give_get_option('gateways_v3', [])
);
}

// Return from here if we do not have gateways setting.
if ( empty( $gateways_setting ) ) {
Expand All @@ -369,8 +395,7 @@ function give_get_ordered_payment_gateways($gateways, $version = 2)

// Reorder gateways array
foreach ( $gateways_setting as $gateway_key => $value ) {

$new_gateway_value = isset( $gateways[ $gateway_key ] ) ? $gateways[ $gateway_key ] : '';
$new_gateway_value = $gateways[$gateway_key] ?? '';
unset( $gateways[ $gateway_key ] );

if ( ! empty( $new_gateway_value ) ) {
Expand All @@ -381,9 +406,10 @@ function give_get_ordered_payment_gateways($gateways, $version = 2)
/**
* Filter payment gateways order.
*
* @since 3.0.2 add $version param
* @since 1.7
*
* @param array $gateways All the available gateways
*/
return apply_filters('give_payment_gateways_order' . $suffix, $gateways);
return apply_filters('give_payment_gateways_order', $gateways, $version);
}
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -262,6 +262,13 @@ 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.2: October 19th, 2023 =
<<<<<<<<< Temporary merge branch 1
* Fix: Stripe per-form settings are included when migrating a form to the Visual Donation Form Builder
=========
* Fix: Gateways are properly separated in the settings page and Global Settings for Fee Recovery shows all gateways when you select per gateway

>>>>>>>>> Temporary merge branch 2
= 3.0.1: October 17th, 2023 =
* Fix: Resolved a conflict with Matomo plugin that was causing a fatal error

Expand Down
15 changes: 13 additions & 2 deletions src/DonationForms/FormPage/TemplateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace Give\DonationForms\FormPage;

use Give\Helpers\Form\Utils;
use WP_Post as Post;

/**
* @since 3.0.0
*/
class TemplateHandler
{
/**
Expand All @@ -22,17 +26,24 @@ public function __construct( $post, string $formPageTemplatePath )
$this->formPageTemplatePath = $formPageTemplatePath;
}

/**
* @since 3.0.0
*/
public function handle($template)
{
return $this->isNextGenForm()
? $this->formPageTemplatePath
: $template;
}

/**
* @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
{
return $this->post
&& $this->post->post_content
&&'give_forms' === $this->post->post_type;
&& Utils::isV3Form($this->post->ID)
&& 'give_forms' === $this->post->post_type;
}
}
6 changes: 3 additions & 3 deletions src/DonationForms/Repositories/DonationFormRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -477,13 +478,12 @@ function ($value, Closure $fail, string $key, array $values) use ($formId) {
}

/**
* @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
{
$form = DB::table('posts')->select(['post_content', 'data'])->where('ID', $formId)->get();

return empty($form->data);
return ! Utils::isV3Form($formId);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/FormBuilder/Routes/EditFormRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
namespace Give\FormBuilder\Routes;

use Give\FormBuilder\FormBuilderRouteBuilder;
use Give\Helpers\Form\Utils;

/**
* Route to edit an existing form
*/
class EditFormRoute
{
/**
* @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
Expand All @@ -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();
}
Expand Down
14 changes: 11 additions & 3 deletions src/FormBuilder/ViewModels/FormBuilderViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ public function isRecurringEnabled(): bool
/**
* @since 3.0.0
*/
public function getGoalTypeOption(string $value, string $label, string $description): array
public function getGoalTypeOption(
string $value,
string $label,
string $description,
bool $isCurrency = false
): array
{
return [
'value' => $value,
'label' => $label,
'description' => $description,
'isCurrency' => $isCurrency,
];
}

Expand All @@ -105,7 +111,8 @@ public function getGoalTypeOptions(): array
$this->getGoalTypeOption(
GoalType::AMOUNT,
__('Amount Raised', 'give'),
__('The total amount raised for the form', 'give')
__('The total amount raised for the form', 'give'),
true
),
$this->getGoalTypeOption(
GoalType::DONATIONS,
Expand All @@ -124,7 +131,8 @@ public function getGoalTypeOptions(): array
$this->getGoalTypeOption(
GoalType::AMOUNT_FROM_SUBSCRIPTIONS,
__('Subscription Amount Raised', 'give'),
__('The total amount raised for the form through subscriptions', 'give')
__('The total amount raised for the form through subscriptions', 'give'),
true
),
$this->getGoalTypeOption(
GoalType::SUBSCRIPTIONS,
Expand Down
2 changes: 0 additions & 2 deletions src/FormBuilder/resources/js/form-builder/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import BlockEditorContainer from './containers/BlockEditorContainer';
import {FormStateProvider} from './stores/form-state';
import {Storage} from './common';
import defaultBlocks from './blocks.json';
import Feedback from '@givewp/form-builder/feedback';
import {BlockInstance} from '@wordpress/blocks';
import './App.scss';
import FormBuilderErrorBoundary from '@givewp/form-builder/errors/FormBuilderErrorBounday';
Expand Down Expand Up @@ -55,7 +54,6 @@ export default function App() {
<FormStateProvider initialState={initialState}>
<ShortcutProvider>
<BlockEditorContainer />
<Feedback />
<Transfer />
</ShortcutProvider>
</FormStateProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {BlockEditProps} from '@wordpress/blocks';
import {RichText, InspectorControls} from '@wordpress/block-editor';
import {RichText} from '@wordpress/block-editor';
import {__} from '@wordpress/i18n';
import {PanelBody, PanelRow, TextareaControl, TextControl} from "@wordpress/components";

export default function Edit({attributes, setAttributes}: BlockEditProps<any>) {
const {content} = attributes;
Expand All @@ -15,17 +14,6 @@ export default function Edit({attributes, setAttributes}: BlockEditProps<any>) {
onChange={(content) => setAttributes({content})}
placeholder={__('Enter some text', 'give')}
/>
<InspectorControls>
<PanelBody title={__('Attributes', 'give')} initialOpen={true}>
<PanelRow>
<TextareaControl
label={__('Content', 'give')}
value={content}
onChange={(content) => setAttributes({content})}
/>
</PanelRow>
</PanelBody>
</InspectorControls>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type GoalTypeOption = {
value: string;
label: string;
description: string;
isCurrency: boolean;
};

/**
Expand Down
Loading

0 comments on commit 7a560da

Please sign in to comment.