Skip to content

Commit 07ae0fa

Browse files
committed
Merge branch 'trunk' into feat/content-gate-restriction-rules
2 parents 429d4e6 + 74e460a commit 07ae0fa

File tree

16 files changed

+197
-116
lines changed

16 files changed

+197
-116
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# [6.26.0](https://github.com/Automattic/newspack-plugin/compare/v6.25.1...v6.26.0) (2025-12-02)
2+
3+
4+
### Features
5+
6+
* **content-gifting:** metering support and CTA auth links ([#4331](https://github.com/Automattic/newspack-plugin/issues/4331)) ([8d5f500](https://github.com/Automattic/newspack-plugin/commit/8d5f50058fc5661f985066306cacc8d03f1c3d20))
7+
8+
## [6.25.1](https://github.com/Automattic/newspack-plugin/compare/v6.25.0...v6.25.1) (2025-11-25)
9+
10+
11+
### Bug Fixes
12+
13+
* **memberships:** use gate ID for metering meta key ([#4316](https://github.com/Automattic/newspack-plugin/issues/4316)) ([a190a47](https://github.com/Automattic/newspack-plugin/commit/a190a477ad7af079af4fd27659cc8f735f735f42))
14+
115
# [6.25.0](https://github.com/Automattic/newspack-plugin/compare/v6.24.3...v6.25.0) (2025-11-24)
216

317

includes/content-gate/class-content-gate.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ public static function init() {
7474
include __DIR__ . '/content-gifting/class-content-gifting.php';
7575
}
7676

77+
/**
78+
* Whether the first-party Newspack feature is enabled.
79+
*
80+
* @return bool
81+
*/
82+
public static function is_newspack_feature_enabled() {
83+
return defined( 'NEWSPACK_CONTENT_GATES' ) && NEWSPACK_CONTENT_GATES;
84+
}
85+
7786
/**
7887
* Restrict the post.
7988
*

includes/content-gate/class-metering.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function init() {
4747
* @return bool
4848
*/
4949
public static function restrict_post( $restrict ) {
50-
if ( self::is_metering() ) {
50+
if ( $restrict && self::is_metering() ) {
5151
return false;
5252
}
5353
return $restrict;
@@ -216,7 +216,15 @@ public static function has_metering( $post_id = null ) {
216216
* @return bool
217217
*/
218218
public static function is_frontend_metering() {
219-
// Frotend metering strategy should only be applied for anonymous readers.
219+
/**
220+
* This filter documented in the `is_metering` method.
221+
*/
222+
$short_circuit = apply_filters( 'newspack_content_gate_metering_short_circuit', null );
223+
if ( null !== $short_circuit ) {
224+
return false;
225+
}
226+
227+
// Frontend metering strategy should only be applied for anonymous readers.
220228
if ( \is_user_logged_in() ) {
221229
return false;
222230
}
@@ -248,6 +256,14 @@ public static function is_frontend_metering() {
248256
* @return bool
249257
*/
250258
public static function is_logged_in_metering_allowed( $post_id = null ) {
259+
/**
260+
* This filter documented in the `is_metering` method.
261+
*/
262+
$short_circuit = apply_filters( 'newspack_content_gate_metering_short_circuit', null );
263+
if ( null !== $short_circuit ) {
264+
return false;
265+
}
266+
251267
if ( ! $post_id ) {
252268
$post_id = get_the_ID();
253269
}
@@ -272,7 +288,8 @@ public static function is_logged_in_metering_allowed( $post_id = null ) {
272288
}
273289

274290
// Aggregate metering by gate priority, if available.
275-
$user_meta_key = self::METERING_META_KEY . '_' . ( $priority ? $priority : $gate_post_id );
291+
$suffix = Content_Gate::is_newspack_feature_enabled() && $priority ? $priority : $gate_post_id;
292+
$user_meta_key = self::METERING_META_KEY . '_' . $suffix;
276293

277294
$updated_user_data = false;
278295
$user_metering_data = \get_user_meta( get_current_user_id(), $user_meta_key, true );
@@ -327,6 +344,24 @@ public static function is_logged_in_metering_allowed( $post_id = null ) {
327344
* @return bool
328345
*/
329346
public static function is_metering() {
347+
/**
348+
* Short-circuit the metering check. Anything other than null
349+
* will prevent the metering logic from running.
350+
*
351+
* The `is_logged_in_metering_allowed` method also updates the user meta
352+
* to track the content that's been allowed to access. This short-circuit
353+
* prevents this from running if we want the entire metering feature to be
354+
* skipped.
355+
*
356+
* @param mixed $short_circuit Short-circuit value. Default is null.
357+
*
358+
* @return mixed Short-circuit value.
359+
*/
360+
$short_circuit = apply_filters( 'newspack_content_gate_metering_short_circuit', null );
361+
if ( null !== $short_circuit ) {
362+
return false;
363+
}
364+
330365
return self::is_frontend_metering() || self::is_logged_in_metering_allowed();
331366
}
332367

includes/content-gate/content-gifting/class-content-gifting-cta.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,18 @@ public static function print_cta() {
175175
<div class="newspack-ui">
176176
<div class="banner newspack-content-gifting__cta <?php echo esc_attr( $style_class ); ?>">
177177
<div class="wrapper newspack-content-gifting__cta__content">
178-
<span class="newspack-ui__font--s"><?php echo esc_html( self::get_cta_label() ); ?></span>
178+
<div class="newspack-ui__font--s">
179+
<?php echo esc_html( self::get_cta_label() ); ?>
180+
<?php if ( ! is_user_logged_in() ) : ?>
181+
<div class="newspack-ui__font--xs newspack-content-gifting__cta__content__links">
182+
<?php if ( Metering::has_metering( get_the_ID() ) ) : ?>
183+
<a href="#register_modal"><?php echo esc_html( __( 'Create an account', 'newspack-plugin' ) ); ?></a>
184+
<?php else : ?>
185+
<a href="#signin_modal"><?php echo esc_html( __( 'Sign in to an existing account', 'newspack-plugin' ) ); ?></a>
186+
<?php endif; ?>
187+
</div>
188+
<?php endif; ?>
189+
</div>
179190
<?php self::print_subscribe_button(); ?>
180191
</div>
181192
</div>

includes/content-gate/content-gifting/class-content-gifting.php

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static function init() {
4141
add_action( 'init', [ __CLASS__, 'hook_gift_button' ] );
4242
add_action( 'wp', [ __CLASS__, 'unrestrict_content' ], 5 );
4343
add_filter( 'newspack_content_gate_restrict_post', [ __CLASS__, 'restrict_post' ] );
44+
add_filter( 'newspack_content_gate_metering_short_circuit', [ __CLASS__, 'short_circuit_metering' ] );
4445
add_action( 'wp_enqueue_scripts', [ __CLASS__, 'enqueue_assets' ] );
4546
add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue_assets' ] );
4647
add_action( 'wp_ajax_' . self::GENERATE_ACTION, [ __CLASS__, 'ajax_generate_content_key' ] );
@@ -155,7 +156,7 @@ public static function print_gift_button() {
155156
* Whether the current post has been gifted.
156157
*
157158
* @param int|null $post_id The post ID. Default is the current post.
158-
* @param string|null $key The content key. Default is the key from the query arg.
159+
* @param string|null $key The content key. Default is from the request (query arg or cookie).
159160
*
160161
* @return bool
161162
*/
@@ -396,26 +397,6 @@ public static function can_use_gifting( $return_errors = false ) {
396397
$errors->add( 'not_enabled', __( 'Content gifting is not enabled.', 'newspack-plugin' ) );
397398
}
398399

399-
// Check whether all gates have metering enabled.
400-
$gates = array_filter(
401-
Content_Gate::get_gates(),
402-
function( $gate ) {
403-
return $gate['status'] === 'publish';
404-
}
405-
);
406-
if ( ! empty( $gates ) ) {
407-
$all_gates_have_metering = true;
408-
foreach ( $gates as $gate ) {
409-
if ( ! isset( $gate['metering']['enabled'] ) || ! $gate['metering']['enabled'] ) {
410-
$all_gates_have_metering = false;
411-
break;
412-
}
413-
}
414-
if ( $all_gates_have_metering ) {
415-
$errors->add( 'all_gates_have_metering', __( 'Content gifting is not available because all gates have metering enabled.', 'newspack-plugin' ) );
416-
}
417-
}
418-
419400
if ( $return_errors ) {
420401
return $errors;
421402
}
@@ -456,21 +437,6 @@ public static function set_enabled( $enabled = true ) {
456437
do_action( 'newspack_content_gifting_enabled_status_changed', $enabled );
457438
}
458439

459-
/**
460-
* Whether to render the metering notice in the configuration wizard.
461-
*
462-
* @return bool
463-
*/
464-
public static function should_render_metering_notice() {
465-
$gates = Content_Gate::get_gates();
466-
foreach ( $gates as $gate ) {
467-
if ( $gate['status'] === 'publish' && isset( $gate['metering'] ) && $gate['metering']['enabled'] ) {
468-
return true;
469-
}
470-
}
471-
return false;
472-
}
473-
474440
/**
475441
* Enqueue assets.
476442
*/
@@ -673,6 +639,20 @@ public static function restrict_post( $restrict, $post_id ) {
673639
return $restrict;
674640
}
675641

642+
/**
643+
* Short-circuit the metering check.
644+
*
645+
* @param mixed $short_circuit Short-circuit value. Default is null.
646+
*
647+
* @return mixed Short-circuit value.
648+
*/
649+
public static function short_circuit_metering( $short_circuit ) {
650+
if ( self::is_gifted_post( get_the_ID() ) ) {
651+
return true;
652+
}
653+
return $short_circuit;
654+
}
655+
676656
/**
677657
* Whether the current user can gift a given post.
678658
*
@@ -701,10 +681,6 @@ public static function can_gift_post( $post_id = null, $return_errors = false )
701681
$errors->add( 'post_restricted', __( 'User does not have access to this post.', 'newspack-plugin' ) );
702682
}
703683

704-
if ( Metering::has_metering( $post_id ) ) {
705-
$errors->add( 'metering', __( 'Metered content cannot be gifted.', 'newspack-plugin' ) );
706-
}
707-
708684
if ( $return_errors ) {
709685
return $errors;
710686
}

includes/wizards/audience/class-audience-content-gates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function add_page() {
9292
* @return bool
9393
*/
9494
public function is_feature_enabled() {
95-
return defined( 'NEWSPACK_CONTENT_GATES' ) && NEWSPACK_CONTENT_GATES;
95+
return Content_Gate::is_newspack_feature_enabled();
9696
}
9797

9898
/**

includes/wizards/audience/class-audience-wizard.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ public function enqueue_scripts_and_styles() {
107107

108108
$data['is_skipped_campaign_setup'] = Reader_Activation::is_skipped( 'ras_campaign' );
109109

110+
$gates = Content_Gate::get_gates();
111+
$has_metering = false;
112+
foreach ( $gates as $gate ) {
113+
if ( $gate['status'] === 'publish' && isset( $gate['metering'] ) && $gate['metering']['enabled'] ) {
114+
$has_metering = true;
115+
break;
116+
}
117+
}
118+
110119
$data['content_gifting'] = [
111120
'can_use_gifting' => Content_Gifting::can_use_gifting( true ),
112-
'metering_notice' => Content_Gifting::should_render_metering_notice(),
121+
'has_metering' => $has_metering,
113122
];
114123

115124
wp_enqueue_script( 'newspack-wizards' );

newspack.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Newspack
44
* Description: An advanced open-source publishing and revenue-generating platform for news organizations.
5-
* Version: 6.25.0
5+
* Version: 6.26.0
66
* Author: Automattic
77
* Author URI: https://newspack.com/
88
* License: GPL2
@@ -14,7 +14,7 @@
1414

1515
defined( 'ABSPATH' ) || exit;
1616

17-
define( 'NEWSPACK_PLUGIN_VERSION', '6.25.0' );
17+
define( 'NEWSPACK_PLUGIN_VERSION', '6.26.0' );
1818

1919
// Define NEWSPACK_PLUGIN_FILE.
2020
if ( ! defined( 'NEWSPACK_PLUGIN_FILE' ) ) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "newspack",
3-
"version": "6.25.0",
3+
"version": "6.26.0",
44
"description": "The Newspack plugin. https://newspack.com",
55
"bugs": {
66
"url": "https://github.com/Automattic/newspack-plugin/issues"

0 commit comments

Comments
 (0)