芝麻web文件管理V1.00
编辑当前文件:/www/wwwroot/fashionmodelquicktrack.com/wp-content/plugins/fixed-toc/admin/widget/class-widget.php
$classname, 'description' => esc_html__( 'Display a Fixed TOC to the current page content.', 'fixedtoc' ), ) // Args ); // Register sections add_action( 'admin_init', array( $this, 'register_sections' ) ); // Scripts add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); } /** * Front-end display of widget. * * @since 3.0.0. * @access public * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from a database. */ public function widget( $args, $instance ) { if ( 1 <= self::$index ) { return; } if ( ! fixedtoc_is_true( 'toc_page' ) || ! fixedtoc_is_true( 'in_widget' ) ) { return; } $GLOBALS['FIXEDTOC_WIDGET_VALS'] = $instance; $contents = apply_filters( 'fixedtoc_widget_content', '' ); if ( empty( $contents ) ) { return; } do_action( 'fixedtoc_before_widget' ); echo $args['before_widget']; echo '
' . $contents . '
'; echo $args['after_widget']; do_action( 'fixedtoc_after_widget' ); self::$index ++; } /** * Back-end widget form. * * @since 3.0.0. * @access public * @see WP_Widget::form() * * @param array $instance Previously saved values from a database. */ public function form( $instance ) { printf( '
%s
', esc_html__( 'Make sure you have added only one the Fixed TOC widget at the same page.', 'fixedtoc' ) ); require_once plugin_dir_path( dirname( __FILE__ ) ) . 'fields/class-fields-factory.php'; // do_settings_sections($this->fixedtoc_widget_sections_slug); $this->do_settings_sections( $instance ); } /** * Prints out all settings sections. * * @since 3.0.0 * @access private * * @param array $instance Previously saved values from a database. * * @return void */ private function do_settings_sections( $instance ) { global $wp_settings_sections, $wp_settings_fields; $page = $this->fixedtoc_widget_sections_slug; if ( ! isset( $wp_settings_sections[ $page ] ) ) { return; } echo '
'; foreach ( (array) $wp_settings_sections[ $page ] as $section ) { if ( $section['title'] ) { echo "
{$section['title']}
\n"; } if ( $section['callback'] ) { call_user_func( $section['callback'], $section ); } if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section['id'] ] ) ) { continue; } $this->do_settings_fields( $page, $section['id'], $instance ); } echo '
'; } /** * Print out the settings fields for a particular settings section. * * @since 3.0.0 * @access private * * @param string $page . Slug the title of the admin page whose settings fields you want to show. * @param string $section . Slug title of the settings section whose fields you want to show. * @param array $instance Previously saved values from a database. * * @return void * @noinspection PhpUnusedLocalVariableInspection */ private function do_settings_fields( $page, $section, $instance ) { global $wp_settings_fields; if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) { return; } foreach ( (array) $wp_settings_fields[ $page ][ $section ] as $field ) { $data_name = isset( $field['args']['data_name'] ) ? $field['args']['data_name'] : ''; $name = $this->get_field_name( $data_name ); $id = $this->get_field_id( $data_name ); $field['args']['name'] = $this->get_field_name( $data_name ); $field['args']['input_attrs']['id'] = $id; $field['args']['label_for'] = $id; $field['args']['value'] = isset( $instance[ $data_name ] ) ? $instance[ $data_name ] : fixedtoc_get_option( $data_name ); echo '
'; if ( empty( $field['args']['label'] ) ) { echo ''; } elseif ( ! empty( $field['args']['label_for'] ) ) { echo '
' . $field['title'] . '
'; } else { echo '
' . $field['title'] . '
'; } call_user_func( $field['callback'], $field['args'] ); echo '
'; } } /** * Sanitize widget form values as they are saved. * * @since 3.0.0. * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from a database. * * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { return Fixedtoc_Admin_Control::sanitize( $new_instance ); } /** * register sections. * * @since 3.0.0 * @access public * * @return void */ public function register_sections() { require_once 'class-widget-sections.php'; new Fixedtoc_Widget_Sections( $this ); } /** * Add section. * * @since 3.0.0 * @access public * * @param string $id * @param string $title * @param string $callback * * @return string */ public function add_section( $id, $title, $callback ) { add_settings_section( $id, $title, $callback, $this->fixedtoc_widget_sections_slug ); return $id; } /** * Add section. * * @since 3.0.0 * @access public * * @param string $section_id * @param string $field_name * * @return void */ public function add_field( $section_id, $field_name ) { $name = fixedtoc_get_field_data( $field_name, 'name' ); $title = fixedtoc_get_field_data( $field_name, 'label' ); $args = fixedtoc_get_field_data( $field_name ); $args['input_attrs'] = isset( $args['input_attrs'] ) ? $args['input_attrs'] : array(); $args['input_attrs'] = isset( $args['widget_input_attrs'] ) ? $args['widget_input_attrs'] : $args['input_attrs']; $args['des'] = isset( $args['widget_des'] ) ? $args['widget_des'] : ''; $args['data_name'] = $name; add_settings_field( $name, $title, array( $this, 'render_field' ), $this->fixedtoc_widget_sections_slug, $section_id, $args ); } /** * Render field. * * @since 3.0.0 * @access public * * @param array $args */ public function render_field( $args ) { if ( ! $args ) { echo ''; } $html = isset( $args['prefix'] ) && $args['prefix'] ? $args['prefix'] . ' ' : ''; $field_obj = new Fixedtoc_Fields_Factory( $args ); $html .= $field_obj->get_html(); $html .= isset( $args['suffix'] ) && $args['suffix'] ? ' ' . $args['suffix'] . '
' : '
'; $html .= isset( $args['des'] ) && $args['des'] ? '
' . $args['des'] . '
' : ''; echo $html; } /** * Enqueue scripts. * * @since 3.0.0 * @access public * * @param string $hook * * @return void */ public function enqueue_scripts( $hook ) { if ( 'widgets.php' != $hook ) { return; } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'wp-color-picker' ); wp_enqueue_style( 'fixedtoc_widget_style', plugins_url( 'widget-style.css', __FILE__ ) ); wp_enqueue_script( 'underscore' ); wp_enqueue_script( 'fixedtoc_widget_script', plugins_url( 'widget-script.js', __FILE__ ), array( 'jquery' ), '', true ); } }