Skip to content

Commit

Permalink
Merge branch 'trunk' into feat/add-braintree-styles
Browse files Browse the repository at this point in the history
  • Loading branch information
laurelfulford committed Feb 19, 2025
2 parents f9528bf + c316801 commit 765340f
Show file tree
Hide file tree
Showing 86 changed files with 1,245 additions and 995 deletions.
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
# [4.6.0](https://github.com/Automattic/newspack-blocks/compare/v4.5.10...v4.6.0) (2025-02-17)


### Bug Fixes

* enforce the password strength on checkout ([#2037](https://github.com/Automattic/newspack-blocks/issues/2037)) ([b9dcf03](https://github.com/Automattic/newspack-blocks/commit/b9dcf03e9d1ceefcb481eabb59f5837ad56788d4))
* make sure membership gate refreshes after variation purchase ([#2044](https://github.com/Automattic/newspack-blocks/issues/2044)) ([1555b0f](https://github.com/Automattic/newspack-blocks/commit/1555b0ff5a65286bfbf0cc1f19a1eb6df2e9d97c))
* remove OneSignal script from the modal checkout ([#2029](https://github.com/Automattic/newspack-blocks/issues/2029)) ([343ca5e](https://github.com/Automattic/newspack-blocks/commit/343ca5edf001acfd83a91b9726d5dd0687d749d5))
* return no posts for authors without term ([#2033](https://github.com/Automattic/newspack-blocks/issues/2033)) ([e331139](https://github.com/Automattic/newspack-blocks/commit/e331139ea60fa1a784179e3261f36cd94630a67d))


### Features

* **homepage-articles:** rename block and reorganise settings ([#2000](https://github.com/Automattic/newspack-blocks/issues/2000)) ([841de19](https://github.com/Automattic/newspack-blocks/commit/841de1975232307640e730f32715dd5d223600a1))
* rename all homepage posts patterns to content loop patterns ([#2046](https://github.com/Automattic/newspack-blocks/issues/2046)) ([9b6bdee](https://github.com/Automattic/newspack-blocks/commit/9b6bdeed4df250753963f7bbaeca5d85ed76193a))

## [4.5.10](https://github.com/Automattic/newspack-blocks/compare/v4.5.9...v4.5.10) (2025-02-04)


### Bug Fixes

* **modal-checkout:** check WC before enqueue the modal ([#2043](https://github.com/Automattic/newspack-blocks/issues/2043)) ([7a13d37](https://github.com/Automattic/newspack-blocks/commit/7a13d3799c70a926a30518e0a943170b0100394d))

## [4.5.9](https://github.com/Automattic/newspack-blocks/compare/v4.5.8...v4.5.9) (2025-02-03)


### Bug Fixes

* add supported gateways check ([#2009](https://github.com/Automattic/newspack-blocks/issues/2009)) ([1462233](https://github.com/Automattic/newspack-blocks/commit/1462233821b4f41ef6b80f6929243dc1b805cdb1))
* return no posts for authors without term ([#2033](https://github.com/Automattic/newspack-blocks/issues/2033)) ([3b72633](https://github.com/Automattic/newspack-blocks/commit/3b7263349707326bf988ff6a815cf92ffb061972))

## [4.5.8](https://github.com/Automattic/newspack-blocks/compare/v4.5.7...v4.5.8) (2025-02-03)


### Bug Fixes

* **checkout-button:** handle missing saved product ([#2038](https://github.com/Automattic/newspack-blocks/issues/2038)) ([b251f99](https://github.com/Automattic/newspack-blocks/commit/b251f999a2dd71a5c6aedfeb3bf9d03bef24e3f4))

## [4.5.7](https://github.com/Automattic/newspack-blocks/compare/v4.5.6...v4.5.7) (2025-01-31)


### Bug Fixes

* improve formatting of donation amount options ([#2032](https://github.com/Automattic/newspack-blocks/issues/2032)) ([a86472c](https://github.com/Automattic/newspack-blocks/commit/a86472c8068d873c31cb6bb37e08bcfd9d487be3))

## [4.5.6](https://github.com/Automattic/newspack-blocks/compare/v4.5.5...v4.5.6) (2025-01-23)


Expand Down
57 changes: 53 additions & 4 deletions includes/class-modal-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static function init() {
add_filter( 'wc_get_template', [ __CLASS__, 'wc_get_template' ], 10, 2 );
add_filter( 'woocommerce_checkout_fields', [ __CLASS__, 'woocommerce_checkout_fields' ] );
add_filter( 'woocommerce_update_order_review_fragments', [ __CLASS__, 'order_review_fragments' ] );
add_filter( 'woocommerce_cart_needs_payment', [ __CLASS__, 'cart_needs_payment' ] );
add_filter( 'newspack_recaptcha_verify_captcha', [ __CLASS__, 'recaptcha_verify_captcha' ], 10, 3 );
add_filter( 'woocommerce_enqueue_styles', [ __CLASS__, 'dequeue_woocommerce_styles' ] );
add_filter( 'wcs_place_subscription_order_text', [ __CLASS__, 'order_button_text' ], 5 );
Expand All @@ -165,6 +166,7 @@ public static function init() {
add_filter( 'option_woocommerce_woocommerce_payments_settings', [ __CLASS__, 'filter_woocommerce_payments_settings' ] );
add_action( 'init', [ __CLASS__, 'unhook_woocommerce_payments_update_billing_fields' ] );
add_action( 'wp_enqueue_scripts', [ __CLASS__, 'update_password_strength_message' ], 9999 );
add_filter( 'woocommerce_enforce_password_strength_meter_on_checkout', '__return_true' );

/** Custom handling for registered users. */
add_filter( 'woocommerce_checkout_customer_id', [ __CLASS__, 'associate_existing_user' ] );
Expand Down Expand Up @@ -259,7 +261,7 @@ public static function get_supported_payment_gateways() {
*/
public static function has_unsupported_payment_gateway() {
$supported_gateways = self::get_supported_payment_gateways();
$available_gateways = \WC()->payment_gateways->get_available_payment_gateways();
$available_gateways = function_exists( 'WC' ) ? \WC()->payment_gateways->get_available_payment_gateways() : [];
$unsupported_payment_gateway = false;
foreach ( $available_gateways as $id => $gateway ) {
if ( ! in_array( $id, $supported_gateways, true ) ) {
Expand Down Expand Up @@ -831,7 +833,10 @@ public static function enqueue_scripts() {
* Dequeue scripts not needed in the modal checkout.
*/
public static function dequeue_scripts() {
if ( ! self::is_modal_checkout() ) {
if (
! self::is_modal_checkout() ||
( defined( 'NEWSPACK_ALLOW_ALL_CHECKOUT_SCRIPTS' ) && NEWSPACK_ALLOW_ALL_CHECKOUT_SCRIPTS )
) {
return;
}

Expand Down Expand Up @@ -947,6 +952,15 @@ public static function remove_hooks() {
]
);
}
// OneSignal.
array_push(
$remove_list,
[
'hook' => 'wp_head',
'callback' => 'onesignal_init',
]
);

/**
* Filters the hooks to remove from the modal checkout.
*
Expand All @@ -966,6 +980,11 @@ public static function remove_hooks() {
* @param int $product_id Product ID (optional).
*/
public static function enqueue_modal( $product_id = null ) {
// Don't enqueue the modal if WooCommerce is not available.
if ( ! function_exists( 'WC' ) ) {
return;
}

self::$has_modal = true;
if ( ! empty( $product_id ) ) {
self::$products[ $product_id ] = true;
Expand Down Expand Up @@ -1426,6 +1445,30 @@ class="button close-button"
<?php
}

/**
* Is the current request only to validate billing field inputs on the first modal screen?
*
* @return bool True if the request is for validation only.
*/
private static function is_validation_only() {
return boolval( filter_input( INPUT_POST, 'is_validation_only', FILTER_SANITIZE_NUMBER_INT ) );
}

/**
* Determine if the request needs payment.
* If we're just validating billing fields at the first modal screen, this should always be false.
*
* @param bool $needs_payment Whether the cart needs payment.
*
* @return bool False if we're in modal checkout and validating billing fields.
*/
public static function cart_needs_payment( $needs_payment ) {
if ( self::is_modal_checkout() && self::is_validation_only() ) {
return false;
}
return $needs_payment;
}

/**
* Prevent reCAPTCHA from being verified for AJAX checkout (e.g. Apple Pay).
*
Expand All @@ -1438,11 +1481,10 @@ public static function recaptcha_verify_captcha( $should_verify, $url, $context
return $should_verify;
}

$is_validation_only = boolval( filter_input( INPUT_POST, 'is_validation_only', FILTER_SANITIZE_NUMBER_INT ) );
parse_str( \wp_parse_url( $url, PHP_URL_QUERY ), $query );
if (
// Only in the context of a true checkout request.
$is_validation_only ||
self::is_validation_only() ||
(
defined( 'WOOCOMMERCE_CHECKOUT' )
&& isset( $query['wc-ajax'] )
Expand Down Expand Up @@ -1896,6 +1938,13 @@ public static function order_button_html( $html ) {

$newspack_ui_html = preg_replace( '/class=".*?"/', "class='{$class_prefix}__button {$class_prefix}__button--primary {$class_prefix}__button--wide'", $html );

if ( class_exists( 'Newspack\Recaptcha' ) && \Newspack\Recaptcha::can_use_captcha( 'v2' ) ) {
$cloned_button = preg_replace( '/type="submit"/', 'type="button"', $newspack_ui_html );
$cloned_button = preg_replace( '/id="place_order"/', '', $newspack_ui_html );
$cloned_button = preg_replace( '/name=".*?"/', 'id="place_order_clone"', $newspack_ui_html );
$newspack_ui_html = $cloned_button . $newspack_ui_html;
}

return $newspack_ui_html;
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-newspack-blocks-patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function register_block_patterns_and_categories() {
);
}

// Homepage Posts: pages only.
// Content Loop: pages only.
if ( null === $post_type || 'page' === $post_type ) {
array_push(
$block_patterns,
Expand Down Expand Up @@ -155,7 +155,7 @@ public static function register_block_patterns_and_categories() {
);
register_block_pattern_category(
'newspack-homepage-posts',
[ 'label' => __( 'Newspack Homepage Posts', 'newspack-blocks' ) ]
[ 'label' => __( 'Newspack Content Loop', 'newspack-blocks' ) ]
);
register_block_pattern_category(
'newspack-subscribe',
Expand Down
51 changes: 29 additions & 22 deletions includes/class-newspack-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public static function enqueue_block_editor_assets() {
'custom_taxonomies' => self::get_custom_taxonomies(),
'can_use_name_your_price' => self::can_use_name_your_price(),
'tier_amounts_template' => self::get_formatted_amount(),
'currency' => function_exists( 'get_woocommerce_currency' ) ? \get_woocommerce_currency() : 'USD',
];

if ( class_exists( 'WP_REST_Newspack_Author_List_Controller' ) ) {
Expand Down Expand Up @@ -688,6 +689,10 @@ public static function build_articles_query( $attributes, $block_name ) {
$term = $coauthors_plus->get_author_term( $co_author );
if ( $term ) {
$authors_term_ids[] = $term->term_id;
} else {
// If the author term does not exist, force a non-match, otherwise all posts will be returned.
// CAP's cli command to create author terms will only create terms for users that have authored posts.
$authors_term_ids[] = -1;
}

// If it's a guest author, also check the linked author.
Expand Down Expand Up @@ -1420,7 +1425,7 @@ public static function get_article_meta_footer( $post = null ) {
*
* @return string
*/
public static function get_formatted_amount( $amount = 0, $frequency = 'day', $hide_once_label = false ) {
public static function get_formatted_amount( $amount = null, $frequency = null, $hide_once_label = false ) {
if ( ! function_exists( 'wc_price' ) || ( method_exists( 'Newspack\Donations', 'is_platform_wc' ) && ! \Newspack\Donations::is_platform_wc() ) ) {
if ( 0 === $amount ) {
return false;
Expand All @@ -1432,31 +1437,33 @@ public static function get_formatted_amount( $amount = 0, $frequency = 'day', $h
$formatted_price = '<span class="price-amount">' . $formatter->formatCurrency( $amount, 'USD' ) . '</span> <span class="tier-frequency">' . $frequency_string . '</span>';
return str_replace( '.00', '', $formatted_price );
}
if ( ! function_exists( 'wcs_price_string' ) ) {
return \wc_price( $amount );
}
$price_args = [
'recurring_amount' => $amount,
'subscription_period' => 'once' === $frequency ? 'day' : $frequency,
];
$wc_formatted_amount = \wcs_price_string( $price_args );

// A '0' value means we want a placeholder string to replace in the editor.
if ( 0 === $amount ) {
preg_match( '/<\/span>(.*)<\/bdi>/', $wc_formatted_amount, $matches );
if ( ! empty( $matches[1] ) ) {
$wc_formatted_amount = str_replace( $matches[1], 'AMOUNT_PLACEHOLDER', $wc_formatted_amount );
$wc_formatted_amount = '';
if ( null === $amount && null === $frequency ) {
$currency_symbol = function_exists( 'get_woocommerce_currency_symbol' ) ? \get_woocommerce_currency_symbol() : '&#36;';
$wc_formatted_amount = '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">' . $currency_symbol . '</span>AMOUNT_PLACEHOLDER</bdi></span> FREQUENCY_PLACEHOLDER';
} else {
// Format the amount with currency symbol and separators.
$amount_string = \wc_price(
$amount,
[ 'decimals' => is_int( $amount ) ? 0 : 2 ]
);

if ( ! function_exists( 'wcs_price_string' ) ) {
return $amount_string;
}
}
$price_args = [
'recurring_amount' => $amount_string,
'subscription_period' => 'once' === $frequency ? 'day' : $frequency,
];
$wc_formatted_amount = \wcs_price_string( $price_args );

// A 'day' frequency means we want a placeholder string to replace in the editor.
if ( 'day' === $frequency ) {
$wc_formatted_amount = preg_replace( '/ \/ ?.*/', 'FREQUENCY_PLACEHOLDER', $wc_formatted_amount );
} elseif ( 'once' === $frequency ) {
$once_label = $hide_once_label ? '' : __( ' once', 'newspack-blocks' );
$wc_formatted_amount = preg_replace( '/ \/ ?.*/', $once_label, $wc_formatted_amount );
if ( 'once' === $frequency ) {
$once_label = $hide_once_label ? '' : __( ' once', 'newspack-blocks' );
$wc_formatted_amount = preg_replace( '/ \/ ?.*/', $once_label, $wc_formatted_amount );
}
$wc_formatted_amount = str_replace( ' / ', __( ' per ', 'newspack-blocks' ), $wc_formatted_amount );
}
$wc_formatted_amount = str_replace( ' / ', __( ' per ', 'newspack-blocks' ), $wc_formatted_amount );

return '<span class="wpbnbd__tiers__amount__value">' . $wc_formatted_amount . '</span>';
}
Expand Down
Loading

0 comments on commit 765340f

Please sign in to comment.