$end_level ) { $tmp = $start_level; $start_level = $end_level; $end_level = $tmp; } $toc_data = wp_json_encode( array( 'startLevel' => $start_level, 'endLevel' => $end_level, 'contentSelector' => (string) $content_selector, 'excludeSelector' => (string) $exclude_selector, 'minHeadings' => max( 1, $min_headings ), 'collapsible' => 'on' === $collapsible, 'initiallyCollapsed' => 'on' === $initially_collapsed, 'collapsibleSubHeadings' => 'on' === $collapsible_subs, 'subHeadingsCollapsed' => 'on' === $subs_collapsed, 'smoothScroll' => 'on' === $smooth_scroll, 'scrollOffset' => $scroll_offset, 'highlightActive' => 'on' === $highlight_active, 'enableViewMore' => 'on' === $enable_view_more, 'viewMoreCount' => max( 1, $view_more_count ), 'viewMoreText' => (string) $view_more_text, 'viewLessText' => (string) $view_less_text, 'sticky' => 'on' === $sticky, 'stickyOffset' => $sticky_offset, 'stickyMaxHeight' => $sticky_max_height, 'hideOnMobile' => 'on' === $hide_on_mobile, ) ); // AMP / no-JS fallback: a slot that add_heading_ids() fills with the list // once the page HTML exists (AMP strips custom JS). Not with a content or // exclude selector: PHP cannot evaluate CSS selectors, so a server list // would ignore them; the front end builds that list instead. $server_list = ( '' === trim( (string) $content_selector ) && '' === trim( (string) $exclude_selector ) ) ? HeadingIndex::slot( $start_level, $end_level, $min_headings ) : ''; // Module wrapper classes. $preset_slug = preg_replace( '/[^a-z0-9_-]/', '', (string) $style_preset ); $wrapper_classes = array( 'dtq-module', 'dtq-toc', 'dtq-toc-style-' . ( $preset_slug ?: 'default' ) ); if ( 'on' === $sticky ) { $wrapper_classes[] = 'dtq-toc-sticky'; } if ( 'on' === $collapsible && 'on' === $initially_collapsed ) { $wrapper_classes[] = 'dtq-toc-collapsed'; } if ( 'on' === $hide_on_mobile ) { $wrapper_classes[] = 'dtq-toc-hide-mobile'; } if ( 'on' === $collapsible_subs ) { $wrapper_classes[] = 'dtq-toc-collapse-subs'; } $icon_slug = preg_replace( '/[^a-z]/', '', (string) $collapse_icon ); $wrapper_classes[] = 'dtq-toc-icon-' . ( $icon_slug ?: 'chevron' ); // Header. $header_html = ''; if ( 'on' === $show_title || 'on' === $collapsible ) { $title_html = 'on' === $show_title ? sprintf( '%s', esc_html( $title ) ) : ''; $toggle_html = 'on' === $collapsible ? '' : ''; $header_html = sprintf( '