Skip to content

Commit

Permalink
Add: User Color to Options
Browse files Browse the repository at this point in the history
  • Loading branch information
zaher committed Sep 8, 2013
1 parent 6e7c27d commit 4cc2da4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
47 changes: 36 additions & 11 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,33 @@ function metallic_customize_register($wp_customize) {
metallic_add_option($wp_customize, 'show_title', __('Show Title', 'default'));
metallic_add_option($wp_customize, 'gradients', __('Gradients', 'metallic'));
metallic_add_option($wp_customize, 'show_logo', __('Show Logo', 'default'));
metallic_add_option($wp_customize, 'logo_url', __('Logo URL', 'metallic'), 'text');
metallic_add_option($wp_customize, 'logo_url', __('Logo URL', 'metallic'), 'text', '');
// metallic_add_option($wp_customize, 'user_color', __('User Color', 'metallic'), 'colorbox', '');

// =============================
// Select Scheme
// = Color Picker =
// =============================
$wp_customize->add_setting('color_scheme', array(
'default' => 'Gray',
'capability' => 'edit_theme_options',
'type' => 'theme_mod', //or 'option' if u want to have a record in database

$wp_customize->add_setting('user_color', array(
'default' => '',
'sanitize_callback' => 'sanitize_hex_color',
'capability' => 'edit_theme_options',
'type' => 'theme_mod',

));

$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'user_color', array(
'settings' => 'user_color',
'label' => __('User Color', 'metallic'),
'section' => 'metallic_options'
)
)
);

// =============================
// Select Scheme
// =============================

$shemes = array();

$dir = dirname(__FILE__).'/schemes';
Expand All @@ -137,12 +153,19 @@ function metallic_customize_register($wp_customize) {
closedir($handle);
}

$wp_customize->add_control( 'color_select_box', array(
$wp_customize->add_setting('color_scheme', array(
'default' => 'Gray',
'capability' => 'edit_theme_options',
'type' => 'theme_mod', //or 'option' if u want to have a record in database

));

$wp_customize->add_control('color_select_box', array(
'settings' => 'color_scheme',
'label' => 'Select Color:',
'section' => 'metallic_options',
'type' => 'select',
'choices' => $shemes
'label' => __('Select Scheme', 'metallic'),
'section' => 'metallic_options',
'type' => 'select',
'choices' => $shemes
)
);
}
Expand All @@ -163,11 +186,13 @@ function metallic_generate_css_cache(){
global $wp_customize;
$scheme = get_theme_mod('color_scheme', 'gray');
$gradients = get_theme_mod('gradients', true);
$user_color = get_theme_mod('user_color', '');
$css_macro = new CssMacro;
$css_macro->load_values(dirname(__FILE__).'/default.scheme.ini');
$css_macro->load_values(dirname(__FILE__).'/schemes/'.$scheme.'.scheme.ini');
$css_macro->set('gradients', $gradients);
$css_macro->set('scheme', $scheme);
$css_macro->set('user_color', $user_color);
$file= dirname(__FILE__).'/style.css';
if (file_exists($file)) {
$style = file_get_contents($file);
Expand Down
7 changes: 7 additions & 0 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
else
$pass .= '0';

$user_color = get_theme_mod('user_color', '');
if (!empty($user_color)) {
if (substr($user_color, 0, 1) === '#')
$user_color = substr($user_color, 1);
$pass .= '&user_color='.$user_color;
}

if (isset($_GET['scheme']) and !empty($_GET['scheme']))
$scheme = $_GET['scheme'];
/* if Debug is enabled or using theme customize we need on the fly css */
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ embed, iframe, object {
position: relative;
background: $color(base);
$if(gradients)<
background: linear-gradient(to bottom, $color(base, 10) 1%, $color(base, 25) 10%, $color(base) 40%);
background: linear-gradient(to bottom, $color(base, 10) 1%, $color(base, 25) 10%, $color(base) 60%);
>
z-index: 999;
text-decoration: none;
Expand Down
9 changes: 9 additions & 0 deletions style.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@
if (empty($gradients))
$gradients = '0'; //default;

if (isset($_GET['user_color']) and !empty($_GET['user_color']))
$user_color = $_GET['user_color'];

if (!empty($user_color)) {
if (substr($user_color, 0, 1) === '#')
$user_color = substr($user_color, 1);
}

$css_macro = new CssMacro();
$css_macro->load_values(dirname(__FILE__).'/default.scheme.ini'); //load default values
$css_macro->load_values(dirname(__FILE__).'/schemes/'.$scheme.'.scheme.ini');
$css_macro->set('gradients', $gradients);
if (!empty($user_color))
$css_macro->set('base', '#'.$user_color);
$css_macro->set('scheme', $scheme);
echo $css_macro->generate(file_get_contents(dirname(__FILE__).'/style.css'));

Expand Down

0 comments on commit 4cc2da4

Please sign in to comment.