| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | if ( ! defined( 'ABSPATH' ) ) { |
| 14: | exit; |
| 15: | } |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | class EPL_Widget_Contact_Capture extends WP_Widget { |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | public function __construct() { |
| 30: | parent::__construct( false, $name = __( 'EPL - Contact Form', 'easy-property-listings' ), array( 'description' => __( 'Add contact form to a sidebar.', 'easy-property-listings' ) ) ); |
| 31: | |
| 32: | } |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public function widget( $args, $instance ) { |
| 44: | |
| 45: | |
| 46: | |
| 47: | $defaults = epl_contact_capture_get_widget_defaults(); |
| 48: | |
| 49: | $instance = wp_parse_args( (array) $instance, $defaults ); |
| 50: | |
| 51: | foreach ( $args as $arg_key => $arg_val ) { |
| 52: | ${$arg_key} = $arg_val; |
| 53: | } |
| 54: | |
| 55: | $title = apply_filters( 'widget_title', $instance['title'] ); |
| 56: | |
| 57: | echo $before_widget; |
| 58: | if ( $title ) { |
| 59: | echo $before_title . esc_html( $title ) . $after_title; |
| 60: | } |
| 61: | echo epl_contact_capture_form( $instance ); |
| 62: | |
| 63: | echo $after_widget; |
| 64: | } |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | |
| 75: | public function update( $new_instance, $old_instance ) { |
| 76: | $instance = $old_instance; |
| 77: | $all_fields = epl_contact_capture_widget_form_fields(); |
| 78: | foreach ( $all_fields as $all_field ) { |
| 79: | |
| 80: | if ( isset( $new_instance[ $all_field['key'] ] ) ) { |
| 81: | $instance[ $all_field['key'] ] = epl_strip_tags( $new_instance[ $all_field['key'] ], apply_filters( 'epl_contact_form_description_allowed_tags', '<br><p><strong><div><span><hr><img>' ) ); |
| 82: | } else { |
| 83: | |
| 84: | $instance[ $all_field['key'] ] = ''; |
| 85: | |
| 86: | } |
| 87: | } |
| 88: | return $instance; |
| 89: | } |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | public function form( $instance ) { |
| 98: | $defaults = epl_contact_capture_get_widget_defaults(); |
| 99: | |
| 100: | $instance = wp_parse_args( (array) $instance, $defaults ); |
| 101: | $instance = array_map( 'epl_esc_attr', $instance ); |
| 102: | |
| 103: | foreach ( $instance as $in_key => $in_val ) { |
| 104: | |
| 105: | ${$in_key} = $in_val; |
| 106: | } |
| 107: | |
| 108: | $fields = epl_contact_capture_widget_form_fields(); |
| 109: | foreach ( $fields as $field ) { |
| 110: | $field_value = ${$field['key']}; |
| 111: | epl_widget_render_backend_field( $field, $this, $field_value ); |
| 112: | } |
| 113: | } |
| 114: | } |
| 115: | |
| 116: | |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | |
| 122: | |
| 123: | |
| 124: | function epl_register_widget_contact_form() { |
| 125: | register_widget( 'EPL_Widget_Contact_Capture' ); |
| 126: | } |
| 127: | add_action( 'widgets_init', 'epl_register_widget_contact_form' ); |
| 128: | |