PluginProbe
PatternsWP – Gutenberg Block Patterns & Page Templates Library / 1.0.8
PatternsWP – Gutenberg Block Patterns & Page Templates Library v1.0.8
1.1.0 trunk 1.0.0 1.0.1 1.0.10 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
← All changes | includes/class-patternswp-api.php +16 -4 1.0.5 → 1.0.8 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +// Exit if accessed directly
3 +if (!defined('ABSPATH')) {
4 + exit;
5 +}
6 +
2 7 class PatternsWP_API_Section {
3 8
4 9 public $api_url;
5 10
@@ -7,9 +12,9 @@
7 12 * Constructor
8 13 */
9 14 public function __construct() {
10 15 add_action( 'admin_init', array( $this, 'register_patterns_endpoint') );
11 - add_action( 'admin_init', array( $this, 'patternswp_save_transient_if_not_ajax' ) );
16 + add_action('patternswp_hourly_transient_load', array( $this, 'patternswp_save_transient_if_not_ajax' ) );
12 17
13 18 // API URL
14 19 $this->api_url = 'https://pwp4.thepatternswp.com/';
15 20 }
@@ -236,8 +241,12 @@
236 241 }
237 242
238 243 // Return the patterns if not empty.
239 244 if (!empty($patterns)) {
245 + // Apply pattern visibility filter
246 + error_log('[PatternsWP API] Applying filter to ' . count($patterns) . ' patterns from API');
247 + $patterns = apply_filters('patternswp_patterns', $patterns);
248 + error_log('[PatternsWP API] Filter applied, now have ' . count($patterns) . ' patterns');
240 249 return $patterns;
241 250 } else {
242 251 // error_log('Received empty response for patterns.');
243 252 return array();
@@ -264,8 +273,13 @@
264 273 /**
265 274 * Register patterns and categories
266 275 */
267 276 private function register_patterns_and_categories( $patterns ) {
277 + // Apply pattern visibility filter before registering
278 + error_log('[PatternsWP API] Register patterns - applying filter to ' . count($patterns) . ' patterns');
279 + $patterns = apply_filters('patternswp_patterns', $patterns);
280 + error_log('[PatternsWP API] Register patterns - filter applied, now have ' . count($patterns) . ' patterns');
281 +
268 282 $registered_categories = array();
269 283
270 284 foreach ($patterns as $pattern) {
271 285 $categories = $pattern['categories'];
@@ -310,11 +324,9 @@
310 324 /**
311 325 * Save transient if not ajax
312 326 */
313 327 public function patternswp_save_transient_if_not_ajax() {
314 - if ( ! wp_doing_ajax() ) {
315 - $this->patternswp_save_transient_wise_category();
316 - }
328 + $this->patternswp_save_transient_wise_category();
317 329 }
318 330
319 331 /**
320 332 * Save transient wise category