/** * Registers custom sections, settings, and controls for the $wp_customize instance. * * @since 0.1.0 * @author Justin Tadlock <*****@*****.**> * @author Sami Keijonen <*****@*****.**> * @copyright Copyright (c) 2012 * @link http://themehybrid.com/support/topic/add-theme-layout-in-theme-customize * @access public * @param object $wp_customize */ function theme_layouts_customize_register($wp_customize) { /* Get supported theme layouts. */ $layouts = theme_layouts_get_layouts(); $args = theme_layouts_get_args(); if (true === $args['customize']) { /* Add the layout section. */ $wp_customize->add_section('layout', array('title' => esc_html__('Layout', 'theme-layouts'), 'priority' => 190, 'capability' => 'edit_theme_options')); /* Add the 'layout' setting. */ $wp_customize->add_setting('theme_layout', array('default' => get_theme_mod('theme_layout', $args['default']), 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_html_class', 'transport' => 'postMessage')); /* Set up an array for the layout choices and add in the 'default' layout. */ $layout_choices = array(); /* Only add 'default' if it's the actual default layout. */ if ('default' == $args['default']) { $layout_choices['default'] = theme_layouts_get_string('default'); } /* Loop through each of the layouts and add it to the choices array with proper key/value pairs. */ foreach ($layouts as $layout) { $layout_choices[$layout] = theme_layouts_get_string($layout); } /* Add the layout control. */ $wp_customize->add_control('theme-layout-control', array('label' => esc_html__('Global Layout', 'theme-layouts'), 'section' => 'layout', 'settings' => 'theme_layout', 'type' => 'radio', 'choices' => $layout_choices)); /* If viewing the customize preview screen, add a script to show a live preview. */ if ($wp_customize->is_preview() && !is_admin()) { add_action('wp_footer', 'theme_layouts_customize_preview_script', 21); } } }
/** * Theme Layouts Customize Register * Modified from Hybrid Core Theme Layouts Ext. Customizer. * This function/filter might be removed when this option is available in Hybrid Core * * @link https://github.com/justintadlock/hybrid-core/issues/68 * @author Justin Tadlock <*****@*****.**> * @author Sami Keijonen <*****@*****.**> * @since 0.1.0 */ function tamatebako_theme_layouts_customize_register($wp_customize) { /* Get supported theme layouts. */ $layouts = theme_layouts_get_layouts(); $args = theme_layouts_get_args(); if (true === $args['customize']) { /* Add the layout section. */ $wp_customize->add_section('layout', array('title' => esc_html(tamatebako_string('layout')), 'priority' => 190, 'capability' => 'edit_theme_options')); /* Add the 'layout' setting. */ $wp_customize->add_setting('theme_layout', array('default' => get_theme_mod('theme_layout', $args['default']), 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_html_class', 'transport' => 'refresh')); /* Set up an array for the layout choices and add in the 'default' layout. */ $layout_choices = array(); /* Only add 'default' if it's the actual default layout. */ if ('default' == $args['default']) { $layout_choices['default'] = theme_layouts_get_string('default'); } /* Loop through each of the layouts and add it to the choices array with proper key/value pairs. */ foreach ($layouts as $layout) { $layout_choices[$layout] = theme_layouts_get_string($layout); } /* Add the layout control. */ $wp_customize->add_control('theme-layout-control', array('label' => esc_html(tamatebako_string('global-layout')), 'section' => 'layout', 'settings' => 'theme_layout', 'type' => 'radio', 'choices' => $layout_choices)); } }