Changeset 1120675
- Timestamp:
- 03/25/2015 06:12:44 PM (11 years ago)
- Location:
- osd-blog-search-widget
- Files:
-
- 10 added
- 2 edited
-
tags/1.5 (added)
-
tags/1.5/images (added)
-
tags/1.5/images/search.svg (added)
-
tags/1.5/lang (added)
-
tags/1.5/lang/osd-blog-search-widget-sr_RS.mo (added)
-
tags/1.5/lang/osd-blog-search-widget.pot (added)
-
tags/1.5/osd-blog-search-widget.php (added)
-
tags/1.5/readme.txt (added)
-
trunk/images (added)
-
trunk/images/search.svg (added)
-
trunk/osd-blog-search-widget.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
osd-blog-search-widget/trunk/osd-blog-search-widget.php
r1118775 r1120675 1 1 <?php 2 /* 3 Plugin Name: OSD Blog Search Widget 4 Plugin URI: http://outsidesource.com 5 Description: Adds a widget that adds a search form for searching blog posts only. 6 Version: 1.4 7 Author: OSD Web Development Team 8 Text Domain: osd-blog-search-widget 9 License: GPL2v2 10 */ 11 12 class osd_blog_search_widget extends WP_Widget { 13 public function __construct() { 14 parent::__construct( 15 'osd_blog_search_widget', // Base ID 16 /* translators: Widget Name */ 17 __('OSD Blog Search', 'osd-blog-search-widget'), // Name 18 /* translators: Widget Description */ 19 array('description' => __('Search form for searching blog posts only.', 'osd-blog-search-widget')) // Args 20 ); 2 /* 3 Plugin Name: OSD Blog Search Widget 4 Plugin URI: http://outsidesource.com 5 Description: Adds a widget that adds a search form for searching blog posts only. 6 Version: 1.5 7 Author: OSD Web Development Team 8 Text Domain: osd-blog-search-widget 9 License: GPL2v2 10 */ 11 12 class osd_blog_search_widget extends WP_Widget { 13 public function __construct() { 14 parent::__construct( 15 'osd_blog_search_widget', // Base ID 16 /* translators: Widget Name */ 17 __('OSD Blog Search', 'osd-blog-search-widget'), // Name 18 /* translators: Widget Description */ 19 array('description' => __('Search form for searching blog posts only.', 'osd-blog-search-widget')) // Args 20 ); 21 22 // Add front-end filters 23 if (!is_admin()) { 24 add_shortcode("osd_blog_search", array($this, "replace_shortcode")); 25 } 26 } 27 28 // Output to the sidebars 29 public function widget($args, $instance) { 30 extract($args); 31 $title = apply_filters('widget_title', $instance['title']); 32 $extra_menu_args = array('container' => '', 'walker_args' => array()); 33 34 echo $before_widget; 35 36 if (!empty($title)) { 37 echo $before_title . $title . $after_title; 21 38 } 22 23 // Output to the sidebars 24 public function widget($args, $instance) { 25 extract($args); 26 $title = apply_filters('widget_title', $instance['title']); 27 $extra_menu_args = array('container' => '', 'walker_args' => array()); 39 40 echo "<div class='search-form' id='osd-blog-search'> 41 <form method='get' action='".home_url('/')."'> 42 <input type='hidden' name='post_type' value='post' /> 43 <input type='text' name='s' id='s' value='' placeholder='".$instance['placeholder']."' /> 44 <input id='osd-search-submit' class='search-button' type='image' alt='Search' src='".plugins_url()."/osd-blog-search-widget/images/search.svg' /> 45 </form> 46 </div>"; 47 echo $after_widget; 48 } 49 50 // Admin menu options 51 public function form($instance) { 52 ?> 53 <p> 54 <?php /* translators: Widget Field: Title */ ?> 55 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'osd-blog-search-widget'); ?></label> 56 <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"] ); ?>" /> 57 </p> 58 <p> 59 <?php /* translators: Widget Field: Placeholder */ ?> 60 <label for="<?php echo $this->get_field_id( 'placeholder' ); ?>"><?php _e('Placeholder:', 'osd-blog-search-widget'); ?></label> 61 <input class="widefat" id="<?php echo $this->get_field_id( 'placeholder' ); ?>" name="<?php echo $this->get_field_name( 'placeholder' ); ?>" type="text" value="<?php echo esc_attr( $instance["placeholder"] ); ?>" /> 62 </p> 63 <?php 64 } 65 66 // Update the instance 67 public function update($new_instance, $old_instance) { 68 $instance = array(); 69 $instance['title'] = strip_tags($new_instance['title']); 70 $instance['placeholder'] = strip_tags($new_instance['placeholder']); 71 return $instance; 72 } 28 73 29 echo $before_widget; 30 31 if (!empty($title)) { 32 echo $before_title . $title . $after_title; 74 // Add functionality to the custom search widget 75 public static function blog_search_filter($query) { 76 if ($query->is_search && !is_admin()) { 77 $post_type = $_GET['post_type']; 78 if (!$post_type) { 79 $post_type = 'any'; 33 80 } 34 35 echo "<div class='search-form' id='osd-blog-search'> 36 <form method='get' action='".home_url('/')."'> 37 <input type='hidden' name='post_type' value='post' /> 38 <input type='text' name='s' id='s' value='' placeholder='".$instance['placeholder']."' /> 39 <input id='osd-search-submit' class='search-button' type='image' alt='Search' src='".plugins_url()."/osd-blog-search-widget/images/search.svg' /> 40 </form> 41 </div>"; 42 echo $after_widget; 81 $query->set('post_type', $post_type); 43 82 } 44 45 // Admin menu options 46 public function form($instance) { 47 ?> 48 <p> 49 <?php /* translators: Widget Field: Title */ ?> 50 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'osd-blog-search-widget'); ?></label> 51 <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"] ); ?>" /> 52 </p> 53 <p> 54 <?php /* translators: Widget Field: Placeholder */ ?> 55 <label for="<?php echo $this->get_field_id( 'placeholder' ); ?>"><?php _e('Placeholder:', 'osd-blog-search-widget'); ?></label> 56 <input class="widefat" id="<?php echo $this->get_field_id( 'placeholder' ); ?>" name="<?php echo $this->get_field_name( 'placeholder' ); ?>" type="text" value="<?php echo esc_attr( $instance["placeholder"] ); ?>" /> 57 </p> 58 <?php 59 } 60 61 // Update the instance 62 public function update($new_instance, $old_instance) { 63 $instance = array(); 64 $instance['title'] = strip_tags($new_instance['title']); 65 $instance['placeholder'] = strip_tags($new_instance['placeholder']); 66 return $instance; 67 } 83 return $query; 84 } 68 85 69 // Add functionality to the custom search widget 70 public static function blog_search_filter($query) { 71 if ($query->is_search && !is_admin()) { 72 $post_type = $_GET['post_type']; 73 if (!$post_type) { 74 $post_type = 'any'; 75 } 76 $query->set('post_type', $post_type); 77 } 78 return $query; 79 } 80 } 81 add_action('widgets_init', create_function('', 'register_widget("osd_blog_search_widget");')); 82 add_filter('pre_get_posts', array("osd_blog_search_widget", 'blog_search_filter')); 83 load_plugin_textdomain('osd-blog-search-widget', false, basename(dirname(__FILE__))."/lang/"); 84 ?> 86 // Shortcode function (everything runs on the shortcode) 87 function replace_shortcode($atts = array()) { 88 $placeholder = (isset($atts['placeholder'])) ? $atts['placeholder'] : ''; 89 $class = (isset($atts['class'])) ? " ".$atts['class'] : ''; 90 91 $html = "<div class='search-form{$class}' id='osd-blog-search'> 92 <form method='get' action='".home_url('/')."'> 93 <input type='hidden' name='post_type' value='post' /> 94 <input type='text' name='s' id='s' value='' placeholder='{$placeholder}' /> 95 <input id='osd-search-submit' class='search-button' type='image' alt='Search' src='".plugins_url()."/osd-blog-search-widget/images/search.svg' /> 96 </form> 97 </div>"; 98 99 return $html; 100 } 101 } 102 add_action('widgets_init', create_function('', 'register_widget("osd_blog_search_widget");')); 103 add_filter('pre_get_posts', array("osd_blog_search_widget", 'blog_search_filter')); 104 load_plugin_textdomain('osd-blog-search-widget', false, basename(dirname(__FILE__))."/lang/"); -
osd-blog-search-widget/trunk/readme.txt
r1118775 r1120675 3 3 Tags: wordpress, blog search, search, blog posts only search, custom search, search only posts 4 4 Requires at least: 3.4 5 Tested up to: 4. 06 Stable tag: 1. 45 Tested up to: 4.1 6 Stable tag: 1.5 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 OSD Blog Search Widget plugin adds a widget that contains a form for searching blog posts only. 10 OSD Blog Search Widget plugin adds a widget that contains a form for searching blog posts only. Now includes a shortcode with two optional attributes - EX [osd_blog_search placeholder='search terms' class='test classes'] 11 11 12 12 == Description == 13 13 14 OSD Blog Search Widget can be placed in any area on your site that your theme allows. It provides a search box that will only display results from searching your blog posts. It excludes any other post type including Page and custom post types. It is light weight and works fine in conjunction with your current site search form. 14 OSD Blog Search Widget can be placed in any area on your site that your theme allows. It provides a search box that will only display results from searching your blog posts. It excludes any other post type including Page and custom post types. It is light weight and works fine in conjunction with your current site search form. Now includes a shortcode with two optional attributes - EX [osd_blog_search placeholder='search terms' class='test classes'] 15 15 16 16 Translations: … … 37 37 38 38 == Changelog == 39 40 = 1.5 = 41 * Now includes a shortcode with two optional attributes - EX [osd_blog_search placeholder='search terms' class='test classes'] 42 * Place the shortcode anywhere in your content to have a blog only search box 39 43 40 44 = 1.3 =
Note: See TracChangeset
for help on using the changeset viewer.