Changeset 3333677
- Timestamp:
- 07/24/2025 01:34:50 PM (8 months ago)
- Location:
- dblocks-finder
- Files:
-
- 8 edited
- 1 copied
-
tags/1.0.7 (copied) (copied from dblocks-finder/trunk)
-
tags/1.0.7/app/App.php (modified) (3 diffs)
-
tags/1.0.7/dblocks-finder.php (modified) (1 diff)
-
tags/1.0.7/readme.txt (modified) (2 diffs)
-
tags/1.0.7/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/app/App.php (modified) (3 diffs)
-
trunk/dblocks-finder.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dblocks-finder/tags/1.0.7/app/App.php
r3250593 r3333677 95 95 } 96 96 97 // Search for pattern usage in post content 97 // Search for pattern usage in post content - improved method 98 98 foreach ($posts as $post) { 99 // Look for patterns in the content (using LIKE to find pattern references) 100 // Modify the loop that adds pattern usage to ensure each pattern is added only once per post 101 foreach ($patterns as $pattern) { 102 $pattern_id = $pattern['id']; 103 // phpcs:ignore WordPress.DB.DirectDatabaseQuery 104 $pattern_usage_results = $wpdb->get_results($wpdb->prepare( 105 "SELECT p.ID, p.post_title, p.post_type 106 FROM {$wpdb->posts} p 107 WHERE p.post_content LIKE %s 108 AND (p.post_type = %s OR p.post_type = %s)", 109 '%' . $wpdb->esc_like('<!-- wp:block {"ref":' . $pattern_id . '} /-->') . '%', 110 'page', 111 'post' 112 )); 113 114 // If pattern is used, add it to the usage array 115 if (!empty($pattern_usage_results)) { 116 foreach ($pattern_usage_results as $usage) { 117 // Ensure the pattern is only added once per post by checking if it's already in the array 118 if (!in_array($usage->ID, array_column($pattern_usage[$pattern['title']], 'post_id'))) { 119 $pattern_usage[$pattern['title']][] = [ 120 'post_title' => $usage->post_title, 121 'post_type' => $usage->post_type, 122 'post_id' => $usage->ID 123 ]; 124 } 99 // Check for blocks in posts and detect patterns 100 if (has_blocks($post->post_content)) { 101 $post_blocks = parse_blocks($post->post_content); 102 // Use the same logic as our debug method to find patterns 103 foreach ($patterns as $pattern_title => $pattern_data) { 104 if ($this->find_pattern_in_blocks($post_blocks, $pattern_data['id'], $pattern_title)) { 105 // Ensure the pattern is only added once per post by checking if it's already in the array 106 if (!in_array($post->ID, array_column($pattern_usage[$pattern_title], 'post_id'))) { 107 $pattern_usage[$pattern_title][] = [ 108 'post_title' => $post->post_title, 109 'post_type' => $post->post_type, 110 'post_id' => $post->ID 111 ]; 125 112 } 126 113 } 127 114 } 128 129 115 } 116 } 117 118 // Now check for blocks in all posts for regular block detection 119 foreach ($posts as $post) { 130 120 // Check for blocks in posts 131 121 if (has_blocks($post->post_content)) { … … 203 193 204 194 return ['blocks' => $blocks, 'usage' => $used_blocks, 'patterns' => $patterns, 'pattern_usage' => $pattern_usage]; 195 } 196 197 198 199 // Helper method to recursively find patterns in blocks 200 private function find_pattern_in_blocks($blocks, $pattern_id, $pattern_title) { 201 foreach ($blocks as $block) { 202 // Check if this is a pattern block 203 if (isset($block['blockName'])) { 204 // Check for wp:block with ref 205 if ($block['blockName'] === 'core/block' && 206 isset($block['attrs']['ref']) && 207 $block['attrs']['ref'] == $pattern_id) { 208 return true; 209 } 210 211 // Check for wp:pattern with slug 212 if (strpos($block['blockName'], 'core/pattern') === 0 && 213 isset($block['attrs']['slug']) && 214 $block['attrs']['slug'] === $pattern_title) { 215 return true; 216 } 217 } 218 219 // Recurse into inner blocks 220 if (isset($block['innerBlocks']) && !empty($block['innerBlocks'])) { 221 if ($this->find_pattern_in_blocks($block['innerBlocks'], $pattern_id, $pattern_title)) { 222 return true; 223 } 224 } 225 } 226 return false; 205 227 } 206 228 … … 262 284 } 263 285 } 286 -
dblocks-finder/tags/1.0.7/dblocks-finder.php
r3291512 r3333677 5 5 * Requires at least: 6.1 6 6 * Requires PHP: 7.4 7 * Version: 1.0. 67 * Version: 1.0.7 8 8 * Author: DPlugins 9 9 * Author URI: https://dplugins.com/ -
dblocks-finder/tags/1.0.7/readme.txt
r3291512 r3333677 4 4 Requires at least: 6.6.0 5 5 Tested up to: 6.8.1 6 Stable tag: 1.0. 66 Stable tag: 1.0.7 7 7 Requires PHP: 7.4 8 8 License: GPL-2.0-or-later … … 46 46 2. Preview 47 47 48 == Changelog == 49 = 1.0.7 = 50 * Fixed: Sync patterns was not scanned in child pages 48 51 49 52 == Changelog == -
dblocks-finder/tags/1.0.7/vendor/composer/installed.php
r3215751 r3333677 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => ' 52aacd5ee7ff82ab19733f0eff0ad5dfc872c61e',6 'reference' => '48bcea822d3241fa3d05ca944f37f9864de67fd7', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => ' 52aacd5ee7ff82ab19733f0eff0ad5dfc872c61e',16 'reference' => '48bcea822d3241fa3d05ca944f37f9864de67fd7', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../', -
dblocks-finder/trunk/app/App.php
r3250593 r3333677 95 95 } 96 96 97 // Search for pattern usage in post content 97 // Search for pattern usage in post content - improved method 98 98 foreach ($posts as $post) { 99 // Look for patterns in the content (using LIKE to find pattern references) 100 // Modify the loop that adds pattern usage to ensure each pattern is added only once per post 101 foreach ($patterns as $pattern) { 102 $pattern_id = $pattern['id']; 103 // phpcs:ignore WordPress.DB.DirectDatabaseQuery 104 $pattern_usage_results = $wpdb->get_results($wpdb->prepare( 105 "SELECT p.ID, p.post_title, p.post_type 106 FROM {$wpdb->posts} p 107 WHERE p.post_content LIKE %s 108 AND (p.post_type = %s OR p.post_type = %s)", 109 '%' . $wpdb->esc_like('<!-- wp:block {"ref":' . $pattern_id . '} /-->') . '%', 110 'page', 111 'post' 112 )); 113 114 // If pattern is used, add it to the usage array 115 if (!empty($pattern_usage_results)) { 116 foreach ($pattern_usage_results as $usage) { 117 // Ensure the pattern is only added once per post by checking if it's already in the array 118 if (!in_array($usage->ID, array_column($pattern_usage[$pattern['title']], 'post_id'))) { 119 $pattern_usage[$pattern['title']][] = [ 120 'post_title' => $usage->post_title, 121 'post_type' => $usage->post_type, 122 'post_id' => $usage->ID 123 ]; 124 } 99 // Check for blocks in posts and detect patterns 100 if (has_blocks($post->post_content)) { 101 $post_blocks = parse_blocks($post->post_content); 102 // Use the same logic as our debug method to find patterns 103 foreach ($patterns as $pattern_title => $pattern_data) { 104 if ($this->find_pattern_in_blocks($post_blocks, $pattern_data['id'], $pattern_title)) { 105 // Ensure the pattern is only added once per post by checking if it's already in the array 106 if (!in_array($post->ID, array_column($pattern_usage[$pattern_title], 'post_id'))) { 107 $pattern_usage[$pattern_title][] = [ 108 'post_title' => $post->post_title, 109 'post_type' => $post->post_type, 110 'post_id' => $post->ID 111 ]; 125 112 } 126 113 } 127 114 } 128 129 115 } 116 } 117 118 // Now check for blocks in all posts for regular block detection 119 foreach ($posts as $post) { 130 120 // Check for blocks in posts 131 121 if (has_blocks($post->post_content)) { … … 203 193 204 194 return ['blocks' => $blocks, 'usage' => $used_blocks, 'patterns' => $patterns, 'pattern_usage' => $pattern_usage]; 195 } 196 197 198 199 // Helper method to recursively find patterns in blocks 200 private function find_pattern_in_blocks($blocks, $pattern_id, $pattern_title) { 201 foreach ($blocks as $block) { 202 // Check if this is a pattern block 203 if (isset($block['blockName'])) { 204 // Check for wp:block with ref 205 if ($block['blockName'] === 'core/block' && 206 isset($block['attrs']['ref']) && 207 $block['attrs']['ref'] == $pattern_id) { 208 return true; 209 } 210 211 // Check for wp:pattern with slug 212 if (strpos($block['blockName'], 'core/pattern') === 0 && 213 isset($block['attrs']['slug']) && 214 $block['attrs']['slug'] === $pattern_title) { 215 return true; 216 } 217 } 218 219 // Recurse into inner blocks 220 if (isset($block['innerBlocks']) && !empty($block['innerBlocks'])) { 221 if ($this->find_pattern_in_blocks($block['innerBlocks'], $pattern_id, $pattern_title)) { 222 return true; 223 } 224 } 225 } 226 return false; 205 227 } 206 228 … … 262 284 } 263 285 } 286 -
dblocks-finder/trunk/dblocks-finder.php
r3291512 r3333677 5 5 * Requires at least: 6.1 6 6 * Requires PHP: 7.4 7 * Version: 1.0. 67 * Version: 1.0.7 8 8 * Author: DPlugins 9 9 * Author URI: https://dplugins.com/ -
dblocks-finder/trunk/readme.txt
r3291512 r3333677 4 4 Requires at least: 6.6.0 5 5 Tested up to: 6.8.1 6 Stable tag: 1.0. 66 Stable tag: 1.0.7 7 7 Requires PHP: 7.4 8 8 License: GPL-2.0-or-later … … 46 46 2. Preview 47 47 48 == Changelog == 49 = 1.0.7 = 50 * Fixed: Sync patterns was not scanned in child pages 48 51 49 52 == Changelog == -
dblocks-finder/trunk/vendor/composer/installed.php
r3215751 r3333677 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => ' 52aacd5ee7ff82ab19733f0eff0ad5dfc872c61e',6 'reference' => '48bcea822d3241fa3d05ca944f37f9864de67fd7', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => ' 52aacd5ee7ff82ab19733f0eff0ad5dfc872c61e',16 'reference' => '48bcea822d3241fa3d05ca944f37f9864de67fd7', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.