| @@ -1,9 +1,21 @@ | ||
| 1 | 1 | <?php |
| 2 | +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical. | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 2 | 7 | if ( ! betterdocs()->settings->get( 'enable_toc', false ) ) { |
| 3 | - return; | |
| 8 | + return; | |
| 4 | 9 | } |
| 5 | 10 | |
| 11 | +// Check if post is password protected and user hasn't provided correct password | |
| 12 | +// This applies to all contexts: templates, Gutenberg blocks, and Elementor widgets | |
| 13 | +if ( post_password_required() ) { | |
| 14 | + // Don't show ToC for password-protected posts until password is provided | |
| 15 | + return; | |
| 16 | +} | |
| 17 | + | |
| 6 | 18 | $toc_hierarchy = betterdocs()->settings->get( 'toc_hierarchy' ); |
| 7 | 19 | $toc_list_number = betterdocs()->settings->get( 'toc_list_number' ); |
| 8 | 20 | $collapsible_toc_mobile = betterdocs()->settings->get( 'collapsible_toc_mobile' ); |
| 9 | 21 | $supported_tag = betterdocs()->settings->get( 'supported_heading_tag', '' ); |
| @@ -8,12 +20,14 @@ | ||
| 8 | 20 | $collapsible_toc_mobile = betterdocs()->settings->get( 'collapsible_toc_mobile' ); |
| 9 | 21 | $supported_tag = betterdocs()->settings->get( 'supported_heading_tag', '' ); |
| 10 | 22 | $htags = $supported_tag ? implode( ',', $supported_tag ) : ''; |
| 11 | 23 | |
| 12 | -$attributes = betterdocs()->template_helper->get_html_attributes([ | |
| 13 | - 'htags' => "{$htags}", | |
| 14 | - 'hierarchy' => "{$toc_hierarchy}", | |
| 15 | - 'list_number' => "{$toc_list_number}", | |
| 16 | - 'collapsible_on_mobile' => "{$collapsible_toc_mobile}" | |
| 17 | -]); | |
| 24 | +$attributes = betterdocs()->template_helper->get_html_attributes( | |
| 25 | + [ | |
| 26 | + 'htags' => "{$htags}", | |
| 27 | + 'hierarchy' => "{$toc_hierarchy}", | |
| 28 | + 'list_number' => "{$toc_list_number}", | |
| 29 | + 'collapsible_on_mobile' => "{$collapsible_toc_mobile}" | |
| 30 | + ] | |
| 31 | +); | |
| 18 | 32 | |
| 19 | -echo do_shortcode( "[betterdocs_toc ". $attributes ."]" ); | |
| 33 | +echo do_shortcode( '[betterdocs_toc ' . $attributes . ']' ); | |