$this->widget_cssclass, 'description' => $this->widget_description, 'customize_selective_refresh' => true, ); $this->attrs = apply_filters( 'bloglex_widget_base_attr_arr', array( 'type' => 'text', 'class' => '', 'wrapper_class' => '', 'label' => '', 'css' => '', 'std' => '', 'min' => 1, 'max' => 10, 'step' => 1, 'rows' => 4, 'placeholder' => '', 'options' => '', 'desc' => '', 'separator' => false, 'readonly' => false, 'args' => array(), ) ); parent::__construct( $this->widget_id, $this->widget_name, $widget_ops ); /* Load Required Styles and scripts */ add_action( 'admin_enqueue_scripts', array( $this, 'bloglex_widget_scripts' ) ); } /** * Output the html at the start of a widget. * * @param array $args * @param array $instance */ public function widget_start( $args, $instance ) { echo $args['before_widget']; if ( $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ) ) { echo $args['before_title'] . $title . $args['after_title']; } } /** * Output the html at the end of a widget. * * @param array $args */ public function widget_end( $args ) { echo $args['after_widget']; } /** * Updates a particular instance of a widget. * * @see WP_Widget->update * @param array $new_instance * @param array $old_instance * @return array */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; if ( empty( $this->settings ) ) { return $instance; } // Loop settings and get values to save. foreach ( $this->settings as $key => $setting ) { if ( ! isset( $setting['type'] ) ) { continue; } switch ( $setting['type'] ) { case 'text': $instance[ $key ] = sanitize_text_field( $new_instance[ $key ] ); break; case 'url': $instance[ $key ] = esc_url_raw( $new_instance[ $key ] ); break; case 'email': $instance[ $key ] = sanitize_email( $new_instance[ $key ] ); break; case 'number': $instance[ $key ] = absint( $new_instance[ $key ] ); if ( isset( $setting['min'] ) && '' !== $setting['min'] ) { $instance[ $key ] = max( $instance[ $key ], $setting['min'] ); } if ( isset( $setting['max'] ) && '' !== $setting['max'] ) { $instance[ $key ] = min( $instance[ $key ], $setting['max'] ); } break; case 'checkbox': $instance[ $key ] = empty( $new_instance[ $key ] ) ? 0 : 1; break; case 'select': case 'radio': $input = $new_instance[ $key ]; $choices = $setting['options']; $instance[ $key ] = array_key_exists( $input, $choices ) ? $input : $setting['std']; break; case 'textarea': $instance[ $key ] = wp_kses( trim( wp_unslash( $new_instance[ $key ] ) ), wp_kses_allowed_html( 'post' ) ); break; case 'color': $instance[ $key ] = sanitize_hex_color( $new_instance[ $key ] ); break; case 'image': $instance[ $key ] = absint( $new_instance[ $key ] ); break; case 'dropdown-pages': $page_id = absint( $new_instance[ $key ] ); $instance[ $key ] = ( 'page' === get_post_type( $page_id ) && 'publish' === get_post_status( $page_id ) ) ? $page_id : $setting['std']; break; case 'dropdown-taxonomies': $instance[ $key ] = ( -1 === $new_instance[ $key ] ) ? -1 : absint( $new_instance[ $key ] ); break; case 'multi-select': $output = array(); $input = $new_instance[ $key ]; $choices = $setting['options']; foreach ( $input as $v ) { if ( array_key_exists( $v, $choices ) ) { $output[] = $v; } } $instance[ $key ] = $output; break; case 'multi-checkbox': $output = array(); $input = $new_instance[ $key ]; $choices = $setting['options']; foreach ( $input as $v ) { if ( array_key_exists( $v, $choices ) ) { $output[] = $v; } } $instance[ $key ] = $output; break; default: $instance[ $key ] = sanitize_text_field( $new_instance[ $key ] ); break; } /** * Sanitize the value of a setting. */ $instance[ $key ] = apply_filters( 'bloglex_widget_settings_sanitize', $instance[ $key ], $new_instance, $key, $setting ); } return $instance; } /** * Output the Back-end widget form. * * @param array $instance Current settings. * * @return void */ public function form( $instance ) { if ( empty( $this->settings ) ) { return; } foreach ( $this->settings as $key => $setting ) { $attr = array_merge( $this->attrs, $setting ); $value = isset( $instance[ $key ] ) ? $instance[ $key ] : $attr['std']; $desc = $separator = ''; if ( $attr['desc'] ) { $desc = '' . wp_kses_post( $attr['desc'] ) . ''; } if ( $attr['separator'] ) { $separator = '
'; } switch ( $setting['type'] ) { case 'text': case 'url': case 'email': ?>

/>

/>


/>


get_field_name( $key ) ); $args['id'] = esc_attr( $this->get_field_id( $key ) ); ?>

'widefat ' . esc_attr( $attr['class'] ), 'show_option_none' => ' ', 'option_none_value' => '', 'selected' => absint( $value ), 'name' => esc_attr( $this->get_field_name( $key ) ), 'id' => esc_attr( $this->get_field_id( $key ) ), 'sort_column' => 'menu_order, post_title', 'post_status' => array( 'publish' ), 'posts_per_page' => -1, 'depth' => 1, 'value_field' => 'ID', 'dropdown_wrapper' => false, 'show_add_new_page' => false, 'link_before' => false, 'link_after' => false, 'echo' => true, 'show_option_none' => ' ', 'option_none_value' => '', 'depth' => 0, 'show_options' => true, ) ); ?>