'abedul_templates',
'description' => __('Use this widget to show one or more of your templates','abedul'),
);
parent::__construct( 'abedul_templates', __('Abedul Templates', 'abedul'), $widget_ops );
}
/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
// outputs the content of the widget
echo $args['before_widget'];
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
echo '
'.$title.'
';
if (!empty($instance['templates']['author'])){
get_template_part('template-parts/section', 'author');
}
if (!empty($instance['templates']['category'])){
get_template_part('template-parts/section', 'category');
}
if (!empty($instance['templates']['category_small'])){
get_template_part('template-parts/section', 'category-small');
}
if (!empty($instance['templates']['small_formats'])){
get_template_part('template-parts/section', 'small-formats');
}
if (!empty($instance['templates']['latest'])){
get_template_part('template-parts/section', 'latest');
}
if (!empty($instance['templates']['featured_content'])){
get_template_part('template-parts/section', 'featured-content');
}
echo $args['after_widget'];
}
/**
* Deal with the settings when they are saved by the admin.
*
* Here is where any validation should happen.
*
* @since Abedul 1.0
*
* @param array $new_instance New widget instance.
* @param array $instance Original widget instance.
* @return array Updated widget instance.
*/
public function update( $new_instance, $instance ) {
$instance['title'] = strip_tags( $new_instance['title'] );
foreach ($this->templates as $key => $value) {
$instance['templates'][$value] = !empty($new_instance['templates'][$value]) ? 1 : 0;
}
return $instance;
}
/**
* Display the form for this widget on the Widgets page of the Admin area.
*
* @since Abedul 1.0
*
* @param array $instance The widget options
*/
public function form( $instance ) {
foreach ($this->templates as $slug) {
$templates[$slug] = false;
}
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'templates' => $templates ));
$title = empty($instance['title'])? '' : esc_attr( $instance['title']);
foreach ($this->templates as $key => $value) {
$value = isset($instance['templates'][$value]) ? (bool) $instance['templates'][$value] :false;
} ?>