Advertisement
AJDesigns

Wordpress Widget - Event Manager Search Form in Sidebar

Jan 25th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1.        
  2. ///////////////////////////////////////////////////////////////////////////
  3. // Custom Widget to display Event Search in Sidebar.///
  4. //////////////////////////////////////////////////////////////////////////////
  5.  
  6. // Creating the widget
  7.    
  8. class em_search_widget extends WP_Widget {
  9.  
  10. function __construct() {
  11. parent::__construct(
  12. // Base ID of your widget
  13. 'em_search_widget',
  14.  
  15. // Widget name will appear in UI
  16. __('Events Search Widget', 'wpb_widget_domain'),
  17.  
  18. // Widget description
  19. array( 'description' => __( 'Show the default Events Manager Searh form.', 'wpb_widget_domain' ), )
  20. );
  21. }
  22.  
  23. // Creating widget front-end
  24. // This is where the action happens
  25. public function widget( $args, $instance ) {
  26.  
  27. $title = apply_filters( 'widget_title', $instance['title'] );
  28. // before and after widget arguments are defined by themes
  29. echo $args['before_widget'];
  30. if ( ! empty( $title ) )
  31. echo $args['before_title'] . $title . $args['after_title'];
  32.  
  33. // This is where you run the code and display the output
  34.  
  35. echo do_shortcode('[event_search_form]');
  36.        
  37. echo $args['after_widget']; }
  38.  
  39.        
  40. // Widget Backend
  41. public function form( $instance ) {
  42. if ( isset( $instance[ 'title' ] ) ) {
  43. $title = $instance[ 'title' ];
  44. }
  45. else {
  46. $title = __( 'Search', 'wpb_widget_domain' );
  47. }
  48. // Widget admin form
  49.  
  50. echo '<p>', '<label for="', $this->get_field_id( 'title' ), '">' ,
  51. _e( 'Title:' ), '</label> <input class="widefat" id="', $this->get_field_id( 'title' ),  '" name="',
  52.  $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ), '" />
  53. </p>';
  54.  
  55. }
  56.    
  57. // Updating widget replacing old instances with new
  58. public function update( $new_instance, $old_instance ) {
  59. $instance = array();
  60. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  61. return $instance;
  62. }
  63. } // Class wpb_widget ends here
  64.  
  65. // Register and load the widget
  66. function wpb_load_widget() {
  67.     register_widget( 'em_search_widget' );
  68. }
  69. add_action( 'widgets_init', 'wpb_load_widget' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement