| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: SimpleTOC - Table of Contents Block |
| 4 | 4 | * Plugin URI: https://marc.tv/simpletoc-wordpress-inhaltsverzeichnis-plugin-gutenberg/ |
| 5 | 5 | * Description: SEO-friendly Table of Contents Gutenberg block. No JavaScript or CSS by default. |
| 6 | - * Version: 7.4.0 | |
| 6 | + * Version: 7.4.1 | |
| 7 | 7 | * Requires at least: 6.2 |
| 8 | 8 | * Requires PHP: 7.3 |
| 9 | 9 | * Author: Marc Tönsing |
| 10 | 10 | * Author URI: https://toensing.com |
| @@ -20,9 +20,9 @@ | ||
| 20 | 20 | require_once __DIR__ . '/simpletoc-admin-settings.php'; |
| 21 | 21 | require_once __DIR__ . '/simpletoc-class-headline-ids.php'; |
| 22 | 22 | |
| 23 | 23 | const DEFAULT_BOX_COLOR = '#ebebeb'; |
| 24 | -const SIMPLETOC_VERSION = '7.4.0'; | |
| 24 | +const SIMPLETOC_VERSION = '7.4.1'; | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Prevents direct execution of the plugin file. |
| 28 | 28 | * If a WordPress function does not exist, it means that the file has not been run by WordPress. |
| @@ -224,9 +224,15 @@ | ||
| 224 | 224 | // Need two separate instances so that IDs aren't double counted. |
| 225 | 225 | $inner_html_id_instance = new SimpleTOC_Headline_Ids(); |
| 226 | 226 | $inner_content_id_instance = new SimpleTOC_Headline_Ids(); |
| 227 | 227 | |
| 228 | + $ignored_blocks = simpletoc_get_excluded_blocks(); | |
| 229 | + | |
| 228 | 230 | foreach ( $blocks as &$block ) { |
| 231 | + if ( isset( $block['blockName'] ) && in_array( $block['blockName'], $ignored_blocks, true ) ) { | |
| 232 | + continue; | |
| 233 | + } | |
| 234 | + | |
| 229 | 235 | if ( isset( $block['blockName'] ) && in_array( $block['blockName'], $supported_blocks, true ) && isset( $block['innerHTML'] ) && isset( $block['innerContent'] ) && isset( $block['innerContent'][0] ) ) { |
| 230 | 236 | $block['innerHTML'] = add_anchor_attribute( $block['innerHTML'], $inner_html_id_instance, $block ); |
| 231 | 237 | $block['innerContent'][0] = add_anchor_attribute( $block['innerContent'][0], $inner_content_id_instance, $block ); |
| 232 | 238 | } elseif ( ! empty( $block['innerBlocks'] ) ) { |
| @@ -370,8 +376,22 @@ | ||
| 370 | 376 | return $headings; |
| 371 | 377 | } |
| 372 | 378 | |
| 373 | 379 | /** |
| 380 | + * Gets blocks excluded from both anchor generation and TOC collection. | |
| 381 | + * | |
| 382 | + * Query templates render repeatedly in a different post context. | |
| 383 | + * | |
| 384 | + * @return string[] Excluded block names. | |
| 385 | + */ | |
| 386 | +function simpletoc_get_excluded_blocks() { | |
| 387 | + return apply_filters( | |
| 388 | + 'simpletoc_excluded_blocks', | |
| 389 | + array( 'core/query', 'generateblocks/query-loop', 'generateblocks/query' ) | |
| 390 | + ); | |
| 391 | +} | |
| 392 | + | |
| 393 | +/** | |
| 374 | 394 | * Return all headings with a recursive walk through all blocks. |
| 375 | 395 | * This includes groups and reusable block with groups within reusable blocks. |
| 376 | 396 | * |
| 377 | 397 | * @param array[] $blocks The blocks to filter headings from. |
| @@ -384,9 +404,9 @@ | ||
| 384 | 404 | return $arr; |
| 385 | 405 | } |
| 386 | 406 | |
| 387 | 407 | // allow developers to ignore specific blocks. |
| 388 | - $ignored_blocks = apply_filters( 'simpletoc_excluded_blocks', array() ); | |
| 408 | + $ignored_blocks = simpletoc_get_excluded_blocks(); | |
| 389 | 409 | |
| 390 | 410 | foreach ( $blocks as $inner_block ) { |
| 391 | 411 | if ( is_array( $inner_block ) ) { |
| 392 | 412 | // if block is ignored, skip. |