| @@ -36,9 +36,9 @@ | ||
| 36 | 36 | add_action('init', array($this, 'maybe_deregister_theme_patterns'), 9999); |
| 37 | 37 | add_action('init', array($this, 'maybe_deregister_uncategorized_patterns'), 10000); |
| 38 | 38 | add_action('init', array($this, 'maybe_deregister_core_patterns'), 10001); |
| 39 | 39 | |
| 40 | - error_log('[PatternsWP] Constructor - All pattern deregistration hooks registered'); | |
| 40 | + // error_log('[PatternsWP] Constructor - All pattern deregistration hooks registered'); | |
| 41 | 41 | |
| 42 | 42 | // Apply filters for different pattern sources |
| 43 | 43 | add_filter('patternswp_patterns', array($this, 'filter_patterns_by_visibility'), 20); |
| 44 | 44 | add_filter('block_editor_settings_all', array($this, 'filter_block_editor_settings'), 10, 2); |
| @@ -70,9 +70,9 @@ | ||
| 70 | 70 | $hide_theme = get_option('patternswp_hide_theme_patterns', false); |
| 71 | 71 | $hide_uncategorized = get_option('patternswp_hide_uncategorized_patterns', false); |
| 72 | 72 | $hide_core = get_option('patternswp_hide_core_patterns', false); |
| 73 | 73 | |
| 74 | - error_log('[PatternsWP] Settings Check - Theme: ' . ($hide_theme ? 'true' : 'false') . ', Uncategorized: ' . ($hide_uncategorized ? 'true' : 'false') . ', Core: ' . ($hide_core ? 'true' : 'false')); | |
| 74 | + // error_log('[PatternsWP] Settings Check - Theme: ' . ($hide_theme ? 'true' : 'false') . ', Uncategorized: ' . ($hide_uncategorized ? 'true' : 'false') . ', Core: ' . ($hide_core ? 'true' : 'false')); | |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * Add admin menu |
| @@ -466,12 +466,12 @@ | ||
| 466 | 466 | * Attempt to deregister any patterns from the active or child theme. |
| 467 | 467 | */ |
| 468 | 468 | public function maybe_deregister_theme_patterns() { |
| 469 | 469 | $hide_theme_patterns = get_option('patternswp_hide_theme_patterns', false); |
| 470 | - error_log('[PatternsWP] maybe_deregister_theme_patterns called - hide_theme_patterns: ' . ($hide_theme_patterns ? 'true' : 'false')); | |
| 470 | + // error_log('[PatternsWP] maybe_deregister_theme_patterns called - hide_theme_patterns: ' . ($hide_theme_patterns ? 'true' : 'false')); | |
| 471 | 471 | |
| 472 | 472 | if (!$hide_theme_patterns) { |
| 473 | - error_log('[PatternsWP] Theme pattern hiding is disabled'); | |
| 473 | + // error_log('[PatternsWP] Theme pattern hiding is disabled'); | |
| 474 | 474 | return; |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | // Get the active theme. |
| @@ -488,15 +488,15 @@ | ||
| 488 | 488 | $paths_to_search[] = $parent_theme->template; |
| 489 | 489 | } |
| 490 | 490 | $paths_to_search = array_unique($paths_to_search); |
| 491 | 491 | |
| 492 | - error_log('[PatternsWP] Theme paths to search: ' . implode(', ', $paths_to_search)); | |
| 492 | + // error_log('[PatternsWP] Theme paths to search: ' . implode(', ', $paths_to_search)); | |
| 493 | 493 | |
| 494 | 494 | // Get all registered patterns. |
| 495 | 495 | $patterns = \WP_Block_Patterns_Registry::get_instance(); |
| 496 | 496 | $all_patterns = $patterns->get_all_registered(); |
| 497 | 497 | |
| 498 | - error_log('[PatternsWP] Total registered patterns: ' . count($all_patterns)); | |
| 498 | + // error_log('[PatternsWP] Total registered patterns: ' . count($all_patterns)); | |
| 499 | 499 | |
| 500 | 500 | // Loop through all patterns and deregister any that are from the active or child theme. |
| 501 | 501 | foreach ($all_patterns as $index => $pattern) { |
| 502 | 502 | $file_path = $pattern['filePath'] ?? ''; |
| @@ -507,9 +507,9 @@ | ||
| 507 | 507 | // Check if the pattern is from the active or child theme. |
| 508 | 508 | foreach ($paths_to_search as $path) { |
| 509 | 509 | if (false !== strpos($file_path, 'themes/' . $path)) { |
| 510 | 510 | unregister_block_pattern($pattern['name']); |
| 511 | - error_log('[PatternsWP] Deregistered theme pattern: ' . $pattern['name'] . ' from path: ' . $file_path); | |
| 511 | + // error_log('[PatternsWP] Deregistered theme pattern: ' . $pattern['name'] . ' from path: ' . $file_path); | |
| 512 | 512 | } |
| 513 | 513 | } |
| 514 | 514 | } |
| 515 | 515 | } |
| @@ -518,13 +518,13 @@ | ||
| 518 | 518 | * Deregister any uncategorized patterns. |
| 519 | 519 | */ |
| 520 | 520 | public function maybe_deregister_uncategorized_patterns() { |
| 521 | 521 | $hide_uncategorized_enabled = get_option('patternswp_hide_uncategorized_patterns', false); |
| 522 | - error_log('[PatternsWP] maybe_deregister_uncategorized_patterns called - hide_uncategorized: ' . ($hide_uncategorized_enabled ? 'true' : 'false')); | |
| 522 | + // error_log('[PatternsWP] maybe_deregister_uncategorized_patterns called - hide_uncategorized: ' . ($hide_uncategorized_enabled ? 'true' : 'false')); | |
| 523 | 523 | |
| 524 | 524 | // Exit early if not enabled. |
| 525 | 525 | if (!$hide_uncategorized_enabled) { |
| 526 | - error_log('[PatternsWP] Uncategorized pattern hiding is disabled'); | |
| 526 | + // error_log('[PatternsWP] Uncategorized pattern hiding is disabled'); | |
| 527 | 527 | return; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | // Retrieve all patterns. |
| @@ -530,15 +530,15 @@ | ||
| 530 | 530 | // Retrieve all patterns. |
| 531 | 531 | $patterns = \WP_Block_Patterns_Registry::get_instance(); |
| 532 | 532 | $all_patterns = $patterns->get_all_registered(); |
| 533 | 533 | |
| 534 | - error_log('[PatternsWP] Checking ' . count($all_patterns) . ' patterns for uncategorized ones'); | |
| 534 | + // error_log('[PatternsWP] Checking ' . count($all_patterns) . ' patterns for uncategorized ones'); | |
| 535 | 535 | |
| 536 | 536 | // Loop through all patterns and deregister any that are uncategorized. |
| 537 | 537 | foreach ($all_patterns as $index => $pattern) { |
| 538 | 538 | if (!isset($pattern['categories']) || empty($pattern['categories'])) { |
| 539 | 539 | unregister_block_pattern($pattern['name']); |
| 540 | - error_log('[PatternsWP] Deregistered uncategorized pattern: ' . $pattern['name']); | |
| 540 | + // error_log('[PatternsWP] Deregistered uncategorized pattern: ' . $pattern['name']); | |
| 541 | 541 | } else { |
| 542 | 542 | $found = false; |
| 543 | 543 | $block_categories = $pattern['categories'] ?? array(); |
| 544 | 544 | foreach ($block_categories as $block_category) { |
| @@ -548,9 +548,9 @@ | ||
| 548 | 548 | } |
| 549 | 549 | } |
| 550 | 550 | if (!$found) { |
| 551 | 551 | unregister_block_pattern($pattern['name']); |
| 552 | - error_log('[PatternsWP] Deregistered uncategorized pattern (invalid category): ' . $pattern['name']); | |
| 552 | + // error_log('[PatternsWP] Deregistered uncategorized pattern (invalid category): ' . $pattern['name']); | |
| 553 | 553 | } |
| 554 | 554 | } |
| 555 | 555 | } |
| 556 | 556 | } |
| @@ -559,13 +559,13 @@ | ||
| 559 | 559 | * Deregister core patterns. |
| 560 | 560 | */ |
| 561 | 561 | public function maybe_deregister_core_patterns() { |
| 562 | 562 | $hide_core_patterns = get_option('patternswp_hide_core_patterns', false); |
| 563 | - error_log('[PatternsWP] maybe_deregister_core_patterns called - hide_core_patterns: ' . ($hide_core_patterns ? 'true' : 'false')); | |
| 563 | + // error_log('[PatternsWP] maybe_deregister_core_patterns called - hide_core_patterns: ' . ($hide_core_patterns ? 'true' : 'false')); | |
| 564 | 564 | |
| 565 | 565 | // Exit early if not enabled. |
| 566 | 566 | if (!$hide_core_patterns) { |
| 567 | - error_log('[PatternsWP] Core pattern hiding is disabled'); | |
| 567 | + // error_log('[PatternsWP] Core pattern hiding is disabled'); | |
| 568 | 568 | return; |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | // Retrieve all patterns. |
| @@ -571,9 +571,9 @@ | ||
| 571 | 571 | // Retrieve all patterns. |
| 572 | 572 | $patterns = \WP_Block_Patterns_Registry::get_instance(); |
| 573 | 573 | $all_patterns = $patterns->get_all_registered(); |
| 574 | 574 | |
| 575 | - error_log('[PatternsWP] Checking ' . count($all_patterns) . ' patterns for core ones'); | |
| 575 | + // error_log('[PatternsWP] Checking ' . count($all_patterns) . ' patterns for core ones'); | |
| 576 | 576 | |
| 577 | 577 | // Loop through all patterns and deregister any that are core patterns. |
| 578 | 578 | foreach ($all_patterns as $index => $pattern) { |
| 579 | 579 | // Core patterns typically have names starting with 'core/' or no file path |
| @@ -603,9 +603,9 @@ | ||
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | if ($is_core_pattern) { |
| 606 | 606 | unregister_block_pattern($pattern['name']); |
| 607 | - error_log('[PatternsWP] Deregistered core pattern: ' . $pattern['name'] . ' (' . $reason . ')'); | |
| 607 | + // error_log('[PatternsWP] Deregistered core pattern: ' . $pattern['name'] . ' (' . $reason . ')'); | |
| 608 | 608 | } |
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | |
| @@ -612,15 +612,15 @@ | ||
| 612 | 612 | /** |
| 613 | 613 | * Filter the block patterns list in the editor |
| 614 | 614 | */ |
| 615 | 615 | public function filter_block_patterns_list($patterns) { |
| 616 | - error_log('[PatternsWP] filter_block_patterns_list called with ' . count($patterns) . ' patterns'); | |
| 616 | + // error_log('[PatternsWP] filter_block_patterns_list called with ' . count($patterns) . ' patterns'); | |
| 617 | 617 | |
| 618 | 618 | $hide_theme_patterns = get_option('patternswp_hide_theme_patterns', false); |
| 619 | 619 | $hide_uncategorized = get_option('patternswp_hide_uncategorized_patterns', false); |
| 620 | 620 | $hide_core_patterns = get_option('patternswp_hide_core_patterns', false); |
| 621 | 621 | |
| 622 | - error_log('[PatternsWP] Block patterns filter - Theme: ' . ($hide_theme_patterns ? 'true' : 'false') . ', Uncategorized: ' . ($hide_uncategorized ? 'true' : 'false') . ', Core: ' . ($hide_core_patterns ? 'true' : 'false')); | |
| 622 | + // error_log('[PatternsWP] Block patterns filter - Theme: ' . ($hide_theme_patterns ? 'true' : 'false') . ', Uncategorized: ' . ($hide_uncategorized ? 'true' : 'false') . ', Core: ' . ($hide_core_patterns ? 'true' : 'false')); | |
| 623 | 623 | |
| 624 | 624 | // If no filters are enabled, return original patterns |
| 625 | 625 | if (!$hide_theme_patterns && !$hide_uncategorized && !$hide_core_patterns) { |
| 626 | 626 | return $patterns; |
| @@ -635,14 +635,14 @@ | ||
| 635 | 635 | if ($hide_theme_patterns && $should_include) { |
| 636 | 636 | // Check if pattern name starts with theme prefix |
| 637 | 637 | if (isset($pattern['name']) && strpos($pattern['name'], 'theme-') === 0) { |
| 638 | 638 | $should_include = false; |
| 639 | - error_log('[PatternsWP] Excluding theme pattern by name: ' . $pattern['name']); | |
| 639 | + // error_log('[PatternsWP] Excluding theme pattern by name: ' . $pattern['name']); | |
| 640 | 640 | } |
| 641 | 641 | // Check if pattern has theme file path |
| 642 | 642 | if (isset($pattern['filePath']) && strpos($pattern['filePath'], 'themes/') !== false) { |
| 643 | 643 | $should_include = false; |
| 644 | - error_log('[PatternsWP] Excluding theme pattern by path: ' . $pattern['name']); | |
| 644 | + // error_log('[PatternsWP] Excluding theme pattern by path: ' . $pattern['name']); | |
| 645 | 645 | } |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | // Check uncategorized patterns |
| @@ -648,9 +648,9 @@ | ||
| 648 | 648 | // Check uncategorized patterns |
| 649 | 649 | if ($hide_uncategorized && $should_include) { |
| 650 | 650 | if (!isset($pattern['categories']) || empty($pattern['categories'])) { |
| 651 | 651 | $should_include = false; |
| 652 | - error_log('[PatternsWP] Excluding uncategorized pattern: ' . $pattern['name']); | |
| 652 | + // error_log('[PatternsWP] Excluding uncategorized pattern: ' . $pattern['name']); | |
| 653 | 653 | } |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // Check core patterns |
| @@ -656,9 +656,9 @@ | ||
| 656 | 656 | // Check core patterns |
| 657 | 657 | if ($hide_core_patterns && $should_include) { |
| 658 | 658 | if (isset($pattern['name']) && strpos($pattern['name'], 'core/') === 0) { |
| 659 | 659 | $should_include = false; |
| 660 | - error_log('[PatternsWP] Excluding core pattern: ' . $pattern['name']); | |
| 660 | + // error_log('[PatternsWP] Excluding core pattern: ' . $pattern['name']); | |
| 661 | 661 | } |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | if ($should_include) { |
| @@ -665,9 +665,9 @@ | ||
| 665 | 665 | $filtered_patterns[] = $pattern; |
| 666 | 666 | } |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - error_log('[PatternsWP] Filtered from ' . count($patterns) . ' to ' . count($filtered_patterns) . ' patterns'); | |
| 669 | + // error_log('[PatternsWP] Filtered from ' . count($patterns) . ' to ' . count($filtered_patterns) . ' patterns'); | |
| 670 | 670 | |
| 671 | 671 | return $filtered_patterns; |
| 672 | 672 | } |
| 673 | 673 | |
| @@ -717,9 +717,9 @@ | ||
| 717 | 717 | } |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | if ($should_hide) { |
| 721 | - error_log('[PatternsWP] Filtering REST response for pattern: ' . ($pattern_data['title'] ?? 'Unknown')); | |
| 721 | + // error_log('[PatternsWP] Filtering REST response for pattern: ' . ($pattern_data['title'] ?? 'Unknown')); | |
| 722 | 722 | // Return an error response to hide this pattern |
| 723 | 723 | return new WP_Error( |
| 724 | 724 | 'rest_pattern_hidden', |
| 725 | 725 | 'Pattern is hidden by visibility settings', |
| @@ -930,13 +930,13 @@ | ||
| 930 | 930 | * Filter patterns based on visibility settings |
| 931 | 931 | */ |
| 932 | 932 | public function filter_patterns_by_visibility($patterns) { |
| 933 | 933 | // Debug logging |
| 934 | - error_log('[PatternsWP] Filter applied with ' . count((array)$patterns) . ' patterns'); | |
| 934 | + // error_log('[PatternsWP] Filter applied with ' . count((array)$patterns) . ' patterns'); | |
| 935 | 935 | |
| 936 | 936 | // If no patterns or not an array, return early |
| 937 | 937 | if (empty($patterns) || !is_array($patterns)) { |
| 938 | - error_log('[PatternsWP] No patterns to filter'); | |
| 938 | + // error_log('[PatternsWP] No patterns to filter'); | |
| 939 | 939 | return $patterns; |
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | $filtered_patterns = array(); |
| @@ -943,11 +943,11 @@ | ||
| 943 | 943 | $hide_theme_patterns = get_option('patternswp_hide_theme_patterns', false); |
| 944 | 944 | $hide_uncategorized = get_option('patternswp_hide_uncategorized_patterns', false); |
| 945 | 945 | $hide_core_patterns = get_option('patternswp_hide_core_patterns', false); |
| 946 | 946 | |
| 947 | - error_log('[PatternsWP] Settings - Hide Theme: ' . ($hide_theme_patterns ? 'true' : 'false') . | |
| 948 | - ', Hide Uncategorized: ' . ($hide_uncategorized ? 'true' : 'false') . | |
| 949 | - ', Hide Core: ' . ($hide_core_patterns ? 'true' : 'false')); | |
| 947 | + // error_log('[PatternsWP] Settings - Hide Theme: ' . ($hide_theme_patterns ? 'true' : 'false') . | |
| 948 | + // ', Hide Uncategorized: ' . ($hide_uncategorized ? 'true' : 'false') . | |
| 949 | + // ', Hide Core: ' . ($hide_core_patterns ? 'true' : 'false')); | |
| 950 | 950 | |
| 951 | 951 | foreach ($patterns as $pattern) { |
| 952 | 952 | // Skip if pattern is not an array |
| 953 | 953 | if (!is_array($pattern)) { |
| @@ -956,21 +956,21 @@ | ||
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | // Skip theme patterns if enabled |
| 959 | 959 | if ($hide_theme_patterns && $this->is_theme_pattern($pattern)) { |
| 960 | - error_log('[PatternsWP] Skipping theme pattern: ' . ($pattern['title'] ?? 'Unknown')); | |
| 960 | + // error_log('[PatternsWP] Skipping theme pattern: ' . ($pattern['title'] ?? 'Unknown')); | |
| 961 | 961 | continue; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | // Skip core patterns if enabled |
| 965 | 965 | if ($hide_core_patterns && $this->is_core_pattern($pattern)) { |
| 966 | - error_log('[PatternsWP] Skipping core pattern: ' . ($pattern['title'] ?? 'Unknown')); | |
| 966 | + // error_log('[PatternsWP] Skipping core pattern: ' . ($pattern['title'] ?? 'Unknown')); | |
| 967 | 967 | continue; |
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | // Skip uncategorized patterns if enabled |
| 971 | 971 | if ($hide_uncategorized && $this->is_uncategorized_pattern($pattern)) { |
| 972 | - error_log('[PatternsWP] Skipping uncategorized pattern: ' . ($pattern['title'] ?? 'Unknown')); | |
| 972 | + // error_log('[PatternsWP] Skipping uncategorized pattern: ' . ($pattern['title'] ?? 'Unknown')); | |
| 973 | 973 | continue; |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | $filtered_patterns[] = $pattern; |
| @@ -975,9 +975,9 @@ | ||
| 975 | 975 | |
| 976 | 976 | $filtered_patterns[] = $pattern; |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | - error_log('[PatternsWP] Filtered to ' . count($filtered_patterns) . ' patterns'); | |
| 979 | + // error_log('[PatternsWP] Filtered to ' . count($filtered_patterns) . ' patterns'); | |
| 980 | 980 | return $filtered_patterns; |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |