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