Last active
August 6, 2025 17:49
-
-
Save greenhornet79/5a57b87e552c641c3d079c9513be8485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 1. content_matches_restriction_exceptions | |
public function content_matches_restriction_exceptions() { | |
$cache_key = 'lp_restriction_exception_' . $this->post_id; | |
if ( false === ( $match = get_transient( $cache_key ) ) ) { | |
$match = false; | |
$settings = get_leaky_paywall_settings(); | |
$category_exceptions = $settings['post_category_exceptions']; | |
$category_exception_ids = explode(',', $category_exceptions); | |
if (! empty($category_exception_ids)) { | |
$post_categories = get_the_category($this->post_id); | |
foreach ($post_categories as $cat) { | |
if (in_array($cat->term_id, $category_exception_ids)) { | |
$match = true; | |
} | |
} | |
} | |
$tag_exceptions = $settings['post_tag_exceptions']; | |
$tag_exception_ids = explode(',', $tag_exceptions); | |
if (! empty($tag_exception_ids)) { | |
$post_tag = get_the_tags($this->post_id); | |
if (is_array($post_tag)) { | |
foreach ($post_tag as $tag) { | |
if (in_array($tag->term_id, $tag_exception_ids)) { | |
$match = true; | |
} | |
} | |
} | |
} | |
set_transient($cache_key, $match, 900); | |
} | |
return $match; | |
} | |
// 2. content_restricted_by_settings | |
public function content_restricted_by_settings() { | |
$cache_key = 'lp_restricted_' . $this->post_id; | |
if ( false === ( $is_restricted = get_transient($cache_key))) { | |
set_transient($cache_key, false, 900); // default to false | |
$restrictions = $this->get_restriction_settings(); | |
if (empty($restrictions)) { | |
set_transient($cache_key, false, 900); | |
} else { | |
$content_post_type = get_post_type($this->post_id); | |
foreach ($restrictions['post_types'] as $key => $restriction) { | |
if (! is_numeric($key)) { | |
continue; | |
} | |
$restriction_taxomony = isset($restriction['taxonomy']) ? $restriction['taxonomy'] : 'all'; | |
if ($restriction['post_type'] === $content_post_type && 'all' === $restriction_taxomony) { | |
set_transient($cache_key, true, 900); | |
return true; | |
} | |
if ($restriction['post_type'] === $content_post_type && $this->content_taxonomy_matches($restriction_taxomony)) { | |
set_transient($cache_key, true, 900); | |
return true; | |
} | |
} | |
} | |
} | |
return $is_restricted; | |
} |
Yep, you're right. I've updated the code.
@aosmichenko I wanted to check in and see if these updates are helping with site speed?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@greenhornet79 https://gist.github.com/greenhornet79/5a57b87e552c641c3d079c9513be8485#file-lp-restrictions-transients-php-L7-L9 I think there is a key issue.