Changeset 1038274
- Timestamp:
- 12/04/2014 04:36:36 PM (11 years ago)
- Location:
- osd-blog-search-widget
- Files:
-
- 7 added
- 2 edited
-
tags/1.2 (added)
-
tags/1.2/lang (added)
-
tags/1.2/lang/osd-blog-search-widget.pot (added)
-
tags/1.2/osd-blog-search-widget.php (added)
-
tags/1.2/readme.txt (added)
-
trunk/lang (added)
-
trunk/lang/osd-blog-search-widget.pot (added)
-
trunk/osd-blog-search-widget.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
osd-blog-search-widget/trunk/osd-blog-search-widget.php
r984299 r1038274 3 3 Plugin Name: OSD Blog Search Widget 4 4 Plugin URI: http://outsidesource.com 5 Description: A plugin that adds a new widget that will add a search form forblog posts only.6 Version: 1. 15 Description: Adds a widget that adds a search form for searching blog posts only. 6 Version: 1.2 7 7 Author: OSD Web Development Team 8 Author URI: http://outsidesource.com8 Text Domain: osd-blog-search-widget 9 9 License: GPL2v2 10 10 */ 11 11 12 12 class osd_blog_search_widget extends WP_Widget { 13 14 13 public function __construct() { 15 14 parent::__construct( 16 15 'osd_blog_search_widget', // Base ID 17 'OSD Blog Search Widget', // Name 18 array('description' => __('Search form for blog posts only.')) // Args 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 19 20 ); 20 21 } 21 22 22 // output to the sidebars23 // Output to the sidebars 23 24 public function widget($args, $instance) { 24 25 extract($args); … … 28 29 echo $before_widget; 29 30 30 if (!empty($title)) {31 if (!empty($title)) { 31 32 echo $before_title . $title . $after_title; 32 33 } 33 34 34 echo __("<div class='search-form' id='osd-blog-search'> 35 <form method='get' action='".home_url('/')."'> 36 <input type='hidden' name='post_type' value='post' /> 37 <input type='text' name='s' id='s' value='' placeholder='Search blog' /> 38 <input id='osd-search-submit' class='search-button' type='image' alt='Search' src='".get_bloginfo('template_url')."/images/search.svg' /> 39 </form> 40 </div>"); 41 42 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='".get_bloginfo('template_url')."/images/search.svg' /> 40 </form> 41 </div>"; 43 42 echo $after_widget; 44 43 } 45 44 46 // admin menu options45 // Admin menu options 47 46 public function form($instance) { 48 $title = isset($instance['title']) ? $instance['title'] : '';49 50 47 ?> 51 48 <p> 52 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 53 <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( $title ); ?>" /> 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"] ); ?>" /> 54 57 </p> 55 58 <?php 56 59 } 57 60 58 // loadthe instance61 // Update the instance 59 62 public function update($new_instance, $old_instance) { 60 63 $instance = array(); 61 64 $instance['title'] = strip_tags($new_instance['title']); 62 65 $instance['placeholder'] = strip_tags($new_instance['placeholder']); 63 66 return $instance; 67 } 68 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; 64 79 } 65 80 } 66 81 add_action('widgets_init', create_function('', 'register_widget("osd_blog_search_widget");')); 67 68 //add functionality to the custom search widget 69 function osd_blog_search_filter($query) { 70 if($query->is_search && !is_admin()) { 71 $post_type = $_GET['post_type']; 72 if(!$post_type) { 73 $post_type = 'any'; 74 } 75 $query->set('post_type', $post_type); 76 } 77 return $query; 78 } 79 add_filter('pre_get_posts','osd_blog_search_filter'); 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/"); 80 84 ?> -
osd-blog-search-widget/trunk/readme.txt
r984299 r1038274 4 4 Requires at least: 3.4 5 5 Tested up to: 4.0 6 Stable tag: 1. 16 Stable tag: 1.2 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 35 35 == Changelog == 36 36 37 = 1.2 = 38 * Added placeholder field for search input 39 * Added internationalization support .pot file 40 37 41 = 1.1 = 38 42 * Removed erroneous PHP notice in debug mode
Note: See TracChangeset
for help on using the changeset viewer.