Files
sage/inc/roots-options.php
Corey Wagehoft d045e1be56 Updating Bootstrap to v.2.0.0
roots-actions.php:  added responsive css framework file
roots-options.php: changed default css classes for bootstrap v2.0.0
roots-scripts.php: updated less to v1.2.1, changed the load order and
added new scripts for bootstrap v2.0.0

Added all of the new css, js, less asset files and updated all of the
previous ones for bootstrap v2.0.0
2012-02-01 10:18:39 -06:00

442 lines
16 KiB
PHP

<?php
function roots_admin_enqueue_scripts($hook_suffix) {
if ($hook_suffix !== 'appearance_page_theme_options')
return;
wp_enqueue_style('roots-theme-options', get_template_directory_uri() . '/inc/css/theme-options.css');
wp_enqueue_script('roots-theme-options', get_template_directory_uri() . '/inc/js/theme-options.js');
}
add_action('admin_enqueue_scripts', 'roots_admin_enqueue_scripts');
function roots_theme_options_init() {
if (false === roots_get_theme_options())
add_option('roots_theme_options', roots_get_default_theme_options());
register_setting(
'roots_options',
'roots_theme_options',
'roots_theme_options_validate'
);
}
add_action('admin_init', 'roots_theme_options_init');
function roots_option_page_capability($capability) {
return 'edit_theme_options';
}
add_filter('option_page_capability_roots_options', 'roots_option_page_capability');
function roots_theme_options_add_page() {
$roots_options = roots_get_theme_options();
$roots_activation_options = roots_get_theme_activation_options();
if ($roots_activation_options['first_run']) {
$theme_page = add_theme_page(
__('Theme Options', 'roots'),
__('Theme Options', 'roots'),
'edit_theme_options',
'theme_options',
'roots_theme_options_render_page'
);
}
}
add_action('admin_menu', 'roots_theme_options_add_page');
function roots_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->add_menu(array(
'parent' => 'appearance',
'id' => 'theme_options',
'title' => __('Theme Options', 'roots'),
'href' => admin_url('themes.php?page=theme_options')
));
}
add_action('wp_before_admin_bar_render', 'roots_admin_bar_render');
global $roots_css_frameworks;
$roots_css_frameworks = array(
'blueprint' => array(
'name' => 'blueprint',
'label' => __('Blueprint CSS', 'roots'),
'classes' => array(
'container' => 'span-24',
'main' => 'span-14 append-1',
'sidebar' => 'span-8 prepend-1 last',
'fullwidth' => 'span-24'
)
),
'960gs_12' => array(
'name' => '960gs_12',
'label' => __('960gs (12 cols)', 'roots'),
'classes' => array(
'container' => 'container_12',
'main' => 'grid_7 suffix_1',
'sidebar' => 'grid_4',
'fullwidth' => 'grid_12'
)
),
'960gs_16' => array(
'name' => '960gs_16',
'label' => __('960gs (16 cols)', 'roots'),
'classes' => array(
'container' => 'container_16',
'main' => 'grid_9 suffix_1',
'sidebar' => 'grid_6',
'fullwidth' => 'grid_16'
)
),
'960gs_24' => array(
'name' => '960gs_24',
'label' => __('960gs (24 cols)', 'roots'),
'classes' => array(
'container' => 'container_24',
'main' => 'grid_15 suffix_1',
'sidebar' => 'grid_8',
'fullwidth' => 'grid_24'
)
),
'1140' => array(
'name' => '1140',
'label' => __('1140', 'roots'),
'classes' => array(
'container' => 'row',
'main' => 'eightcol',
'sidebar' => 'fourcol last',
'fullwidth' => 'twelvecol'
)
),
'adapt' => array(
'name' => 'adapt',
'label' => __('Adapt.js', 'roots'),
'classes' => array(
'container' => 'container_12 clearfix',
'main' => 'grid_7 suffix_1',
'sidebar' => 'grid_4',
'fullwidth' => 'grid_12'
)
),
'less' => array(
'name' => 'less',
'label' => __('Less Framework 4', 'roots'),
'classes' => array(
'container' => 'container',
'main' => '',
'sidebar' => '',
'fullwidth' => ''
)
),
'foundation' => array(
'name' => 'foundation',
'label' => __('Foundation', 'roots'),
'classes' => array(
'container' => 'row',
'main' => 'eight columns',
'sidebar' => 'four columns',
'fullwidth' => 'twelve columns'
)
),
'bootstrap' => array(
'name' => 'bootstrap',
'label' => __('Bootstrap', 'roots'),
'classes' => array(
'container' => 'row',
'main' => 'span9',
'sidebar' => 'span3',
'fullwidth' => 'span12'
)
),
'bootstrap_less' => array(
'name' => 'bootstrap_less',
'label' => __('Bootstrap w/ Less', 'roots'),
'classes' => array(
'container' => 'row',
'main' => 'span9',
'sidebar' => 'span3',
'fullwidth' => 'span12'
)
),
'none' => array(
'name' => 'none',
'label' => __('None', 'roots'),
'classes' => array(
'container' => '',
'main' => '',
'sidebar' => '',
'fullwidth' => ''
)
)
);
// Write the above array of CSS frameworks into a script tag
function roots_add_frameworks_object_script() {
global $roots_css_frameworks;
$json = json_encode($roots_css_frameworks);
?>
<script>
var roots_css_frameworks = <?php echo $json; ?>;
</script>
<?php
}
add_action('admin_head', 'roots_add_frameworks_object_script');
function roots_get_default_theme_options($default_framework = '') {
global $roots_css_frameworks;
if ($default_framework == '') { $default_framework = apply_filters('roots_default_css_framework', 'blueprint'); }
$default_framework_settings = $roots_css_frameworks[$default_framework];
$default_theme_options = array(
'css_framework' => $default_framework,
'container_class' => $default_framework_settings['classes']['container'],
'main_class' => $default_framework_settings['classes']['main'],
'sidebar_class' => $default_framework_settings['classes']['sidebar'],
'fullwidth_class' => $default_framework_settings['classes']['fullwidth'],
'google_analytics_id' => '',
'root_relative_urls' => true,
'clean_menu' => true,
'bootstrap_javascript' => false,
'bootstrap_less_javascript' => false,
);
return apply_filters('roots_default_theme_options', $default_theme_options);
}
function roots_get_theme_options() {
return get_option('roots_theme_options', roots_get_default_theme_options());
}
function roots_theme_options_render_page() {
global $roots_css_frameworks;
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php printf(__('%s Theme Options', 'roots'), get_current_theme()); ?></h2>
<?php settings_errors(); ?>
<form method="post" action="options.php">
<?php
settings_fields('roots_options');
$roots_options = roots_get_theme_options();
$roots_default_options = roots_get_default_theme_options($roots_options['css_framework']);
?>
<input type="hidden" value="1" name="roots_theme_options[first_run]" />
<table class="form-table">
<tr valign="top" class="radio-option"><th scope="row"><?php _e('CSS Grid Framework', 'roots'); ?></th>
<td>
<fieldset class="roots_css_frameworks"><legend class="screen-reader-text"><span><?php _e('CSS Grid Framework', 'roots'); ?></span></legend>
<select name="roots_theme_options[css_framework]" id="roots_theme_options[css_framework]">
<?php foreach ($roots_css_frameworks as $css_framework) { ?>
<option value="<?php echo esc_attr($css_framework['name']); ?>" <?php selected($roots_options['css_framework'], $css_framework['name']); ?>><?php echo $css_framework['label']; ?></option>
<?php } ?>
</select>
</fieldset>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('#main CSS Classes', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('#main CSS Classes', 'roots'); ?></span></legend>
<input type="text" name="roots_theme_options[main_class]" id="main_class" value="<?php echo esc_attr($roots_options['main_class']); ?>" class="regular-text" />
<br />
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['main_class']; ?></span></small>
</fieldset>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('#sidebar CSS Classes', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('#sidebar CSS Classes', 'roots'); ?></span></legend>
<input type="text" name="roots_theme_options[sidebar_class]" id="sidebar_class" value="<?php echo esc_attr($roots_options['sidebar_class']); ?>" class="regular-text" />
<br />
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['sidebar_class']; ?></span></small>
</fieldset>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Full Width CSS Classes', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('#fullwidth CSS Classes', 'roots'); ?></span></legend>
<input type="text" name="roots_theme_options[fullwidth_class]" id="fullwidth_class" value="<?php echo esc_attr($roots_options['fullwidth_class']); ?>" class="regular-text" />
<br />
<small class="description"><?php _e('Default:', 'roots'); ?> <span><?php echo $roots_default_options['fullwidth_class']; ?></span></small>
</fieldset>
</td>
</tr>
<?php if($roots_options['css_framework'] == 'bootstrap') { ?>
<tr valign="top"><th scope="row"><?php _e('Bootstrap Javascript Packages', 'roots'); ?></th>
<td>
<fieldset class="roots_bootstrap_js"><legend class="screen-reader-text"><span><?php _e('Enable Bootstrap Javascript', 'roots'); ?></span></legend>
<select name="roots_theme_options[bootstrap_javascript]" id="roots_theme_options[bootstrap_javascript]">
<option value="yes" <?php selected($roots_options['bootstrap_javascript'], true); ?>><?php echo _e('Yes', 'roots'); ?></option>
<option value="no" <?php selected($roots_options['bootstrap_javascript'], false); ?>><?php echo _e('No', 'roots'); ?></option>
</select>
</fieldset>
</td>
</tr>
<?php } ?>
<?php if($roots_options['css_framework'] == 'bootstrap_less') { ?>
<tr valign="top"><th scope="row"><?php _e('Bootstrap Javascript Packages', 'roots'); ?></th>
<td>
<fieldset class="roots_bootstrap_js"><legend class="screen-reader-text"><span><?php _e('Enable Bootstrap Javascript', 'roots'); ?></span></legend>
<select name="roots_theme_options[bootstrap_less_javascript]" id="roots_theme_options[bootstrap_less_javascript]">
<option value="yes" <?php selected($roots_options['bootstrap_less_javascript'], true); ?>><?php echo _e('Yes', 'roots'); ?></option>
<option value="no" <?php selected($roots_options['bootstrap_less_javascript'], false); ?>><?php echo _e('No', 'roots'); ?></option>
</select>
</fieldset>
</td>
</tr>
<?php } ?>
<tr valign="top"><th scope="row"><?php _e('Google Analytics ID', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('Google Analytics ID', 'roots'); ?></span></legend>
<input type="text" name="roots_theme_options[google_analytics_id]" id="google_analytics_id" value="<?php echo esc_attr($roots_options['google_analytics_id']); ?>" />
<br />
<small class="description"><?php printf(__('Enter your UA-XXXXX-X ID', 'roots')); ?></small>
</fieldset>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Enable Root Relative URLs', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('Enable Root Relative URLs', 'roots'); ?></span></legend>
<select name="roots_theme_options[root_relative_urls]" id="roots_theme_options[root_relative_urls]">
<option value="yes" <?php selected($roots_options['root_relative_urls'], true); ?>><?php echo _e('Yes', 'roots'); ?></option>
<option value="no" <?php selected($roots_options['root_relative_urls'], false); ?>><?php echo _e('No', 'roots'); ?></option>
</select>
</fieldset>
</td>
</tr>
<tr valign="top"><th scope="row"><?php _e('Cleanup Menu Output', 'roots'); ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('Cleanup Menu Output', 'roots'); ?></span></legend>
<select name="roots_theme_options[clean_menu]" id="roots_theme_options[clean_menu]">
<option value="yes" <?php selected($roots_options['clean_menu'], true); ?>><?php echo _e('Yes', 'roots'); ?></option>
<option value="no" <?php selected($roots_options['clean_menu'], false); ?>><?php echo _e('No', 'roots'); ?></option>
</select>
</fieldset>
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
function roots_theme_options_validate($input) {
global $roots_css_frameworks;
$output = $defaults = roots_get_default_theme_options();
if (isset($input['css_framework']) && array_key_exists($input['css_framework'], $roots_css_frameworks))
$output['css_framework'] = $input['css_framework'];
// set the value of the main container class depending on the selected grid framework
$output['container_class'] = $roots_css_frameworks[$output['css_framework']]['classes']['container'];
if (isset($input['main_class'])) {
$output['main_class'] = wp_filter_nohtml_kses($input['main_class']);
}
if (isset($input['sidebar_class'])) {
$output['sidebar_class'] = wp_filter_nohtml_kses($input['sidebar_class']);
}
if (isset($input['fullwidth_class'])) {
$output['fullwidth_class'] = wp_filter_nohtml_kses($input['fullwidth_class']);
}
if (isset($input['google_analytics_id'])) {
if (preg_match('/^ua-\d{4,9}-\d{1,4}$/i', $input['google_analytics_id'])) {
$output['google_analytics_id'] = $input['google_analytics_id'];
}
}
if (isset($input['root_relative_urls'])) {
if ($input['root_relative_urls'] === 'yes') {
$input['root_relative_urls'] = true;
}
if ($input['root_relative_urls'] === 'no') {
$input['root_relative_urls'] = false;
}
$output['root_relative_urls'] = $input['root_relative_urls'];
}
if (isset($input['clean_menu'])) {
if ($input['clean_menu'] === 'yes') {
$input['clean_menu'] = true;
}
if ($input['clean_menu'] === 'no') {
$input['clean_menu'] = false;
}
$output['clean_menu'] = $input['clean_menu'];
}
if (isset($input['bootstrap_javascript'])) {
if ($input['bootstrap_javascript'] === 'yes') {
$input['bootstrap_javascript'] = true;
}
if ($input['bootstrap_javascript'] === 'no') {
$input['bootstrap_javascript'] = false;
}
$output['bootstrap_javascript'] = $input['bootstrap_javascript'];
}
if (isset($input['bootstrap_less_javascript'])) {
if ($input['bootstrap_less_javascript'] === 'yes') {
$input['bootstrap_less_javascript'] = true;
}
if ($input['bootstrap_less_javascript'] === 'no') {
$input['bootstrap_less_javascript'] = false;
}
$output['bootstrap_less_javascript'] = $input['bootstrap_less_javascript'];
}
return apply_filters('roots_theme_options_validate', $output, $input, $defaults);
}
function roots_current_framework() {
global $roots_options;
switch ($roots_options['css_framework']) {
case 'blueprint' :
return 'blueprint';
break;
case '960gs_12' :
return '960gs_12';
break;
case '960gs_16' :
return '960gs_16';
break;
case '960gs_24' :
return '960gs_24';
break;
case '1140' :
return '1140';
break;
case 'adapt' :
return 'adapt';
break;
case 'foundation' :
return 'foundation';
break;
case 'less' :
return 'less';
break;
case 'bootstrap' :
return 'bootstrap';
break;
case 'bootstrap_less' :
return 'bootstrap_less';
break;
}
}
?>