Advertisement
rakeshr

callmeback-custom-widget

Nov 16th, 2012
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.12 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: Call me back widget
  4.  * Plugin URI: http://wpguru.in
  5.  * Description: Request call me back widget by WPGuru.in
  6.  * Version: 1.0
  7.  * Author: Rakesh Raja
  8.  * Author URI: http://wpguru.in
  9.  *
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  */
  14.  
  15. /**
  16.  * Add function to widgets_init that'll load our widget.
  17.  * @since 0.1
  18.  */
  19. add_action( 'widgets_init', 'wpg_callmeback' );
  20.  
  21. /**
  22.  * Register our widget.
  23.  * 'wpgcallmeback_Widget' is the widget class used below.
  24.  *
  25.  * @since 0.1
  26.  */
  27. function wpg_callmeback() {
  28.     register_widget( 'wpgcallmeback_Widget' );
  29. }
  30.  
  31. /**
  32.  * Example Widget class.
  33.  * This class handles everything that needs to be handled with the widget:
  34.  * the settings, form, display, and update.  Nice!
  35.  *
  36.  * @since 0.1
  37.  */
  38. class wpgcallmeback_Widget extends WP_Widget {
  39.  
  40.     /**
  41.      * Widget setup.
  42.      */
  43.     function wpgcallmeback_Widget() {
  44.         /* Widget settings. */
  45.         $widget_ops = array( 'classname' => 'wpgcallmeback', 'description' => __('A request call me back widget by WPGuru.in', 'wpgcallmeback') );
  46.  
  47.         /* Widget control settings. */
  48.         $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'wpgcallmeback-widget' );
  49.  
  50.         /* Create the widget. */
  51.         $this->WP_Widget( 'wpgcallmeback-widget', __('Reqest call me back', 'wpgcallmeback'), $widget_ops, $control_ops );
  52.     }
  53.  
  54.     /**
  55.      * How to display the widget on the screen.
  56.      */
  57.     function widget( $args, $instance ) {
  58.         extract( $args );
  59.  
  60.         /* Our variables from the widget settings. */
  61.         $title = apply_filters('widget_title', $instance['wpgtitle'] );
  62.         $wpgslogan = $instance['wpgslogan'];
  63.         $wpginfo = $instance['wpginfo'];
  64.         $wpgcallbut = $instance['wpgcallbut'];
  65.         $wpgcallus = $instance['wpgcallus'];
  66.         $wpgphonenum = $instance['wpgphonenum'];
  67.         $wpglinesinfo = $instance['wpglinesinfo'];
  68.         $show_form = isset( $instance['show_form'] ) ? $instance['show_form'] : false;
  69.  
  70.         /* Before widget (defined by themes). */
  71.         echo $before_widget;
  72.  
  73.         /* call back from start */
  74.         if ( $show_form )
  75.  
  76.  
  77. if(isset($_POST['submit']))
  78. {
  79.  
  80.  
  81.     $rname = $_POST['rname'];
  82.     $mailbody = "$rname";
  83.     $headers = 'From: dotcommakers@gmail.com' . "\r\n" .
  84.     'Reply-To: dotcommakers@gmail.com' . "\r\n" .
  85.     'X-Mailer: PHP/' . phpversion();
  86. if (mail('me@rakesh.in','My Subject',$rname,$headers))
  87. {
  88.  echo   "Thanks for query. We'll call you soon!";
  89.  }
  90.  else
  91.  {
  92.     echo('Sorry there is error in process. Contact admin at me@rakesh.in');
  93.  }
  94.    
  95.  
  96.  
  97. } else { ?>
  98.    
  99.     <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" enctype="application/x-www-form-urlencoded" name="callbackwidget">
  100. <input name="rname" type="text" value="Name" size="17" />
  101. <input name="rnumber" type="text" value="Number" size="17" />
  102. <input name="rtime" type="text" value="Best time to call" size="17" />
  103. <input name="remail" type="text" value="Email" size="17" />
  104. <input name="submit" type="submit" value="Call me back" />
  105. </form> <?php
  106.    
  107.     }
  108.  
  109.  
  110.  
  111.  
  112.         /* After widget (defined by themes). */
  113.         echo $after_widget;
  114.     }
  115.  
  116.     /**
  117.      * Update the widget settings.
  118.      */
  119.     function update( $new_instance, $old_instance ) {
  120.         $instance = $old_instance;
  121.  
  122.         /* Strip tags for title and name to remove HTML (important for text inputs). */
  123.         $instance['wpgtitle'] = strip_tags( $new_instance['wpgtitle'] );
  124.         $instance['wpgslogan'] = strip_tags( $new_instance['wpgslogan'] );
  125.         $instance['wpginfo'] = strip_tags( $new_instance['wpginfo'] );
  126.         $instance['wpgcallbut'] = strip_tags( $new_instance['wpgcallbut'] );
  127.         $instance['wpgcallus'] = strip_tags( $new_instance['wpgcallus'] );
  128.         $instance['wpgphonenum'] = strip_tags( $new_instance['wpgphonenum'] );
  129.         $instance['wpglinesinfo'] = strip_tags( $new_instance['wpglinesinfo'] );
  130.         /* No need to strip tags for show_form. */
  131.         $instance['show_form'] = $new_instance['show_form'];
  132.  
  133.  
  134.         return $instance;
  135.     }
  136.  
  137.     /**
  138.      * Displays the widget settings controls on the widget panel.
  139.      * Make use of the get_field_id() and get_field_name() function
  140.      * when creating your form elements. This handles the confusing stuff.
  141.      */
  142.     function form( $instance ) {
  143.  
  144.         /* Set up some default widget settings. */
  145.         $defaults = array( 'show_form' => true );
  146.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  147.  
  148.         <!-- Widget Title: Text Input -->
  149.         <p>
  150.             <label for="<?php echo $this->get_field_id( 'wpgtitle' ); ?>"><?php _e('Title:', 'wpgtitle'); ?></label>
  151.             <input id="<?php echo $this->get_field_id( 'wpgtitle' ); ?>" name="<?php echo $this->get_field_name( 'wpgtitle' ); ?>" value="<?php echo $instance['wpgtitle']; ?>" style="width:100%;" />
  152.         </p>
  153.  
  154.    
  155.         <p>
  156.             <label for="<?php echo $this->get_field_id( 'wpgslogan' ); ?>"><?php _e('Slogan:', 'wpgcallmeback'); ?></label>
  157.             <input id="<?php echo $this->get_field_id( 'wpgslogan' ); ?>" name="<?php echo $this->get_field_name( 'wpgslogan' ); ?>" value="<?php echo $instance['wpgslogan']; ?>" style="width:100%;" />
  158.         </p>
  159.        
  160.             <p>
  161.             <label for="<?php echo $this->get_field_id( 'wpginfo' ); ?>"><?php _e('Information:', 'wpginfo'); ?></label>
  162.             <input id="<?php echo $this->get_field_id( 'wpginfo' ); ?>" name="<?php echo $this->get_field_name( 'wpginfo' ); ?>" value="<?php echo $instance['wpginfo']; ?>" style="width:100%;" />
  163.         </p>
  164.        
  165.         <p>
  166.             <label for="<?php echo $this->get_field_id( 'wpgcallbut' ); ?>"><?php _e('Call button:', 'wpgcallbut'); ?></label>
  167.             <input id="<?php echo $this->get_field_id( 'wpgcallbut' ); ?>" name="<?php echo $this->get_field_name( 'wpgcallbut' ); ?>" value="<?php echo $instance['wpgcallbut']; ?>" style="width:100%;" />
  168.         </p>
  169.        
  170.          <p>
  171.             <label for="<?php echo $this->get_field_id( 'wpgcallus' ); ?>"><?php _e('Call Us Title:', 'wpgcallus'); ?></label>
  172.             <input id="<?php echo $this->get_field_id( 'wpgcallus' ); ?>" name="<?php echo $this->get_field_name( 'wpgcallus' ); ?>" value="<?php echo $instance['wpgcallus']; ?>" style="width:100%;" />
  173.         </p>
  174.        
  175.                  <p>
  176.             <label for="<?php echo $this->get_field_id( 'wpgphonenum' ); ?>"><?php _e('Phone Number:', 'wpgphonenum'); ?></label>
  177.             <input id="<?php echo $this->get_field_id( 'wpgphonenum' ); ?>" name="<?php echo $this->get_field_name( 'wpgphonenum' ); ?>" value="<?php echo $instance['wpgphonenum']; ?>" style="width:100%;" />
  178.         </p>
  179.        
  180.        
  181.          <p>
  182.             <label for="<?php echo $this->get_field_id( 'wpglinesinfo' ); ?>"><?php _e('Phone lines info:', 'wpglinesinfo'); ?></label>
  183.             <input id="<?php echo $this->get_field_id( 'wpglinesinfo' ); ?>" name="<?php echo $this->get_field_name( 'wpglinesinfo' ); ?>" value="<?php echo $instance['wpglinesinfo']; ?>" style="width:100%;" />
  184.         </p>
  185.        
  186.  
  187.    
  188.  
  189.         <p>
  190.             <input class="checkbox" type="checkbox" <?php checked( $instance['show_form'], true ); ?> id="<?php echo $this->get_field_id( 'show_form' ); ?>" name="<?php echo $this->get_field_name( 'show_form' ); ?>" />
  191.             <label for="<?php echo $this->get_field_id( 'show_form' ); ?>"><?php _e('Display form publicly?', 'example'); ?></label>
  192.         </p>
  193.  
  194.     <?php
  195.     }
  196. }
  197.  
  198. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement