| 1 |
<?php |
| 2 |
/* |
| 3 |
* Weaver X Widgets and shortcodes - widgets |
| 4 |
*/ |
| 5 |
|
| 6 |
class WeaverSP_Widget_Text extends WP_Widget { |
| 7 |
|
| 8 |
function __construct() { |
| 9 |
$widget_ops = array('classname' => 'WeaverSS_Widget_Slider', |
| 10 |
'description' => esc_html__('Show Posts in a widget','show-posts' /*adm*/)); |
| 11 |
$control_ops = array('width' => 400, 'height' => 350); |
| 12 |
parent::__construct('wvr_showposts', esc_html__('Weaver Show Posts','show-posts' /*adm*/), $widget_ops, $control_ops); |
| 13 |
} |
| 14 |
|
| 15 |
function widget($args, $instance) { |
| 16 |
// Get menu |
| 17 |
|
| 18 |
$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
| 19 |
|
| 20 |
$post_list = $instance['post_list']; |
| 21 |
if (!$post_list) $post_list = 'default'; |
| 22 |
|
| 23 |
$add_class = $instance['add_class']; |
| 24 |
if (!$add_class) $add_class =''; |
| 25 |
|
| 26 |
|
| 27 |
echo $args['before_widget']; |
| 28 |
|
| 29 |
if ( !empty($instance['title']) ) |
| 30 |
echo $args['before_title'] . $instance['title'] . $args['after_title']; |
| 31 |
|
| 32 |
$before = $add_class ? "<div class='{$add_class}'>" : ''; |
| 33 |
$after = $add_class ? "</div>" : ''; |
| 34 |
|
| 35 |
require_once(dirname( __FILE__ ) . '/atw-showposts-sc.php'); |
| 36 |
|
| 37 |
echo $before . atw_show_posts_shortcode( array('filter' => $post_list) ) . $after; |
| 38 |
|
| 39 |
echo $args['after_widget']; |
| 40 |
} |
| 41 |
|
| 42 |
function update( $new_instance, $old_instance ) { |
| 43 |
$instance['title'] = strip_tags( stripslashes($new_instance['title']) ); |
| 44 |
$instance['post_list'] = $new_instance['post_list']; |
| 45 |
$instance['add_class'] = strip_tags( stripslashes($new_instance['add_class']) ); |
| 46 |
return $instance; |
| 47 |
} |
| 48 |
|
| 49 |
function form( $instance ) { |
| 50 |
$title = isset( $instance['title'] ) ? $instance['title'] : ''; |
| 51 |
$post_list = isset( $instance['post_list'] ) ? $instance['post_list'] : 'default'; |
| 52 |
$add_class = isset( $instance['add_class'] ) ? $instance['add_class'] : ''; |
| 53 |
|
| 54 |
|
| 55 |
// Get posts |
| 56 |
|
| 57 |
$posts = atw_posts_getopt('filters'); |
| 58 |
|
| 59 |
|
| 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 $this->get_field_id('title'); ?>"><?php echo('Title (optional):' /*a*/ ) ?></label> |
| 69 |
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_textarea($title); ?>" /> |
| 70 |
</p> |
| 71 |
|
| 72 |
<p> |
| 73 |
<label for="<?php echo $this->get_field_id('post_list'); ?>"><?php echo('Select a Post'); ?></label><br /> |
| 74 |
<select id="<?php echo $this->get_field_id('post_list'); ?>" name="<?php echo $this->get_field_name('post_list'); ?>"> |
| 75 |
<?php |
| 76 |
foreach ( $posts as $post) { |
| 77 |
$selected = $post_list == $post['slug'] ? ' selected="selected"' : ''; |
| 78 |
echo '<option'. $selected .' value="' . $post['slug'] .'">'. $post['name'] .'</option>'; |
| 79 |
} |
| 80 |
?> |
| 81 |
</select> |
| 82 |
</p> |
| 83 |
|
| 84 |
<p> |
| 85 |
<label for="<?php echo $this->get_field_id('add_class'); ?>"><?php echo('Additional Classes to Wrap Posts (optional):' ) ?></label> |
| 86 |
<input type="text" class="widefat" id="<?php echo $this->get_field_id('add_class'); ?>" name="<?php echo $this->get_field_name('add_class'); ?>" value="<?php echo esc_textarea($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 |
} |
| 99 |
|