@@ -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 }
0 commit comments