SlideShare a Scribd company logo
1 of 42
Download to read offline
anthonyhortin
@maddisondesigns
#WPMELB
Developing For The
WordPress Customizer
The Theme Customization
API, added in WordPress 3.4,
allows developers to
customize and add controls
to the Appearance >
Customize admin screen
Even for themes that don’t
provide additional options,
there are certain core
features built into the
Customizer…
Site Identity
Menus
Widgets
Static Front Page
Additional CSS (since WP 4.7)
it is strongly recommended that developers study the core
customizer code (all core files containing “customize”). This is
considered the canonical, official documentation for the
Customize API outside of the inline documentation within the
core code.*
*According to the Theme Handbook
https://developer.wordpress.org/themes/customize-api/
There are four main types of Customizer objects
Panels are containers for Sections. Allows you to group multiple Sections together.
Sections are where your Controls reside. They typically contain multiple Controls.
Settings associate Controls with the settings that are saved in the database.
Controls are the actual UI Elements such as Checkboxes, Select Lists & Radio Buttons.
1. Registering Customizer Content
To add anything to the Customizer, you need to use the
customize_register action hook.
This hook gives you access to the $wp_customize object, which is
an instance of the WP_Customize_Manager class.
It’s this class object that controls the Customizer screen.
1. Registering Customizer Content
Add your Panels, Sections, Settings & Controls (including
Custom Controls) within a function used by this hook.
/**
 * Add our Customizer content
 */
function mytheme_customize_register( $wp_customize ) {
   // Add all your Customizer content (i.e. Panels, Sections, Settings & Controls) here...
);
add_action( 'customize_register', 'mytheme_customize_register' );
2. Adding Panels
Panels allow you to group multiple Sections together.
Sections do not need to be nested under a panel.
Panels must contain at least one Section, which must contain at
least one Control, to be displayed.
2. Adding Panels
/**
 * Add our Header & Navigation Panel
 */
 $wp_customize->add_panel( 'header_naviation_panel',
   array(
      'title' => __( 'Header & Navigation' ),
      'description' => esc_html__( 'Adjust your Header and Navigation sections.' ), // Include html tags such as <p>
      'priority' => 160, // Not typically needed. Default is 160
      'capability' => 'edit_theme_options', // Not typically needed. Default is edit_theme_options
      'theme_supports' => '', // Rarely needed.
      'active_callback' => '', // Rarely needed
   )
);
3. Adding Sections
Sections are where your Controls will reside.
You’ll typically have multiple Controls in each Section.
Sections can be added to Panels, but in most instances, this
wont be necessary.
3. Adding Sections
/**
 * Add our Sample Section
 */
$wp_customize->add_section( 'sample_custom_controls_section',
   array(
      'title' => __( 'Sample Custom Controls' ),
      'description' => esc_html__( 'These are an example of Customizer Custom Controls.' ),
      'panel' => '', // Only needed if adding your Section to a Panel
      'priority' => 160, // Not typically needed. Default is 160
      'capability' => 'edit_theme_options', // Not typically needed. Default is edit_theme_options
      'theme_supports' => '', // Rarely needed
      'active_callback' => '', // Rarely needed
      'description_hidden' => 'false', // Rarely needed. Default is False
   )
);
4. Adding Settings
Settings and Controls work together.
Settings handle live-previewing, saving, and sanitization of your
customizer objects.
Each Control that you register needs to have a matching
Setting.
4. Adding Settings
$wp_customize->add_setting( 'sample_default_text',
   array(
      'default' => '', // Optional.
      'transport' => 'refresh', // Optional. 'refresh' or 'postMessage'. Default: 'refresh'
      'type' => 'theme_mod', // Optional. 'theme_mod' or 'option'. Default: 'theme_mod'
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
      'theme_supports' => '', // Optional. Rarely needed
      'validate_callback' => '', // Optional. The name of function that will be called to validate Customizer settings
      'sanitize_callback' => '', // Optional. The name of function that will be called to sanitize the input data before saving it to the database
      'sanitize_js_callback' => '', // Optional. The name the function that will be called to sanitize the data before outputting to javascript
      'dirty' => false, // Optional. Rarely needed. Whether or not the setting is initially dirty when created. Default: False
   )
);
5. Adding Controls
Controls are the actual UI Elements that you’ll use to modify
your theme settings.
There are a number of Controls built into WordPress Core (e.g.
Checkboxes, Select Lists, Radio Buttons etc.).
For all other types of controls, you’ll need to extend the
WP_Customize_Control class to create your own custom controls.
There are several Core
Controls that are ready to
use straight-out-of-the-box…
text, checkbox, textarea,
radio buttons, select lists &

