PluginProbe
Weaver Show Posts / trunk
Weaver Show Posts vtrunk
2.0.5 2.0.4 trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.6 1.0.7 1.1 1.2 1.2.1 1.2.2 1.2.4 1.3 1.3.1 1.3.1.1 1.3.10 1.3.13 1.3.15 1.3.2 1.3.3 1.3.5 1.3.6 1.3.7 All 37 releases
show-posts / includes / posts-widgets.php

posts-widgets.php in Weaver Show Posts trunk, at includes/posts-widgets.php

98 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // File refactored: 2026-03-27
3 if ( ! defined( 'ABSPATH' ) ) exit;
4 /*
5 * Weaver X Widgets and shortcodes - widgets
6 */
7
8 class WeaverSP_Widget_Text extends WP_Widget {
9
10 function __construct() {
11 $widget_ops = array('classname' => 'WeaverSS_Widget_Slider',
12 'description' => esc_html__('Show Posts in a widget','show-posts' /*adm*/));
13 $control_ops = array('width' => 400, 'height' => 350);
14 parent::__construct('wvr_showposts', esc_html__('Weaver Show Posts','show-posts' /*adm*/), $widget_ops, $control_ops);
15 }
16
17 function widget($args, $instance) {
18 // Get menu
19
20 $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
21
22 $post_list = $instance['post_list'];
23 if (!$post_list) $post_list = 'default';
24
25 $add_class = $instance['add_class'];
26 if (!$add_class) $add_class ='';
27
28
29 echo wp_kses_post($args['before_widget']);
30
31 if ( !empty($instance['title']) )
32 echo wp_kses_post($args['before_title']) . esc_html($instance['title']) . wp_kses_post($args['after_title']);
33
34 $before = $add_class ? "<div class='" . esc_attr($add_class) . "'>" : '';
35 $after = $add_class ? "</div>" : '';
36
37 require_once(dirname( __FILE__ ) . '/atw-showposts-sc.php');
38
39 echo wp_kses_post($before) . wp_kses_post(atw_show_posts_shortcode( array('filter' => $post_list) )) . wp_kses_post($after);
40
41 echo wp_kses_post($args['after_widget']);
42 }
43
44 function update( $new_instance, $old_instance ) {
45 $instance['title'] = wp_strip_all_tags( stripslashes($new_instance['title']) );
46 $instance['post_list'] = $new_instance['post_list'];
47 $instance['add_class'] = wp_strip_all_tags( stripslashes($new_instance['add_class']) );
48 return $instance;
49 }
50
51 function form( $instance ) {
52 $title = isset( $instance['title'] ) ? $instance['title'] : '';
53 $post_list = isset( $instance['post_list'] ) ? $instance['post_list'] : 'default';
54 $add_class = isset( $instance['add_class'] ) ? $instance['add_class'] : '';
55
56
57 // Get posts
58
59 $posts = atw_posts_getopt('filters');
60
61 // If no menus exists, direct the user to go and create some.
62 if ( empty($posts) ) {
63 echo '<p>' . 'No Post Filters have been created yet. Create some on the <em>Weaver Posts (& Slider Options) -> Filters</em> admin menu.' .'</p>';
64 return;
65 }
66 ?>
67 <p>
68 <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php echo('Title (optional):' /*a*/ ) ?></label>
69 <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); ?>" />
70 </p>
71
72 <p>
73 <label for="<?php echo esc_attr($this->get_field_id('post_list')); ?>"><?php echo('Select a Post'); ?></label><br />
74 <select id="<?php echo esc_attr($this->get_field_id('post_list')); ?>" name="<?php echo esc_attr($this->get_field_name('post_list')); ?>">
75 <?php
76 foreach ( $posts as $post) {
77 $selected = $post_list == $post['slug'] ? ' selected="selected"' : '';
78 echo '<option' . esc_attr($selected) . ' value="' . esc_attr($post['slug']) . '">' . esc_attr($post['name']) . '</option>';
79 }
80 ?>
81 </select>
82 </p>
83
84 <p>
85 <label for="<?php echo esc_attr($this->get_field_id('add_class')); ?>"><?php echo('Additional Classes to Wrap Posts (optional):' ) ?></label>
86 <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); ?>" />
87 </p>
88 <?php
89 }
90 }
91
92
93 add_action("widgets_init", "wvrx_sp_load_widgets");
94
95
96 function wvrx_sp_load_widgets() {
97 register_widget("WeaverSP_Widget_Text");
98 }