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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
<?php /** * SMOF Admin * * @package WordPress * @subpackage SMOF * @since 1.4.0 * @author Syamil MJ */
/** * Head Hook * * @since 1.0.0 */ function of_head() { do_action( 'of_head' ); }
/** * Add default options upon activation else DB does not exist * * DEPRECATED, Class_options_machine now does this on load to ensure all values are set * * @since 1.0.0 */ function of_option_setup() { global $of_options, $options_machine; $options_machine = new Options_Machine($of_options); if (!of_get_options()) { of_save_options($options_machine->Defaults); } }
/** * Change activation message * * @since 1.0.0 */ function optionsframework_admin_message() { //Tweaked the message on theme activate ?> <script type="text/javascript"> jQuery(function(){ var message = '<p>This theme comes with an <a href="<?php echo admin_url('admin.php?page=optionsframework'); ?>">options panel</a> to configure settings. This theme also supports widgets, please visit the <a href="<?php echo admin_url('widgets.php'); ?>">widgets settings page</a> to configure them.</p>'; jQuery('.themes-php #message2').html(message); }); </script> <?php }
/** * Get header classes * * @since 1.0.0 */ function of_get_header_classes_array() { global $of_options; foreach ($of_options as $value) { if ($value['type'] == 'heading') $hooks[] = str_replace(' ','',strtolower($value['name'])); } return $hooks; }
/** * Get options from the database and process them with the load filter hook. * * @author Jonah Dahlquist * @since 1.4.0 * @return array */ function of_get_options($key = null, $data = null) { global $smof_data;
do_action('of_get_options_before', array( 'key'=>$key, 'data'=>$data )); if ($key != null) { // Get one specific value $data = get_theme_mod($key, $data); } else { // Get all values $data = get_theme_mods(); } $data = apply_filters('of_options_after_load', $data); if ($key == null) { $smof_data = $data; } else { $smof_data[$key] = $data; } do_action('of_option_setup_before', array( 'key'=>$key, 'data'=>$data )); return $data;
}
/** * Save options to the database after processing them * * @param $data Options array to save * @author Jonah Dahlquist * @since 1.4.0 * @uses update_option() * @return void */
function of_save_options($data, $key = null) { global $smof_data; if (empty($data)) return; do_action('of_save_options_before', array( 'key'=>$key, 'data'=>$data )); $data = apply_filters('of_options_before_save', $data); if ($key != null) { // Update one specific value if ($key == BACKUPS) { unset($data['smof_init']); // Don't want to change this. } set_theme_mod($key, $data); } else { // Update all values in $data foreach ( $data as $k=>$v ) { if (!isset($smof_data[$k]) || $smof_data[$k] != $v) { // Only write to the DB when we need to set_theme_mod($k, $v); } else if (is_array($v)) { foreach ($v as $key=>$val) { if ($key != $k && $v[$key] == $val) { set_theme_mod($k, $v); break; } } } } }
do_action('of_save_options_after', array( 'key'=>$key, 'data'=>$data ));
}
/** * For use in themes * * @since forever */
$data = of_get_options(); if (!isset($smof_details)) $smof_details = array();
|