I'm currently trying to work on a WordPress theme based on Sage. The stage I'm at is creating custom controls to display on the customize screen for WordPress where you typically change things like the site title or theme colors if you're an end user.
It seems that the new setting I'm trying to add with add_setting
isn't actually creating a database entry (Calling get_theme_mod
on that particular setting returns nothing). I'm thinking that it has something to do with the add_control method but I've checked the WordPress Documentation on this and I have it matching as far I can tell.
namespace Roots\Sage\Customizer;
use Roots\Sage\Assets;
/**
* Add customization settings for the theme
*/
function customize_register($wp_customize) {
//////////////////////////
// WIDGET STYLE OPTIONS //
//////////////////////////
$wp_customize->add_section( 'widget_style_section', array(
'title' => __('Widget Styling', __NAMESPACE__),
'priority' => 115,
));
$wp_customize->add_setting( 'widget_list_style', array(
'default' => 'hide',
'transport' => 'postMessage',
));
$wp_customize->add_control( 'widget_list_style_control', array(
'label' => __( 'Display List Style?', __NAMESPACE__),
'Description' => __('Removes the symbols next to bulleted and unbulleted lists in Widgets', __NAMESPACE__),
'section' => 'widget_style_section',
'settings' => 'widget_list_style',
'type' => 'radio', // TODO: CONTROL IS CONFUSED ABOUT WHAT TYPE IT IS, THATS WHY NO REFRESH
'choices' => array(
'hide' => __('Hide'),
'show' => __('Show'),
),
));
// Add postMessage support
$wp_customize->get_setting('blogname')->transport = 'postMessage';
$wp_customize->get_setting('blogdescription')->transport = 'postMessage';
// TEST - To see if widget_list_style is storing properly
echo get_theme_mod('widget_list_style');
}
add_action('customize_register', __NAMESPACE__ . '\\customize_register');