dropdown-pages
Later versions of WP also
introduced…
Color, Media, Image &
Cropped Image
5.1 Input Control
$wp_customize->add_control( 'sample_default_text',
   array(
      'label' => __( 'Default Text Control’ ),
      'description' => esc_html__( 'Text controls Type can be either text, email, url, number, hidden, or date’ ),
      'section' => 'default_controls_section',
      'priority' => 10, // Optional. Order priority to load the control. Default: 10
      'type' => 'text', // Can be either text, email, url, number, hidden, or date
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
      'input_attrs' => array( // Optional.
         'class' => 'my-custom-class',
         'style' => 'border: 1px solid rebeccapurple',
         'placeholder' => __( 'Enter name...' ),
      ),
   )
);
5.2 Checkbox Control
$wp_customize->add_control( 'sample_default_checkbox',
   array(
      'label' => __( 'Default Checkbox Control', 'ephemeris' ),
      'description' => esc_html__( 'Sample description’ ),
      'section'  => 'default_controls_section',
      'priority' => 10, // Optional. Order priority to load the control. Default: 10
      'type'=> 'checkbox',
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
   )
);
5.3 Select Control
$wp_customize->add_control( 'sample_default_select',
   array(
      'label' => __( ’Standard Select Control’ ),
      'description' => esc_html__( 'Sample description’ ),
      'section' => 'default_controls_section',
      'priority' => 10, // Optional. Order priority to load the control. Default: 10
      'type' => 'select',
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
      'choices' => array( // Optional.
         'wordpress' => 'WordPress',
         'hamsters' => 'Hamsters',
         'jet-fuel' => 'Jet Fuel',
         'nuclear-energy' => 'Nuclear Energy'
      )
   )
);
5.4 Radio Button Control
$wp_customize->add_control( 'sample_default_radio',
   array(
      'label' => __( ’Standard Radio Control’ ),
      'description' => esc_html__( 'Sample description’ ),
      'section' => 'default_controls_section',
      'priority' => 10, // Optional. Order priority to load the control. Default: 10
      'type' => 'radio',
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
      'choices' => array( // Optional.
         'captain-america' => 'Captain America',
         'iron-man' => 'Iron Man',
         'spider-man' => 'Spider-Man',
         'thor' => 'Thor'
      )
   )
);
5.5 Dropdown Pages Control
$wp_customize->add_control( 'sample_default_dropdownpages',
   array(
      'label' => __( ’Default Dropdown Pages Control’ ),
      'description' => esc_html__( 'Sample description’ ),
      'section' => 'default_controls_section',
      'priority' => 10, // Optional. Order priority to load the control. Default: 10
      'type' => 'dropdown-pages',
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
   )
);
5.6 Textarea Control
$wp_customize->add_control( 'sample_default_textarea',
   array(
      'label' => __( ’Default Textarea Control’ ),
      'description' => esc_html__( 'Sample description’ ),
      'section' => 'default_controls_section',
      'priority' => 10, // Optional. Order priority to load the control. Default: 10
      'type' => 'textarea',
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
      'input_attrs' => array( // Optional.
         'class' => ‘my-custom-class', // Optional. Specify additional classes
         'style' => 'border: 1px solid #999’, // Optional. Additional CSS for Control
         'placeholder' => __( 'Enter message...' ), // Optional. Specify Placeholder text
      ),
   )
);
5.7 Color Control
$wp_customize->add_control( 'sample_default_color',
   array(
      'label' => __( ’Default Color Control’ ),
      'description' => esc_html__( 'Sample description’ ),
      'section' => 'default_controls_section',
      'priority' => 10, // Optional. Order priority to load the control. Default: 10
      'type' => 'color',
      'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'
   )
);
5.8 Media Control
$wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'sample_default_media',
   array(
      'label' => __( ’Default Media Control’ ),
      'description' => esc_html__( 'This is the description for the Media Control’ ),
      'section' => 'default_controls_section',
      'mime_type' => ‘image', // Required. Can be image, audio, video, application, text.
      'button_labels' => array( // Optional.
         ‘select' => __( 'Select File' ),
         ‘change' => __( 'Change File' ),
         ‘default' => __( 'Default' ),
         ‘remove' => __( 'Remove' ),
         ‘placeholder' => __( 'No file selected' ),
         ‘frame_title' => __( 'Select File' ),
         ‘frame_button' => __( 'Choose File' ),
      )
   )
) );
5.9 Image Control
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'sample_default_image',
   array(
      'label' => __( ’Default Image Control’ ),
      'description' => esc_html__( 'This is the description for the Image Control’ ),
      'section' => 'default_controls_section',
      'button_labels' => array(
         ‘select' => __( 'Select Image' ),
         ‘change' => __( 'Change Image' ),
         ‘remove' => __( 'Remove' ),
         ‘default' => __( 'Default' ),
         ‘placeholder' => __( 'No image selected' ),
         ‘frame_title' => __( 'Select Image' ),
         ‘frame_button' => __( 'Choose Image' ),
      )
   )
) );
5.10 Cropped Image Control
$wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'sample_default_cropped_image',
   array(
      'label' => __( 'Default Cropped Image Control' ),
      'description' => esc_html__( 'This is the description for the Cropped Image Control' ),
      'section' => 'default_controls_section',
      'flex_width' => false, // Optional. Default: false
      'flex_height' => true, // Optional. Default: false
      'width' => 800, // Optional. Default: 150
      'height' => 400 // Optional. Default: 150
   )
) );
6. Data Sanitization
Whenever you’re accepting data from users, the Number One
rule is Trust Nobody.
It’s always important that you validate and/or sanitize your data,
especially if this data is being saved back to your database.
xkcd: Exploits of a mum
6. Data Sanitization
The type of sanitizing will depend on the type of data your
expecting. e.g. Sanitizing an email is different than text
For a simple text field, you could use wp_filter_nohtml_kses() which
will strip all html from the content.
$wp_customize->add_setting( 'sample_default_text',
   array(
      'default' => __( 'This is some default text' ),
      'sanitize_callback' => 'wp_filter_nohtml_kses',
   )
);
7. Adding Controls to existing Sections
You can add Controls to existing Sections rather than creating
your own section.
Identical to adding Settings and Controls to your own Sections,
the only difference is the section argument.
$wp_customize->add_setting( 'my_new_header_image',
   array(
      'default' => __( 'center' ),
      'sanitize_callback' => 'sanitize_text_field',
   )
);
$wp_customize->add_control( 'my_new_header_image',
   array(
      'label' => __( 'Header Image Alignment' ),
      'section' => 'header_image',
      'type' => 'select',
      'choices' => array(
         'left' => 'Left',
         'center' => 'Center',
         'right' => 'Right',
      )
   )
);
8. Refreshing the Preview
Two ways in which you can update the preview window
- Refresh the whole page
- Partial refresh, which is a refresh of just part of the page
The type of refresh to use is set by the transport argument
$wp_customize->add_setting( 'sample_default_text',
   array(
      'default' => '',
      'transport' => ‘postMessage' // Optional. Either refresh or postMessage. Default: refresh
   )
);
8.1 Full Refresh
The default preview refresh in the Customizer is the full page
refresh.
The type of refresh to use is set by the transport argument
$wp_customize->add_setting( 'sample_default_text',
   array(
      'default' => '',
      'transport' => ‘refresh' // Optional. Either refresh or postMessage. Default: refresh
   )
);
8.2 Partial Refresh Option A - Use PHP & AJAX
When adding your setting set transport to postMessage
To use a PHP function (via AJAX) you need to register a Partial.
$wp_customize->selective_refresh->add_partial( 'social_urls',
   array(
      'selector' => '.social-header',
      'container_inclusive' => false,
      'render_callback' => function() {
         echo mytheme_get_social_media_icons();
      },
      'fallback_refresh' => true
   )
);
8.2 Partial Refresh Option B - Use jQuery
Enqueue your script for use in the Customizer using the
customize_preview_init action hook & bind your jQuery function to the
control you want to update
jQuery( document ).ready(function($) {
   wp.customize('search_menu_icon', function(control) {
      control.bind(function( controlValue ) {
         if( controlValue == true ) {
            $('.nav-menu').append('<li class="menu-item menu-item-search"><a href=“#">New menu item</a></li>');
         }
         else {
            $('li.menu-item-search').remove();
         }
      });
   });
});
9. Developing Custom Controls
If none of the basic core controls suit your needs, you can create
and add your own custom controls.
Custom Controls, Sections, and Panels can be created by
subclassing the PHP objects associated with each Customizer
object: WP_Customize_Control, WP_Customize_Section, and
WP_Customize_Panel.
9.1 Registering Custom Control Content
Either use the customize_register action hook.
function mytheme_customize_register( $wp_customize ) {
   // Add all your Customizer content (i.e. Panels, Sections, Settings & Controls) here...
);
add_action( 'customize_register', 'mytheme_customize_register' );
Or simply check for the existence of the WP_Customize_Control class
if ( class_exists( 'WP_Customize_Control' ) ) {
   // Add all your Customizer Custom Control classes here...
};
9.2 Creating our Custom Control Class
To create our Custom Control extend the WP_Customize_Control
class.
Display our own html content for the control by overriding the
render_content() function.
Enqueue CSS and Javascript files by overriding the enqueue()
function.
9.2 Creating our Custom Control Class
/**
 * Sample Custom Control
 */
class My_Awesome_Custom_Control extends WP_Customize_Control {
   // The type of control being rendered
   public $type = ‘sample_custom_control’;
   // Enqueue our scripts and styles
   public function enqueue() {
      // Enqueue our scripts here...
   }
   // Render the control in the customizer
   public function render_content() {
      // Render our control HTML here...
   }
}
9.3 Using our New Custom Control
Use Custom Controls in the same way as default built-in
controls.
First add the setting, then add the control. Only difference is we
have to specify our new class that we created.
9.3 Using our New Custom Control
// Test of Sample Custom Control
$wp_customize->add_setting( ‘sample_custom_control',
array(
'transport' => 'postMessage',
'sanitize_callback' => 'wp_filter_nohtml_kses'
)
);
$wp_customize->add_control( new My_Awesome_Custom_Control( $wp_customize, 'sample_custom_control',
array(
'label' => __( ‘Sample Custom Control' ),
'description' => esc_html__( 'This is the Custom Control description.' ),
'section' => 'sample_custom_controls_section'
)
) );
10. Triggering Changes for your Control
If you dynamically alter the content of your control using jQuery,
make sure you trigger a change event.
// Important! Make sure to trigger change event so Customizer knows it has to save the field
url.val('http://' + val).trigger('change');
11. Retrieving Cutomizer Settings
To retrieve your customizer settings, use get_theme_mod()
<?php echo get_theme_mod( 'background_color', '#fff' ); ?>
This example will retrieve (and echo) the theme setting with the
id background_color. If that doesn’t exist, it will return #fff instead.
Theme Options – The Customize API

https://developer.wordpress.org/themes/customize-api
#customize on Make WordPress Core

https://make.wordpress.org/core/tag/customize
Data Sanitization/Escaping

https://developer.wordpress.org/themes/theme-security/data-sanitization-escaping
Customizer Custom Controls & Example Code

https://github.com/maddisondesigns/customizer-custom-controls
Links to Remember
I’m Anthony Hortin
You can find me here
@maddisondesigns
maddisondesigns.com
@easywpguide
easywpguide.com
Thanks!
Questions?
https://maddisondesigns.com/developing-for-the-wordpress-customizer

More Related Content

What's hot

First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentNuvole
 
Vtlib 1.1
Vtlib 1.1Vtlib 1.1
Vtlib 1.1Arun n
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 
Best Practices for Magento Debugging
Best Practices for Magento Debugging Best Practices for Magento Debugging
Best Practices for Magento Debugging varien
 
Custom Post Types and Meta Fields
Custom Post Types and Meta FieldsCustom Post Types and Meta Fields
Custom Post Types and Meta FieldsLiton Arefin
 
Coldfusion Tips and Tricks
Coldfusion Tips and TricksColdfusion Tips and Tricks
Coldfusion Tips and TricksPradeep P
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4Javier Eguiluz
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHendy Irawan
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extensionHendy Irawan
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2Javier Eguiluz
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with AngularAna Cidre
 
Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)Jake Goldman
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsMark
 
ILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterpriseILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterpriseRené Winkelmeyer
 
Android Develpment vol. 3, MFF UK, 2015
Android Develpment vol. 3, MFF UK, 2015Android Develpment vol. 3, MFF UK, 2015
Android Develpment vol. 3, MFF UK, 2015Tomáš Kypta
 

What's hot (20)

First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 
Vtlib 1.1
Vtlib 1.1Vtlib 1.1
Vtlib 1.1
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 
Best Practices for Magento Debugging
Best Practices for Magento Debugging Best Practices for Magento Debugging
Best Practices for Magento Debugging
 
Custom Post Types and Meta Fields
Custom Post Types and Meta FieldsCustom Post Types and Meta Fields
Custom Post Types and Meta Fields
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Coldfusion Tips and Tricks
Coldfusion Tips and TricksColdfusion Tips and Tricks
Coldfusion Tips and Tricks
 
Zend framework 04 - forms
Zend framework 04 - formsZend framework 04 - forms
Zend framework 04 - forms
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
How to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento ExtensionHow to Create A Magento Adminhtml Controller in Magento Extension
How to Create A Magento Adminhtml Controller in Magento Extension
 
How to create a magento controller in magento extension
How to create a magento controller in magento extensionHow to create a magento controller in magento extension
How to create a magento controller in magento extension
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
 
Web components with Angular
Web components with AngularWeb components with Angular
Web components with Angular
 
Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)Editing the Visual Editor (WordPress)
Editing the Visual Editor (WordPress)
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
ILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterpriseILUG 2010 - Deploying plug-ins to the enterprise
ILUG 2010 - Deploying plug-ins to the enterprise
 
Zend Lab
Zend LabZend Lab
Zend Lab
 
Alfredo-PUMEX
Alfredo-PUMEXAlfredo-PUMEX
Alfredo-PUMEX
 
Android Develpment vol. 3, MFF UK, 2015
Android Develpment vol. 3, MFF UK, 2015Android Develpment vol. 3, MFF UK, 2015
Android Develpment vol. 3, MFF UK, 2015
 

Similar to Developing For The WordPress Customizer

WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 
Top Wordpress dashboard hacks
Top Wordpress dashboard hacks Top Wordpress dashboard hacks
Top Wordpress dashboard hacks Pankaj Subedi
 
Easy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme IntegrationEasy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme IntegrationSankhala Info Solutions
 
May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014Chad Windnagle
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress themeHardeep Asrani
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentTammy Hart
 
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Damien Carbery
 
Whmcs addon module docs
Whmcs addon module docsWhmcs addon module docs
Whmcs addon module docsquyvn
 
Best practice for WordPress theme building - WordPress North East June 2021
Best practice for WordPress theme building - WordPress North East June 2021Best practice for WordPress theme building - WordPress North East June 2021
Best practice for WordPress theme building - WordPress North East June 2021Peacock Carter Ltd
 
Drupal 7 — Circle theme
Drupal 7 — Circle themeDrupal 7 — Circle theme
Drupal 7 — Circle themeKirill Borzov
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme EnlightenmentAmanda Giles
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress developmentSteve Mortiboy
 
Getting Started With WordPress Development
Getting Started With WordPress DevelopmentGetting Started With WordPress Development
Getting Started With WordPress DevelopmentAndy Brudtkuhl
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalChandra Prakash Thapa
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017Amanda Giles
 
WordPress 3.0 at DC PHP
WordPress 3.0 at DC PHPWordPress 3.0 at DC PHP
WordPress 3.0 at DC PHPandrewnacin
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 

Similar to Developing For The WordPress Customizer (20)

Theme customization
Theme customizationTheme customization
Theme customization
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
Top Wordpress dashboard hacks
Top Wordpress dashboard hacks Top Wordpress dashboard hacks
Top Wordpress dashboard hacks
 
Easy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme IntegrationEasy Guide to WordPress Theme Integration
Easy Guide to WordPress Theme Integration
 
May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014May the core be with you - JandBeyond 2014
May the core be with you - JandBeyond 2014
 
WordCamp Praga 2015
WordCamp Praga 2015WordCamp Praga 2015
WordCamp Praga 2015
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
 
Whmcs addon module docs
Whmcs addon module docsWhmcs addon module docs
Whmcs addon module docs
 
Best practice for WordPress theme building - WordPress North East June 2021
Best practice for WordPress theme building - WordPress North East June 2021Best practice for WordPress theme building - WordPress North East June 2021
Best practice for WordPress theme building - WordPress North East June 2021
 
Drupal 7 — Circle theme
Drupal 7 — Circle themeDrupal 7 — Circle theme
Drupal 7 — Circle theme
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Getting Started With WordPress Development
Getting Started With WordPress DevelopmentGetting Started With WordPress Development
Getting Started With WordPress Development
 
Theme Customization
Theme CustomizationTheme Customization
Theme Customization
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
WordPress 3.0 at DC PHP
WordPress 3.0 at DC PHPWordPress 3.0 at DC PHP
WordPress 3.0 at DC PHP
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 

More from Anthony Hortin

Why you should be using WordPress child themes
Why you should be using WordPress child themesWhy you should be using WordPress child themes
Why you should be using WordPress child themesAnthony Hortin
 
Working with WooCommerce Custom Fields
Working with WooCommerce Custom FieldsWorking with WooCommerce Custom Fields
Working with WooCommerce Custom FieldsAnthony Hortin
 
Introduction to Advanced Custom Fields
Introduction to Advanced Custom FieldsIntroduction to Advanced Custom Fields
Introduction to Advanced Custom FieldsAnthony Hortin
 
The Why, When, How of WordPress Child Themes
The Why, When, How of WordPress Child ThemesThe Why, When, How of WordPress Child Themes
The Why, When, How of WordPress Child ThemesAnthony Hortin
 
Essential plugins for your WordPress Website
Essential plugins for your WordPress WebsiteEssential plugins for your WordPress Website
Essential plugins for your WordPress WebsiteAnthony Hortin
 
Building a Membership Site with WooCommerce Memberships
Building a Membership Site with WooCommerce MembershipsBuilding a Membership Site with WooCommerce Memberships
Building a Membership Site with WooCommerce MembershipsAnthony Hortin
 
Building a Membership Site with WooCommerce
Building a Membership Site with WooCommerceBuilding a Membership Site with WooCommerce
Building a Membership Site with WooCommerceAnthony Hortin
 
Getting to Grips with Firebug
Getting to Grips with FirebugGetting to Grips with Firebug
Getting to Grips with FirebugAnthony Hortin
 
Getting to Know WordPress May 2015
Getting to Know WordPress May 2015Getting to Know WordPress May 2015
Getting to Know WordPress May 2015Anthony Hortin
 
25 WordPress Plugins to Complement Your Site
25 WordPress Plugins to Complement Your Site25 WordPress Plugins to Complement Your Site
25 WordPress Plugins to Complement Your SiteAnthony Hortin
 
WordCamp San Francisco & WooCommerce Conference Recap
WordCamp San Francisco & WooCommerce Conference RecapWordCamp San Francisco & WooCommerce Conference Recap
WordCamp San Francisco & WooCommerce Conference RecapAnthony Hortin
 
Creating a multilingual site with WPML
Creating a multilingual site with WPMLCreating a multilingual site with WPML
Creating a multilingual site with WPMLAnthony Hortin
 
WordPress Visual Editor Mastery
WordPress Visual Editor MasteryWordPress Visual Editor Mastery
WordPress Visual Editor MasteryAnthony Hortin
 
Getting to know WordPress
Getting to know WordPressGetting to know WordPress
Getting to know WordPressAnthony Hortin
 
Do's & Don'ts for WordPress Theme Development
Do's & Don'ts for WordPress Theme DevelopmentDo's & Don'ts for WordPress Theme Development
Do's & Don'ts for WordPress Theme DevelopmentAnthony Hortin
 
Getting Started with WooCommerce
Getting Started with WooCommerceGetting Started with WooCommerce
Getting Started with WooCommerceAnthony Hortin
 
Submitting to the WordPress Theme Directory
Submitting to the WordPress Theme DirectorySubmitting to the WordPress Theme Directory
Submitting to the WordPress Theme DirectoryAnthony Hortin
 
WordPress Queries - the right way
WordPress Queries - the right wayWordPress Queries - the right way
WordPress Queries - the right wayAnthony Hortin
 
Getting to grips with firebug
Getting to grips with firebugGetting to grips with firebug
Getting to grips with firebugAnthony Hortin
 

More from Anthony Hortin (20)

Why you should be using WordPress child themes
Why you should be using WordPress child themesWhy you should be using WordPress child themes
Why you should be using WordPress child themes
 
Working with WooCommerce Custom Fields
Working with WooCommerce Custom FieldsWorking with WooCommerce Custom Fields
Working with WooCommerce Custom Fields
 
WordPress Gutenberg
WordPress GutenbergWordPress Gutenberg
WordPress Gutenberg
 
Introduction to Advanced Custom Fields
Introduction to Advanced Custom FieldsIntroduction to Advanced Custom Fields
Introduction to Advanced Custom Fields
 
The Why, When, How of WordPress Child Themes
The Why, When, How of WordPress Child ThemesThe Why, When, How of WordPress Child Themes
The Why, When, How of WordPress Child Themes
 
Essential plugins for your WordPress Website
Essential plugins for your WordPress WebsiteEssential plugins for your WordPress Website
Essential plugins for your WordPress Website
 
Building a Membership Site with WooCommerce Memberships
Building a Membership Site with WooCommerce MembershipsBuilding a Membership Site with WooCommerce Memberships
Building a Membership Site with WooCommerce Memberships
 
Building a Membership Site with WooCommerce
Building a Membership Site with WooCommerceBuilding a Membership Site with WooCommerce
Building a Membership Site with WooCommerce
 
Getting to Grips with Firebug
Getting to Grips with FirebugGetting to Grips with Firebug
Getting to Grips with Firebug
 
Getting to Know WordPress May 2015
Getting to Know WordPress May 2015Getting to Know WordPress May 2015
Getting to Know WordPress May 2015
 
25 WordPress Plugins to Complement Your Site
25 WordPress Plugins to Complement Your Site25 WordPress Plugins to Complement Your Site
25 WordPress Plugins to Complement Your Site
 
WordCamp San Francisco & WooCommerce Conference Recap
WordCamp San Francisco & WooCommerce Conference RecapWordCamp San Francisco & WooCommerce Conference Recap
WordCamp San Francisco & WooCommerce Conference Recap
 
Creating a multilingual site with WPML
Creating a multilingual site with WPMLCreating a multilingual site with WPML
Creating a multilingual site with WPML
 
WordPress Visual Editor Mastery
WordPress Visual Editor MasteryWordPress Visual Editor Mastery
WordPress Visual Editor Mastery
 
Getting to know WordPress
Getting to know WordPressGetting to know WordPress
Getting to know WordPress
 
Do's & Don'ts for WordPress Theme Development
Do's & Don'ts for WordPress Theme DevelopmentDo's & Don'ts for WordPress Theme Development
Do's & Don'ts for WordPress Theme Development
 
Getting Started with WooCommerce
Getting Started with WooCommerceGetting Started with WooCommerce
Getting Started with WooCommerce
 
Submitting to the WordPress Theme Directory
Submitting to the WordPress Theme DirectorySubmitting to the WordPress Theme Directory
Submitting to the WordPress Theme Directory
 
WordPress Queries - the right way
WordPress Queries - the right wayWordPress Queries - the right way
WordPress Queries - the right way
 
Getting to grips with firebug
Getting to grips with firebugGetting to grips with firebug
Getting to grips with firebug
 

Recently uploaded

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Developing For The WordPress Customizer

  • 2. The Theme Customization API, added in WordPress 3.4, allows developers to customize and add controls to the Appearance > Customize admin screen
  • 3. Even for themes that don’t provide additional options, there are certain core features built into the Customizer… Site Identity Menus Widgets Static Front Page Additional CSS (since WP 4.7)
  • 4. it is strongly recommended that developers study the core customizer code (all core files containing “customize”). This is considered the canonical, official documentation for the Customize API outside of the inline documentation within the core code.* *According to the Theme Handbook https://developer.wordpress.org/themes/customize-api/
  • 5. There are four main types of Customizer objects Panels are containers for Sections. Allows you to group multiple Sections together. Sections are where your Controls reside. They typically contain multiple Controls. Settings associate Controls with the settings that are saved in the database. Controls are the actual UI Elements such as Checkboxes, Select Lists & Radio Buttons.
  • 6. 1. Registering Customizer Content To add anything to the Customizer, you need to use the customize_register action hook. This hook gives you access to the $wp_customize object, which is an instance of the WP_Customize_Manager class. It’s this class object that controls the Customizer screen.
  • 7. 1. Registering Customizer Content Add your Panels, Sections, Settings & Controls (including Custom Controls) within a function used by this hook. /**  * Add our Customizer content  */ function mytheme_customize_register( $wp_customize ) {    // Add all your Customizer content (i.e. Panels, Sections, Settings & Controls) here... ); add_action( 'customize_register', 'mytheme_customize_register' );
  • 8. 2. Adding Panels Panels allow you to group multiple Sections together. Sections do not need to be nested under a panel. Panels must contain at least one Section, which must contain at least one Control, to be displayed.
  • 9. 2. Adding Panels /**  * Add our Header & Navigation Panel  */  $wp_customize->add_panel( 'header_naviation_panel',    array(       'title' => __( 'Header & Navigation' ),       'description' => esc_html__( 'Adjust your Header and Navigation sections.' ), // Include html tags such as <p>       'priority' => 160, // Not typically needed. Default is 160       'capability' => 'edit_theme_options', // Not typically needed. Default is edit_theme_options       'theme_supports' => '', // Rarely needed.       'active_callback' => '', // Rarely needed    ) );
  • 10. 3. Adding Sections Sections are where your Controls will reside. You’ll typically have multiple Controls in each Section. Sections can be added to Panels, but in most instances, this wont be necessary.
  • 11. 3. Adding Sections /**  * Add our Sample Section  */ $wp_customize->add_section( 'sample_custom_controls_section',    array(       'title' => __( 'Sample Custom Controls' ),       'description' => esc_html__( 'These are an example of Customizer Custom Controls.' ),       'panel' => '', // Only needed if adding your Section to a Panel       'priority' => 160, // Not typically needed. Default is 160       'capability' => 'edit_theme_options', // Not typically needed. Default is edit_theme_options       'theme_supports' => '', // Rarely needed       'active_callback' => '', // Rarely needed       'description_hidden' => 'false', // Rarely needed. Default is False    ) );
  • 12. 4. Adding Settings Settings and Controls work together. Settings handle live-previewing, saving, and sanitization of your customizer objects. Each Control that you register needs to have a matching Setting.
  • 13. 4. Adding Settings $wp_customize->add_setting( 'sample_default_text',    array(       'default' => '', // Optional.       'transport' => 'refresh', // Optional. 'refresh' or 'postMessage'. Default: 'refresh'       'type' => 'theme_mod', // Optional. 'theme_mod' or 'option'. Default: 'theme_mod'       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'       'theme_supports' => '', // Optional. Rarely needed       'validate_callback' => '', // Optional. The name of function that will be called to validate Customizer settings       'sanitize_callback' => '', // Optional. The name of function that will be called to sanitize the input data before saving it to the database       'sanitize_js_callback' => '', // Optional. The name the function that will be called to sanitize the data before outputting to javascript       'dirty' => false, // Optional. Rarely needed. Whether or not the setting is initially dirty when created. Default: False    ) );
  • 14. 5. Adding Controls Controls are the actual UI Elements that you’ll use to modify your theme settings. There are a number of Controls built into WordPress Core (e.g. Checkboxes, Select Lists, Radio Buttons etc.). For all other types of controls, you’ll need to extend the WP_Customize_Control class to create your own custom controls.
  • 15. There are several Core Controls that are ready to use straight-out-of-the-box… text, checkbox, textarea, radio buttons, select lists &
 dropdown-pages Later versions of WP also introduced… Color, Media, Image & Cropped Image
  • 16. 5.1 Input Control $wp_customize->add_control( 'sample_default_text',    array(       'label' => __( 'Default Text Control’ ),       'description' => esc_html__( 'Text controls Type can be either text, email, url, number, hidden, or date’ ),       'section' => 'default_controls_section',       'priority' => 10, // Optional. Order priority to load the control. Default: 10       'type' => 'text', // Can be either text, email, url, number, hidden, or date       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'       'input_attrs' => array( // Optional.          'class' => 'my-custom-class',          'style' => 'border: 1px solid rebeccapurple',          'placeholder' => __( 'Enter name...' ),       ),    ) );
  • 17. 5.2 Checkbox Control $wp_customize->add_control( 'sample_default_checkbox',    array(       'label' => __( 'Default Checkbox Control', 'ephemeris' ),       'description' => esc_html__( 'Sample description’ ),       'section'  => 'default_controls_section',       'priority' => 10, // Optional. Order priority to load the control. Default: 10       'type'=> 'checkbox',       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'    ) );
  • 18. 5.3 Select Control $wp_customize->add_control( 'sample_default_select',    array(       'label' => __( ’Standard Select Control’ ),       'description' => esc_html__( 'Sample description’ ),       'section' => 'default_controls_section',       'priority' => 10, // Optional. Order priority to load the control. Default: 10       'type' => 'select',       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'       'choices' => array( // Optional.          'wordpress' => 'WordPress',          'hamsters' => 'Hamsters',          'jet-fuel' => 'Jet Fuel',          'nuclear-energy' => 'Nuclear Energy'       )    ) );
  • 19. 5.4 Radio Button Control $wp_customize->add_control( 'sample_default_radio',    array(       'label' => __( ’Standard Radio Control’ ),       'description' => esc_html__( 'Sample description’ ),       'section' => 'default_controls_section',       'priority' => 10, // Optional. Order priority to load the control. Default: 10       'type' => 'radio',       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'       'choices' => array( // Optional.          'captain-america' => 'Captain America',          'iron-man' => 'Iron Man',          'spider-man' => 'Spider-Man',          'thor' => 'Thor'       )    ) );
  • 20. 5.5 Dropdown Pages Control $wp_customize->add_control( 'sample_default_dropdownpages',    array(       'label' => __( ’Default Dropdown Pages Control’ ),       'description' => esc_html__( 'Sample description’ ),       'section' => 'default_controls_section',       'priority' => 10, // Optional. Order priority to load the control. Default: 10       'type' => 'dropdown-pages',       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'    ) );
  • 21. 5.6 Textarea Control $wp_customize->add_control( 'sample_default_textarea',    array(       'label' => __( ’Default Textarea Control’ ),       'description' => esc_html__( 'Sample description’ ),       'section' => 'default_controls_section',       'priority' => 10, // Optional. Order priority to load the control. Default: 10       'type' => 'textarea',       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'       'input_attrs' => array( // Optional.          'class' => ‘my-custom-class', // Optional. Specify additional classes          'style' => 'border: 1px solid #999’, // Optional. Additional CSS for Control          'placeholder' => __( 'Enter message...' ), // Optional. Specify Placeholder text       ),    ) );
  • 22. 5.7 Color Control $wp_customize->add_control( 'sample_default_color',    array(       'label' => __( ’Default Color Control’ ),       'description' => esc_html__( 'Sample description’ ),       'section' => 'default_controls_section',       'priority' => 10, // Optional. Order priority to load the control. Default: 10       'type' => 'color',       'capability' => 'edit_theme_options', // Optional. Default: 'edit_theme_options'    ) );
  • 23. 5.8 Media Control $wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'sample_default_media',    array(       'label' => __( ’Default Media Control’ ),       'description' => esc_html__( 'This is the description for the Media Control’ ),       'section' => 'default_controls_section',       'mime_type' => ‘image', // Required. Can be image, audio, video, application, text.       'button_labels' => array( // Optional.          ‘select' => __( 'Select File' ),          ‘change' => __( 'Change File' ),          ‘default' => __( 'Default' ),          ‘remove' => __( 'Remove' ),          ‘placeholder' => __( 'No file selected' ),          ‘frame_title' => __( 'Select File' ),          ‘frame_button' => __( 'Choose File' ),       )    ) ) );
  • 24. 5.9 Image Control $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'sample_default_image',    array(       'label' => __( ’Default Image Control’ ),       'description' => esc_html__( 'This is the description for the Image Control’ ),       'section' => 'default_controls_section',       'button_labels' => array(          ‘select' => __( 'Select Image' ),          ‘change' => __( 'Change Image' ),          ‘remove' => __( 'Remove' ),          ‘default' => __( 'Default' ),          ‘placeholder' => __( 'No image selected' ),          ‘frame_title' => __( 'Select Image' ),          ‘frame_button' => __( 'Choose Image' ),       )    ) ) );
  • 25. 5.10 Cropped Image Control $wp_customize->add_control( new WP_Customize_Cropped_Image_Control( $wp_customize, 'sample_default_cropped_image',    array(       'label' => __( 'Default Cropped Image Control' ),       'description' => esc_html__( 'This is the description for the Cropped Image Control' ),       'section' => 'default_controls_section',       'flex_width' => false, // Optional. Default: false       'flex_height' => true, // Optional. Default: false       'width' => 800, // Optional. Default: 150       'height' => 400 // Optional. Default: 150    ) ) );
  • 26. 6. Data Sanitization Whenever you’re accepting data from users, the Number One rule is Trust Nobody. It’s always important that you validate and/or sanitize your data, especially if this data is being saved back to your database. xkcd: Exploits of a mum
  • 27. 6. Data Sanitization The type of sanitizing will depend on the type of data your expecting. e.g. Sanitizing an email is different than text For a simple text field, you could use wp_filter_nohtml_kses() which will strip all html from the content. $wp_customize->add_setting( 'sample_default_text',    array(       'default' => __( 'This is some default text' ),       'sanitize_callback' => 'wp_filter_nohtml_kses',    ) );
  • 28. 7. Adding Controls to existing Sections You can add Controls to existing Sections rather than creating your own section. Identical to adding Settings and Controls to your own Sections, the only difference is the section argument. $wp_customize->add_setting( 'my_new_header_image',    array(       'default' => __( 'center' ),       'sanitize_callback' => 'sanitize_text_field',    ) ); $wp_customize->add_control( 'my_new_header_image',    array(       'label' => __( 'Header Image Alignment' ),       'section' => 'header_image',       'type' => 'select',       'choices' => array(          'left' => 'Left',          'center' => 'Center',          'right' => 'Right',       )    ) );
  • 29. 8. Refreshing the Preview Two ways in which you can update the preview window - Refresh the whole page - Partial refresh, which is a refresh of just part of the page The type of refresh to use is set by the transport argument $wp_customize->add_setting( 'sample_default_text',    array(       'default' => '',       'transport' => ‘postMessage' // Optional. Either refresh or postMessage. Default: refresh    ) );
  • 30. 8.1 Full Refresh The default preview refresh in the Customizer is the full page refresh. The type of refresh to use is set by the transport argument $wp_customize->add_setting( 'sample_default_text',    array(       'default' => '',       'transport' => ‘refresh' // Optional. Either refresh or postMessage. Default: refresh    ) );
  • 31. 8.2 Partial Refresh Option A - Use PHP & AJAX When adding your setting set transport to postMessage To use a PHP function (via AJAX) you need to register a Partial. $wp_customize->selective_refresh->add_partial( 'social_urls',    array(       'selector' => '.social-header',       'container_inclusive' => false,       'render_callback' => function() {          echo mytheme_get_social_media_icons();       },       'fallback_refresh' => true    ) );
  • 32. 8.2 Partial Refresh Option B - Use jQuery Enqueue your script for use in the Customizer using the customize_preview_init action hook & bind your jQuery function to the control you want to update jQuery( document ).ready(function($) {    wp.customize('search_menu_icon', function(control) {       control.bind(function( controlValue ) {          if( controlValue == true ) {             $('.nav-menu').append('<li class="menu-item menu-item-search"><a href=“#">New menu item</a></li>');          }          else {             $('li.menu-item-search').remove();          }       });    }); });
  • 33. 9. Developing Custom Controls If none of the basic core controls suit your needs, you can create and add your own custom controls. Custom Controls, Sections, and Panels can be created by subclassing the PHP objects associated with each Customizer object: WP_Customize_Control, WP_Customize_Section, and WP_Customize_Panel.
  • 34. 9.1 Registering Custom Control Content Either use the customize_register action hook. function mytheme_customize_register( $wp_customize ) {    // Add all your Customizer content (i.e. Panels, Sections, Settings & Controls) here... ); add_action( 'customize_register', 'mytheme_customize_register' ); Or simply check for the existence of the WP_Customize_Control class if ( class_exists( 'WP_Customize_Control' ) ) {    // Add all your Customizer Custom Control classes here... };
  • 35. 9.2 Creating our Custom Control Class To create our Custom Control extend the WP_Customize_Control class. Display our own html content for the control by overriding the render_content() function. Enqueue CSS and Javascript files by overriding the enqueue() function.
  • 36. 9.2 Creating our Custom Control Class /**  * Sample Custom Control  */ class My_Awesome_Custom_Control extends WP_Customize_Control {    // The type of control being rendered    public $type = ‘sample_custom_control’;    // Enqueue our scripts and styles    public function enqueue() {       // Enqueue our scripts here...    }    // Render the control in the customizer    public function render_content() {       // Render our control HTML here...    } }
  • 37. 9.3 Using our New Custom Control Use Custom Controls in the same way as default built-in controls. First add the setting, then add the control. Only difference is we have to specify our new class that we created.
  • 38. 9.3 Using our New Custom Control // Test of Sample Custom Control $wp_customize->add_setting( ‘sample_custom_control', array( 'transport' => 'postMessage', 'sanitize_callback' => 'wp_filter_nohtml_kses' ) ); $wp_customize->add_control( new My_Awesome_Custom_Control( $wp_customize, 'sample_custom_control', array( 'label' => __( ‘Sample Custom Control' ), 'description' => esc_html__( 'This is the Custom Control description.' ), 'section' => 'sample_custom_controls_section' ) ) );
  • 39. 10. Triggering Changes for your Control If you dynamically alter the content of your control using jQuery, make sure you trigger a change event. // Important! Make sure to trigger change event so Customizer knows it has to save the field url.val('http://' + val).trigger('change');
  • 40. 11. Retrieving Cutomizer Settings To retrieve your customizer settings, use get_theme_mod() <?php echo get_theme_mod( 'background_color', '#fff' ); ?> This example will retrieve (and echo) the theme setting with the id background_color. If that doesn’t exist, it will return #fff instead.
  • 41. Theme Options – The Customize API
 https://developer.wordpress.org/themes/customize-api #customize on Make WordPress Core
 https://make.wordpress.org/core/tag/customize Data Sanitization/Escaping
 https://developer.wordpress.org/themes/theme-security/data-sanitization-escaping Customizer Custom Controls & Example Code
 https://github.com/maddisondesigns/customizer-custom-controls Links to Remember
  • 42. I’m Anthony Hortin You can find me here @maddisondesigns maddisondesigns.com @easywpguide easywpguide.com Thanks! Questions? https://maddisondesigns.com/developing-for-the-wordpress-customizer