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