Skip to content
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
14 changes: 7 additions & 7 deletions includes/data-events/class-memberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Newspack\Data_Events;

use Newspack\Memberships as NewspackMemberships;
use Newspack\Content_Gate;
use Newspack\Reader_Activation;
use Newspack\Data_Events;
use WP_Error;
Expand All @@ -17,7 +17,7 @@
*/
final class Memberships {

const METADATA_NAME = 'memberships_content_gate';
const METADATA_NAME = 'gate_post_id';

/**
* The name of the action for form submissions
Expand Down Expand Up @@ -74,7 +74,7 @@ public static function checkout_cart_item_data( $cart_item_data ) {
*/
public static function checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) {
if ( ! empty( $values[ self::METADATA_NAME ] ) ) {
$order->add_meta_data( '_memberships_content_gate', $values[ self::METADATA_NAME ] );
$order->add_meta_data( '_gate_post_id', $values[ self::METADATA_NAME ] );
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public static function registration_submission( $email, $authenticate, $user_id,
return;
}
$data = array_merge(
NewspackMemberships::get_gate_metadata(),
Content_Gate::get_gate_metadata(),
[
'action' => self::FORM_SUBMISSION,
'action_type' => 'registration',
Expand Down Expand Up @@ -182,7 +182,7 @@ public static function registration_submission_with_status( $email, $authenticat
$action = self::FORM_SUBMISSION_FAILURE;
}
$data = array_merge(
NewspackMemberships::get_gate_metadata(),
Content_Gate::get_gate_metadata(),
[
'action' => $action,
'action_type' => 'registration',
Expand All @@ -202,13 +202,13 @@ public static function registration_submission_with_status( $email, $authenticat
* @return ?array
*/
private static function get_order_data( $order_id, $order ) {
$is_from_gate = $order->get_meta( '_memberships_content_gate' );
$is_from_gate = $order->get_meta( '_gate_post_id' ) ? $order->get_meta( '_gate_post_id' ) : $order->get_meta( '_memberships_content_gate' ); // Handle legacy _memberships_content_gate meta key.
if ( ! $is_from_gate ) {
return;
}
$item = array_shift( $order->get_items() );
$data = array_merge(
NewspackMemberships::get_gate_metadata(),
Content_Gate::get_gate_metadata(),
[
'action_type' => 'paid_membership',
'order_id' => $order_id,
Expand Down
1 change: 1 addition & 0 deletions includes/plugins/wc-memberships/class-memberships.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Newspack;

use Newspack\Content_Gate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we're already in Newspack namespace, this and the one below are superfluous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I didn't check this and just followed the existing pattern 😄

use Newspack\WooCommerce_Connection;

defined( 'ABSPATH' ) || exit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
defined( 'ABSPATH' ) || exit;

use Newspack\Memberships;
use Newspack\Memberships\Metering;
use Newspack\Metering;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous comment, these 3 lines are superfluous

use Newspack\Content_Gate_Countdown_Block;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/content-gate/gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function initReloadHandler() {
}

/**
* Adds 'memberships_content_gate' hidden input to every form inside the gate.
* Adds 'gate_post_id' hidden input to every form inside the gate.
*
* @param {HTMLElement} gate The gate element.
*/
Expand All @@ -115,10 +115,10 @@ function addFormInputs( gate ) {
...gate.querySelectorAll( '.wp-block-newspack-blocks-donate form' ), // Donate block.
];
forms.forEach( form => {
if ( ! form.querySelector( 'input[name="memberships_content_gate"]' ) ) {
if ( ! form.querySelector( 'input[name="gate_post_id"]' ) ) {
const input = document.createElement( 'input' );
input.type = 'hidden';
input.name = 'memberships_content_gate';
input.name = 'gate_post_id';
input.value = newspack_content_gate.metadata?.gate_post_id || '1';
form.appendChild( input );
form.addEventListener( 'submit', evt => handleFormSubmission( evt, gate ) );
Expand Down
4 changes: 2 additions & 2 deletions src/reader-activation-auth/auth-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ window.newspackRAS.push( function ( readerActivation ) {
readerActivation.setAuthenticated( !! data.authenticated );
const activity = { email: data.email };
const body = new FormData( form );
if ( data.metadata?.gate_post_id || body.has( 'memberships_content_gate' ) ) {
activity.gate_post_id = data.metadata.gate_post_id || body.get( 'memberships_content_gate' );
if ( data.metadata?.gate_post_id || body.has( 'gate_post_id' ) ) {
activity.gate_post_id = data.metadata.gate_post_id || body.get( 'gate_post_id' );
}
if ( data.metadata?.newspack_popup_id || body.has( 'newspack_popup_id' ) ) {
activity.newspack_popup_id = data.metadata.newspack_popup_id || body.get( 'newspack_popup_id' );
Expand Down