Created
September 26, 2013 13:36
-
-
Save enapupe/6714284 to your computer and use it in GitHub Desktop.
functions.
This file contains 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 | |
ob_settings_config { | |
var $group = "enapupe"; // defines setting groups (should be bespoke to your settings) | |
var $page_name = "enapupe"; // defines which pages settings will appear on. Either bespoke or media/discussion/reading etc | |
var $title = "Detrick"; // page title that is displayed | |
var $nav_title = "Detrick"; // how page is listed on left-hand Settings panel | |
var $sections = array( | |
'main' => array( | |
'title' => "Geral", | |
'fields' => array ( | |
// 'telefone_ddd' => array( | |
// 'label' => "DDD Telefone" | |
// ), | |
// 'telefone' => array( | |
// 'label' => "Telefone" | |
// ), | |
// 'logradouro' => array( | |
// 'label' => "Logradouro" | |
// ), | |
// 'cidade' => array( | |
// 'label' => "Cidade - Estado - País" | |
// ), | |
// 'cep' => array( | |
// 'label' => "CEP" | |
// ), | |
'social_facebook' => array ( | |
'label' => "Página do facebook", | |
'description' => "http://", | |
'length' => "200" | |
), | |
'social_twitter' => array ( | |
'label' => "URL do Twitter", | |
'description' => "http://", | |
'length' => "200" | |
), | |
'social_instagram' => array ( | |
'label' => "URL do Instagram", | |
'description' => "http://", | |
'length' => "200" | |
), | |
'analytics' => array ( | |
'label' => "Código ID Analytics", | |
'description' => "UA-XXXXXXXXXXX", | |
'length' => "20" | |
), | |
'email_contato' => array ( | |
'label' => "E-mail destino do formulário do contato", | |
'description' => "xxx@bbb.aa", | |
'length' => "200" | |
), | |
'coordenada_mapa' => array ( | |
'label' => "Coordenadas do centro do mapa do contato", | |
'description' => "lat,long", | |
'length' => "30" | |
), | |
'coordenada_marcador' => array ( | |
'label' => "Coordenadas do marcador do endereço", | |
'description' => "lat,long", | |
'length' => "30" | |
), | |
'zoom_mapa' => array ( | |
'label' => "Zoom inicial mapa do contato", | |
'length' => "2" | |
), | |
) | |
) | |
); | |
var $dropdown_options = array ('dd_colour' => array ( | |
'#f00' => "Red", | |
'#0f0' => "Green", | |
'#00f' => "Blue", | |
'#fff' => "White", | |
'#000' => "Black", | |
'#aaa' => "Gray") ); | |
// end class | |
}; | |
class ob_settings { | |
function ob_settings($settings_class) { | |
global $ob_settings; | |
$ob_settings = get_class_vars($settings_class); | |
if (function_exists('add_action')) : | |
add_action('admin_init', array(&$this, 'plugin_admin_init')); | |
add_action('admin_menu', array(&$this, 'plugin_admin_add_page')); | |
endif; | |
} | |
function plugin_admin_add_page() { | |
global $ob_settings; | |
add_options_page($ob_settings['title'], $ob_settings['nav_title'], 'publish_posts', 'enapupe', array(&$this, 'plugin_options_page')); | |
} | |
function plugin_options_page() { | |
global $ob_settings; | |
printf('</pre> | |
<div> | |
<h2>%s</h2> | |
%s | |
<form action="options.php" method="post">', $ob_settings['title'], $ob_settings['intro_text']); | |
settings_fields($ob_settings['group']); | |
do_settings_sections($ob_settings['page_name']); | |
printf('<input type="submit" name="Submit" value="%s" /></form></div> | |
<pre> | |
', __('Save Changes')); | |
} | |
function plugin_admin_init() { | |
global $ob_settings; | |
foreach ($ob_settings["sections"] AS $section_key => $section_value) : | |
add_settings_section($section_key, $section_value['title'], array(&$this, 'plugin_section_text'), $ob_settings['page_name'], $section_value); | |
foreach ($section_value['fields'] AS $field_key => $field_value) : | |
$function = (!empty($field_value['dropdown'])) ? array(&$this, 'plugin_setting_dropdown') : array(&$this, 'plugin_setting_string'); | |
$function = (!empty($field_value['function'])) ? $field_value['function'] : $function; | |
$callback = (!empty($field_value['callback'])) ? $field_value['callback'] : NULL; | |
add_settings_field($ob_settings['group'] . '_' . $field_key, $field_value['label'], $function, $ob_settings['page_name'], $section_key, array_merge($field_value, array('name' => $ob_settings['group'] . '_' . $field_key))); | |
register_setting($ob_settings['group'], $ob_settings['group'] . '_' . $field_key, $callback); | |
endforeach; | |
endforeach; | |
} | |
function plugin_section_text($value = NULL) { | |
global $ob_settings; | |
printf(" | |
%s | |
", $ob_settings['sections'][$value['id']]['description']); | |
} | |
function plugin_setting_string($value = NULL) { | |
$options = get_option($value['name']); | |
$default_value = (!empty($value['default_value'])) ? $value['default_value'] : NULL; | |
printf('<input id="%s" type="text" name="%1$s[text_string]" value="%2$s" size="40" /> %3$s%4$s', $value['name'], (!empty($options['text_string'])) ? $options['text_string'] : $default_value, (!empty($value['suffix'])) ? $value['suffix'] : NULL, (!empty($value['description'])) ? sprintf("<em>%s</em>", $value['description']) : NULL); | |
} | |
function plugin_setting_dropdown($value = NULL) { | |
global $ob_settings; | |
$options = get_option($value['name']); | |
$default_value = (!empty($value['default_value'])) ? $value['default_value'] : NULL; | |
$current_value = ($options['text_string']) ? $options['text_string'] : $default_value; | |
$chooseFrom = ""; | |
$choices = $ob_settings['dropdown_options'][$value['dropdown']]; | |
foreach ($choices AS $key => $option) : | |
$chooseFrom .= sprintf('<option value="%s" %s>%s</option>', $key, ($current_value == $key ) ? ' selected="selected"' : NULL, $option); | |
endforeach; | |
printf(' | |
<select id="%s" name="%1$s[text_string]">%2$s</select> | |
%3$s', $value['name'], $chooseFrom, (!empty($value['description'])) ? sprintf("<em>%s</em>", $value['description']) : NULL); | |
} | |
//end class | |
} | |
$ob_settings_init = new ob_settings('ob_settings_config'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment