Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: Call me back widget
- * Plugin URI: http://wpguru.in
- * Description: Request call me back widget by WPGuru.in
- * Version: 1.0
- * Author: Rakesh Raja
- * Author URI: http://wpguru.in
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- */
- /**
- * Add function to widgets_init that'll load our widget.
- * @since 0.1
- */
- add_action( 'widgets_init', 'wpg_callmeback' );
- /**
- * Register our widget.
- * 'wpgcallmeback_Widget' is the widget class used below.
- *
- * @since 0.1
- */
- function wpg_callmeback() {
- register_widget( 'wpgcallmeback_Widget' );
- }
- /**
- * Example Widget class.
- * This class handles everything that needs to be handled with the widget:
- * the settings, form, display, and update. Nice!
- *
- * @since 0.1
- */
- class wpgcallmeback_Widget extends WP_Widget {
- /**
- * Widget setup.
- */
- function wpgcallmeback_Widget() {
- /* Widget settings. */
- $widget_ops = array( 'classname' => 'wpgcallmeback', 'description' => __('A request call me back widget by WPGuru.in', 'wpgcallmeback') );
- /* Widget control settings. */
- $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'wpgcallmeback-widget' );
- /* Create the widget. */
- $this->WP_Widget( 'wpgcallmeback-widget', __('Reqest call me back', 'wpgcallmeback'), $widget_ops, $control_ops );
- }
- /**
- * How to display the widget on the screen.
- */
- function widget( $args, $instance ) {
- extract( $args );
- /* Our variables from the widget settings. */
- $title = apply_filters('widget_title', $instance['wpgtitle'] );
- $wpgslogan = $instance['wpgslogan'];
- $wpginfo = $instance['wpginfo'];
- $wpgcallbut = $instance['wpgcallbut'];
- $wpgcallus = $instance['wpgcallus'];
- $wpgphonenum = $instance['wpgphonenum'];
- $wpglinesinfo = $instance['wpglinesinfo'];
- $show_form = isset( $instance['show_form'] ) ? $instance['show_form'] : false;
- /* Before widget (defined by themes). */
- echo $before_widget;
- /* call back from start */
- if ( $show_form )
- if(isset($_POST['submit']))
- {
- $rname = $_POST['rname'];
- $mailbody = "$rname";
- $headers = 'From: dotcommakers@gmail.com' . "\r\n" .
- 'Reply-To: dotcommakers@gmail.com' . "\r\n" .
- 'X-Mailer: PHP/' . phpversion();
- if (mail('me@rakesh.in','My Subject',$rname,$headers))
- {
- echo "Thanks for query. We'll call you soon!";
- }
- else
- {
- echo('Sorry there is error in process. Contact admin at me@rakesh.in');
- }
- } else { ?>
- <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" enctype="application/x-www-form-urlencoded" name="callbackwidget">
- <input name="rname" type="text" value="Name" size="17" />
- <input name="rnumber" type="text" value="Number" size="17" />
- <input name="rtime" type="text" value="Best time to call" size="17" />
- <input name="remail" type="text" value="Email" size="17" />
- <input name="submit" type="submit" value="Call me back" />
- </form> <?php
- }
- /* After widget (defined by themes). */
- echo $after_widget;
- }
- /**
- * Update the widget settings.
- */
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- /* Strip tags for title and name to remove HTML (important for text inputs). */
- $instance['wpgtitle'] = strip_tags( $new_instance['wpgtitle'] );
- $instance['wpgslogan'] = strip_tags( $new_instance['wpgslogan'] );
- $instance['wpginfo'] = strip_tags( $new_instance['wpginfo'] );
- $instance['wpgcallbut'] = strip_tags( $new_instance['wpgcallbut'] );
- $instance['wpgcallus'] = strip_tags( $new_instance['wpgcallus'] );
- $instance['wpgphonenum'] = strip_tags( $new_instance['wpgphonenum'] );
- $instance['wpglinesinfo'] = strip_tags( $new_instance['wpglinesinfo'] );
- /* No need to strip tags for show_form. */
- $instance['show_form'] = $new_instance['show_form'];
- 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. */
- $defaults = array( 'show_form' => true );
- $instance = wp_parse_args( (array) $instance, $defaults ); ?>
- <!-- Widget Title: Text Input -->
- <p>
- <label for="<?php echo $this->get_field_id( 'wpgtitle' ); ?>"><?php _e('Title:', 'wpgtitle'); ?></label>
- <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%;" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'wpgslogan' ); ?>"><?php _e('Slogan:', 'wpgcallmeback'); ?></label>
- <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%;" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'wpginfo' ); ?>"><?php _e('Information:', 'wpginfo'); ?></label>
- <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%;" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'wpgcallbut' ); ?>"><?php _e('Call button:', 'wpgcallbut'); ?></label>
- <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%;" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'wpgcallus' ); ?>"><?php _e('Call Us Title:', 'wpgcallus'); ?></label>
- <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%;" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'wpgphonenum' ); ?>"><?php _e('Phone Number:', 'wpgphonenum'); ?></label>
- <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%;" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'wpglinesinfo' ); ?>"><?php _e('Phone lines info:', 'wpglinesinfo'); ?></label>
- <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%;" />
- </p>
- <p>
- <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' ); ?>" />
- <label for="<?php echo $this->get_field_id( 'show_form' ); ?>"><?php _e('Display form publicly?', 'example'); ?></label>
- </p>
- <?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement