Skip to content

Commit

Permalink
Merge pull request #1981 from Automattic/trunk
Browse files Browse the repository at this point in the history
Alpha release Nov 29
  • Loading branch information
leogermani authored Nov 29, 2024
2 parents 569c06a + 52a5c57 commit 450e4e3
Show file tree
Hide file tree
Showing 283 changed files with 13,613 additions and 10,275 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
labeler:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'trunk'
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'trunk' && github.event.pull_request.user.login != 'dependabot[bot]'
permissions:
contents: read
pull-requests: write
Expand All @@ -14,7 +14,7 @@ jobs:
- uses: actions/labeler@v5

comment_pr:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'trunk'
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'trunk' && github.event.pull_request.user.login != 'dependabot[bot]'
permissions:
contents: read
pull-requests: write
Expand All @@ -25,7 +25,7 @@ jobs:
uses: thollander/actions-comment-pull-request@v3
with:
message: |
Hey @${{ github.event.pull_request.assignee.login }}, good job getting this PR merged! :tada:
Hey @${{ github.event.pull_request.user.login }}, good job getting this PR merged! :tada:
Now, the `needs-changelog` label has been added to it.
Expand Down
1,599 changes: 1,130 additions & 469 deletions includes/class-modal-checkout.php

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions includes/class-newspack-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,43 @@ public static function block_classes( $type, $attributes = array(), $extra = arr
if ( ! empty( $attributes['align'] ) ) {
$classes[] = 'align' . $attributes['align'];
}
if ( ! empty( $attributes['hideControls'] ) ) {
$classes[] = 'hide-controls';
}
if ( isset( $attributes['className'] ) ) {
array_push( $classes, $attributes['className'] );
}
if ( is_array( $extra ) && ! empty( $extra ) ) {
$classes = array_merge( $classes, $extra );
}
if ( ! empty( $attributes['hideControls'] ) ) {
$classes[] = 'hide-controls';
}

return implode( ' ', $classes );
}

/**
* Utility to assemble the styles for a server-side rendered block.
*
* @param array $attributes Block attributes.
* @param array $extra Additional styles to be added to the style list.
*
* @return string style list.
*/
public static function block_styles( $attributes = [], $extra = [] ) {
$styles = [];
if ( isset( $attributes['style'] ) && is_array( $attributes['style'] ) ) {
$engine_styles = wp_style_engine_get_styles( $attributes['style'], [ 'context' => 'block-supports' ] );
if ( isset( $engine_styles['css'] ) ) {
$styles[] = $engine_styles['css'];
}
}

if ( is_array( $extra ) && ! empty( $extra ) ) {
$styles = array_merge( $styles, $extra );
}

return implode( '', $styles );
}

/**
* Return the most appropriate thumbnail size to display.
*
Expand Down Expand Up @@ -745,6 +769,9 @@ public static function build_articles_query( $attributes, $block_name ) {
'authors' => $authors,
'coauthors' => $co_authors_names,
];

// Also, in these cases, never offload the query to Elastic Search.
$args['newspack_no_es_query'] = true;
}
}
}
Expand Down
191 changes: 191 additions & 0 deletions includes/tracking/class-data-events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php
/**
* Newspack Blocks Tracking Data Events Integration.
*
* @package Newspack
*/

namespace Newspack_Blocks\Tracking;

/**
* Tracking Data Events Class.
*/
final class Data_Events {

/**
* The name of the action for form submissions
*/
const FORM_SUBMISSION_SUCCESS = 'form_submission_success';

/**
* The name of the action for form submissions
*/
const FORM_SUBMISSION_FAILURE = 'form_submission_failure';

/**
* Initialize hooks.
*/
public static function init() {
add_action( 'plugins_loaded', [ __CLASS__, 'register_listeners' ] );
}

/**
* Register listeners.
*/
public static function register_listeners() {
if ( ! method_exists( 'Newspack\Data_Events', 'register_handler' ) ) {
return;
}

/**
* Modal Checkout Interation: Completed Order.
*/
\Newspack\Data_Events::register_listener(
'woocommerce_checkout_order_processed',
'modal_checkout_interaction',
[ __CLASS__, 'order_status_completed' ]
);
}

/**
* Returns whether a product is a one time purchase, or recurring and when.
*
* @param string $product_id Product's ID.
*/
public static function get_purchase_recurrence( $product_id ) {
$recurrence = get_post_meta( $product_id, '_subscription_period', true );
if ( empty( $recurrence ) ) {
$recurrence = 'once';
}
return $recurrence;
}

/**
* Returns whether a product ID is associated with a membership.
*
* @param string $product_id Product's ID.
*/
public static function is_membership_product( $product_id ) {
if ( ! function_exists( 'wc_memberships_get_membership_plans' ) ) {
return false;
}
$membership_plans = wc_memberships_get_membership_plans();
$plans = [];

foreach ( $membership_plans as $plan ) {
$subscription_plan = new \WC_Memberships_Integration_Subscriptions_Membership_Plan( $plan->get_id() );
$required_products = $subscription_plan->get_subscription_product_ids();
if ( in_array( $product_id, $required_products ) ) {
return true;
}
}
return false;
}


/**
* Returns the product type: product, subscription, donation, or membership.
* TODOGA4: move this check & related functions into a more central location, and update based on final decision for product types.
*
* @param string $product_id Product's ID.
*/
public static function get_product_type( $product_id ) {
$product_type = 'product';
$recurrence = self::get_purchase_recurrence( $product_id );

// Check if it's a subscription product.
if ( 'once' !== $recurrence ) {
$product_type = 'subscription';
}

// Check if it's a membership product.
if ( self::is_membership_product( $product_id ) ) {
$product_type = 'membership';
}

// Check if it's a donation product.
if ( method_exists( 'Newspack\Donations', 'is_donation_product' ) ) {
if ( \Newspack\Donations::is_donation_product( $product_id ) ) {
$product_type = 'donation';
}
}

return $product_type;
}

/**
* Returns the action type: checkout_button or donation.
*
* @param string $product_id Product's ID.
*/
public static function get_action_type( $product_id ) {
$action_type = 'checkout_button';
// Check if it's a donation product, and update action_type, product_type.
if ( method_exists( 'Newspack\Donations', 'is_donation_product' ) ) {
if ( \Newspack\Donations::is_donation_product( $product_id ) ) {
$action_type = 'donation';
}
}
return $action_type;
}

/**
* Returns an array of product information.
*
* @param string $product_id Product's ID.
* @param array $cart_item Cart item.
* @param string $product_parent_id Product's ID when it has variations.
*/
public static function build_js_data_events( $product_id, $cart_item, $product_parent_id = '' ) {
// Reassign the IDs to make sure the product is the product and the variation is the variation.
$variation_id = '';
if ( '' !== $product_parent_id && 0 !== $product_parent_id ) {
$variation_id = $product_id;
$product_id = $product_parent_id;
}

$data_order_details = [
'amount' => $cart_item['data']->get_price(),
'action_type' => self::get_action_type( $product_id ),
'currency' => function_exists( 'get_woocommerce_currency' ) ? \get_woocommerce_currency() : 'USD',
'product_id' => strval( $product_id ),
'product_type' => self::get_product_type( $product_id ),
'referrer' => str_replace( home_url(), '', $cart_item['referer'] ), // Keeps format consistent for Homepage with Donate and Checkout Button blocks.
'recurrence' => self::get_purchase_recurrence( $product_id ),
'variation_id' => strval( $variation_id ),
];
return $data_order_details;
}

/**
* Send data to GA4.
*
* @param string $order_id Order's ID.
* @param array $posted_data Posted Data.
* @param \WC_Order $order Order object.
*/
public static function order_status_completed( $order_id, $posted_data, $order ) {
// Check if in a modal checkout; if no, bail.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$is_modal_checkout = ( isset( $_REQUEST['modal_checkout'] ) ? true : false );
if ( ! $is_modal_checkout ) {
return;
}

$data = \Newspack\Data_Events\Utils::get_order_data( $order_id );
if ( empty( $data ) ) {
return;
}

$product_id = is_array( $data['platform_data']['product_id'] ) ? $data['platform_data']['product_id'][0] : $data['platform_data']['product_id'];

$data['action'] = self::FORM_SUBMISSION_SUCCESS;
$data['action_type'] = self::get_action_type( $product_id );
$data['product_id'] = $product_id;
$data['product_type'] = self::get_product_type( $product_id );
$data['recurrence'] = self::get_purchase_recurrence( $product_id );

return $data;
}
}
Data_Events::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"release\/newspack-blocks\/src\/blocks\/iframe\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Hide iframe preview":[""],"Show iframe preview":[""],"This block will take over the page content.":[""],"Newspack embedded iframe":[""],"An error occured when uploading the iframe archive.":[""],"An error occured when setting the iframe from the archive media.":[""],"Iframe Settings":[""],"Fullscreen":[""],"If enabled, the iframe will be full screen and hide all the post content.":[""],"Width":[""],"Height":[""]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"release\/newspack-blocks\/dist\/placeholder_blocks.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Ad Unit":[""],"Render an ad unit from your inventory.":[""],"Place ad units inside your page by installing Newspack Ads.":[""],"The \"%s\" block is currently not available.":[""],"Visit Plugin Page":[""],"Remove Block":[""]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"dist\/carousel\/view.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Slide %s":[""],"Slide %1$s of %2$s":[""],"Image: %s, ":[""],"Playing":[""],"Paused":[""]}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2023-12-07 12:20-0800","generator":"WP-CLI\/2.8.1","source":"src\/setup\/placeholder-blocks.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Ad Unit":[""],"Render an ad unit from your inventory.":[""],"Place ad units inside your page by installing Newspack Ads.":[""],"The \"%s\" block is currently not available.":[""],"Visit Plugin Page":[""],"Remove Block":[""]}}}
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"src\/setup\/placeholder-blocks.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Ad Unit":[""],"Render an ad unit from your inventory.":[""],"Place ad units inside your page by installing Newspack Ads.":[""],"The \"%s\" block is currently not available.":[""],"Visit Plugin Page":[""],"Remove Block":[""]}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2023-12-07 12:20-0800","generator":"WP-CLI\/2.8.1","source":"src\/blocks\/author-list\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"author":[""],"Author List":[""],"block style\u0004Default":["Standard"],"block style\u0004Centered":[""],"profile":[""],"Display a list of author profile cards.":[""]}}}
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"src\/blocks\/author-list\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"author":[""],"Author List":[""],"profile":[""],"Display a list of author profile cards.":[""],"block style\u0004Default":["Standard"],"block style\u0004Centered":[""]}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2023-12-07 12:20-0800","generator":"WP-CLI\/2.8.1","source":"src\/blocks\/author-profile\/single-author.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"More by":[""]}}}
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"src\/blocks\/author-profile\/single-author.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"More by":[""]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"release\/newspack-blocks\/src\/blocks\/carousel\/create-swiper.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Slide %s":[""],"Slide %1$s of %2$s":[""],"Image: %s, ":[""],"Playing":[""],"Paused":[""]}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2023-12-07 12:20-0800","generator":"WP-CLI\/2.8.1","source":"src\/components\/query-controls.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"(no name)":["(kein Name)"],"(no title)":["(kein Titel)"],"Categories":["Kategorien"],"Choose Specific Posts":[""],"Posts":["Beitr\u00e4ge"],"Begin typing post title, click autocomplete result to select.":[""],"Authors":["Autoren"],"Include subcategories ":[""],"Tags":["Schlagw\u00f6rter"],"Excluded Tags":[""],"Excluded Categories":[""],"Hide Advanced Filters":[""],"Show Advanced Filters":[""]}}}
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"src\/components\/query-controls.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"(no name)":["(kein Name)"],"(no title)":["(kein Titel)"],"Choose Specific Posts":[""],"Posts":["Beitr\u00e4ge"],"Begin typing post title, click autocomplete result to select.":[""],"Authors":["Autoren"],"Categories":["Kategorien"],"Include subcategories ":[""],"Tags":["Schlagw\u00f6rter"],"Hide Advanced Filters":[""],"Show Advanced Filters":[""],"Excluded Tags":[""],"Excluded Categories":[""],"Excluded %s":[""]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"release\/newspack-blocks\/src\/blocks\/video-playlist\/index.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"YouTube Video Playlist":[""],"video":[""],"playlist":[""],"youtube":[""],"Embed a playlist of latest YouTube videos.":[""]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"release\/newspack-blocks\/src\/blocks\/author-list\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Author Profile Settings":[""],"Text Size":[""],"Avatar Settings":[""],"Display avatar":[""],"Hide default avatar":[""],"Avatar border radius":[""],"Show avatar on left":[""],"Show avatar on right":[""],"Edit selection":[""],"(no name)":["(kein Name)"],"author":[""],"authors":[""],"Author List":[""],"Error fetching authors.":[""],"Author List Settings":[""],"Author Type":[""],"%s will be displayed.":[""],"Both guest authors and WP users":[""],"%s only":[""],"Guest authors":[""],"WP users":[""],"All authors":[""],"Columns":["Spalten"],"WP User Roles":[""],"Display alphabetical separators":[""],"Chunk authors alphabetically.":[""],"Group authors by alphabet":[""],"Display each alphabetical chunk as a discrete section.":[""],"Exclude authors with 0 posts":[""],"Authors with no published posts will be %s.":[""],"hidden":[""],"displayed":[""],"Search by author name":[""],"Authors selected here will not be displayed.":[""],"Avatar Size":[""],"List":[""],"Fetching authors\u2026":[""]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"release\/newspack-blocks\/src\/blocks\/video-playlist\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"(no title)":["(kein Titel)"],"Categories":["Kategorien"],"Error":["Fehler"],"No videos found":[""],"Settings":[""],"Videos":[""],"The maximum number of videos to pull from posts.":[""]}}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"translation-revision-date":"2023-12-07 12:20-0800","generator":"WP-CLI\/2.8.1","source":"src\/blocks\/author-list\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Error fetching authors.":[""],"Author List Settings":[""],"Author Type":[""],"%s will be displayed.":[""],"Both guest authors and WP users":[""],"%s only":[""],"All authors":[""],"Guest authors":[""],"WP users":[""],"Columns":["Spalten"],"WP User Roles":[""],"Display alphabetical separators":[""],"Chunk authors alphabetically.":[""],"Group authors by alphabet":[""],"Display each alphabetical chunk as a discrete section.":[""],"Exclude authors with 0 posts":[""],"Authors with no published posts will be %s.":[""],"Search by author name":[""],"Authors selected here will not be displayed.":[""],"(no name)":["(kein Name)"],"author":[""],"authors":[""],"Author Profile Settings":[""],"Text Size":[""],"Avatar Settings":[""],"Display avatar":[""],"Hide default avatar":[""],"Avatar Size":[""],"Avatar border radius":[""],"List":[""],"Show avatar on left":[""],"Show avatar on right":[""],"Edit selection":[""],"Author List":[""],"Fetching authors\u2026":[""],"hidden":[""],"displayed":[""]}}}
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"src\/blocks\/author-list\/edit.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Author Profile Settings":[""],"Text Size":[""],"Avatar Settings":[""],"Display avatar":[""],"Hide default avatar":[""],"Avatar border radius":[""],"Show avatar on left":[""],"Show avatar on right":[""],"Edit selection":[""],"(no name)":["(kein Name)"],"author":[""],"authors":[""],"Author List":[""],"Error fetching authors.":[""],"Author List Settings":[""],"Author Type":[""],"%s will be displayed.":[""],"Both guest authors and WP users":[""],"%s only":[""],"Guest authors":[""],"WP users":[""],"All authors":[""],"Columns":["Spalten"],"WP User Roles":[""],"Display alphabetical separators":[""],"Chunk authors alphabetically.":[""],"Group authors by alphabet":[""],"Display each alphabetical chunk as a discrete section.":[""],"Exclude authors with 0 posts":[""],"Authors with no published posts will be %s.":[""],"hidden":[""],"displayed":[""],"Search by author name":[""],"Authors selected here will not be displayed.":[""],"Avatar Size":[""],"List":[""],"Fetching authors\u2026":[""]}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"translation-revision-date":"2024-08-30 08:45-0700","generator":"WP-CLI\/2.8.1","source":"dist\/placeholder_blocks.js","domain":"messages","locale_data":{"messages":{"":{"domain":"messages","lang":"de","plural-forms":"nplurals=2; plural=(n != 1);"},"Ad Unit":[""],"Render an ad unit from your inventory.":[""],"Place ad units inside your page by installing Newspack Ads.":[""],"The \"%s\" block is currently not available.":[""],"Visit Plugin Page":[""],"Remove Block":[""]}}}
Loading

0 comments on commit 450e4e3

Please sign in to comment.