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 -48 4.4.13.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,49 +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 - return apply_filters( 'the_content', $content );
65 - }
66 -
67 - // Apply only essential content processing filters that handle special characters
68 - // without triggering heavy processing from plugins like WPML, page builders, etc.
69 -
70 - // Handle shortcodes first (but don't execute them, just remove them to avoid conflicts)
71 - $content = strip_shortcodes( $content );
72 -
73 - // Decode HTML entities to handle special characters properly
74 - $content = html_entity_decode( $content, ENT_QUOTES, 'UTF-8' );
75 -
76 - // Convert line breaks to proper HTML if needed
77 - $content = wpautop( $content );
78 -
79 - // Apply specific filters that are safe and necessary for TOC generation
80 - // These are lightweight filters that handle character encoding and basic formatting
81 - $content = apply_filters( 'betterdocs_toc_content_processing', $content );
82 -
83 - // Additional safety: limit content size to prevent memory issues
84 - $max_content_length = apply_filters( 'betterdocs_toc_max_content_length', 500000 ); // 500KB default
85 - if ( strlen( $content ) > $max_content_length ) {
86 - $content = substr( $content, 0, $max_content_length );
87 - }
88 -
89 - return $content;
90 - }
91 -
92 - /**
93 46 * This method is responsible for re-arranging the TOC data based on hierarchy or non-hierarchy
94 47 *
95 48 * @param string $post_content
96 49 * @param string $htag_support
@@ -144,9 +97,9 @@
144 97 $heading_name = preg_replace( '/<[^<]+?>/', '', $current_title );
145 98 $heading_name = ! empty( $heading_name ) ? strtolower( str_replace( ' ', '-', preg_replace( '/[^\p{L}\p{N}\s]/u', '', $heading_name ) ) ) : '';
146 99 preg_match( '/id="(.+?)"/', $current_title, $matches_id );
147 100 $heading_id = isset( $matches_id[1] ) ? strtolower( $matches_id[1] ) : '';
148 - $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' );
149 102
150 103 $new_data = new Node();
151 104 $new_data->key = $current_tag_number;
152 105 $new_data->tag = $current_tag;