ajayver

Untitled

Aug 25th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.70 KB | None | 0 0
  1. add_action( 'after_setup_theme', 'child_theme_setup', 20 );
  2.  
  3. function child_theme_setup() {
  4.     remove_shortcode( 'contacts_form' );
  5.     add_shortcode( 'contacts_form', 'my_contacts_form' );
  6.    
  7. }
  8.  
  9.    
  10. /* i have added a menu option for <select> element to contact form */
  11. function my_contacts_form($attributes, $content = null) {
  12.     global $smof_data;
  13.     $attributes = shortcode_atts(
  14.         array(
  15.         ), $attributes);
  16.  
  17.  
  18.  
  19.     $output =   '<div class="w-form contacts_form">
  20.                     <div class="w-form-h">
  21.  
  22.                         <form class="g-form" action="#" method="post" id="contact_form">
  23.                             <div class="g-form-group">
  24.                                 <div class="g-form-group-rows">';
  25.     if (in_array(@$smof_data['contact_form_name_field'], array('Shown, required', 'Shown, not required')))
  26.     {
  27.         $name_required = (@$smof_data['contact_form_name_field'] == 'Shown, required')?1:0;
  28.         $output .=                  '<div class="g-form-row" id="name_row">
  29.                                         <div class="g-form-row-label">
  30.                                             <label class="g-form-row-label-h">'.__('Your name', 'us').'</label>
  31.                                         </div>
  32.                                         <div class="g-form-row-field">
  33.                                             <i class="fa fa-user"></i>
  34.                                             <input type="text" name="name" data-required="'.$name_required.'">
  35.                                         </div>
  36.                                         <div class="g-form-row-state" id="name_state"></div>
  37.                                     </div>';
  38.     }
  39.  
  40.     if (in_array(@$smof_data['contact_form_name_field'], array('Shown, required', 'Shown, not required')))
  41.     {
  42.         $name_required = (@$smof_data['contact_form_name_field'] == 'Shown, required')?1:0;
  43.         $output .=                  '<div class="g-form-row" id="name_row">
  44.                                         <div class="g-form-row-label">
  45.                                             <label class="g-form-row-label-h">'.__('Business Name', 'us').'</label>
  46.                                         </div>
  47.                                         <div class="g-form-row-field">
  48.                                             <i class="fa fa-user"></i>
  49.                                             <input type="text" name="name" data-required="'.$name_required.'">
  50.                                         </div>
  51.                                         <div class="g-form-row-state" id="name_state"></div>
  52.                                     </div>';
  53.     }
  54.  
  55.     if (in_array(@$smof_data['contact_form_email_field'], array('Shown, required', 'Shown, not required')))
  56.     {
  57.         $email_required = (@$smof_data['contact_form_email_field'] == 'Shown, required')?1:0;
  58.         $output .=                  '<div class="g-form-row" id="email_row">
  59.                                         <div class="g-form-row-label">
  60.                                             <label class="g-form-row-label-h">'.__('Email', 'us').'</label>
  61.                                         </div>
  62.                                         <div class="g-form-row-field">
  63.                                             <i class="fa fa-envelope"></i>
  64.                                                 <input type="email" name="email" data-required="'.$email_required.'">
  65.                                         </div>
  66.                                         <div class="g-form-row-state" id="email_state"></div>
  67.                                     </div>';
  68.     }
  69.  
  70.     if (in_array(@$smof_data['contact_form_phone_field'], array('Shown, required', 'Shown, not required')))
  71.     {
  72.         $phone_required = (@$smof_data['contact_form_phone_field'] == 'Shown, required')?1:0;
  73.         $output .=                  '<div class="g-form-row" id="phone_row">
  74.                                         <div class="g-form-row-label">
  75.                                             <label class="g-form-row-label-h">'.__('Phone Number', 'us').'</label>
  76.                                         </div>
  77.                                         <div class="g-form-row-field">
  78.                                             <i class="fa fa-phone"></i>
  79.                                             <input type="text" name="phone" data-required="'.$phone_required.'">
  80.                                         </div>
  81.                                         <div class="g-form-row-state" id="phone_state"></div>
  82.                                     </div>';
  83.     }
  84.  
  85.     $output .=                      '<div class="g-form-row" id="message_row">
  86.                                         <div class="g-form-row-label">
  87.                                             <label class="g-form-row-label-h">'.__('Number Of Emails Sent Per Month', 'us').'</label>
  88.                                         </div>
  89.                                         <div class="g-form-row-field">
  90.                                             <select>
  91.                                                 <option value="0-9999">Up to 9,999</option>
  92.                                                 <option value="10000-30000">10000-30000</option>
  93.                                                 <option value="30001+">30001+</option>
  94.                                             </select>
  95.                                         </div>
  96.                                         <div class="g-form-row-state" id="message_state"></div>
  97.                                     </div>
  98.                                     <div class="g-form-row">
  99.                                         <div class="g-form-row-label"></div>
  100.                                         <div class="g-form-row-field">
  101.                                             <button class="g-btn type_primary" id="message_send"><span>'.__('Send Message', 'us').'</span></button>
  102.                                         </div>
  103.                                     </div>
  104.                                 </div>
  105.                             </div>
  106.                         </form>
  107.                     </div>
  108.                 </div>';
  109.  
  110.     return $output;
  111. }
  112.  
  113.  
  114. class MY_Widget_Contact extends WP_Widget {
  115.  
  116.     function __construct()
  117.     {
  118.         $widget_ops = array('classname' => 'widget_contact', 'description' => 'Contact Information');
  119.         $control_ops = array();
  120.         $this->WP_Widget('contact', 'Contacts', $widget_ops, $control_ops);
  121.     }
  122.  
  123.     function form($instance)
  124.     {
  125.         $defaults = array('title' => 'Contacts', 'address' => '', 'phone' => '', 'email' => '', 'web' => '', );
  126.         $instance = wp_parse_args((array) $instance, $defaults);
  127. ?>
  128.  
  129.         <p>
  130.             <label for="<?php echo $this->get_field_id('title'); ?>"><?php echo 'Title' ?>:</label>
  131.             <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" /></p>
  132.         </p>
  133.  
  134.         <p>
  135.             <label for="<?php echo $this->get_field_id('address'); ?>"><?php echo 'Address' ?>:</label>
  136.             <textarea class="widefat" rows="5" cols="20" id="<?php echo $this->get_field_id('address'); ?>" name="<?php echo $this->get_field_name('address'); ?>"><?php echo esc_textarea($instance['address']); ?></textarea>
  137.         </p>
  138.  
  139.         <p>
  140.             <label for="<?php echo $this->get_field_id('phone'); ?>"><?php echo 'Phone(s)' ?>:</label>
  141.             <textarea class="widefat" rows="5" cols="20" id="<?php echo $this->get_field_id('phone'); ?>" name="<?php echo $this->get_field_name('phone'); ?>" style="height: 47px;"><?php echo esc_textarea($instance['phone']); ?></textarea>
  142.         </p>
  143.  
  144.             <label for="<?php echo $this->get_field_id('web'); ?>"><?php echo 'Web' ?>:</label>
  145.             <textarea class="widefat" rows="5" cols="20" id="<?php echo $this->get_field_id('web'); ?>" name="<?php echo $this->get_field_name('web'); ?>" style="height: 47px;"><?php echo esc_textarea($instance['web']); ?></textarea>
  146.         </p>
  147.  
  148.         <label for="<?php echo $this->get_field_id('email'); ?>"><?php echo 'Email' ?>:</label>
  149.         <input class="widefat" id="<?php echo $this->get_field_id('email'); ?>" name="<?php echo $this->get_field_name('email'); ?>" type="text" value="<?php echo esc_attr($instance['email']); ?>" />
  150.         </p>
  151.  
  152. <?php
  153.     }
  154.  
  155.     function widget($args, $instance)
  156.     {
  157.         $title = apply_filters('widget_title', empty($instance['title']) ? __('Contacts', 'us') : $instance['title'], $instance, $this->id_base);
  158.  
  159.         echo $args['before_widget'];
  160.         if ($title){
  161.             echo '<h5>'.$title.'</h5>';
  162.         }
  163.         ?><div class="w-contacts"><div class="w-contacts-h"><?php
  164.  
  165.         ?><div class="w-contacts-list"><?php
  166.         if ($instance['address']){
  167.             echo '<div class="w-contacts-item">
  168.                         <i class="fa fa-map-marker"></i>
  169.                         <span class="w-contacts-item-value">'.$instance['address'].'</span>
  170.                     </div>';
  171.         }
  172.         if ($instance['phone']){
  173.             echo '<div class="w-contacts-item">
  174.                         <i class="fa fa-phone"></i>
  175.                         <span class="w-contacts-item-value">'.$instance['phone'].'</span>
  176.                     </div>';
  177.         }
  178.         if ($instance['email']){
  179.             echo '<div class="w-contacts-item">
  180.                         <i class="fa fa-envelope-o"></i>
  181.                         <span class="w-contacts-item-value"><a href="mailto:'.$instance['email'].'">'.$instance['email'].'</a></span>
  182.                     </div>';
  183.         }
  184.         if ($instance['web']){
  185.             echo '<div class="w-contacts-item">
  186.                         <i class="fa fa-laptop"></i>
  187.                         <span class="w-contacts-item-value"><a href="http://'.$instance['web'].'">'.$instance['web'].'</a></span>
  188.                     </div>';
  189.         }
  190.         ?></div></div></div><?php
  191.         echo $args['after_widget'];
  192.     }
  193. }
  194.  
  195. add_action('widgets_init', 'my_register_contact_widget', 20);
  196.  
  197. function my_register_contact_widget()
  198. {
  199.     unregister_widget('US_Widget_Contact');
  200.     register_widget('MY_Widget_Contact');
  201. }
Advertisement
Add Comment
Please, Sign In to add comment