array( 'name' => esc_html__( 'Contact', 'mega' ), 'description' => esc_html__( 'Contact block', 'mega' )), 'universal' => true ); parent::__construct( __CLASS__, $args ); $this->buildContactForm( new Mega_Form_Manager( array( 'type' => 'mega', 'callback' => array( $this, 'setForm' )))); } public function settings( $form ) { $form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Title', 'mega' ), 'value' => esc_html__( 'Contact our team', 'mega' ), 'name' => 'title' )); $form->add_control( 'Mega_Control_Email', array( 'label' => esc_html__( 'Email', 'mega' ), 'value' => get_option( 'admin_email' ), 'name' => 'email' )); $form->add_control( 'Mega_Control_Textarea', array( 'label' => esc_html__( 'Text', 'mega' ), 'value' => esc_html__( 'Get in touch with our 24/7 support team regarding any issues you may have.', 'mega' ), 'name' => 'text', 'pro' => 1 )); $form->add_control( 'Mega_Control_Textarea', array( 'label' => esc_html__( 'Message', 'mega' ), 'desc' => esc_html__( 'Use the name attributes you have given to elements in your form to output the results inside your email, names must be surrounded with [], i.e [my-email-field]', 'mega' ), 'value' => str_replace( '\n', "\n", esc_html__( 'Name: [name]\nEmail: [email]\nSubject: [subject]\nMessage: [message]', 'mega' )), 'name' => 'message', 'pro' => 1 )); } public function getForm() { $this->buildContactForm( new Mega_Form_Manager( array( 'type' => 'echo', 'callback' => array( $this )))); } public function buildContactForm( $form ) { $form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Name', 'mega' ), 'show_label' => 0, 'name' => 'name', 'placeholder' => esc_html__( 'enter your name', 'mega' ), 'required' => 1, 'sanitize' => 'wp_filter_nohtml_kses' )); $form->add_control( 'Mega_Control_Email', array( 'label' => esc_html__( 'Email', 'mega' ), 'show_label' => 0, 'name' => 'email', 'placeholder' => esc_html__( 'enter your email', 'mega' ), 'required' => 1 )); $form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Subject', 'mega' ), 'show_label' => 0, 'name' => 'subject', 'placeholder' => esc_html__( 'enter your subject', 'mega' ), 'required' => 1, 'sanitize' => 'wp_filter_nohtml_kses' )); $form->add_control( 'Mega_Control_Textarea', array( 'label' => esc_html__( 'Message', 'mega' ), 'show_label' => 0, 'name' => 'message', 'placeholder' => esc_html__( 'enter your message', 'mega' ), 'required' => 1, 'sanitize' => 'wp_filter_nohtml_kses' )); $form->add_control( 'Mega_Control_Submit', array( 'value' => esc_html__( 'Submit', 'mega' ))); } public function ajax( $post ) { global $mega_mail; extract( $post ); $instance = $this->mega['settings']; $instance['message'] .= "\n\n\n" . sprintf( esc_html__( 'This email came from contact widget id %s', 'mega' ), $this->mega['args']['number'] ); if ( $mega_mail->do_mail( $instance['email'], $subject, mega_parse_message( $post, $instance['message'] ), $email, $name )) echo '
  • ' . esc_html__( 'Success! The administrator will contact you as soon as possible.', 'mega' ) . '
  • '; else echo '
  • ' . esc_html__( 'Ajax Error!', 'mega' ) . '
  • '; } }