Permalink
Browse files

add custom callback function for background color and merge with cust…

…om colors
  • Loading branch information...
1 parent 28347ab commit 3ddd6e022aa6dd78e2ede575de439b4d920425b3 @bueltge committed Sep 9, 2012
Showing with 92 additions and 53 deletions.
  1. +1 −1 css/style.css
  2. +0 −1 css/style.dev.css
  3. +1 −1 functions.php
  4. +56 −16 inc/head-style.php
  5. +15 −15 inc/theme-customize.php
  6. +19 −19 inc/theme-options.php
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -191,7 +191,6 @@ padding: 5px;
}
#sidebar {
-background: #fff;
width: 25%;
float: right;
margin: 5px 0;
View
@@ -69,7 +69,7 @@ function documentation_setup() {
$args = array(
'default-image' => '',
'default-color' => 'fff',
- 'wp-head-callback' => '_custom_background_cb',
+ 'wp-head-callback' => array( 'Documentation_Head_Style', '_custom_background_cb' ),
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
View
@@ -16,13 +16,13 @@ class Documentation_Head_Style extends Documentation_Options {
/**
* Identifier, namespace
*/
- public static $theme_key = '';
+ private static $theme_key = '';
/**
* The option value in the database will be based on get_stylesheet()
* so child themes don't share the parent theme's option value.
*/
- public static $option_key = '';
+ private static $option_key = '';
/**
* Initialize our options.
@@ -49,27 +49,67 @@ public function __construct( $args = NULL ) {
$this->theme_key = $args['theme_key'];
$this->option_key = $this->theme_key . '_theme_options';
- add_action( 'wp_head', array( $this, 'get_custom_style' ) );
+ //add_action( 'wp_head', array( $this, 'get_custom_style' ) );
}
/**
- * Styles from theme options
- * Write in head of frontend
+ * The custom background callback.
+ * Write style in head of frontend.
*
- * @since 09/07/2012
- * @return void
+ * @since 09/09/2012
+ * @return void
*/
- public function get_custom_style() {
+ public function _custom_background_cb() {
+
+ // $background is the saved custom image, or the default image.
+ $background = set_url_scheme( get_background_image() );
+
+ // $color is the saved custom color.
+ // A default has to be specified in style.css. It will not be printed here.
+ $color = get_theme_mod( 'background_color' );
+
+ if ( ! $color )
+ $color = esc_attr( get_theme_support( 'custom-background', 'default-color' ) );
+
+ $style = $color ? "background-color: #$color;" : '';
+
+ if ( $background ) {
+ $image = " background-image: url('$background');";
+
+ $repeat = get_theme_mod( 'background_repeat', 'repeat' );
+ if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
+ $repeat = 'repeat';
+ $repeat = " background-repeat: $repeat;";
+
+ $position = get_theme_mod( 'background_position_x', 'left' );
+ if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
+ $position = 'left';
+ $position = " background-position: top $position;";
+
+ $attachment = get_theme_mod( 'background_attachment', 'scroll' );
+ if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
+ $attachment = 'scroll';
+ $attachment = " background-attachment: $attachment;";
+
+ $style .= $image . $repeat . $position . $attachment;
+ }
+ // custom theme settings
$options = parent::get_theme_options();
- ?>
- <style type="text/css">
- body { color: <?php echo $options['text_color']; ?>; }
- a:link, a:visited,
- #content h2 a:link, #content h2 a:visited,
- #header h1 a:link, #header h1 a:visited { color: <?php echo $options['link_color']; ?>; }
- </style>
- <?php
+ foreach ($options as $key => $value) {
+ trim( $value );
+ }
+ ?>
+ <style type="text/css" id="custom-theme-options">
+ body {
+ <?php echo trim( $style ) . "\n"; ?>
+ color: <?php echo $options['text_color']; ?>;
+ }
+ a:link, a:visited,
+ #content h2 a:link, #content h2 a:visited,
+ #header h1 a:link, #header h1 a:visited { color: <?php echo $options['link_color']; ?>; }
+ </style>
+ <?php
}
} // end class
View
@@ -15,13 +15,13 @@ class Documentation_Customize extends Documentation_Options {
/**
* Identifier, namespace
*/
- public static $theme_key = '';
+ private static $theme_key = '';
/**
* The option value in the database will be based on get_stylesheet()
* so child themes don't share the parent theme's option value.
*/
- public static $option_key = '';
+ private static $option_key = '';
/**
* Initialize
@@ -33,8 +33,8 @@ public function __construct( $args = NULL ) {
$args['theme_key'] = strtolower( get_stylesheet() );
// Set option key based on get_stylesheet()
- $this->theme_key = $args['theme_key'];
- $this->option_key = $this->theme_key . '_theme_options';
+ self::$theme_key = $args['theme_key'];
+ self::$option_key = self::$theme_key . '_theme_options';
add_action( 'customize_register', array( $this, 'customize_register' ) );
}
@@ -52,51 +52,51 @@ public function customize_register( $wp_customize ) {
$defaults = parent::get_default_theme_options();
// create custom section for rewrite url
- $wp_customize->add_section( $this->option_key . '_rewrite_url', array(
+ $wp_customize->add_section( self::$option_key . '_rewrite_url', array(
'title' => __( 'Rewrite', 'documentation' ),
'priority' => 35,
) );
// add field for rewrite url in custom section
- $wp_customize->add_setting( $this->option_key . '[rewrite_url]', array(
+ $wp_customize->add_setting( self::$option_key . '[rewrite_url]', array(
'default' => $defaults['rewrite_url'],
'type' => 'option',
'capability' => 'edit_theme_options',
) );
- $wp_customize->add_control( $this->option_key . '_rewrite_url', array(
+ $wp_customize->add_control( self::$option_key . '_rewrite_url', array(
'label' => __( 'Rewrite URL', 'documentation' ),
- 'section' => $this->option_key . '_rewrite_url',
- 'settings' => $this->option_key . '[rewrite_url]',
+ 'section' => self::$option_key . '_rewrite_url',
+ 'settings' => self::$option_key . '[rewrite_url]',
'type' => 'text',
) );
// add field for text color in default section for 'colors'
- $wp_customize->add_setting( $this->option_key . '[text_color]', array(
+ $wp_customize->add_setting( self::$option_key . '[text_color]', array(
'default' => $defaults['text_color'],
'type' => 'option',
'capability' => 'edit_theme_options',
) );
// add color field include color picker for text color
- $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $this->option_key . '_text_color', array(
+ $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, self::$option_key . '_text_color', array(
'label' => __( 'Text Color', 'documentation' ),
'section' => 'colors',
- 'settings' => $this->option_key . '[text_color]',
+ 'settings' => self::$option_key . '[text_color]',
) ) );
// add field for text color in default section for 'colors'
- $wp_customize->add_setting( $this->option_key . '[link_color]', array(
+ $wp_customize->add_setting( self::$option_key . '[link_color]', array(
'default' => $defaults['link_color'],
'type' => 'option',
'capability' => 'edit_theme_options',
) );
// add color field include color picker for link color
- $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $this->option_key . '_link_color', array(
+ $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, self::$option_key . '_link_color', array(
'label' => __( 'Link Color', 'documentation' ),
'section' => 'colors',
- 'settings' => $this->option_key . '[link_color]',
+ 'settings' => self::$option_key . '[link_color]',
) ) );
}
Oops, something went wrong.

0 comments on commit 3ddd6e0

Please sign in to comment.