'ez-toc', 'description' => __( 'Display the table of contents.', 'easy-table-of-contents' ) ); parent::__construct( 'ezw_tco', __( 'Table of Contents', 'easy-table-of-contents' ), $options ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueueScripts' ) ); add_action( 'admin_footer-widgets.php', array( $this, 'printScripts' ), 9999 ); } /** * Callback which registers the widget with the Widget API. * * @access public * @since 1.0 * @static * * @return void */ public static function register() { register_widget( __CLASS__ ); } /** * Callback to enqueue scripts on the Widgets admin page. * * @access private * @since 1.0 * * @param string $hook_suffix */ public function enqueueScripts( $hook_suffix ) { if ( 'widgets.php' !== $hook_suffix ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_script( 'underscore' ); } /** * Callback to print the scripts to the Widgets admin page footer. * * @access private * @since 1.0 */ public function printScripts() { ?> hasTOCItems() ) { /** * @var string $before_widget * @var string $after_widget * @var string $before_title * @var string $after_title */ extract( $args ); $class = array( 'ez-toc-v' . str_replace( '.', '_', ezTOC::VERSION ), 'ez-toc-widget', ); $instance_title = ''; if(isset($instance['title'])){ $instance_title = $instance['title']; } $title = apply_filters( 'widget_title', $instance_title, $instance, $this->id_base ); if ( false !== strpos( $title, '%PAGE_TITLE%' ) || false !== strpos( $title, '%PAGE_NAME%' ) ) { $title = str_replace( '%PAGE_TITLE%', get_the_title(), $title ); } if ( ezTOC_Option::get( 'show_hierarchy' ) ) { $class[] = 'counter-hierarchy'; } else { $class[] = 'counter-flat'; } if( ezTOC_Option::get( 'heading-text-direction', 'ltr' ) == 'ltr' ) { $class[] = 'ez-toc-widget-container'; } if( ezTOC_Option::get( 'heading-text-direction', 'ltr' ) == 'rtl' ) { $class[] = 'ez-toc-widget-container-rtl'; } if ( isset($instance['affix']) ) { $class[] = 'ez-toc-affix'; } $class[] = 'ez-toc-widget-direction'; $custom_classes = ezTOC_Option::get( 'css_container_class', '' ); if ( 0 < strlen( $custom_classes ) ) { $custom_classes = explode( ' ', $custom_classes ); $custom_classes = apply_filters( 'ez_toc_container_class', $custom_classes, $this ); if ( is_array( $custom_classes ) ) { $class = array_merge( $class, $custom_classes ); } } $class = array_filter( $class ); $class = array_map( 'trim', $class ); $class = array_map( 'sanitize_html_class', $class ); echo $before_widget; do_action( 'ez_toc_before_widget_container'); echo '
' . PHP_EOL; do_action( 'ez_toc_before_widget' ); /** * @todo Instead of inline style, use the shadow DOM. * @link https://css-tricks.com/playing-shadow-dom/ * * @todo Consider not outputting the style if CSS is disabled. * @link https://wordpress.org/support/topic/inline-styling-triggers-html-validation-error/ */ $title_font_size = $instance[ 'sidebar_title_size' ].$instance[ 'sidebar_title_size_unit' ]; if ( 0 < strlen( $title ) ) { ?> ' . $title . ''; ?> Toggle Table of Content' . ezTOC::getTOCToggleIcon() . ''; } ?> ' . $header_label . '' . ezTOC::getTOCToggleIcon( 'widget-with-visibility_on_header_text' ) . ''; } else { echo $header_label; $htmlCSSIcon = ''; } echo $htmlCSSIcon; ?> style="display:none" /> '. PHP_EOL . $post->getTOCList() . '' . PHP_EOL; do_action( 'ez_toc_after' ); do_action( 'ez_toc_after_widget' ); echo '
' . PHP_EOL; do_action( 'ez_toc_after_widget_container' ); echo $after_widget; } } /** * Update the widget settings. * * @access private * @since 1.0 * * @param array $new_instance * @param array $old_instance * * @return array */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['affix'] = array_key_exists( 'affix', $new_instance ) ? $new_instance['affix'] : '0'; $instance['highlight_color'] = strip_tags( $new_instance['highlight_color'] ); if ( isset ( $new_instance[ 'eztoc_appearance' ] ) && $new_instance[ 'eztoc_appearance' ] == 'on' ){ $instance[ 'sidebar_title_size' ] = ( int ) strip_tags ( $new_instance[ 'sidebar_title_size' ] ); $instance[ 'sidebar_title_size_unit' ] = strip_tags ( $new_instance[ 'sidebar_title_size_unit' ] ); $instance[ 'sidebar_title_weight' ] = strip_tags ( $new_instance[ 'sidebar_title_weight' ] ); $instance[ 'sidebar_title_color' ] = strip_tags ( $new_instance[ 'sidebar_title_color' ] ); }else{ $instance[ 'sidebar_title_size' ] = 120; $instance[ 'sidebar_title_size_unit' ] = '%'; $instance[ 'sidebar_title_weight' ] = '500'; $instance[ 'sidebar_title_color' ] = '#000'; } $instance['hide_inline'] = array_key_exists( 'hide_inline', $new_instance ) ? $new_instance['hide_inline'] : '0'; return $instance; } /** * Displays the widget settings on the Widgets admin page. * * @access private * @since 1.0 * * @param array $instance * * @return string|void */ public function form( $instance ) { $defaults = array( 'affix' => '0', 'eztoc_appearance' => '', 'highlight_color' => '#ededed', 'title' => __('Table of Contents', 'easy-table-of-contents' ), 'sidebar_title_size' => 120, 'sidebar_title_size_unit' => '%', 'sidebar_title_weight' => '500', 'sidebar_title_color' => '#000', ); $instance = wp_parse_args( (array) $instance, $defaults ); $highlight_color = esc_attr( $instance[ 'highlight_color' ] ); $title_color = esc_attr( $instance[ 'sidebar_title_color' ] ); ?>

/>



id="get_field_id( 'affix' ); ?>" name="get_field_name( 'affix' ); ?>" value="1"/>