Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Jan 08 #1637

Merged
merged 11 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# [2.5.0-alpha.2](https://github.com/Automattic/newspack-blocks/compare/v2.5.0-alpha.1...v2.5.0-alpha.2) (2023-12-22)


### Bug Fixes

* avoid duplicity with linked guest authors ([#1632](https://github.com/Automattic/newspack-blocks/issues/1632)) ([608979c](https://github.com/Automattic/newspack-blocks/commit/608979c1e9cb63a7098da27c69c337ec233b7429))
* **modal-checkout:** show order details table with fees ([#1633](https://github.com/Automattic/newspack-blocks/issues/1633)) ([07c0642](https://github.com/Automattic/newspack-blocks/commit/07c0642e77a075750c6f436f12af99cd3e2ef360))


### Features

* **modal-checkout:** allow anonymous purchase for registered email ([#1615](https://github.com/Automattic/newspack-blocks/issues/1615)) ([a0040b4](https://github.com/Automattic/newspack-blocks/commit/a0040b43a3f97c889e5bb5b5b96f07777b52a670))

# [2.5.0-alpha.1](https://github.com/Automattic/newspack-blocks/compare/v2.4.0...v2.5.0-alpha.1) (2023-12-15)


### Features

* accessibility improvements to the donate block tabs ([#1622](https://github.com/Automattic/newspack-blocks/issues/1622)) ([115e9fb](https://github.com/Automattic/newspack-blocks/commit/115e9fb95c78a13f1d87f4d086e767311dc7007d))
* **donate:** support empty value for "other" tier ([#1604](https://github.com/Automattic/newspack-blocks/issues/1604)) ([61ffdbc](https://github.com/Automattic/newspack-blocks/commit/61ffdbc57e6fda320766d4de99f097edac9e58f7))

# [2.4.0](https://github.com/Automattic/newspack-blocks/compare/v2.3.0...v2.4.0) (2023-12-11)


Expand Down
51 changes: 51 additions & 0 deletions includes/class-modal-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public static function init() {
add_filter( 'woocommerce_order_button_text', [ __CLASS__, 'order_button_text' ] );
add_filter( 'option_woocommerce_subscriptions_order_button_text', [ __CLASS__, 'order_button_text' ] );

/** Custom handling for registered users. */
add_filter( 'woocommerce_checkout_customer_id', [ __CLASS__, 'associate_existing_user' ] );
add_filter( 'woocommerce_checkout_posted_data', [ __CLASS__, 'skip_account_creation' ], 11 );

// Remove some stuff from the modal checkout page. It's displayed in an iframe, so it should not be treated as a separate page.
add_action( 'wp_enqueue_scripts', [ __CLASS__, 'dequeue_scripts' ], 11 );
add_filter( 'newspack_reader_activation_should_render_auth', [ __CLASS__, 'is_not_modal_checkout_filter' ] );
Expand Down Expand Up @@ -697,6 +701,9 @@ public static function should_show_order_details() {
if ( 1 < $cart->get_cart_contents_count() ) {
return true;
}
if ( ! empty( $cart->get_fees() ) ) {
return true;
}
return false;
}

Expand Down Expand Up @@ -973,6 +980,50 @@ public static function order_button_text( $text ) {
return $text;
}

/**
* If a reader tries to make a purchase with an email address that
* has been previously registered, automatically associate the transaction
* with the user.
*
* @param int $customer_id Current customer ID.
*
* @return int Modified $customer_id
*/
public static function associate_existing_user( $customer_id ) {
if ( ! self::is_modal_checkout() ) {
return $customer_id;
}
$billing_email = filter_input( INPUT_POST, 'billing_email', FILTER_SANITIZE_EMAIL );
if ( $billing_email ) {
$customer = \get_user_by( 'email', $billing_email );
if ( $customer ) {
$customer_id = $customer->ID;
}
}
return $customer_id;
}

/**
* Don't force account registration/login on Woo purchases for existing users.
*
* @param array $data Array of Woo checkout data.
*
* @return array Modified $data.
*/
public static function skip_account_creation( $data ) {
if ( ! self::is_modal_checkout() ) {
return $data;
}
$email = $data['billing_email'];
$customer = \get_user_by( 'email', $email );
if ( $customer ) {
$data['createaccount'] = 0;
\add_filter( 'woocommerce_checkout_registration_required', '__return_false', 9999 );
}

return $data;
}

/**
* Filter the a value dependent on the page not being modal checkout.
*
Expand Down
4 changes: 2 additions & 2 deletions newspack-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* Author URI: https://newspack.com/
* Text Domain: newspack-blocks
* Domain Path: /languages
* Version: 2.4.0
* Version: 2.5.0-alpha.2
*
* @package Newspack_Blocks
*/

define( 'NEWSPACK_BLOCKS__PLUGIN_FILE', __FILE__ );
define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', 'dist/' );
define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( NEWSPACK_BLOCKS__PLUGIN_FILE ) );
define( 'NEWSPACK_BLOCKS__VERSION', '2.4.0' );
define( 'NEWSPACK_BLOCKS__VERSION', '2.5.0-alpha.2' );

require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks.php';
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-api.php';
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automattic/newspack-blocks",
"version": "2.4.0",
"version": "2.5.0-alpha.2",
"author": "Automattic",
"devDependencies": {
"@rushstack/eslint-patch": "^1.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public function get_authors( $request ) {
// Total number of users and guest authors.
$guest_author_total = 0;
$user_total = 0;
$guest_authors = [];
$linked_guest_authors = [];

// Get Co-authors guest authors.
if ( $is_guest_author ) {
Expand All @@ -108,6 +110,14 @@ public function get_authors( $request ) {
$guest_author_total = count( $guest_authors );
}

foreach ( $guest_authors as $ga ) {
$linked_guest_author = get_post_meta( $ga->ID, 'cap-linked_account', true );

if ( $linked_guest_author ) {
$linked_guest_authors[] = $linked_guest_author;
}
}

$users = [];

// If passed an author ID.
Expand Down Expand Up @@ -187,8 +197,14 @@ function( $acc, $guest_author ) use ( $fields, $avatar_hide_default ) {
),
array_reduce(
$users,
function( $acc, $user ) use ( $fields, $avatar_hide_default ) {
function( $acc, $user ) use ( $fields, $avatar_hide_default, $linked_guest_authors ) {
if ( $user ) {

// This user is linked to a guest author already returned in the query, so skip it.
if ( in_array( $user->data->user_login, $linked_guest_authors, true ) ) {
return $acc;
}

$user_data = [
'id' => intval( $user->data->ID ),
'registered' => $user->data->user_registered,
Expand Down
39 changes: 27 additions & 12 deletions src/blocks/donate/edit/FrequencyBasedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classNames from 'classnames';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useMemo, useEffect, useRef } from '@wordpress/element';
import { useMemo, useEffect, useRef, useState } from '@wordpress/element';
import { SelectControl } from '@wordpress/components';
import { RichText } from '@wordpress/block-editor';

Expand Down Expand Up @@ -68,29 +68,48 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) =
const isRenderingStripePaymentForm =
window.newspack_blocks_data?.is_rendering_stripe_payment_form;

const [ selectedFrequency, setSelectedFrequency ] = useState( attributes.defaultFrequency );

const renderFrequencySelect = ( frequencySlug: DonationFrequencySlug ) => (
<>
<input
type="radio"
value={ frequencySlug }
id={ `newspack-donate-${ frequencySlug }-${ uid }` }
name="donation_frequency"
defaultChecked={ frequencySlug === attributes.defaultFrequency }
checked={ frequencySlug === selectedFrequency }
onChange={ evt => setSelectedFrequency( evt.target.value as 'once' | 'month' | 'year' ) }
/>
<label
htmlFor={ 'newspack-donate-' + frequencySlug + '-' + uid }
className="wpbnbd__button freq-label"
>
<label htmlFor={ 'newspack-donate-' + frequencySlug + '-' + uid }>
{ FREQUENCIES[ frequencySlug ] }
</label>
</>
);

const renderTab = ( frequencySlug: DonationFrequencySlug ) => (
<button
key={ frequencySlug }
role="tab"
className={ classNames( 'wpbnbd__button freq-label', {
'wpbnbd__button--active': frequencySlug === selectedFrequency,
} ) }
id={ `tab-newspack-donate-${ frequencySlug }-${ uid }` }
onClick={ evt => {
evt.preventDefault();
setSelectedFrequency( frequencySlug );
} }
>
{ FREQUENCIES[ frequencySlug ] }
</button>
);

// This code is fired on tab select and updates aria elements, tabindex states, and radio buttons
const displayAmount = ( amount: number ) => amount.toFixed( 2 ).replace( /\.?0*$/, '' );

const renderUntieredForm = () => (
<div className="wp-block-newspack-blocks-donate__options">
<div className="wp-block-newspack-blocks-donate__frequencies frequencies">
<div className="tab-container">{ availableFrequencies.map( renderTab ) }</div>
{ availableFrequencies.map( frequencySlug => (
<div
className="wp-block-newspack-blocks-donate__frequency frequency"
Expand Down Expand Up @@ -123,6 +142,7 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) =
const renderTieredForm = () => (
<div className="wp-block-newspack-blocks-donate__options">
<div className="wp-block-newspack-blocks-donate__frequencies frequencies">
<div className="tab-container">{ availableFrequencies.map( renderTab ) }</div>
{ availableFrequencies.map( frequencySlug => (
<div
className="wp-block-newspack-blocks-donate__frequency frequency"
Expand Down Expand Up @@ -166,12 +186,7 @@ const FrequencyBasedLayout = ( props: { isTiered: boolean } & ComponentProps ) =
</label>
<div className="wp-block-newspack-blocks-donate__money-input money-input">
<span className="currency">{ settings.currencySymbol }</span>
<AmountValueInput
{ ...props }
frequencySlug={ frequencySlug }
tierIndex={ index }
id={ `${ id }-other-input` }
/>
<input type="number" readOnly />
</div>
</>
) : null }
Expand Down
37 changes: 21 additions & 16 deletions src/blocks/donate/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const TIER_LABELS = [
__( 'Low-tier', 'newspack-blocks' ),
__( 'Mid-tier', 'newspack-blocks' ),
__( 'High-tier', 'newspack-blocks' ),
__( 'Other', 'newspack-blocks' ),
];

const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
Expand Down Expand Up @@ -302,21 +301,27 @@ const Edit = ( { attributes, setAttributes, className }: EditProps ) => {
false
) && renderMinAmountWarning() }

{ amounts[ frequency ].map( ( suggestedAmount, tierIndex ) => (
<AmountValueInput
ignoreMinimumAmount
{ ...componentProps }
key={ `amount-${ frequency }-${ tierIndex }` }
frequencySlug={ frequency }
tierIndex={ tierIndex }
label={ TIER_LABELS[ tierIndex ] }
id={ `${ frequency }-${ tierIndex }-amount` }
disabled={
isTierBasedLayoutEnabled &&
tierIndex === DISABLED_IN_TIERS_BASED_LAYOUT_TIER_INDEX
}
/>
) ) }
{ amounts[ frequency ].map( ( suggestedAmount, tierIndex ) => {
// The "Other" tier is no longer customizable and should always render empty for tiered layout.
if ( tierIndex === 3 ) {
return null;
}
return (
<AmountValueInput
ignoreMinimumAmount
{ ...componentProps }
key={ `amount-${ frequency }-${ tierIndex }` }
frequencySlug={ frequency }
tierIndex={ tierIndex }
label={ TIER_LABELS[ tierIndex ] }
id={ `${ frequency }-${ tierIndex }-amount` }
disabled={
isTierBasedLayoutEnabled &&
tierIndex === DISABLED_IN_TIERS_BASED_LAYOUT_TIER_INDEX
}
/>
);
} ) }
</div>
) }
</Fragment>
Expand Down
Loading