Created
December 22, 2014 05:16
-
-
Save designbuildtest/8d77c02c54b1ebf2b2cb to your computer and use it in GitHub Desktop.
Modular Custom CSS reloaded
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
| /** | |
| * Enable Administrators to add a Custom CSS Control to the Customiser. | |
| */ | |
| function onehundred_enable_custom_css() { | |
| if ( current_user_can('create_users') ) { | |
| function onehundred_enable_custom_css_option() { | |
| register_setting('general', 'onehundred_enable_custom_css', 'wp_filter_nohtml_kses'); | |
| add_settings_field('onehundred_enable_custom_css', __('Enable Custom CSS?', 'onehundred') , 'onehundred_enable_custom_css_form', 'general'); | |
| } | |
| add_filter('admin_init', 'onehundred_enable_custom_css_option'); | |
| function onehundred_enable_custom_css_form() { | |
| $access = get_option('onehundred_enable_custom_css', 'no'); | |
| $current_theme = wp_get_theme(); | |
| $current_theme = $current_theme->stylesheet; | |
| ?> | |
| <select id="onehundred_enable_custom_css" name="onehundred_enable_custom_css" value="<?php echo $access; ?>"> | |
| <option value="no" <?php selected('no' == $access); ?>><?php _e('No', 'onehundred'); ?></option> | |
| <option value="yes" <?php selected('yes' == $access); ?>><?php _e('Yes', 'onehundred'); ?></option> | |
| </select> | |
| <p class="description"><?php _e('<strong>Advanced Users Only.</strong> If Custom CSS support is enabled, a new control will be added to the', 'onehundred'); ?> | |
| <a href="<?php echo admin_url(); ?>customize.php?theme=<?php echo $current_theme; ?>"><?php _e('Customizer.', 'onehundred'); ?></a></p><?php | |
| } | |
| $access = get_option('onehundred_enable_custom_css', 'no'); | |
| if ( $access == 'yes' ) { | |
| function onehundred_custom_css_customize_register($wp_customize) { | |
| $wp_customize->add_section('custom_theme_css', array( | |
| 'title' => __('Custom CSS', 'onehundred'), | |
| 'priority' => 105, | |
| ) ); | |
| $wp_customize->add_setting('custom_theme_css' , array( | |
| 'transport' => 'postMessage', | |
| 'sanitize_callback' => 'onehundred_sanitize_text_input', | |
| ) ); | |
| $wp_customize->add_control('custom_theme_css', array( | |
| 'section' => 'custom_theme_css', | |
| 'type' => 'textarea', | |
| ) ); | |
| } | |
| add_action('customize_register','onehundred_custom_css_customize_register'); | |
| } | |
| } | |
| function onehundred_custom_css_wp_head() { | |
| $custom_theme_css = get_theme_mod('custom_theme_css', ''); | |
| echo '<style type="text/css" id="custom-theme-css">' . $custom_theme_css . '</style>'; | |
| } | |
| add_action('wp_head', 'onehundred_custom_css_wp_head'); | |
| } | |
| add_action('init', 'onehundred_enable_custom_css'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment