$this->widget_cssclass, 'description' => $this->widget_description, 'customize_selective_refresh' => true, ); $this->attrs = apply_filters( 'applica_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 Require Styles and scripts*/ add_action( 'admin_enqueue_scripts', array( $this, 'applica_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 $k => $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 $k => $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( 'applica_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 = '' . esc_html( $attr['desc'] ) . ''; } if ( $attr['separator'] ) { $separator = '
/>
/>
/>
$v ) : ?>
/>