Plugin Directory

Changeset 1038274


Ignore:
Timestamp:
12/04/2014 04:36:36 PM (11 years ago)
Author:
osdwebdev
Message:

Release 1.2

Location:
osd-blog-search-widget
Files:
7 added
2 edited

Legend:

Unmodified
Added
Removed
  • osd-blog-search-widget/trunk/osd-blog-search-widget.php

    r984299 r1038274  
    33    Plugin Name: OSD Blog Search Widget
    44    Plugin URI: http://outsidesource.com
    5     Description: A plugin that adds a new widget that will add a search form for blog posts only.
    6     Version: 1.1
     5    Description: Adds a widget that adds a search form for searching blog posts only.
     6    Version: 1.2
    77    Author: OSD Web Development Team
    8     Author URI: http://outsidesource.com
     8    Text Domain: osd-blog-search-widget
    99    License: GPL2v2
    1010    */
    1111   
    1212    class osd_blog_search_widget extends WP_Widget {
    13      
    1413        public function __construct() {
    1514            parent::__construct(
    1615                '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
    1920            );
    2021        }
    2122     
    22         //output to the sidebars
     23        // Output to the sidebars
    2324        public function widget($args, $instance) {
    2425            extract($args); 
     
    2829            echo $before_widget;
    2930     
    30             if(!empty($title)) {
     31            if (!empty($title)) {
    3132                echo $before_title . $title . $after_title;
    3233            }
    3334           
    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>";
    4342            echo $after_widget;
    4443        }
    4544     
    46         //admin menu options
     45        // Admin menu options
    4746        public function form($instance) {
    48             $title = isset($instance['title']) ? $instance['title'] : '';
    49      
    5047            ?>
    5148            <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"] ); ?>" />
    5457            </p>
    5558            <?php
    5659        }
    5760     
    58         //load the instance
     61        // Update the instance
    5962        public function update($new_instance, $old_instance) {
    6063            $instance = array();
    6164            $instance['title'] = strip_tags($new_instance['title']);
    62      
     65            $instance['placeholder'] = strip_tags($new_instance['placeholder']);
    6366            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;
    6479        }
    6580    }
    6681    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/");
    8084?>
  • osd-blog-search-widget/trunk/readme.txt

    r984299 r1038274  
    44Requires at least: 3.4
    55Tested up to: 4.0
    6 Stable tag: 1.1
     6Stable tag: 1.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535== Changelog ==
    3636
     37= 1.2 =
     38* Added placeholder field for search input
     39* Added internationalization support .pot file
     40
    3741= 1.1 =
    3842* Removed erroneous PHP notice in debug mode
Note: See TracChangeset for help on using the changeset viewer.