# show-posts/trunk/includes/posts-widgets.php

Weaver Show Posts, version trunk. 98 lines.

- Page: https://pluginprobe.com/plugins/show-posts/trunk/code/includes/posts-widgets.php
- Raw: https://pluginprobe.com/plugins/show-posts/trunk/raw/includes/posts-widgets.php
- Modified: 2026-04-19T00:52:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/show-posts/trunk/code/includes/posts-widgets.php#L10-L20`.

```php
<?php
// File refactored: 2026-03-27
if ( ! defined( 'ABSPATH' ) ) exit;
/*
 *  Weaver X Widgets and shortcodes - widgets
 */

class WeaverSP_Widget_Text extends WP_Widget {

    function __construct() {
        $widget_ops = array('classname' => 'WeaverSS_Widget_Slider',
                'description' => esc_html__('Show Posts in a widget','show-posts' /*adm*/));
        $control_ops = array('width' => 400, 'height' => 350);
        parent::__construct('wvr_showposts', esc_html__('Weaver Show Posts','show-posts' /*adm*/), $widget_ops, $control_ops);
    }

    function widget($args, $instance) {
        // Get menu

        $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);

        $post_list = $instance['post_list'];
        if (!$post_list) $post_list = 'default';

        $add_class = $instance['add_class'];
        if (!$add_class) $add_class ='';


        echo wp_kses_post($args['before_widget']);

        if ( !empty($instance['title']) )
            echo wp_kses_post($args['before_title']) . esc_html($instance['title']) . wp_kses_post($args['after_title']);

        $before = $add_class ? "<div class='" . esc_attr($add_class) . "'>" : '';
        $after = $add_class ? "</div>" : '';

        require_once(dirname( __FILE__ ) . '/atw-showposts-sc.php');

        echo wp_kses_post($before) . wp_kses_post(atw_show_posts_shortcode( array('filter' => $post_list) )) . wp_kses_post($after);

        echo wp_kses_post($args['after_widget']);
    }

    function update( $new_instance, $old_instance ) {
        $instance['title'] = wp_strip_all_tags( stripslashes($new_instance['title']) );
        $instance['post_list'] = $new_instance['post_list'];
        $instance['add_class'] = wp_strip_all_tags( stripslashes($new_instance['add_class']) );
        return $instance;
    }

    function form( $instance ) {
        $title = isset( $instance['title'] ) ? $instance['title'] : '';
        $post_list = isset( $instance['post_list'] ) ? $instance['post_list'] : 'default';
        $add_class = isset( $instance['add_class'] ) ? $instance['add_class'] : '';


        // Get posts

        $posts = atw_posts_getopt('filters');

        // If no menus exists, direct the user to go and create some.
        if ( empty($posts)  ) {
            echo '<p>' . 'No Post Filters have been created yet. Create some on the <em>Weaver Posts (& Slider Options) -> Filters</em> admin menu.' .'</p>';
            return;
        }
        ?>
        <p>
            <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php echo('Title (optional):' /*a*/ ) ?></label>
            <input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" value="<?php echo esc_attr($title); ?>" />
        </p>

        <p>
            <label for="<?php echo esc_attr($this->get_field_id('post_list')); ?>"><?php echo('Select a Post'); ?></label><br />
            <select id="<?php echo esc_attr($this->get_field_id('post_list')); ?>" name="<?php echo esc_attr($this->get_field_name('post_list')); ?>">
                <?php
                foreach ( $posts as $post) {
                    $selected = $post_list == $post['slug'] ? ' selected="selected"' : '';
                    echo '<option' . esc_attr($selected) . ' value="' . esc_attr($post['slug']) . '">' . esc_attr($post['name']) . '</option>';
                }
                ?>
            </select>
        </p>

        <p>
            <label for="<?php echo esc_attr($this->get_field_id('add_class')); ?>"><?php echo('Additional Classes to Wrap Posts (optional):'  ) ?></label>
            <input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id('add_class')); ?>" name="<?php echo esc_attr($this->get_field_name('add_class')); ?>" value="<?php echo esc_attr($add_class); ?>" />
        </p>
        <?php
    }
}


add_action("widgets_init", "wvrx_sp_load_widgets");


function wvrx_sp_load_widgets() {
    register_widget("WeaverSP_Widget_Text");
}
```
