Created
July 26, 2013 12:05
-
-
Save sang4lv/6088370 to your computer and use it in GitHub Desktop.
Settings API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //Options Page Configuration | |
| function admin_init_callback() { | |
| register_setting( 'msp_settings', 'msp_duration' ); | |
| add_settings_section( 'msp_settings', __('Multisite Posts Configuration'), false, 'general' ); | |
| add_settings_field( 'msp_duration', __('Cache Duration'), array($this, 'msp_settings_callback'), 'general', 'msp_settings', array( | |
| "id" => "msp_duration", | |
| "type" => "dropdown", | |
| "values"=> array( | |
| array( | |
| "name" => __('Every 6 hours'), | |
| "value" => 60 * 60 * 6, | |
| ), | |
| array( | |
| "name" => __('Every 12 hours'), | |
| "value" => 60 * 60 * 12, | |
| ), | |
| array( | |
| "name" => __('Every 24 hours'), | |
| "value" => 60 * 60 * 24, | |
| ), | |
| array( | |
| "name" => __('Every 48 hours'), | |
| "value" => 60 * 60 * 48, | |
| ), | |
| array( | |
| "name" => __('Every Week'), | |
| "value" => 60 * 60 * 24 * 7, | |
| ), | |
| ) | |
| ) ); | |
| return; | |
| } | |
| function msp_settings_callback($args) { | |
| $value = get_option( $args["id"] ); | |
| if("dropdown" == $args["type"]) { | |
| var_dump($value); | |
| ?> | |
| <select name="<?php echo $args["id"]; ?>"> | |
| <?php | |
| foreach ($args["values"] as $option) { | |
| echo '<option value="' . $option["value"] . '" '; | |
| checked( $value, $option["value"], $echo = true ); | |
| echo '>' . $option["name"] . '</option>'; | |
| } | |
| ?> | |
| </select> | |
| <?php | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment