Plugin Directory

Changeset 1402460


Ignore:
Timestamp:
04/22/2016 09:44:27 PM (10 years ago)
Author:
sillybean
Message:

Widget update

Location:
random-posts-from-category
Files:
11 added
2 edited

Legend:

Unmodified
Added
Removed
  • random-posts-from-category/trunk/random-from-category-widget.php

    r1045190 r1402460  
    44Plugin URI: http://sillybean.net/code/wordpress/
    55Description: A widget that lists random posts from a chosen category.
    6 Version: 1.2
     6Version: 1.30
    77Author: Stephanie Leary
    88Author URI: http://sillybean.net/
     
    1313class RandomPostsFromCategory extends WP_Widget {
    1414
    15     function RandomPostsFromCategory() {
     15    function __construct() {
    1616            $widget_ops = array('classname' => 'random_from_cat', 'description' => __( 'random posts from a chosen category', 'random-posts-from-category') );
    17             $this->WP_Widget('RandomPostsFromCategory', __('Random Posts from Category', 'random-posts-from-category'), $widget_ops);
     17            parent::__construct('RandomPostsFromCategory', __('Random Posts from Category', 'random-posts-from-category'), $widget_ops);
    1818    }
    1919   
     
    3232                echo $before_title.$title.$after_title;
    3333            }
    34             ?>
    35             <ul>
    36             <?php
     34           
    3735            $args = array(
    3836                'cat' => $instance['cat'],
     
    4442            // the Loop
    4543            if ($random->have_posts()) :
    46             while ($random->have_posts()) : $random->the_post();   
    47                 global $post;
    48                 setup_postdata($post);
    49                 ?>
    50                 <li>
    51                 <?php
    52                     if ($instance['content'] != 'excerpt-notitle' && $instance['content'] != 'content-notitle') { ?>
    53                     <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    54                 <?php
    55                 }
    56                 if ($instance['content'] == 'excerpt' || $instance['content'] == 'excerpt-notitle') {
    57                     if (function_exists('the_excerpt_reloaded'))
    58                         the_excerpt_reloaded($instance['words'], $instance['tags'], 'content', FALSE, '', '', '1', '');
    59                     else the_excerpt();  // this covers Advanced Excerpt as well as the built-in one
    60                 }
    61                 if ($instance['content'] == 'content' || $instance['content'] == 'content-notitle') the_content();
    62             endwhile; endif;
    63             ?>
    64             </ul>
    65             <?php
     44                echo '<ul>';
     45                while ($random->have_posts()) : $random->the_post(); ?>
     46                    <li>
     47                    <?php
     48                        if ($instance['content'] != 'excerpt-notitle' && $instance['content'] != 'content-notitle') { ?>
     49                        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
     50                    <?php
     51                    }
     52                    if ($instance['content'] == 'excerpt' || $instance['content'] == 'excerpt-notitle') {
     53                        if (function_exists('the_excerpt_reloaded'))
     54                            the_excerpt_reloaded($instance['words'], $instance['tags'], 'content', FALSE, '', '', '1', '');
     55                        else the_excerpt();  // this covers Advanced Excerpt as well as the built-in one
     56                    }
     57                    if ($instance['content'] == 'content' || $instance['content'] == 'content-notitle') the_content();
     58                endwhile;
     59                echo '</ul>';
     60            endif;
     61           
    6662            echo $after_widget;
    67            
    68             wp_reset_postdata();
    6963            wp_reset_query();
    7064    }
     
    7367    function update( $new_instance, $old_instance ) {
    7468            $instance = $old_instance;
    75             $instance['title'] = strip_tags($new_instance['title']);
    76             $instance['cat'] = $new_instance['cat'];
    77             $instance['showposts'] = $new_instance['showposts'];
    78             $instance['content'] = $new_instance['content'];
    79             $instance['postlink'] = $new_instance['postlink'];
    80             $instance['words'] = $new_instance['words'];
     69            $instance['title'] = sanitize_text_field($new_instance['title']);
     70            $instance['cat'] = intval($new_instance['cat']);
     71            $instance['showposts'] = intval($new_instance['showposts']);
     72            $instance['content'] = sanitize_text_field($new_instance['content']);
     73            $instance['postlink'] = intval($new_instance['postlink']);
     74            $instance['words'] = intval($new_instance['words']);
    8175            $instance['tags'] = $new_instance['tags'];
    8276            return $instance;
     
    132126<label for="<?php echo $this->get_field_id('words'); ?>"><?php _e('Limit excerpts to how many words?:', 'random-posts-from-category'); ?></label>
    133127<input class="widefat" id="<?php echo $this->get_field_id('words'); ?>" name="<?php echo $this->get_field_name('words'); ?>"
    134     type="text" value="<?php echo $instance['words']; ?>" />
     128    type="text" value="<?php echo esc_attr($instance['words']); ?>" />
    135129</p>
    136130
  • random-posts-from-category/trunk/readme.txt

    r1139592 r1402460  
    22Contributors: sillybean
    33Tags: widget, random, posts
    4 Donate link: http://stephanieleary.com/code/wordpress/random-posts-from-category/
    5 Text Domain: RandomPostsFromCategory
    6 Domain Path: /languages
    74Requires at least: 2.8
    8 Tested up to: 4.2
    9 Stable tag: 1.16
     5Tested up to: 4.5
     6Stable tag: 1.30
    107
    118A widget that lists random posts from a chosen category. 
     
    3027Go to Appearance &rarr; Widgets to add widgets to your sidebar in widget-ready themes.
    3128
    32 To use with a custom post type, add this to your post type plugin file or theme functions.php:
     29== Frequently Asked Questions ==
    3330
    34 `
    35 add_filter('random_posts_from_category_args', 'random_post_widget_args');
     31= Known bugs =
    3632
    37 function random_post_widget_args($args) {
    38     $args['post_type'] = 'mycpt_name';
    39     return $args;
    40 }
    41 `
     33Some dropdown menus are not displaying correctly after widget options have been saved. This appears to be affecting many widgets, not just this one. This will be fixed as soon as we figure out what's happening! In the meantime, simply refreshing the widget page in your browser will knock the menus back into shape.
    4234
    4335== Screenshots ==
     
    4739== Changelog ==
    4840
    49 = 1.2 =
    50 * Added 'random_posts_from_category_args' filter to query arguments; fixed query reset.
    5141= 1.16 =
    5242* Romanian (ro_RO) translation by Web Geek Science (<a href="http://webhostinggeeks.com/">Web
Note: See TracChangeset for help on using the changeset viewer.