'toc_widget', 'description' => __( 'Display the table of contents in the sidebar with this widget', 'table-of-contents-plus' ), ]; $control_options = [ 'width' => 250, 'height' => 350, 'id_base' => 'toc-widget', ]; parent::__construct( 'toc-widget', 'TOC+', $widget_options, $control_options ); } /** * Widget output to the public */ public function widget( $args, $instance ) { global $toc_plus, $wp_query; if ( is_null( $wp_query->post ) ) { return; } $html = ''; $items = ''; $custom_toc_position = ''; $find = []; $replace = []; $toc_options = $toc_plus->get_options(); $post = get_post( $wp_query->post->ID ); $custom_toc_position = strpos( $post->post_content, '[toc]' ); // at this point, shortcodes haven't run yet so we can't search for if ( $toc_plus->is_eligible( $custom_toc_position ) ) { $items = $toc_plus->extract_headings( $find, $replace, wptexturize( do_shortcode( $post->post_content ) ) ); $title = ( array_key_exists( 'title', $instance ) ) ? apply_filters( 'widget_title', $instance['title'] ) : ''; if ( false !== strpos( $title, '%PAGE_TITLE%' ) ) { $title = str_replace( '%PAGE_TITLE%', get_the_title(), $title ); } if ( false !== strpos( $title, '%PAGE_NAME%' ) ) { $title = str_replace( '%PAGE_NAME%', get_the_title(), $title ); } $hide_inline = $toc_options['show_toc_in_widget_only']; $css_classes = ''; // bullets? if ( $toc_options['bullet_spacing'] ) { $css_classes .= ' have_bullets'; } else { $css_classes .= ' no_bullets'; } if ( $items ) { // before widget (defined by themes) $html .= $args['before_widget']; // display the widget title if one was input (before and after titles defined by themes) if ( $title ) { $html .= $args['before_title'] . $title . $args['after_title']; } // display the list $html .= '
'; // after widget (defined by themes) $html .= $args['after_widget']; echo wp_kses_post( $html ); } } } /** * Update the widget settings */ public function update( $new_instance, $old_instance ) { global $toc_plus; $instance = $old_instance; // strip tags for title to remove HTML (important for text inputs) $instance['title'] = wp_strip_all_tags( trim( $new_instance['title'] ) ); // no need to strip tags for the following //$instance['hide_inline'] = $new_instance['hide_inline']; $toc_plus->set_show_toc_in_widget_only( $new_instance['hide_inline'] ); $toc_plus->set_show_toc_in_widget_only_post_types( (array) $new_instance['show_toc_in_widget_only_post_types'] ); return $instance; } /** * Displays the widget settings on the widget panel. */ public function form( $instance ) { global $toc_plus; $toc_options = $toc_plus->get_options(); $defaults = [ 'title' => $toc_options['heading_text'] ]; $instance = wp_parse_args( (array) $instance, $defaults ); ?>
id="get_field_id( 'hide_inline' ) ); ?>" name="get_field_name( 'hide_inline' ) ); ?>" value="1">