web/wp-content/themes/malleable/library/admin/theme-settings-admin.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 
       
     3 /**
       
     4 * Returns an array of the theme settings
       
     5 * Add all options to a single array
       
     6 * This makes one entry in the database
       
     7 *
       
     8 * @since 0.1
       
     9 */
       
    10 function malleable_theme_settings() {
       
    11 	$settings_arr = array(
       
    12 		'general_address' => false,
       
    13 		'general_address_street' => false,
       
    14 		'general_address_city' => false,
       
    15 		'general_address_state' => false,
       
    16 		'general_address_zip' => false,
       
    17 		'general_address_phone' => false,
       
    18 				
       
    19 		'feature_category' => false,
       
    20 		'feature_num_posts' => false,
       
    21 		'excerpt_category' => false,
       
    22 		'excerpt_num_posts' => false,
       
    23 		'headlines_category' => array(),
       
    24 		'headlines_num_posts' => false,
       
    25 	);
       
    26 
       
    27 	return apply_filters('malleable_settings_args', $settings_arr);
       
    28 }
       
    29 
       
    30 /**
       
    31 * Handles the theme settings
       
    32 *
       
    33 * @since 0.1
       
    34 */
       
    35 function malleable_theme_page() {
       
    36 
       
    37 	/*
       
    38 	* Variables to be used throughout the settings page
       
    39 	*/
       
    40 	$theme_name = __('Malleable','malleable');
       
    41 	$settings_page_title = __('Malleable Theme Settings','malleable');
       
    42 	$hidden_field_name = 'malleable_submit_hidden';
       
    43 
       
    44 	/*
       
    45 	* Get the theme settings and add them to the database
       
    46 	*/
       
    47 	$settings_arr = malleable_theme_settings();
       
    48 	add_option('malleable_theme_settings', $settings_arr);
       
    49 
       
    50 	/*
       
    51 	* Set form data IDs the same as settings keys
       
    52 	*/
       
    53 	$settings_keys = array_keys($settings_arr);
       
    54 	foreach($settings_keys as $key) :
       
    55 		$data[$key] = $key;
       
    56 	endforeach;
       
    57 
       
    58 	/*
       
    59 	* Get existing options from the database
       
    60 	*/
       
    61 	$settings = get_option('malleable_theme_settings');
       
    62 
       
    63 	foreach($settings_arr as $key => $value) :
       
    64 		$val[$key] = $settings[$key];
       
    65 	endforeach;
       
    66 	
       
    67 	/*
       
    68 	* If the form has been set
       
    69 	* Loop through the values
       
    70 	* Set the option in the database
       
    71 	*/
       
    72 	if($_POST[$hidden_field_name] == 'Y') :
       
    73 
       
    74 		foreach($settings_arr as $key => $value) :
       
    75 			$settings[$key] = $val[$key] = $_POST[$data[$key]];
       
    76 		endforeach;
       
    77 
       
    78 		update_option('malleable_theme_settings', $settings);
       
    79 
       
    80 		/*
       
    81 		* Open main div for the theme settings
       
    82 		*/
       
    83 		echo '<div class="wrap">';
       
    84 		echo '<h2>' . $settings_page_title . '</h2>';
       
    85 		echo '<div class="updated" style="margin:15px 0;">';
       
    86 		echo '<p><strong>' . __('Settings saved.','malleable') . '</strong></p>';
       
    87 		echo '</div>';
       
    88 
       
    89 	else :
       
    90 		echo '<div class="wrap">';
       
    91 		echo '<h2>' . $settings_page_title . '</h2>';
       
    92 
       
    93 	endif;
       
    94 
       
    95 	/*
       
    96 	* Load the theme settings form
       
    97 	*/
       
    98 	include(MALLEABLE . '/library/admin/theme-settings-xhtml.php');
       
    99 }
       
   100 
       
   101 ?>