PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.3
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
← All changes | views/shortcodes/toc.php +23 -41 4.9.23.5.3 View file →
@@ -1,51 +1,33 @@
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 -}
7 -/** @var \WPDeveloper\BetterDocs\Shortcodes\ToC $widget */
8 -if ( $post !== null ) {
9 - // Check if post is password protected and user hasn't provided correct password
10 - if ( post_password_required( $post->ID ) ) {
11 - // Don't show ToC for password-protected posts until password is provided
12 - return;
13 - }
2 + /** @var \WPDeveloper\BetterDocs\Shortcodes\ToC $widget */
3 + $toc_data = $widget->format_toc_data( $post->post_content, $htags, $hierarchy );
14 4
15 - // Process content for special characters without triggering heavy content filters
16 - // This prevents memory issues from plugins like WPML while still handling special characters
17 - $processed_content = $widget->process_content_for_toc( $post->post_content );
18 - $toc_data = $widget->format_toc_data( $processed_content, $htags, $hierarchy );
19 - if ( empty( $toc_data->items ) ) {
20 - return;
21 - }
22 -} else {
23 - return;
24 -}
5 + if ( empty( $toc_data->items ) ) {
6 + return;
7 + }
25 8
9 + $collapsible_arrow = '';
10 + $wrapper_classes = ['betterdocs-toc'];
26 11
27 - $collapsible_arrow = '';
28 - $wrapper_classes = [ 'betterdocs-toc' ];
12 + if ( empty( $toc_title ) ) {
13 + $toc_title = betterdocs()->settings->get( 'toc_title', __( 'Table of Contents', 'betterdocs' ) );
14 + $toc_title = stripslashes( $toc_title );
15 + }
29 16
30 -if ( empty( $toc_title ) ) {
31 - $toc_title = betterdocs()->settings->get( 'toc_title', __( 'Table of Contents', 'betterdocs' ) );
32 - $toc_title = esc_html( stripslashes( $toc_title ) );
33 -}
17 + if ( $collapsible_on_mobile == '1' ) {
18 + $wrapper_classes[] = 'collapsible-sm';
19 + $collapsible_arrow = "<svg class='angle-icon angle-up' aria-hidden='true' focusable='false' data-prefix='fas' data-icon='angle-up' class='svg-inline--fa fa-angle-up fa-w-10' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'><path fill='currentColor' d='M177 159.7l136 136c9.4 9.4 9.4 24.6 0 33.9l-22.6 22.6c-9.4 9.4-24.6 9.4-33.9 0L160 255.9l-96.4 96.4c-9.4 9.4-24.6 9.4-33.9 0L7 329.7c-9.4-9.4-9.4-24.6 0-33.9l136-136c9.4-9.5 24.6-9.5 34-.1z'></path></svg><svg class='angle-icon angle-down' aria-hidden='true' focusable='false' data-prefix='fas' data-icon='angle-down' class='svg-inline--fa fa-angle-down fa-w-10' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'><path fill='currentColor' d='M143 352.3L7 216.3c-9.4-9.4-9.4-24.6 0-33.9l22.6-22.6c9.4-9.4 24.6-9.4 33.9 0l96.4 96.4 96.4-96.4c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9l-136 136c-9.2 9.4-24.4 9.4-33.8 0z'></path></svg>";
20 + }
34 21
35 -if ( $collapsible_on_mobile == '1' ) {
36 - $wrapper_classes[] = 'collapsible-sm';
37 - $collapsible_arrow = "<svg class='angle-icon angle-up' aria-hidden='true' focusable='false' data-prefix='fas' data-icon='angle-up' class='svg-inline--fa fa-angle-up fa-w-10' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'><path fill='currentColor' d='M177 159.7l136 136c9.4 9.4 9.4 24.6 0 33.9l-22.6 22.6c-9.4 9.4-24.6 9.4-33.9 0L160 255.9l-96.4 96.4c-9.4 9.4-24.6 9.4-33.9 0L7 329.7c-9.4-9.4-9.4-24.6 0-33.9l136-136c9.4-9.5 24.6-9.5 34-.1z'></path></svg><svg class='angle-icon angle-down' aria-hidden='true' focusable='false' data-prefix='fas' data-icon='angle-down' class='svg-inline--fa fa-angle-down fa-w-10' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'><path fill='currentColor' d='M143 352.3L7 216.3c-9.4-9.4-9.4-24.6 0-33.9l22.6-22.6c9.4-9.4 24.6-9.4 33.9 0l96.4 96.4 96.4-96.4c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9l-136 136c-9.2 9.4-24.4 9.4-33.8 0z'></path></svg>";
38 -}
39 -
40 -if ( $list_number == '1' ) {
41 - $wrapper_classes[] = 'toc-list-number';
42 -}
22 + if ( $list_number == '1' ) {
23 + $wrapper_classes[] = 'toc-list-number';
24 + }
43 25 ?>
44 26
45 -<div class="<?php echo esc_attr( implode( ' ', $wrapper_classes ) ); ?>">
46 - <span class="toc-title">
47 - <?php echo $toc_title . $collapsible_arrow; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Title Is Escaped Above & Svg's Cannot Be Escaped ?>
48 - </span>
27 +<div class="<?php echo esc_attr( implode( ' ', $wrapper_classes ) );?>">
28 + <span class="toc-title">
29 + <?php echo $toc_title . $collapsible_arrow; ?>
30 + </span>
49 31
50 - <?php echo $toc_data->print( $toc_data->items, $hierarchy, 1 ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already Escaped Above, Svg Is Not Needed For Escaping ?>
32 + <?php echo $toc_data->print( $toc_data->items, $hierarchy, 1 ); ?>
51 33 </div>