PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.9
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.9
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 | includes/Shortcodes/ToC.php +1 -49 4.9.23.8.9 View file →
@@ -32,14 +32,8 @@
32 32 ];
33 33 }
34 34
35 35 public function render( $atts, $content = null ) {
36 - // Check if post is password protected and user hasn't provided correct password
37 - if ( post_password_required( $this->attributes['post_id'] ) ) {
38 - // Don't show ToC for password-protected posts until password is provided
39 - return '';
40 - }
41 -
42 36 $this->views( 'shortcodes/toc' );
43 37 }
44 38
45 39 public function view_params() {
@@ -48,50 +42,8 @@
48 42 ];
49 43 }
50 44
51 45 /**
52 - * Process content for TOC generation without triggering heavy content filters
53 - * This handles special characters while avoiding memory issues from plugins like WPML
54 - *
55 - * @param string $content Raw post content
56 - * @return string Processed content
57 - */
58 - public function process_content_for_toc( $content ) {
59 - // Check if we should use the full content filter (for backward compatibility)
60 - $use_full_filter = apply_filters( 'betterdocs_toc_use_full_content_filter', false );
61 -
62 - if ( $use_full_filter ) {
63 - // Use the full content filter if explicitly enabled
64 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- intentional WP core filter integration to render content as the platform would.
65 - return apply_filters( 'the_content', $content );
66 - }
67 -
68 - // Apply only essential content processing filters that handle special characters
69 - // without triggering heavy processing from plugins like WPML, page builders, etc.
70 -
71 - // Handle shortcodes first (but don't execute them, just remove them to avoid conflicts)
72 - $content = strip_shortcodes( $content );
73 -
74 - // Decode HTML entities to handle special characters properly
75 - $content = html_entity_decode( $content, ENT_QUOTES, 'UTF-8' );
76 -
77 - // Convert line breaks to proper HTML if needed
78 - $content = wpautop( $content );
79 -
80 - // Apply specific filters that are safe and necessary for TOC generation
81 - // These are lightweight filters that handle character encoding and basic formatting
82 - $content = apply_filters( 'betterdocs_toc_content_processing', $content );
83 -
84 - // Additional safety: limit content size to prevent memory issues
85 - $max_content_length = apply_filters( 'betterdocs_toc_max_content_length', 500000 ); // 500KB default
86 - if ( strlen( $content ) > $max_content_length ) {
87 - $content = substr( $content, 0, $max_content_length );
88 - }
89 -
90 - return $content;
91 - }
92 -
93 - /**
94 46 * This method is responsible for re-arranging the TOC data based on hierarchy or non-hierarchy
95 47 *
96 48 * @param string $post_content
97 49 * @param string $htag_support
@@ -145,9 +97,9 @@
145 97 $heading_name = preg_replace( '/<[^<]+?>/', '', $current_title );
146 98 $heading_name = ! empty( $heading_name ) ? strtolower( str_replace( ' ', '-', preg_replace( '/[^\p{L}\p{N}\s]/u', '', $heading_name ) ) ) : '';
147 99 preg_match( '/id="(.+?)"/', $current_title, $matches_id );
148 100 $heading_id = isset( $matches_id[1] ) ? strtolower( $matches_id[1] ) : '';
149 - $tag_number = ! empty( $heading_id ) ? $heading_id : ( ! empty( $heading_name ) && $dynamic_toc_title_switch ? $heading_name : $tag_counter . '-toc-title' );
101 + $tag_number = ! empty( $heading_id ) ? $heading_id : ( ! empty( $heading_name ) && $this->settings->get( 'toc_dynamic_title' ) ? $heading_name : $tag_counter . '-toc-title' );
150 102
151 103 $new_data = new Node();
152 104 $new_data->key = $current_tag_number;
153 105 $new_data->tag = $current_tag;