Permalink
Browse files

Better code for theme layout in customize and setting page.

  • Loading branch information...
1 parent b7907c2 commit dd1558d41cb54966945c3cb3bec8cef10fc53aff @samikeijonen committed Aug 2, 2012
Showing with 30 additions and 19 deletions.
  1. +10 −8 admin/functions-admin.php
  2. +2 −0 changelog.txt
  3. +14 −9 functions.php
  4. +4 −2 js/customize/path-customizer.js
View
@@ -104,7 +104,11 @@ function path_theme_meta_box_background() { ?>
}
/* Function for displaying the layout meta box. */
-function path_theme_meta_box_layout() { ?>
+function path_theme_meta_box_layout() {
+
+ /* Get theme layouts. */
+ $path_supported_layouts = get_theme_support( 'theme-layouts' );
+ $path_layouts = $path_supported_layouts[0]; // Array of all layouts without the 'layout-' prefix. ?>
<table class="form-table">
@@ -115,13 +119,11 @@ function path_theme_meta_box_layout() { ?>
</th>
<td>
<select id="<?php echo esc_attr( hybrid_settings_field_id( 'path_global_layout' ) ); ?>" name="<?php echo esc_attr( hybrid_settings_field_name( 'path_global_layout' ) ); ?>">
- <option value="layout-default" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-default' ); ?>> <?php echo __( 'Default', 'path' ) ?> </option>
- <option value="layout-1c" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-1c' ); ?>> <?php echo __( 'One Column', 'path' ) ?> </option>
- <option value="layout-2c-l" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-2c-l' ); ?>> <?php echo __( 'Two Columns, Left', 'path' ) ?> </option>
- <option value="layout-2c-r" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-2c-r' ); ?>> <?php echo __( 'Two Columns, Right', 'path' ) ?> </option>
- <option value="layout-3c-l" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-3c-l' ); ?>> <?php echo __( 'Three Columns, Left', 'path' ) ?> </option>
- <option value="layout-3c-r" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-3c-r' ); ?>> <?php echo __( 'Three Columns, Right', 'path' ) ?> </option>
- <option value="layout-3c-c" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-3c-c' ); ?>> <?php echo __( 'Three Columns, Center', 'path' ) ?> </option>
+ <option value="layout-default" <?php selected( hybrid_get_setting( 'path_global_layout' ), 'layout-default' ); ?>> <?php echo esc_html( theme_layouts_get_string( 'default' ) ); ?> </option>
+ <?php
+ foreach ( $path_layouts as $path_layout ) { ?>
+ <option value="<?php echo esc_attr( "layout-{$path_layout}" ); ?>" <?php selected( hybrid_get_setting( 'path_global_layout' ), "layout-{$path_layout}" ); ?>> <?php echo esc_html( theme_layouts_get_string( $path_layout ) ); ?> </option>
+ <?php } ?>
</select>
<p><span class="description"><?php _e( 'Set the layout for the entire site. The default layout is 2 columns with content on the left. You can overwrite this value in individual post or page. Note! Three column layouts will only work if you use Primary and Secondary Widget areas and browser window is wide enough.', 'path' ); ?></span></p>
</td>
View
@@ -1,5 +1,7 @@
31.7.2012 - version 0.1.1
+* Better code in theme customize and settings page when choosing global layout.
+
* Arrows fixed back to normal. They were replaced by ?-mark when compressing style.css.
* @link: http://stackoverflow.com/questions/2701192/ascii-character-for-up-down-triangle-arrow-to-display-in-html
View
@@ -549,20 +549,25 @@ function path_customize_register( $wp_customize ) {
'transport' => 'postMessage',
) );
+ /* Get theme layouts. */
+ $path_supported_layouts = get_theme_support( 'theme-layouts' );
+ $path_layouts = $path_supported_layouts[0]; // Array of all layouts without the 'layout-' prefix.
+
+ /* Add layout-default to $path_layout_choices. */
+ $path_layout_choices['layout-default'] = theme_layouts_get_string( 'default' );
+
+ /* Then add rest of what user had added in add_theme_support( 'theme-layouts' ). */
+ foreach ( $path_layouts as $path_layout ) {
+ $path_layout_choices["layout-{$path_layout}"] = theme_layouts_get_string( $path_layout );
+ }
+
// Layout control
$wp_customize->add_control( 'path_theme_settings[path_global_layout]', array(
+ 'label' => __( 'Global Layout:', 'path' ),
'section' => 'path_customize_layout',
'settings' => 'path_theme_settings[path_global_layout]',
'type' => 'radio',
- 'choices' => array(
- 'layout-default' => __( 'Default', 'path' ),
- 'layout-1c' => __( 'One Column', 'path' ),
- 'layout-2c-l' => __( 'Two Columns, Left', 'path' ),
- 'layout-2c-r' => __( 'Two Columns, Right', 'path' ),
- 'layout-3c-l' => __( 'Three Columns, Left', 'path' ),
- 'layout-3c-r' => __( 'Three Columns, Right', 'path' ),
- 'layout-3c-c' => __( 'Three Columns, Center', 'path' ),
- ),
+ 'choices' => $path_layout_choices,
) );
}
@@ -11,7 +11,9 @@
} );
wp.customize( 'path_theme_settings[path_global_layout]', function( value ) {
value.bind( function( to ) {
- $( 'body' ).removeClass( 'layout-default layout-1c layout-2c-l layout-2c-r layout-3c-l layout-3c-r layout-3c-c' ).addClass( to );
+ var classes = $( 'body' ).attr( 'class' ).replace( /layout-[a-zA-Z0-9_-]*/g, '' ); // replace class with prefix layout- to ''
+ $( 'body' ).attr( 'class', classes ).addClass( to ); // add new class
} );
} );
-} )( jQuery );
+
+} )( jQuery );

0 comments on commit dd1558d

Please sign in to comment.