Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTheAdams committed Apr 6, 2023
2 parents faf4b90 + d90fa05 commit 505e493
Show file tree
Hide file tree
Showing 28 changed files with 595 additions and 125 deletions.
14 changes: 12 additions & 2 deletions assets/src/js/frontend/give-donations.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,18 @@ jQuery( function( $ ) {
// Auto set give price id.
$( 'input[name="give-price-id"]', parent_form ).val( price_id );

// Update hidden amount field
parent_form.find( '.give-amount-hidden' ).val( Give.form.fn.formatAmount( value_now, parent_form, {} ) );
// Update hidden amount field
const hiddenAmountField = parent_form.find('.give-amount-hidden');
if (hiddenAmountField) {
hiddenAmountField.val(Give.form.fn.formatAmount(value_now, parent_form, {}));
// Trigger change event.
// We use amount field classes to trigger change event on input field,
// But when custom amount disabled then we use hidden field to store amount and span HTML tag to show amount.
// This means, if logic depends on amount change event (field with "give-amount" name) then it will not work.
// So, it is required to trigger change event on 'give-amount' hidden field.
// For example: Form field manager (feature: conditional field visibility)
hiddenAmountField.trigger('change');
}

// Remove old selected class & add class for CSS purposes
parent_form.find( '.give-default-level' ).removeClass( 'give-default-level' );
Expand Down
6 changes: 4 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: 2.25.3
* Version: 2.26.0
* Requires at least: 5.0
* Requires PHP: 7.0
* Text Domain: give
Expand Down Expand Up @@ -56,6 +56,7 @@
use Give\Form\LegacyConsumer\ServiceProvider as FormLegacyConsumerServiceProvider;
use Give\Form\Templates;
use Give\Framework\Database\ServiceProvider as DatabaseServiceProvider;
use Give\Framework\DesignSystem\DesignSystemServiceProvider;
use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
use Give\Framework\Exceptions\UncaughtExceptionLogger;
use Give\Framework\Http\ServiceProvider as HttpServiceProvider;
Expand Down Expand Up @@ -209,6 +210,7 @@ final class Give
ValidationServiceProvider::class,
ValidationRulesServiceProvider::class,
HttpServiceProvider::class,
DesignSystemServiceProvider::class,
];

/**
Expand Down Expand Up @@ -312,7 +314,7 @@ private function setup_constants()
{
// Plugin version.
if (!defined('GIVE_VERSION')) {
define('GIVE_VERSION', '2.25.2');
define('GIVE_VERSION', '2.26.0');
}

// Plugin Root File.
Expand Down
5 changes: 4 additions & 1 deletion includes/admin/admin-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,10 @@ function give_donation_import_callback() {
$import_setting['dry_run'] = $output['dry_run'];

// Parent key id.
$main_key = maybe_unserialize( $output['main_key'] );
$main_key = is_serialized( $output['main_key'] )
/** @since 2.26.0 Avoid insecure usage of `unserialize` when the data could be submitted by the user. */
? @unserialize( trim( $output['main_key'] ), ['allowed_classes' => false] )
: $output['main_key'];

$current = absint( $_REQUEST['current'] );
$total_ajax = absint( $_REQUEST['total_ajax'] );
Expand Down
7 changes: 4 additions & 3 deletions includes/admin/import-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ function give_import_donation_report_reset() {
/**
* Give get form data from csv if not then create and form and return the form value.
*
* @since 1.8.13.
* @since 1.8.13.
* @since 2.26.0 Replace deprecated get_page_by_title() with give_get_page_by_title().
*
* @param $data .
*
Expand Down Expand Up @@ -73,7 +74,7 @@ function give_import_get_form_data_from_csv( $data, $import_setting = [] ) {
}

if ( false === $form && ! empty( $data['form_title'] ) ) {
$form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' );
$form = give_get_page_by_title($data['form_title'], OBJECT, 'give_forms');

if ( ! empty( $form->ID ) ) {

Expand All @@ -96,7 +97,7 @@ function give_import_get_form_data_from_csv( $data, $import_setting = [] ) {

}

$form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' );
$form = give_get_page_by_title($data['form_title'], OBJECT, 'give_forms');
if ( ! empty( $form->ID ) ) {
$form = new Give_Donate_Form( $form->ID );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ public static function upload_widget_settings_file() {
public static function json_upload_mimes( $existing_mimes = array() ) {

$existing_mimes['json'] = 'application/json';
$existing_mimes['text'] = 'text/plain';

return $existing_mimes;
}
Expand Down
34 changes: 34 additions & 0 deletions includes/misc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2578,3 +2578,37 @@ function give_check_addon_updates( $_transient_data ) {

return $_transient_data;
}

/**
* Get page by title
*
* @since 2.26.0
*
* @param string $page_title
* @param string $output
* @param string $post_type
*
* @return null|WP_Post
*/
function give_get_page_by_title($page_title, $output = OBJECT, $post_type)
{
$args = [
'title' => $page_title,
'post_type' => $post_type,
'post_status' => get_post_stati(),
'posts_per_page' => 1,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'no_found_rows' => true,
'orderby' => 'post_date ID',
'order' => 'ASC',
];
$query = new WP_Query($args);
$pages = $query->posts;

if (empty($pages)) {
return null;
}

return get_post($pages[0], $output);
}
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@fortawesome/free-regular-svg-icons": "^5.15.1",
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/react-fontawesome": "^0.1.12",
"@givewp/design-system-foundation": "^1.1.0",
"@paypal/paypal-js": "^1.0.2",
"@reach/tabs": "^0.16.1",
"@stripe/react-stripe-js": "^1.2.2",
Expand Down
24 changes: 20 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: givewp, dlocc, webdevmattcrom, ravinderk, mehul0810, kevinwhoffman
Donate link: https://go.givewp.com/home
Tags: donation, donate, recurring donations, fundraising, crowdfunding
Requires at least: 5.0
Tested up to: 6.1
Tested up to: 6.2
Requires PHP: 7.0
Stable tag: 2.25.3
Stable tag: 2.26.0
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -128,6 +128,13 @@ Are you a developer? GiveWP is built with best practices and easy to extend and
* [Site Redesigns Without Donation Data Loss](https://go.givewp.com/datalossdoc)
* [Handling Custom CSS in WordPress](https://go.givewp.com/cssdoc)

=== 🚀 Join the Journey to Create the Next Generation of WordPress Donation Forms ===
Team Give has been working hard for the past several years on updating how donation forms are created. The user experience is going to change for the better, but we want your help shaping what that means!

Help us test our new visual form builder with the GiveWP 3.0 Feature plugin. The Feaure Plugin (or GiveWP 3.0 Beta) is meant to be used alongside GiveWP core on a staging or local environment. We are looking specifically at the form builder with this beta test and would love for all GiveWP users to give it a try. All feedback is welcome! [Download the beta plugin directly on WordPress](https://go.givewp.com/corewppg) or through your admin dashboard plugins area.

Learn more about how we're creating the next generation of WordPress donation forms, [directly on our website](https://go.givewp.com/corenextgen).

=== 💚 About the GiveWP Team ===

GiveWP is part of StellarWP, a Liquid Web Family Brand. Our donation plugin is backed by a growing team of WordPress developers, support engineers, customer success managers, and marketing professionals who’ve worked with WordPress and nonprofits since 2009. This means GiveWP is made with best practices in mind; extremely extensible and customizable, stable, and reliable. We’ll be here in years to come for you and your nonprofit organization.
Expand All @@ -144,11 +151,11 @@ Stay in touch with us for important plugin news and updates:

=== 🐱‍💻 Contribute to GiveWP ===

This plugin is proudly open source (GPL license) and we’re always looking for more contributors. Whether you know another language, can code like no one’s business, or just have an idea, we would love your help and input.
This plugin is proudly open source (GPL license) and we’re always looking for more contributors. Whether you know another language, love to code, or just have an idea, we would love your help and input.

Here’s a few ways you can contribute to GiveWP:

* Star/fork/watch the [GiveWP GitHub repository](https://go.givewp.com/github "Visit the GiveWP GitHub Repo") to learn more about what issues we're tackling and the project is developing. If you've never worked with Github before, learn about [pull requests here](https://help.github.com/articles/about-pull-requests/) and submit one for GiveWP, we'd love to give you our feedback.
* Star/fork/watch the [GiveWP GitHub repository](https://go.givewp.com/github) to learn more about what issues we're tackling and the project is developing. If you've never worked with Github before, learn about [pull requests here](https://help.github.com/articles/about-pull-requests/) and submit one for GiveWP, we'd love to give you our feedback.

* Translate GiveWP into your native language. The best place to do that is here on wordpress.org. Go to [https://translate.wordpress.org/](https://translate.wordpress.org/projects/wp-plugins/give), then search for your language, click the "Plugins" tab, then search for "GiveWP". When you've submitted at least 95% of GiveWP's strings, the language moderators will review and approve your translations and then they will be available to all WordPress users for your native language. If you are interested in translating any of our Premium Add-ons, [contact us](https://go.givewp.com/contact), we'd love to chat with you about that.

Expand Down Expand Up @@ -251,6 +258,15 @@ The 2% fee on Stripe donations only applies to donations taken via our free Stri
8. GiveWP has a dedicated support team to help answer any questions you may have and help you through stumbling blocks.

== Changelog ==
= 2.26.0: April 6th, 2023 =
* Enhancement: Minor updates for improved WordPress 6.2 compatibility
* Enhancement: A number of under the hood improvements in preparation for the upcoming Visual Donation Form Builder feature plugin release
* Enhancement: Improvements to recurring donations in the Gateway API
* Enhancement: Implemented our new GiveWP design system to improve designs across our website and prdocuts
* Fix: Conditionals fields based on the amount field work again
* Fix: Files with a text mime type now work when uploading files for import
* Fix: If an error occurs in the Donor Dashboard when canceling a subscription, that subscription is no longer marked as canceled

= 2.25.3: March 22nd, 2023 =
* Security: Protect against CSRF during donation import

Expand Down
15 changes: 14 additions & 1 deletion src/DonorDashboards/Tabs/Contracts/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Give\DonorDashboards\Tabs\Contracts;

use Exception;
use Give\API\RestRoute;
use Give\DonorDashboards\Helpers as DonorDashboardHelpers;
use Give\Log\Log;
use WP_Error;
use WP_REST_Request;
use WP_REST_Response;

Expand Down Expand Up @@ -69,6 +71,9 @@ public function registerRoute()
);
}

/**
* @since 2.26.0 add try/catch to handleRequest
*/
public function handleRequestWithDonorIdCheck(WP_REST_Request $request)
{
// Check that the provided donor ID is valid
Expand Down Expand Up @@ -102,6 +107,14 @@ public function handleRequestWithDonorIdCheck(WP_REST_Request $request)
);
}

return $this->handleRequest($request);
try {
$response = $this->handleRequest($request);

return rest_ensure_response($response ?? []);
} catch (Exception $exception) {
$error = new WP_Error('error', $exception->getMessage());

return rest_ensure_response($error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@ import {cancelSubscriptionWithAPI} from './utils';

import {__} from '@wordpress/i18n';
import './style.scss';
import {useState} from 'react';

const responseIsError = (response) => {
return response?.data?.code.includes('error');
};

const getErrorMessageFromResponse = (response) => {
if (response?.data?.code === 'internal_server_error' || !response?.data?.message) {
return __('An error occurred while cancelling your subscription.', 'give');
}

return response?.data?.message;
};

const SubscriptionCancelModal = ({id, onRequestClose}) => {
const [cancelling, setCancelling] = useState(false);
const handleCancel = async () => {
await cancelSubscriptionWithAPI(id);
setCancelling(true);
const response = await cancelSubscriptionWithAPI(id);

if (responseIsError(response)) {
const errorMessage = getErrorMessageFromResponse(response);

window.alert(errorMessage);
}

setCancelling(false);

onRequestClose();
};

Expand All @@ -16,7 +40,9 @@ const SubscriptionCancelModal = ({id, onRequestClose}) => {
<div className="give-donor-dashboard-cancel-modal__header">{__('Cancel Subscription?', 'give')}</div>
<div className="give-donor-dashboard-cancel-modal__body">
<div className="give-donor-dashboard-cancel-modal__buttons">
<Button onClick={() => handleCancel()}>{__('Yes, cancel', 'give')}</Button>
<Button disabled={cancelling} onClick={() => handleCancel()}>
{!cancelling ? __('Yes, cancel', 'give') : __('Cancelling...', 'give')}
</Button>
<a className="give-donor-dashboard-cancel-modal__cancel" onClick={() => onRequestClose()}>
{__('Nevermind', 'give')}
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import {donorDashboardApi} from '../../../utils';
import {fetchSubscriptionsDataFromAPI} from '../../../tabs/recurring-donations/utils';

export const cancelSubscriptionWithAPI = (id) => {
return donorDashboardApi
.post(
export const cancelSubscriptionWithAPI = async (id) => {
try {
const response = await donorDashboardApi.post(
'recurring-donations/subscription/cancel',
{
id: id,
},
{}
)
.then(async (response) => {
await fetchSubscriptionsDataFromAPI();
return response;
});
);

await fetchSubscriptionsDataFromAPI();

return await response;
} catch (error) {
return error.response;
}
};
21 changes: 21 additions & 0 deletions src/Framework/DesignSystem/Actions/RegisterDesignSystemStyles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Give\Framework\DesignSystem\Actions;

class RegisterDesignSystemStyles
{
/**
* @since 2.26.0
*/
public function __invoke()
{
$version = file_get_contents(GIVE_PLUGIN_DIR . 'assets/dist/css/design-system/version');

wp_register_style(
'givewp-design-system-foundation',
GIVE_PLUGIN_URL . 'assets/dist/css/design-system/foundation.css',
[],
$version
);
}
}
26 changes: 26 additions & 0 deletions src/Framework/DesignSystem/DesignSystemServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Give\Framework\DesignSystem;

use Give\Framework\DesignSystem\Actions\RegisterDesignSystemStyles;
use Give\Helpers\Hooks;
use Give\ServiceProviders\ServiceProvider;

class DesignSystemServiceProvider implements ServiceProvider
{
/**
* @since 2.26.0
*/
public function register()
{
}

/**
* @since 2.26.0
*/
public function boot()
{
Hooks::addAction('wp_enqueue_scripts', RegisterDesignSystemStyles::class);
Hooks::addAction('admin_enqueue_scripts', RegisterDesignSystemStyles::class);
}
}
Loading

0 comments on commit 505e493

Please sign in to comment.