tabbed = true;
// Sections
$theme_options->sections['default'] = __( 'Default', 'blogy' );
// Options
$theme_options->settings['logo'] = array(
'section' => 'default',
'title' => __( 'Logo', 'blogy' ),
'desc' => __( 'Upload a logo in PNG or JPG format.', 'blogy' ),
'type' => 'upload',
'std' => ''
);
$theme_options->settings['favicon'] = array(
'section' => 'default',
'title' => __( 'Favicon', 'blogy' ),
'desc' => __( 'Upload a favicon in PNG format sized to 16px by 16px.', 'blogy' ),
'type' => 'upload',
'std' => ''
);
$theme_options->settings['font'] = array(
'section' => 'default',
'title' => __( 'Headline Font', 'blogy' ),
'desc' => __( 'Select a font to use for your headlines.', 'blogy' ),
'type' => 'select',
'std' => '',
'choices' => blogy_font_array()
);
$theme_options->settings['font_alt'] = array(
'section' => 'default',
'title' => __( 'Body Font', 'blogy' ),
'desc' => __( 'Select a font to use for your paragraphs.', 'blogy' ),
'type' => 'select',
'std' => '',
'choices' => blogy_font_array()
);
$theme_options->settings['css'] = array(
'section' => 'default',
'title' => __( 'Custom CSS', 'blogy' ),
'desc' => __( 'Add some custom CSS to quickly change the design of your site.', 'blogy' ),
'type' => 'textarea',
'std' => ''
);
/**
* Set theme options above to global theme settings
* @since blogy 1.0
*/
global $blogy_settings;
$blogy_settings = $theme_options->settings;
/**
* Items that need to be ran during "theme activation".
* @since blogy 1.0
*/
add_action( 'load-themes.php', 'blogy_theme_activation' );
function blogy_theme_activation() {
global $pagenow, $blogy_settings;
$blogy_theme = new ThemeOptions;
$new_version = $blogy_theme->theme['version'];
$version_var = 'blogy_version';
$version = get_option( $version_var );
if ( $pagenow != 'themes.php' || ! isset( $_GET['activated'] ) )
return;
if ( $version ) {
if( version_compare( $version, $new_version ) == 1 ) {
return;
}
}
update_option( $version_var, $new_version );
$blogy_theme->initializeSettings( $blogy_settings );
}
/**
* Integrates with the Theme Customizer in WP 3.4
*/
add_action( 'customize_register', 'blogy_customize_register' );
function blogy_customize_register( $wp_customize ) {
// get our theme options so we can use defaults below
$options = get_option( 'blogy_options' );
// enables live change support
$wp_customize->get_setting('blogname')->transport='postMessage';
$wp_customize->get_setting('blogdescription')->transport='postMessage';
$wp_customize->get_setting('header_textcolor')->transport='postMessage';
// add a setting to an existing theme option
$wp_customize->add_setting( 'blogy_options[logo]', array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
//'transport' => 'postMessage'
) );
// intercept the theme option and control it
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'logo', array(
'label' => __( 'Upload Logo', 'blogy' ),
'section' => 'title_tagline',
'settings' => 'blogy_options[logo]'
) ) );
// add a setting to an existing theme option
$wp_customize->add_setting( 'blogy_options[color]', array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage'
) );
// add customizer section
$wp_customize->add_section( 'blogy_fonts', array(
'title' => __( 'Fonts', 'blogy' ),
'priority' => 45
) );
// add a setting to an existing theme option
$wp_customize->add_setting( 'blogy_options[font]', array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage'
) );
// intercept the theme option and control it
$wp_customize->add_control( 'blogy_font_customizer', array(
'settings' => 'blogy_options[font]',
'label' => __( 'Headline Font', 'blogy' ),
'section' => 'blogy_fonts',
'type' => 'select',
'choices' => blogy_font_array() // don't call all fonts on public themes. Choose a few.
) );
// add a setting to an existing theme option
$wp_customize->add_setting( 'blogy_options[font_alt]', array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage'
) );
// intercept the theme option and control it
$wp_customize->add_control( 'blogy_font_alt_customizer', array(
'settings' => 'blogy_options[font_alt]',
'label' => __( 'Body Font', 'blogy' ),
'section' => 'blogy_fonts',
'type' => 'select',
'choices' => blogy_font_array() // don't call all fonts on public themes. Choose a few.
) );
// extending the field type to textarea
class blogy_CSS_Control extends WP_Customize_Control {
public $type = 'customarea';
public function render_content() {
$options = get_option( 'blogy_options' );
$stored = "";
if( isset( $options['css'] ) ) { $stored = $options['css']; }
echo '';
}
public function enqueue() {
wp_enqueue_script( 'customarea', get_template_directory_uri() . '/lib/theme-options/js/customarea.js', array( 'customize-controls' ), '20120607', true );
}
}
// add customizer section
$wp_customize->add_section( 'blogy_css', array(
'title' => __( 'Custom CSS', 'blogy' ),
'priority' => 60
) );
// add a setting to an existing theme option
$wp_customize->add_setting( 'blogy_options[css]', array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
'transport' => 'postMessage'
) );
// intercept the theme option and control it
$wp_customize->add_control( new blogy_CSS_Control( $wp_customize, 'css', array(
'settings' => 'blogy_options[css]',
'label' => __( 'Custom CSS', 'blogy' ),
'section' => 'blogy_css'
) ) );
if ( $wp_customize->is_preview() && ! is_admin() )
add_action( 'wp_footer', 'blogy_customize_preview_js', 21 );
}
/**
* Bind JS handlers to make Theme Customizer preview reload changes asynchronously.
* Used with fonts
*
*/
function blogy_customize_preview_js() { ?>
(function($){
$(document).ready(function() {
wp.customize("blogname", function(value) {
value.bind(function(to) {
$(".site-title a").html(to);
});
});
wp.customize("blogdescription", function(value) {
value.bind(function(to) {
$(".site-description").html(to);
});
});
wp.customize( "header_textcolor", function( value ) {
value.bind( function( to ) {
$(".site-title a, .site-description").css("color", to ? to : "" );
});
});
wp.customize("blogy_options[logo]", function(value) {
value.bind(function(to) {
$(".site-title a").html("" );
});
});
wp.customize("blogy_options[font]",function(value) {
value.bind(function(to) {
$("#fontdiv").remove();
var googlefont = to.split(",");
$("body").append("