-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-usage.php
61 lines (49 loc) · 1.5 KB
/
example-usage.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Example usage of the Automagic Widgets class.
*
* This shows you how you can implement Automagic Widgets
*
*/
require( "SI_Automagic_Widgets.class.php" );
class My_Theme_Sidebars {
function __construct() {
# Add widgets automagically on theme activate
add_action( "after_switch_theme", array( &$this, "register_widgets" ) );
}
function register_widgets( $theme_name ) {
# Check if it is indeed our theme we're activating, and if we haven't
# added the widgets before
if ( 'My_Theme_Name' == get_current_theme() && false == get_option( "my_theme_automagic_widgets_added" ) ) {
# Check if Automated Widgets class exists
if( class_exists( "SI_Automagic_Widgets" ) ) {
# Initiate the class
$auto_widgets = new SI_Automagic_Widgets;
# Add your widgets.
# Note that you should to have these sidebars registered by now.
$auto_widgets->add_widgets(
array(
# Add a text widget to my homepage sidebar
array(
"sidebar" => "homepage_sidebar",
"widget" => "text",
"args" => array( "title" => "My text widget", "text" => "Lorem ipsum dolor sit amet." )
),
# Add a text widget to my blog sidebar
array(
"sidebar" => "blog_sidebar",
"widget" => "search",
"args" => array( "title" => "Search blog" )
)
# Etc...
)
);
# Note this action for the future
update_option( "my_theme_automagic_widgets_added", 1 );
}
}
}
}
# Initiate the class
new My_Theme_Sidebars;
?>