From 95cec62519557acda02a617b3475edbbfee69da0 Mon Sep 17 00:00:00 2001 From: dkoo Date: Wed, 10 Apr 2024 20:18:16 -0600 Subject: [PATCH] fix: revert #3050 due to performance issues --- .../wc-memberships/class-memberships.php | 66 ------------------- 1 file changed, 66 deletions(-) diff --git a/includes/plugins/wc-memberships/class-memberships.php b/includes/plugins/wc-memberships/class-memberships.php index 5358b832ae..fba2686f88 100644 --- a/includes/plugins/wc-memberships/class-memberships.php +++ b/includes/plugins/wc-memberships/class-memberships.php @@ -33,14 +33,6 @@ class Memberships { */ public static $active_statuses = [ 'active', 'complimentary', 'free-trial', 'pending' ]; - /** - * WooCommerce Subscription statuses that should be considered active. - * See: https://woo.com/document/subscriptions/statuses/ - * - * @var array - */ - public static $active_subscription_statuses = [ 'active', 'pending', 'pending-cancel' ]; - /** * Initialize hooks and filters. */ @@ -59,8 +51,6 @@ public static function init() { add_filter( 'newspack_popups_assess_has_disabled_popups', [ __CLASS__, 'disable_popups' ] ); add_filter( 'newspack_reader_activity_article_view', [ __CLASS__, 'suppress_article_view_activity' ], 100 ); add_filter( 'user_has_cap', [ __CLASS__, 'user_has_cap' ], 10, 3 ); - add_filter( 'get_post_metadata', [ __CLASS__, 'ensure_no_expire_date_for_active_subscriptions' ], 10, 4 ); - add_filter( 'get_post_status', [ __CLASS__, 'ensure_active_status_for_active_subscriptions' ], 10, 2 ); /** Add gate content filters to mimic 'the_content'. See 'wp-includes/default-filters.php' for reference. */ add_filter( 'newspack_gate_content', 'capital_P_dangit', 11 ); @@ -833,62 +823,6 @@ public static function user_has_cap( $all_caps, $caps, $args ) { return $all_caps; } - /** - * Is the given user membership tied to a currently active subscription? - * - * @param int $membership_id User membership ID. - * - * @return bool - */ - public static function membership_is_tied_to_active_subscription( $membership_id ) { - if ( function_exists( 'wc_memberships_get_user_membership' ) ) { - $membership = \wc_memberships_get_user_membership( $membership_id ); - $plan = $membership->get_plan(); - if ( $membership && $plan && method_exists( $plan, 'get_access_length_type' ) && 'subscription' === $plan->get_access_length_type() && method_exists( $membership, 'get_subscription_id' ) && function_exists( 'wcs_get_subscription' ) ) { - $subscription = \wcs_get_subscription( $membership->get_subscription_id() ); - if ( $subscription && in_array( $subscription->get_status(), self::$active_subscription_statuses, true ) ) { - return true; - } - } - } - - return false; - } - - /** - * Ensure that WC User Memberships that are tied to an active subscription do not have an Expire date. - * - * @param mixed $value The value get_metadata() should return - a single metadata value, or an array of values. - * @param int $object_id ID of the object metadata is for. - * @param string $meta_key Metadata key. - * @param bool $single Whether to return a single value. - * - * @return mixed - */ - public static function ensure_no_expire_date_for_active_subscriptions( $value, $object_id, $meta_key, $single ) { - if ( ( '_cancelled_date' === $meta_key || '_end_date' === $meta_key ) && self::membership_is_tied_to_active_subscription( $object_id ) ) { - $value = ''; - } - return $value; - } - - /** - * Ensuer that WC User Memberships that are tied to an active subscription have an active status. - * - * @param string $status The status of the membership. - * @param WP_Post $post The post object. - * - * @return string - */ - public static function ensure_active_status_for_active_subscriptions( $status, $post ) { - if ( 'wc_user_membership' === $post->post_type && 'wcm-active' !== $post->post_status && self::membership_is_tied_to_active_subscription( $post->ID ) ) { - $status = 'wcm-active'; - $membership = \wc_memberships_get_user_membership( $post->ID ); - $membership->update_status( 'active' ); - } - return $status; - } - /** * Checks if a user has content access from rules. * Overrides behvavior from the WooCommerce Memberships plugin to decide whether to show restricted content.