-
Notifications
You must be signed in to change notification settings - Fork 0
/
wordpress-widget-template
48 lines (33 loc) · 1.16 KB
/
wordpress-widget-template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Widget_Sponsor extends WP_Widget {
public function __construct() {
parent::__construct(
'widget_sponsor', // Base ID
__('Sponsor', 'widget-sponsor'), // Name
array( 'description' => __( 'Display Sponsor', 'widget-sponsor' ), )
);
}
public function widget( $args, $instance ) {
if ( ! isset( $args['widget_id'] ) ) {
$args['widget_id'] = $this->id;
}
// widget ID with prefix for use in ACF API functions
$widget_id = 'widget_' . $args['widget_id'];
//Widget Markup
ob_start();
include(get_template_directory() . '/template-parts/components/widget-sponsor.php' );
$html = ob_get_clean();
echo $html;
}
public function form( $instance ) {
// outputs the options form in the admin
return $instance;
}
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
return $new_instance;
}
}
function register_widget_sponsor() {
register_widget( 'Widget_Sponsor' );
}
add_action( 'widgets_init', 'register_widget_sponsor' );