'', 'text' => '', 'fields' => array(), 'send_to' => '', 'msg_height' => 6, 'button_size' => 'm', 'button_title' => '' ); public static $fields_list = array(); /* Widget setup */ function __construct() { /* Widget settings. */ $widget_ops = array( 'description' => _x( 'Contact form', 'widget', 'the7mk2' ) ); /* Create the widget. */ parent::__construct( 'presscore-contact-form-widget', DT_WIDGET_PREFIX . _x( 'Contact form', 'widget', 'the7mk2' ), $widget_ops ); // fill fields list self::$fields_list = array( 'name' => array( 'title' => __( 'Name', 'the7mk2' ), 'defaults' => array( 'on' => true, 'required' => true ) ), 'email' => array( 'title' => __( 'E-mail', 'the7mk2' ), 'defaults' => array( 'on' => true, 'required' => true ) ), 'telephone' => array( 'title' => __( 'Telephone', 'the7mk2' ), 'defaults' => array( 'on' => false, 'required' => false ) ), 'country' => array( 'title' => __( 'Country', 'the7mk2' ), 'defaults' => array( 'on' => false, 'required' => false ) ), 'city' => array( 'title' => __( 'City', 'the7mk2' ), 'defaults' => array( 'on' => false, 'required' => false ) ), 'company' => array( 'title' => __( 'Company', 'the7mk2' ), 'defaults' => array( 'on' => false, 'required' => false ) ), 'website' => array( 'title' => __( 'Website', 'the7mk2' ), 'defaults' => array( 'on' => false, 'required' => false ) ), 'message' => array( 'title' => __( 'Message', 'the7mk2' ), 'defaults' => array( 'on' => true, 'required' => false ) ), ); // if ( !is_admin() ) { // add_action('init', array(&$this, 'presscore_enqueue_styles')); // } add_filter('dt_core_send_mail-to', array(&$this, 'presscore_send_to_filter'), 20); } /* Display the widget */ function widget( $args, $instance ) { // enqueue script in footer $this->presscore_enqueue_scripts(); static $number = 0; $number++; extract( $args ); $instance = wp_parse_args( (array) $instance, self::$widget_defaults ); /* Our variables from the widget settings. */ $title = apply_filters( 'widget_title', $instance['title'] ); $text = $instance['text']; $send_to = $instance['send_to']; $fields = $instance['fields']; $fields_not_empty = in_array(true, wp_list_pluck($fields, 'on') ); $msg_height = $instance['msg_height']; $class_adapter = array( 'email' => 'mail' ); echo $before_widget ; // title if ( $title ) echo $before_title . $title . $after_title; // content if ( $text ) echo '
'; // fields if ( $fields_not_empty ) { // form begin echo '' . "\n"; } echo $after_widget; } /* Update the widget settings */ function update( $new_instance, $old_instance ) { $instance = wp_parse_args( $old_instance, self::$widget_defaults ); $instance['title'] = strip_tags($new_instance['title']); $instance['text'] = $new_instance['text']; $instance['send_to'] = $new_instance['send_to']; $instance['fields'] = self::presscore_sanitize_fields($new_instance['fields']); $instance['msg_height'] = absint( $new_instance['msg_height'] ); $instance['button_size'] = in_array( $instance['button_size'], array( 's', 'm', 'l' ) ) ? $instance['button_size'] : self::$widget_defaults['button_size']; $instance['button_title'] = esc_html( $instance['button_title'] ); return $instance; } /** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function form( $instance ) { /* Set up some default widget settings. */ $instance = wp_parse_args( (array) $instance, self::$widget_defaults ); $fields = empty( $instance['fields'] ) ? array() : $instance['fields']; ?>
id == $_POST['widget_id'] ) { $option = get_option($this->option_name); if ( isset($option[ $this->number ]) && !empty($option[ $this->number ]['send_to']) ) { $em = $option[ $this->number ]['send_to']; } } return $em; } public static function presscore_sanitize_fields( $fields = array() ) { // clear fields $fields = array_intersect_key($fields, self::$fields_list); // sanitize data foreach ( $fields as &$field ) { $field['on'] = (bool) absint($field['on']); $field['required'] = isset( $field['required'] ); } return $fields; } public static function presscore_register_widget() { register_widget( get_class() ); } }