1 | <?php
|
---|
2 |
|
---|
3 | $settings = array(
|
---|
4 | 'youtube' => 'H5h95s0OuEg',
|
---|
5 | "gravatar"=>"enabled",
|
---|
6 | "gravatar_fallback"=>"identicon",
|
---|
7 | );
|
---|
8 |
|
---|
9 | # Settings
|
---|
10 |
|
---|
11 | $themename = "SlickPress Theme";
|
---|
12 | $shortname = "slickpress";
|
---|
13 | $options = array (
|
---|
14 |
|
---|
15 | array( "name" => "Main Settings",
|
---|
16 | "type" => "header"
|
---|
17 | ),
|
---|
18 |
|
---|
19 | array( "name" => "Youtube Video ID",
|
---|
20 | "id" => $shortname."_youtube",
|
---|
21 | "std" => $settings['youtube'],
|
---|
22 | "type" => "text",
|
---|
23 | "note" => "<strong>Example: </strong> http://www.youtube.com/watch?v=<strong style='color: #ff0000;'>H5h95s0OuEg</strong>"),
|
---|
24 |
|
---|
25 | array( "name" => "Gravatars",
|
---|
26 | "id" => $shortname."_gravatar",
|
---|
27 | "std" => $settings['gravatar'],
|
---|
28 | "type" => "select",
|
---|
29 | "options" => array(0=>'enabled', 1=>'disabled')),
|
---|
30 |
|
---|
31 | array( "name" => "Gravatar Fallback",
|
---|
32 | "id" => $shortname."_gravatar_fallback",
|
---|
33 | "std" => $settings['gravatar_fallback'],
|
---|
34 | "type" => "text",
|
---|
35 | "note" => "<strong>Example: </strong> monsterid, identicon, etc."),
|
---|
36 |
|
---|
37 | );
|
---|
38 |
|
---|
39 | function mytheme_add_admin() {
|
---|
40 |
|
---|
41 | global $themename, $shortname, $options;
|
---|
42 |
|
---|
43 | if ( $_GET['page'] == basename(__FILE__) ) {
|
---|
44 |
|
---|
45 | if ( 'save' == $_REQUEST['action'] ) {
|
---|
46 |
|
---|
47 | foreach ($options as $value) {
|
---|
48 | if ($value['type']!='header') {
|
---|
49 | update_option( $value['id'], $_REQUEST[ $value['id'] ] );
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | foreach ($options as $value) {
|
---|
54 | if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
|
---|
55 |
|
---|
56 | header("Location: themes.php?page=settings.php&saved=true");
|
---|
57 | die;
|
---|
58 |
|
---|
59 | } else if( 'reset' == $_REQUEST['action'] ) {
|
---|
60 |
|
---|
61 | foreach ($options as $value) {
|
---|
62 | delete_option( $value['id'] ); }
|
---|
63 |
|
---|
64 | header("Location: themes.php?page=settings.php&reset=true");
|
---|
65 | die;
|
---|
66 |
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | add_theme_page($themename." Settings", "Theme Settings", 'edit_themes', basename(__FILE__), 'mytheme_admin');
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
74 | function mytheme_admin() {
|
---|
75 |
|
---|
76 | global $themename, $shortname, $options;
|
---|
77 |
|
---|
78 | if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
|
---|
79 | if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
|
---|
80 |
|
---|
81 | ?>
|
---|
82 | <style type="text/css">
|
---|
83 | th {
|
---|
84 | text-align: left;
|
---|
85 | }
|
---|
86 | td {
|
---|
87 | padding: 5px 10px !important;
|
---|
88 | }
|
---|
89 | tr.header {
|
---|
90 | background-color: #99CC66 !important;
|
---|
91 | color: #ffffff;
|
---|
92 | }
|
---|
93 | .header td {
|
---|
94 | padding: 2px 10px !important;
|
---|
95 | font-size: 14px !important;
|
---|
96 | font-weight: bold !important;
|
---|
97 | }
|
---|
98 | </style>
|
---|
99 | <div class="wrap">
|
---|
100 | <h2><?php echo $themename; ?> Settings</h2>
|
---|
101 |
|
---|
102 | <form method="post">
|
---|
103 |
|
---|
104 | <table class="form-table">
|
---|
105 |
|
---|
106 | <?php foreach ($options as $value) {
|
---|
107 |
|
---|
108 | if ($value['type'] == "text") { ?>
|
---|
109 |
|
---|
110 | <tr>
|
---|
111 | <th scope="row" style="width: 25%"><?php echo $value['name']; ?>:</th>
|
---|
112 | <td>
|
---|
113 | <input onfocus="this.select();" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" />
|
---|
114 | <?php echo $value['note']; ?>
|
---|
115 | </td>
|
---|
116 | </tr>
|
---|
117 |
|
---|
118 | <?php } elseif ($value['type'] == "select") { ?>
|
---|
119 |
|
---|
120 | <tr>
|
---|
121 | <th scope="row"><?php echo $value['name']; ?>:</th>
|
---|
122 | <td>
|
---|
123 | <select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
|
---|
124 | <?php foreach ($value['options'] as $option) { ?>
|
---|
125 | <option value="<?php echo $option; ?>" <?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option>
|
---|
126 | <?php } ?>
|
---|
127 | </select>
|
---|
128 | <?php echo $value['note']; ?>
|
---|
129 | </td>
|
---|
130 | </tr>
|
---|
131 |
|
---|
132 | <?php
|
---|
133 | } elseif ($value['type'] == "header") {?>
|
---|
134 |
|
---|
135 | <tr class="header"><td colspan="2"><?php echo $value['name'] ?> <span style="font-size: 11px; font-weight: normal;"><?php echo $value['note']; ?></span></td></tr>
|
---|
136 |
|
---|
137 | <?php
|
---|
138 | }
|
---|
139 | }
|
---|
140 | ?>
|
---|
141 |
|
---|
142 | </table>
|
---|
143 |
|
---|
144 | <p class="submit">
|
---|
145 | <input name="save" type="submit" value="Save changes" />
|
---|
146 | <input type="hidden" name="action" value="save" />
|
---|
147 | </p>
|
---|
148 | </form>
|
---|
149 | <form method="post">
|
---|
150 | <p class="submit" style="border: 0;">
|
---|
151 | <input name="reset" type="submit" value="Reset" />
|
---|
152 | <input type="hidden" name="action" value="reset" />
|
---|
153 | </p>
|
---|
154 | </form>
|
---|
155 |
|
---|
156 | <?php
|
---|
157 | }
|
---|
158 |
|
---|
159 | add_action('admin_menu', 'mytheme_add_admin');
|
---|
160 |
|
---|
161 | foreach ($options as $value) {
|
---|
162 | if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } }
|
---|
163 |
|
---|
164 |
|
---|
165 | # Set Values
|
---|
166 | foreach ($settings as $k=>$v) {
|
---|
167 | $var = $shortname.'_'.$k;
|
---|
168 | if (!empty($$var)) $settings[$k] = $$var;
|
---|
169 | }
|
---|
170 |
|
---|
171 | ?>
|
---|