| 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 |
} |
| 7 |
if ( ! betterdocs()->settings->get( 'enable_toc', false ) ) { |
| 8 |
return; |
| 9 |
} |
| 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 |
|
| 18 |
$toc_hierarchy = betterdocs()->settings->get( 'toc_hierarchy' ); |
| 19 |
$toc_list_number = betterdocs()->settings->get( 'toc_list_number' ); |
| 20 |
$collapsible_toc_mobile = betterdocs()->settings->get( 'collapsible_toc_mobile' ); |
| 21 |
$supported_tag = betterdocs()->settings->get( 'supported_heading_tag', '' ); |
| 22 |
$htags = $supported_tag ? implode( ',', $supported_tag ) : ''; |
| 23 |
|
| 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 |
); |
| 32 |
|
| 33 |
echo do_shortcode( '[betterdocs_toc ' . $attributes . ']' ); |
| 34 |
|