From ed05605e9b5834b85108e660533ec23fd6eb2b67 Mon Sep 17 00:00:00 2001 From: Ronald Huereca Date: Thu, 18 Dec 2025 16:21:18 -0600 Subject: [PATCH 1/2] Adding direct file limits. --- simpletoc-admin-settings.php | 5 +++++ simpletoc-class-headline-ids.php | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/simpletoc-admin-settings.php b/simpletoc-admin-settings.php index 692b61e..a59fb8a 100644 --- a/simpletoc-admin-settings.php +++ b/simpletoc-admin-settings.php @@ -7,6 +7,11 @@ namespace MToensing\SimpleTOC; +if ( ! defined( 'ABSPATH' ) ) { + header( 'Status: 403 Forbidden' ); + header( 'HTTP/1.1 403 Forbidden' ); + exit; +} /** * Add SimpleTOC global settings page. */ diff --git a/simpletoc-class-headline-ids.php b/simpletoc-class-headline-ids.php index 85b95e9..e4b9de5 100644 --- a/simpletoc-class-headline-ids.php +++ b/simpletoc-class-headline-ids.php @@ -9,6 +9,12 @@ namespace MToensing\SimpleTOC; +if ( ! defined( 'ABSPATH' ) ) { + header( 'Status: 403 Forbidden' ); + header( 'HTTP/1.1 403 Forbidden' ); + exit; +} + /** * Class to manage headline IDs. * From 9079fe180f7b44d90ca569096b7a753d51b5548a Mon Sep 17 00:00:00 2001 From: Ronald Huereca Date: Thu, 18 Dec 2025 16:46:10 -0600 Subject: [PATCH 2/2] Fixing recursion for Table of Content IDs. --- plugin.php | 9 ++-- simpletoc-class-headline-ids-wrapper.php | 57 ++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 simpletoc-class-headline-ids-wrapper.php diff --git a/plugin.php b/plugin.php index 3d364ce..4d889c3 100644 --- a/plugin.php +++ b/plugin.php @@ -17,6 +17,7 @@ require_once __DIR__ . '/simpletoc-admin-settings.php'; require_once __DIR__ . '/simpletoc-class-headline-ids.php'; +require_once __DIR__ . '/simpletoc-class-headline-ids-wrapper.php'; /** * Prevents direct execution of the plugin file. @@ -166,6 +167,8 @@ function simpletoc_add_ids_to_content( $content ) { add_filter( 'the_content', __NAMESPACE__ . '\simpletoc_add_ids_to_content', 1 ); + + /** * Recursively adds IDs to the headings of a nested block structure. * @@ -187,9 +190,9 @@ function add_ids_to_blocks_recursive( $blocks ) { */ $supported_blocks = apply_filters( 'simpletoc_supported_blocks_for_ids', $supported_blocks ); - // Need two separate instances so that IDs aren't double coubnted. - $inner_html_id_instance = new SimpleTOC_Headline_Ids(); - $inner_content_id_instance = new SimpleTOC_Headline_Ids(); + // Need two separate instances so that IDs aren't double counted. + $inner_html_id_instance = SimpleTOC_Headline_Ids_Wrapper::get_inner_html_id_instance(); + $inner_content_id_instance = SimpleTOC_Headline_Ids_Wrapper::get_inner_content_id_instance(); foreach ( $blocks as &$block ) { if ( isset( $block['blockName'] ) && in_array( $block['blockName'], $supported_blocks, true ) && isset( $block['innerHTML'] ) && isset( $block['innerContent'] ) && isset( $block['innerContent'][0] ) ) { diff --git a/simpletoc-class-headline-ids-wrapper.php b/simpletoc-class-headline-ids-wrapper.php new file mode 100644 index 0000000..37e5676 --- /dev/null +++ b/simpletoc-class-headline-ids-wrapper.php @@ -0,0 +1,57 @@ +