Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Last active May 4, 2016 21:31
Show Gist options
  • Save stephanieleary/28a21e82cc53c388fab1ec52dce79524 to your computer and use it in GitHub Desktop.
Save stephanieleary/28a21e82cc53c388fab1ec52dce79524 to your computer and use it in GitHub Desktop.
Genesis color scheme selector meta box
<?php
// Register admin stylesheet
add_action( 'admin_enqueue_scripts', 'berkeley_settings_admin_styles' );
function berkeley_settings_admin_styles( $hook ) {
wp_enqueue_style( 'berkeley-admin-css', get_stylesheet_directory_uri() . '/css/admin-style.css' );
}
// Register colors
add_theme_support( 'genesis-style-selector', berkeley_get_colors() );
function berkeley_get_colors() {
return array(
'pool' => __( 'Pool', 'beng' ),
'pool light' => __( 'Pool Light', 'beng' ),
'punch' => __( 'Punch', 'beng' ),
'punch light' => __( 'Punch Light', 'beng' ),
'classic' => __( 'Classic', 'beng' ),
'classic light' => __( 'Classic Light', 'beng' ),
'earth' => __( 'Earth', 'beng' ),
'earth light' => __( 'Earth Light', 'beng' ),
'woods' => __( 'Woods', 'beng' ),
'woods light' => __( 'Woods Light', 'beng' ),
'pacific' => __( 'Pacific', 'beng' ),
'pacific light' => __( 'Pacific Light', 'beng' ),
);
}
/**
* Color Selector
*
* Add a visual color scheme selector to Theme Settings, to replace the Color Style dropdown.
*/
add_action( 'genesis_theme_settings_metaboxes', 'berkeley_register_options_settings_box' );
function berkeley_register_options_settings_box( $_genesis_theme_settings_pagehook ) {
// Remove Genesis color settings box
remove_meta_box( 'genesis-theme-settings-style-selector', $_genesis_theme_settings_pagehook, 'main' );
// Register new color settings box
add_meta_box( 'berkeley-color-settings', __( 'Color Scheme', 'beng' ), 'berkeley_color_settings_box', $_genesis_theme_settings_pagehook, 'main', 'high' );
}
function berkeley_color_settings_box() {
?>
<table class="form-table">
<tbody>
<tr valign="top">
<th scope="row"><?php _e( 'Select Theme Colors', 'beng' ) ?></th>
<td>
<fieldset class="genesis-layout-selector">
<legend class="screen-reader-text"><?php _e( 'Color Scheme', 'beng' ); ?></legend>
<?php
$colors = berkeley_get_colors();
foreach ( $colors as $color => $label ) {
$classes = 'box';
// create a second row
if ( $color == 'earth' )
$classes .= ' clear';
if ( genesis_get_option( 'style_selection' ) == $color )
$classes .= ' selected';
$path = get_stylesheet_directory_uri() . '/images/color-schemes/' . sanitize_title( $color );
printf( '<label for="%1$s" class="%2$s">
<img alt="%3$s" title="%3$s" src="%4$s.png">
<input type="radio" class="screen-reader-text"
%5$s
value="%1$s"
id="%1$s"
name="%6$s[style_selection]">
<span class="color-scheme-caption">%3$s </span>
</label>',
$color,
$classes,
$label,
$path,
checked( genesis_get_option( 'style_selection' ), $color, false ),
GENESIS_SETTINGS_FIELD
);
}
?>
</fieldset>
<br class="clear">
</td>
</tr>
</tbody>
</table>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment