Permalink
Browse files

change to use only the Customizer to set options

  • Loading branch information...
1 parent e51e8ef commit 523ddef314a4721f44ea1e7bef4b1a2d84e08cac @bueltge committed Sep 17, 2012
Showing with 116 additions and 85 deletions.
  1. +7 −8 functions.php
  2. +53 −56 inc/head-style.php
  3. +56 −21 inc/theme-customize.php
View
@@ -42,22 +42,21 @@ function documentation_setup() {
*
* @see https://github.com/bueltge/WordPress-Basis-Theme/tree/namespace/inc/admin
*/
- locate_template( 'inc/class-branding.php', TRUE, TRUE );
+ require_once( get_template_directory() . '/inc/class-branding.php' );
new Documentation_Admin_Branding( array() );
// params for options class
$args = array(
'theme_key' => strtolower( get_stylesheet() )
);
- // ToDo: Loader for include files
// Load up our theme options page and related code.
- locate_template( 'inc/theme-options.php', TRUE, TRUE );
- $documentation_options = new Documentation_Options( $args );
+ //require_once( get_template_directory() . '/inc/theme-options.php' );
+ //$documentation_options = new Documentation_Options( $args );
// Include the theme customizer for options of theme options
- locate_template( 'inc/theme-customize.php', TRUE, TRUE );
+ require_once( get_template_directory() . '/inc/theme-customize.php' );
$documentation_customize = new Documentation_Customize( $args );
// include to write the custom theme options in theme head
- locate_template( 'inc/head-style.php', TRUE, TRUE );
+ require_once( get_template_directory() . '/inc/head-style.php' );
$documentation_head_style = new Documentation_Head_Style( $args );
// Add default posts and comments RSS feed links to <head>.
@@ -70,7 +69,7 @@ function documentation_setup() {
$args = array(
'default-image' => '',
'default-color' => 'fff',
- 'wp-head-callback' => array( 'Documentation_Head_Style', '_custom_background_cb' ),
+ 'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
@@ -96,7 +95,7 @@ function documentation_setup() {
*/
function documentation_get_options( $value = '' ) {
- $documentation_options = new Documentation_Options();
+ $documentation_options = new Documentation_Customize();
$options = $documentation_options->get_theme_options();
View
@@ -8,21 +8,18 @@
* @since 09/05/2012
*/
-if ( ! class_exists( 'Documentation_Options' ) )
- return NULL;
-
-class Documentation_Head_Style extends Documentation_Options {
+class Documentation_Head_Style {
/**
* Identifier, namespace
*/
- private static $theme_key = '';
+ public 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.
*/
- private static $option_key = '';
+ public static $option_key = '';
/**
* Initialize our options.
@@ -46,68 +43,68 @@ public function __construct( $args = NULL ) {
$args['theme_key'] = strtolower( get_stylesheet() );
// Set option key based on get_stylesheet()
- self::$theme_key = $args['theme_key'];
- self::$option_key = self::$theme_key . '_theme_options';
+ $this->theme_key = $args['theme_key'];
+ $this->option_key = $this->theme_key . '_theme_options';
+
+ add_action( 'wp_head', array( $this, 'get_custom_style' ) );
}
/**
- * The custom background callback.
- * Write style in head of frontend.
+ * Returns the default options.
+ * Use the hook 'documentation_default_theme_options' for change via plugin
*
- * @since 09/09/2012
- * @return void
+ * @since 08/09/2012
+ * @return Array
*/
- public function _custom_background_cb() {
+ public function get_default_theme_options( $value = NULL ) {
+
+ $default_theme_options = array(
+ 'rewrite_url' => 'wp-admin/edit.php',
+ 'text_color' => '#333',
+ 'link_color' => '#0100BE'
+ );
- // $background is the saved custom image, or the default image.
- $background = set_url_scheme( get_background_image() );
+ if ( NULL !== $value )
+ return $default_theme_options[$value];
- // $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' );
+ return apply_filters( $this->theme_key . '_default_theme_options', $default_theme_options );
+ }
+
+ /**
+ * Returns the options array.
+ *
+ * @since 09/07/2012
+ * @return Array
+ */
+ public function get_theme_options() {
- if ( ! $color )
- $color = esc_attr( get_theme_support( 'custom-background', 'default-color' ) );
+ $saved = (array) get_option( $this->option_key );
+ $defaults = $this->get_default_theme_options();
- $style = $color ? "background-color: #$color;" : '';
+ $options = wp_parse_args( $saved, $defaults );
+ $options = array_intersect_key( $options, $defaults );
- 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;";
+ return apply_filters( $this->theme_key . '_theme_options', $options );
+ }
- $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;
- }
+ /**
+ * Styles from theme options
+ * Write in head of frontend
+ *
+ * @since 09/07/2012
+ * @return void
+ */
+ public function get_custom_style() {
- // get custom theme settings
- $options = parent::get_theme_options();
- 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
+ $options = $this->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
}
} // end class
@@ -7,21 +7,18 @@
* @since 09/06/2012
*/
-if ( ! class_exists( 'Documentation_Options' ) )
- return NULL;
-
-class Documentation_Customize extends Documentation_Options {
+class Documentation_Customize {
/**
* Identifier, namespace
*/
- private static $theme_key = '';
+ public 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.
*/
- private static $option_key = '';
+ public static $option_key = '';
/**
* Initialize
@@ -33,12 +30,50 @@ public function __construct( $args = NULL ) {
$args['theme_key'] = strtolower( get_stylesheet() );
// Set option key based on get_stylesheet()
- self::$theme_key = $args['theme_key'];
- self::$option_key = self::$theme_key . '_theme_options';
+ $this->theme_key = $args['theme_key'];
+ $this->option_key = $this->theme_key . '_theme_options';
add_action( 'customize_register', array( $this, 'customize_register' ) );
}
-
+
+ /**
+ * Returns the default options.
+ * Use the hook 'documentation_default_theme_options' for change via plugin
+ *
+ * @since 08/09/2012
+ * @return Array
+ */
+ public function get_default_theme_options( $value = NULL ) {
+
+ $default_theme_options = array(
+ 'rewrite_url' => 'wp-admin/edit.php',
+ 'text_color' => '#111',
+ 'link_color' => '#0100BE'
+ );
+
+ if ( NULL !== $value )
+ return $default_theme_options[$value];
+
+ return apply_filters( $this->theme_key . '_default_theme_options', $default_theme_options );
+ }
+
+ /**
+ * Returns the options array.
+ *
+ * @since 08/09/2012
+ * @return Array
+ */
+ public function get_theme_options() {
+
+ $saved = (array) get_option( $this->option_key );
+ $defaults = $this->get_default_theme_options();
+
+ $options = wp_parse_args( $saved, $defaults );
+ $options = array_intersect_key( $options, $defaults );
+
+ return apply_filters( $this->theme_key . '_theme_options', $options );
+ }
+
/**
* Implement theme options into Theme Customizer on Frontend
*
@@ -49,54 +84,54 @@ public function __construct( $args = NULL ) {
*/
public function customize_register( $wp_customize ) {
- $defaults = parent::get_default_theme_options();
+ $defaults = $this->get_default_theme_options();
// create custom section for rewrite url
- $wp_customize->add_section( self::$option_key . '_rewrite_url', array(
+ $wp_customize->add_section( $this->option_key . '_rewrite_url', array(
'title' => __( 'Rewrite', 'documentation' ),
'priority' => 35,
) );
// add field for rewrite url in custom section
- $wp_customize->add_setting( self::$option_key . '[rewrite_url]', array(
+ $wp_customize->add_setting( $this->option_key . '[rewrite_url]', array(
'default' => $defaults['rewrite_url'],
'type' => 'option',
'capability' => 'edit_theme_options',
) );
- $wp_customize->add_control( self::$option_key . '_rewrite_url', array(
+ $wp_customize->add_control( $this->option_key . '_rewrite_url', array(
'label' => __( 'Rewrite URL', 'documentation' ),
- 'section' => self::$option_key . '_rewrite_url',
- 'settings' => self::$option_key . '[rewrite_url]',
+ 'section' => $this->option_key . '_rewrite_url',
+ 'settings' => $this->option_key . '[rewrite_url]',
'type' => 'text',
) );
// add field for text color in default section for 'colors'
- $wp_customize->add_setting( self::$option_key . '[text_color]', array(
+ $wp_customize->add_setting( $this->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, self::$option_key . '_text_color', array(
+ $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $this->option_key . '_text_color', array(
'label' => __( 'Text Color', 'documentation' ),
'section' => 'colors',
- 'settings' => self::$option_key . '[text_color]',
+ 'settings' => $this->option_key . '[text_color]',
) ) );
// add field for text color in default section for 'colors'
- $wp_customize->add_setting( self::$option_key . '[link_color]', array(
+ $wp_customize->add_setting( $this->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, self::$option_key . '_link_color', array(
+ $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $this->option_key . '_link_color', array(
'label' => __( 'Link Color', 'documentation' ),
'section' => 'colors',
- 'settings' => self::$option_key . '[link_color]',
+ 'settings' => $this->option_key . '[link_color]',
) ) );
}

0 comments on commit 523ddef

Please sign in to comment.