GSC_Widget

Google Custom Search Widget class.

Defined (1)

The class is defined in the following location(s).

/widget.php  
  1. class GSC_Widget extends WP_Widget 
  2.  
  3. /** 
  4. * Widget setup. 
  5. */ 
  6. function GSC_Widget() 
  7. /** Widget settings. */ 
  8. $widget_ops = array('classname' => 'google custom search', 'description' => __('Unleash Google Search on Your Website.', 'google custom search')); 
  9.  
  10. /** Widget control settings. */ 
  11. $control_ops = array('width' => 300, 'height' => 350, 'id_base' => 'gsc-widget'); 
  12.  
  13. /** Create the widget. */ 
  14. $this->WP_Widget('gsc-widget', __('Google Custom Search'), $widget_ops, $control_ops); 
  15.  
  16. /** 
  17. * How to display the widget on the screen. 
  18. */ 
  19. function widget($args, $instance) 
  20. extract($args); 
  21.  
  22. $gsc_search_engine_id = get_option('gsc_search_engine_id'); 
  23.  
  24. /** Get variables from the widget settings. */ 
  25. $display_results_option = $instance['display_results_option']; 
  26. $hide_widget_format = isset($instance['hide_widget_format']) ? $instance['hide_widget_format'] : false; 
  27.  
  28. /** Before widget (defined by themes). */ 
  29. if (!$hide_widget_format) 
  30. echo $before_widget; 
  31.  
  32. display_search_box($display_results_option); 
  33.  
  34. /** After widget (defined by themes). */ 
  35. if (!$hide_widget_format) 
  36. echo $after_widget; 
  37.  
  38. /** 
  39. * Update the widget settings. 
  40. */ 
  41. function update($new_instance, $old_instance) 
  42. $instance = $old_instance; 
  43.  
  44. $instance['display_results_option'] = $new_instance['display_results_option']; 
  45. $instance['hide_widget_format'] = $new_instance['hide_widget_format']; 
  46.  
  47. return $instance; 
  48.  
  49. /** 
  50. * Displays the widget settings controls on the widget panel. 
  51. * Make use of the get_field_id() and get_field_name() function 
  52. * when creating your form elements. This handles the confusing stuff. 
  53. */ 
  54. function form($instance) 
  55.  
  56. /** Set up some default widget settings. */ 
  57. $defaults = array('display_results_option' => 0, 'hide_widget_format' => false); 
  58. $instance = wp_parse_args((array)$instance, $defaults); ?> 
  59.  
  60. <!-- Display Results: Select Box --> 
  61. <p> 
  62. <label 
  63. for="<?php echo $this->get_field_id('display_results_option'); ?>"><?php _e('Display Results:', 'example'); ?></label> 
  64. <select id="<?php echo $this->get_field_id('display_results_option'); ?>" 
  65. name="<?php echo $this->get_field_name('display_results_option'); ?>" class="widefat" 
  66. style="width:100%;"> 
  67. <option <?php if (DISPLAY_RESULTS_AS_POP_UP == $instance['display_results_option']) echo 'selected="selected"'; ?> 
  68. value=0>Pop-up 
  69. </option> 
  70. <option <?php if (DISPLAY_RESULTS_IN_UNDER_SEARCH_BOX == $instance['display_results_option']) echo 'selected="selected"'; ?> 
  71. value=1>Within Widget 
  72. </option> 
  73. <option <?php if (DISPLAY_RESULTS_CUSTOM == $instance['display_results_option']) echo 'selected="selected"'; ?> 
  74. value=2>Custom (needs configuring. refer to plugin docs) 
  75. </option> 
  76. </select> 
  77. </p> 
  78.  
  79. <!-- Hide Widget Format --> 
  80. <p> 
  81. <input class="checkbox" 
  82. type="checkbox" <?php if ($instance['hide_widget_format'] == 'on') echo 'checked'; ?> 
  83. id="<?php echo $this->get_field_id('hide_widget_format'); ?>" 
  84. name="<?php echo $this->get_field_name('hide_widget_format'); ?>"/> 
  85. <label 
  86. for="<?php echo $this->get_field_id('hide_widget_format'); ?>"><?php _e('Hide Widget Format?', 'example'); ?></label> 
  87. </p> 
  88.  
  89. <?php