Creating Customizer Options for Themes and Plugins

R-Cubed Design Forge
R-Cubed Design ForgeR-Cubed Design Forge
r3df.com
lumostech.training
Rick Radko
“Creating Customizer Options
for Themes and Plugins”
WordCamp Toronto
October 4th, 2015
Slides at: slideshare.net/r3df
© 2015 Rick Radko, r3df.com
What's this talk about?
 An introduction to adding customizer options to
your plugins and themes.
Topics:
 Introduction
 Brief introduction to customizer
 Creating customizer options
 4 steps
 Using the options
 Beyond the Basics
1Slides at: slideshare.net/r3df
© 2015 Rick Radko, r3df.com
Objectives of this talk:
 Demonstrate that it is easy to add basic
customizer options to plugins and themes.
 Encourage you to start using the customizer for
your options.
For code examples for this presentation, I'm going
to use a plugin I created recently:
 wordpress.org/plugins/r3df-copyright-message
 (Version 1.1.0)
2Slides at: slideshare.net/r3df
© 2015 Rick Radko, r3df.com
About me
 Rick Radko, @r3designforge
Software, website and app designer/developer,
trainer, speaker.
 R-Cubed Design Forge: r3df.com
 LumosTech Training: lumostech.training
Creating custom web sites since 1996.
 WordPress sites since 2008.
An organizer of:
 WordCamp Ottawa.
 The Ottawa WordPress Group.
3Slides at: slideshare.net/r3df
© 2015 Rick Radko, r3df.com
Theme Customizer - WordPress 3.4
4
© 2015 Rick Radko, r3df.com
Customizer in 4.3
5
© 2015 Rick Radko, r3df.com
Customizer in 4.3 - Menus
6
© 2015 Rick Radko, r3df.com
Customizer in 4.3 - Site Icon
7
© 2015 Rick Radko, r3df.com
Why use the Customizer for options?
It provides a ready to use options framework:
 Native to WordPress
 No need to re-invent the wheel.
 Lots of built in controls.
 Can add custom controls.
 Now required for themes in wordpress.org repo.
 It’s the future for options.
I'm using it for:
 Custom theme & child theme options.
 Small plugins.
8
© 2015 Rick Radko, r3df.com
Plugin: Custom Login Page Customizer
9
© 2015 Rick Radko, r3df.com
Example Plugin: R3DF Copyright Message
10
wordpress.org/plugins/r3df-copyright-message
© 2015 Rick Radko, r3df.com
Adding a customizer option - 4 easy steps
1. Register your customizer set-up function.
2. Add a section.
3. Add settings.
4. Add controls to connect the settings to the
section.
11
© 2015 Rick Radko, r3df.com
Step 1. Register the customizer function
12
© 2015 Rick Radko, r3df.com
A gotcha for the 'customize_register' hook
From the codex:
"Important: Do not conditionally load your Customizer
code with an is_admin() check."
13
© 2015 Rick Radko, r3df.com
Step 2. Add a section
 $section_id - A unique ID for the section.
 $args: array
 title - the name of the section
 priority - (optional) controls display order of the
sections
 description - (optional) add descriptive text to the
section
14
© 2015 Rick Radko, r3df.com
Priorities for top level items
15
Priority (Order)
20
40
60
80
100
110
120
160 (default)
© 2015 Rick Radko, r3df.com
The section code for the plugin
Note:
 You will not be able to see the section until it
contains at least one control.
16
© 2015 Rick Radko, r3df.com
Step 3. Add setting(s)
 $setting_id - A unique ID for the setting.
 $args: array
 default - default value for the setting
 type - (optional)
types are 'option' or 'theme_mod'
type defaults to 'theme_mod'
Note:
 You will not be able to see the setting until it is
registered with a control.
17
© 2015 Rick Radko, r3df.com
Where are the values stored?
By default:
 Values are stored in the "wp_options" table.
 The option key depends on setting type:
 theme_mod:
Option key: theme_mods_{theme-name}
Array key (in the option): setting_id
 option:
Option key: setting_id
18
© 2015 Rick Radko, r3df.com
The settings code for the plugin
Note:
 The pseudo array notation, for the setting id, stores
the options as an array.
19
© 2015 Rick Radko, r3df.com
Step 4. Add control(s)
 $control_id - A unique ID for the control.
 If you set it to the value of a setting id, it will control
that setting. (instead of setting the settings arg)
 $args: array
 label - a label for the control
 description - a description below the label
 section - the section for the control
 type - basic types include:
text, checkbox, radio, select, dropdown-pages,
textarea…
20
© 2015 Rick Radko, r3df.com
The controls code for the plugin
21
© 2015 Rick Radko, r3df.com
The controls code for the plugin
22
© 2015 Rick Radko, r3df.com
The plugin display so far in customizer
23
© 2015 Rick Radko, r3df.com
The plugin - expanded
24
© 2015 Rick Radko, r3df.com
Where’s the copyright message?
25
© 2015 Rick Radko, r3df.com
Using saved option values
Setting type:
 theme_mod:
 option:
 Can use with standard WordPress options.
ie: convert existing plugin
26
© 2015 Rick Radko, r3df.com
The plugin's output code
27
© 2015 Rick Radko, r3df.com
The complete result in the customizer
28
© 2015 Rick Radko, r3df.com
The result on the frontend
29
© 2015 Rick Radko, r3df.com
Beyond the basics - Conditional actions
Conditional display – dependent on radio button 30
© 2015 Rick Radko, r3df.com
Beyond the basics - Transport
By default, when a customizer setting is changed:
 The preview is updated with a page refresh.
 This has a notable lag…
But, we can fix that…
31
© 2015 Rick Radko, r3df.com
Beyond the basics - Transport
Add some javascript…
…and the page will update “instantly”.
Note:
 Preview javascript is loaded on the
"customize_preview_init" action 32
© 2015 Rick Radko, r3df.com
Beyond the basics - Sanitizing values
Input data can be sanitized by adding callbacks to
the add_setting() definition:
 Built in WordPress functions can often be used.
 sanitize_key() checks that the data looks like an
internal identifier (key).
33
© 2015 Rick Radko, r3df.com
Beyond the basics - Panels
34
2 Items
© 2015 Rick Radko, r3df.com
Beyond the basics - Panels
35
New top level
© 2015 Rick Radko, r3df.com
Beyond the basics - Panels
36
© 2015 Rick Radko, r3df.com
Beyond the basics - Panels
 Panel with 2 sections
37
© 2015 Rick Radko, r3df.com
Beyond the basics - Modifying existing sections
 get_panel() for panels, get_setting() for settings, and
get_control() for controls
38
Section Id
title_tagline
colors
header_image
background_image
nav_menus
widgets
static_front_page
r3df_copyright_message_settings
© 2015 Rick Radko, r3df.com
Beyond the basics - Advanced controls
Advanced Controls:
 Color picker: WP_Customize_Color_Control()
 Media uploader: WP_Customize_Upload_Control()
 Image uploader: WP_Customize_Image_Control()
 Background image control:
WP_Customize_Background_Image_Control()
 Header image control:
WP_Customize_Header_Image_Control()
Custom controls:
 ottopress.com/2012/making-a-custom-control-for-
the-theme-customizer/
39
© 2015 Rick Radko, r3df.com
How does preview update without saving?
The customizer preview intercepts calls to:
 get_theme_mod
 get_option
Replaces them with the "live" content from the
customizer controls.
Note:
 This only seems to work on or after the action
"parse_request".
40
© 2015 Rick Radko, r3df.com
Learn More…
 codex.wordpress.org/Theme_Customization_API
 developer.wordpress.org/themes/advanced-topics/customizer-api/
 developer.wordpress.org/reference/classes/wp_customize_manager/
 ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-
themes/
 ottopress.com/2012/theme-customizer-part-deux-getting-rid-of-options-
pages/
 ottopress.com/2012/making-a-custom-control-for-the-theme-customizer/
 ottopress.com/2015/whats-new-with-the-customizer/
 gavick.com/blog/contextual-controls-theme-customizer
 gavick.com/blog/using-javascript-theme-customization-screen
 make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-
for-the-customizer/
 make.wordpress.org/core/2015/07/27/site-icon/
41
© 2015 Rick Radko, r3df.com
Contact
Rick Radko
 email: wpinfo@r3df.com
 twitter: @r3designforge
Websites:
 r3df.com
 lumostech.training
Slides at:
 www.slideshare.net/r3df
42
1 of 43

Recommended

Intro to WordPress Plugin Development by
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentR-Cubed Design Forge
2.4K views71 slides
How to WordPress: the basics, part 2 by
How to WordPress:  the basics, part 2How to WordPress:  the basics, part 2
How to WordPress: the basics, part 2R-Cubed Design Forge
1.5K views108 slides
WordPress page builders - a new tool to build awesome pages quickly by
WordPress page builders - a new tool to build awesome pages quicklyWordPress page builders - a new tool to build awesome pages quickly
WordPress page builders - a new tool to build awesome pages quicklyR-Cubed Design Forge
456 views40 slides
WordPress page builders a quick introduction by
WordPress page builders a quick introductionWordPress page builders a quick introduction
WordPress page builders a quick introductionR-Cubed Design Forge
518 views25 slides
WordPress website backups – they're not optional by
WordPress website backups – they're not optionalWordPress website backups – they're not optional
WordPress website backups – they're not optionalR-Cubed Design Forge
362 views45 slides
Overview on WordPress theme file structure and working functionality by
Overview on WordPress theme file structure and working functionality Overview on WordPress theme file structure and working functionality
Overview on WordPress theme file structure and working functionality Rakesh Kushwaha
8.5K views25 slides

More Related Content

What's hot

How to convert your Full Trust Solutions to the SharePoint Framework (SPFx) by
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)Brian Culver
205 views25 slides
Introduction to-concrete-5 by
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5ketanraval
6K views14 slides
Introduction to-concrete-5 by
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5Ketan Raval
4.4K views14 slides
The Future of the Web: HTML5 by
The Future of the Web: HTML5The Future of the Web: HTML5
The Future of the Web: HTML5Derek Bender
8.2K views33 slides
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) by
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)Brian Culver
243 views25 slides
soft-shake.ch - WebMatrix: Your Web Made Easy by
soft-shake.ch - WebMatrix: Your Web Made Easysoft-shake.ch - WebMatrix: Your Web Made Easy
soft-shake.ch - WebMatrix: Your Web Made Easysoft-shake.ch
1.7K views20 slides

What's hot(19)

How to convert your Full Trust Solutions to the SharePoint Framework (SPFx) by Brian Culver
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
How to convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver205 views
Introduction to-concrete-5 by ketanraval
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
ketanraval6K views
Introduction to-concrete-5 by Ketan Raval
Introduction to-concrete-5Introduction to-concrete-5
Introduction to-concrete-5
Ketan Raval4.4K views
The Future of the Web: HTML5 by Derek Bender
The Future of the Web: HTML5The Future of the Web: HTML5
The Future of the Web: HTML5
Derek Bender8.2K views
Convert your Full Trust Solutions to the SharePoint Framework (SPFx) by Brian Culver
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Brian Culver243 views
soft-shake.ch - WebMatrix: Your Web Made Easy by soft-shake.ch
soft-shake.ch - WebMatrix: Your Web Made Easysoft-shake.ch - WebMatrix: Your Web Made Easy
soft-shake.ch - WebMatrix: Your Web Made Easy
soft-shake.ch1.7K views
Wordpress Command-Line by wpperu
Wordpress Command-LineWordpress Command-Line
Wordpress Command-Line
wpperu371 views
Mage Titans USA 2016 M2 deployment by Olga Kopylova
Mage Titans USA 2016  M2 deploymentMage Titans USA 2016  M2 deployment
Mage Titans USA 2016 M2 deployment
Olga Kopylova5.7K views
The Workflow Methodology to Train Your Team on Drupal 8 by Acquia
The Workflow Methodology to Train Your Team on Drupal 8The Workflow Methodology to Train Your Team on Drupal 8
The Workflow Methodology to Train Your Team on Drupal 8
Acquia1.3K views
Using composer with WordPress by Micah Wood
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
Micah Wood1.2K views
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes by Acquia
Speedrun: Build a Website with Panels, Media, and More in 45 MinutesSpeedrun: Build a Website with Panels, Media, and More in 45 Minutes
Speedrun: Build a Website with Panels, Media, and More in 45 Minutes
Acquia1.8K views
Getting started with WordPress development by Steve Mortiboy
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
Steve Mortiboy1.3K views
Grav CMS by btopro
Grav CMSGrav CMS
Grav CMS
btopro293 views
Meetup-js-112815 by Joe Devlin
Meetup-js-112815Meetup-js-112815
Meetup-js-112815
Joe Devlin457 views
HTML5--The 30,000' View (A fast-paced overview of HTML5) by Peter Lubbers
HTML5--The 30,000' View (A fast-paced overview of HTML5)HTML5--The 30,000' View (A fast-paced overview of HTML5)
HTML5--The 30,000' View (A fast-paced overview of HTML5)
Peter Lubbers55.9K views
Nürnberg WooCommerce Talk - 11/24/16 by tshellberg
Nürnberg WooCommerce Talk - 11/24/16Nürnberg WooCommerce Talk - 11/24/16
Nürnberg WooCommerce Talk - 11/24/16
tshellberg2.4K views

Viewers also liked

Ecomm 101 by
Ecomm 101Ecomm 101
Ecomm 101Al Davis
1.7K views20 slides
Wordcamp_mcglade_ux_mashups by
Wordcamp_mcglade_ux_mashupsWordcamp_mcglade_ux_mashups
Wordcamp_mcglade_ux_mashupsAnalytical Engine Interactive Inc.
1.7K views20 slides
Using Actions and Filters in WordPress to Make a Plugin Your Own by
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnBrian Hogg
1.7K views17 slides
Systematic Unit Testing by
Systematic Unit TestingSystematic Unit Testing
Systematic Unit Testingscotchfield
1.7K views80 slides
A Noob's Journey to the Core by
A Noob's Journey to the CoreA Noob's Journey to the Core
A Noob's Journey to the CoreRyan Welcher
1.6K views55 slides
How I Made a Career Using WordPress Without Knowing a Line of Code by
How I Made a Career Using WordPress Without Knowing a Line of CodeHow I Made a Career Using WordPress Without Knowing a Line of Code
How I Made a Career Using WordPress Without Knowing a Line of CodeAndrea Zoellner
1.6K views15 slides

Viewers also liked(20)

Ecomm 101 by Al Davis
Ecomm 101Ecomm 101
Ecomm 101
Al Davis1.7K views
Using Actions and Filters in WordPress to Make a Plugin Your Own by Brian Hogg
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your Own
Brian Hogg1.7K views
Systematic Unit Testing by scotchfield
Systematic Unit TestingSystematic Unit Testing
Systematic Unit Testing
scotchfield1.7K views
A Noob's Journey to the Core by Ryan Welcher
A Noob's Journey to the CoreA Noob's Journey to the Core
A Noob's Journey to the Core
Ryan Welcher1.6K views
How I Made a Career Using WordPress Without Knowing a Line of Code by Andrea Zoellner
How I Made a Career Using WordPress Without Knowing a Line of CodeHow I Made a Career Using WordPress Without Knowing a Line of Code
How I Made a Career Using WordPress Without Knowing a Line of Code
Andrea Zoellner1.6K views
Help Me Help You: Practical Tips for Designers from A WordPress Developer by daraskolnick
Help Me Help You: Practical Tips for Designers from A WordPress DeveloperHelp Me Help You: Practical Tips for Designers from A WordPress Developer
Help Me Help You: Practical Tips for Designers from A WordPress Developer
daraskolnick1.4K views
Here Be Dragons - Debugging WordPress by Rami Sayar
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
Rami Sayar2K views
WordCamp Toronto 2015- API Simple Talk by ting-y
WordCamp Toronto 2015- API Simple TalkWordCamp Toronto 2015- API Simple Talk
WordCamp Toronto 2015- API Simple Talk
ting-y1.6K views
Building and Maintaining A Remote Workforce - A Startup Story by Sucuri
Building and Maintaining A Remote Workforce - A Startup StoryBuilding and Maintaining A Remote Workforce - A Startup Story
Building and Maintaining A Remote Workforce - A Startup Story
Sucuri 1.7K views
Community Consultation Creates Compelling Content by Christine Pollock
Community Consultation Creates Compelling Content  Community Consultation Creates Compelling Content
Community Consultation Creates Compelling Content
Christine Pollock1.7K views
You have 2 hands Toronto by Shayda Torabi
You have 2 hands TorontoYou have 2 hands Toronto
You have 2 hands Toronto
Shayda Torabi1.7K views
Writing Secure Code for WordPress by Shawn Hooper
Writing Secure Code for WordPressWriting Secure Code for WordPress
Writing Secure Code for WordPress
Shawn Hooper2K views
Speeding up your WordPress Site - WordCamp Toronto 2015 by Alan Lok
Speeding up your WordPress Site - WordCamp Toronto 2015Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015
Alan Lok4.1K views
Best Friend || Worst Enemy: WordPress Multisite by Taylor McCaslin
Best Friend || Worst Enemy: WordPress MultisiteBest Friend || Worst Enemy: WordPress Multisite
Best Friend || Worst Enemy: WordPress Multisite
Taylor McCaslin2.4K views
Delightful Design with the Kano Model (WordCamp Toronto 2015) by Jesse Emmanuel Rosario
Delightful Design with the Kano Model (WordCamp Toronto 2015)Delightful Design with the Kano Model (WordCamp Toronto 2015)
Delightful Design with the Kano Model (WordCamp Toronto 2015)
How to use CSS3 in WordPress by Suzette Franck
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
Suzette Franck6.1K views

Similar to Creating Customizer Options for Themes and Plugins

WordPress customizer: for themes and more by
WordPress customizer: for themes and moreWordPress customizer: for themes and more
WordPress customizer: for themes and moreR-Cubed Design Forge
790 views40 slides
A peek into the world of WordPress plugin development by
A peek into the world of WordPress plugin developmentA peek into the world of WordPress plugin development
A peek into the world of WordPress plugin developmentR-Cubed Design Forge
8.5K views56 slides
Introduction to WordPress by
Introduction to WordPressIntroduction to WordPress
Introduction to WordPressR-Cubed Design Forge
2.3K views148 slides
Intro to development sites and site migration by
Intro to development sites and site migrationIntro to development sites and site migration
Intro to development sites and site migrationR-Cubed Design Forge
1.6K views73 slides
Introduction to WordPress, WordCamp Ottawa 2019 by
Introduction to WordPress, WordCamp Ottawa 2019Introduction to WordPress, WordCamp Ottawa 2019
Introduction to WordPress, WordCamp Ottawa 2019rickrrr
78 views77 slides
Multisite for multilingual by
Multisite for multilingualMultisite for multilingual
Multisite for multilingualR-Cubed Design Forge
1.9K views50 slides

Similar to Creating Customizer Options for Themes and Plugins(20)

A peek into the world of WordPress plugin development by R-Cubed Design Forge
A peek into the world of WordPress plugin developmentA peek into the world of WordPress plugin development
A peek into the world of WordPress plugin development
Introduction to WordPress, WordCamp Ottawa 2019 by rickrrr
Introduction to WordPress, WordCamp Ottawa 2019Introduction to WordPress, WordCamp Ottawa 2019
Introduction to WordPress, WordCamp Ottawa 2019
rickrrr78 views
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA) by cgmonroe
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
Tips on Securing Drupal Sites - DrupalCamp Atlanta (DCA)
cgmonroe67 views
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz... by Nagios
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios1.2K views
Gutenberg 101/Blocks - How to get along with, and even like WordPress's block... by R-Cubed Design Forge
Gutenberg 101/Blocks - How to get along with, and even like WordPress's block...Gutenberg 101/Blocks - How to get along with, and even like WordPress's block...
Gutenberg 101/Blocks - How to get along with, and even like WordPress's block...
CISOA Conference 2020 Banner 9 Development by Brad Rippe
CISOA Conference 2020 Banner 9 DevelopmentCISOA Conference 2020 Banner 9 Development
CISOA Conference 2020 Banner 9 Development
Brad Rippe164 views
Hand-On Lab: CA Release Automation Rapid Development Kit and SDK by CA Technologies
Hand-On Lab: CA Release Automation Rapid Development Kit and SDKHand-On Lab: CA Release Automation Rapid Development Kit and SDK
Hand-On Lab: CA Release Automation Rapid Development Kit and SDK
CA Technologies1.2K views
Pre-Con Education: Zero to Compliance Using Software Asset Management Soluti... by CA Technologies
Pre-Con Education: Zero to Compliance Using Software Asset Management Soluti...Pre-Con Education: Zero to Compliance Using Software Asset Management Soluti...
Pre-Con Education: Zero to Compliance Using Software Asset Management Soluti...
CA Technologies3.4K views
Turbogears2 tutorial to create mvc app by fRui Apps
Turbogears2 tutorial to create mvc appTurbogears2 tutorial to create mvc app
Turbogears2 tutorial to create mvc app
fRui Apps1.5K views
Developer insight into why applications run amazingly Fast in CF 2018 by Pavan Kumar
Developer insight into why applications run amazingly Fast in CF 2018Developer insight into why applications run amazingly Fast in CF 2018
Developer insight into why applications run amazingly Fast in CF 2018
Pavan Kumar248 views
Working with Images in WordPress by randyhoyt
Working with Images in WordPress Working with Images in WordPress
Working with Images in WordPress
randyhoyt1.3K views

More from R-Cubed Design Forge

Finding themes for your WordPress site by
Finding themes for your WordPress siteFinding themes for your WordPress site
Finding themes for your WordPress siteR-Cubed Design Forge
83 views23 slides
Setting up a local web server environment by
Setting up a local web server environmentSetting up a local web server environment
Setting up a local web server environmentR-Cubed Design Forge
303 views8 slides
Gutenberg - The future of WordPress by
Gutenberg - The future of WordPressGutenberg - The future of WordPress
Gutenberg - The future of WordPressR-Cubed Design Forge
181 views18 slides
Backups, Backups, Backups by
Backups, Backups, BackupsBackups, Backups, Backups
Backups, Backups, BackupsR-Cubed Design Forge
260 views50 slides
Setting up a local web server for WordPress by
Setting up a local web server for WordPressSetting up a local web server for WordPress
Setting up a local web server for WordPressR-Cubed Design Forge
482 views6 slides
Backing up your WordPress website – it’s not optional by
Backing up your WordPress website – it’s not optionalBacking up your WordPress website – it’s not optional
Backing up your WordPress website – it’s not optionalR-Cubed Design Forge
1.3K views43 slides

More from R-Cubed Design Forge(8)

Recently uploaded

SUPPLIER SOURCING.pptx by
SUPPLIER SOURCING.pptxSUPPLIER SOURCING.pptx
SUPPLIER SOURCING.pptxangelicacueva6
16 views1 slide
Future of AR - Facebook Presentation by
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentationssuserb54b561
15 views27 slides
Case Study Copenhagen Energy and Business Central.pdf by
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdfAitana
16 views3 slides
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...Jasper Oosterveld
19 views49 slides
Powerful Google developer tools for immediate impact! (2023-24) by
Powerful Google developer tools for immediate impact! (2023-24)Powerful Google developer tools for immediate impact! (2023-24)
Powerful Google developer tools for immediate impact! (2023-24)wesley chun
10 views38 slides
PRODUCT LISTING.pptx by
PRODUCT LISTING.pptxPRODUCT LISTING.pptx
PRODUCT LISTING.pptxangelicacueva6
14 views1 slide

Recently uploaded(20)

Future of AR - Facebook Presentation by ssuserb54b561
Future of AR - Facebook PresentationFuture of AR - Facebook Presentation
Future of AR - Facebook Presentation
ssuserb54b56115 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
Powerful Google developer tools for immediate impact! (2023-24) by wesley chun
Powerful Google developer tools for immediate impact! (2023-24)Powerful Google developer tools for immediate impact! (2023-24)
Powerful Google developer tools for immediate impact! (2023-24)
wesley chun10 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson92 views
6g - REPORT.pdf by Liveplex
6g - REPORT.pdf6g - REPORT.pdf
6g - REPORT.pdf
Liveplex10 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker40 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi132 views
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf

Creating Customizer Options for Themes and Plugins

  • 1. r3df.com lumostech.training Rick Radko “Creating Customizer Options for Themes and Plugins” WordCamp Toronto October 4th, 2015 Slides at: slideshare.net/r3df
  • 2. © 2015 Rick Radko, r3df.com What's this talk about?  An introduction to adding customizer options to your plugins and themes. Topics:  Introduction  Brief introduction to customizer  Creating customizer options  4 steps  Using the options  Beyond the Basics 1Slides at: slideshare.net/r3df
  • 3. © 2015 Rick Radko, r3df.com Objectives of this talk:  Demonstrate that it is easy to add basic customizer options to plugins and themes.  Encourage you to start using the customizer for your options. For code examples for this presentation, I'm going to use a plugin I created recently:  wordpress.org/plugins/r3df-copyright-message  (Version 1.1.0) 2Slides at: slideshare.net/r3df
  • 4. © 2015 Rick Radko, r3df.com About me  Rick Radko, @r3designforge Software, website and app designer/developer, trainer, speaker.  R-Cubed Design Forge: r3df.com  LumosTech Training: lumostech.training Creating custom web sites since 1996.  WordPress sites since 2008. An organizer of:  WordCamp Ottawa.  The Ottawa WordPress Group. 3Slides at: slideshare.net/r3df
  • 5. © 2015 Rick Radko, r3df.com Theme Customizer - WordPress 3.4 4
  • 6. © 2015 Rick Radko, r3df.com Customizer in 4.3 5
  • 7. © 2015 Rick Radko, r3df.com Customizer in 4.3 - Menus 6
  • 8. © 2015 Rick Radko, r3df.com Customizer in 4.3 - Site Icon 7
  • 9. © 2015 Rick Radko, r3df.com Why use the Customizer for options? It provides a ready to use options framework:  Native to WordPress  No need to re-invent the wheel.  Lots of built in controls.  Can add custom controls.  Now required for themes in wordpress.org repo.  It’s the future for options. I'm using it for:  Custom theme & child theme options.  Small plugins. 8
  • 10. © 2015 Rick Radko, r3df.com Plugin: Custom Login Page Customizer 9
  • 11. © 2015 Rick Radko, r3df.com Example Plugin: R3DF Copyright Message 10 wordpress.org/plugins/r3df-copyright-message
  • 12. © 2015 Rick Radko, r3df.com Adding a customizer option - 4 easy steps 1. Register your customizer set-up function. 2. Add a section. 3. Add settings. 4. Add controls to connect the settings to the section. 11
  • 13. © 2015 Rick Radko, r3df.com Step 1. Register the customizer function 12
  • 14. © 2015 Rick Radko, r3df.com A gotcha for the 'customize_register' hook From the codex: "Important: Do not conditionally load your Customizer code with an is_admin() check." 13
  • 15. © 2015 Rick Radko, r3df.com Step 2. Add a section  $section_id - A unique ID for the section.  $args: array  title - the name of the section  priority - (optional) controls display order of the sections  description - (optional) add descriptive text to the section 14
  • 16. © 2015 Rick Radko, r3df.com Priorities for top level items 15 Priority (Order) 20 40 60 80 100 110 120 160 (default)
  • 17. © 2015 Rick Radko, r3df.com The section code for the plugin Note:  You will not be able to see the section until it contains at least one control. 16
  • 18. © 2015 Rick Radko, r3df.com Step 3. Add setting(s)  $setting_id - A unique ID for the setting.  $args: array  default - default value for the setting  type - (optional) types are 'option' or 'theme_mod' type defaults to 'theme_mod' Note:  You will not be able to see the setting until it is registered with a control. 17
  • 19. © 2015 Rick Radko, r3df.com Where are the values stored? By default:  Values are stored in the "wp_options" table.  The option key depends on setting type:  theme_mod: Option key: theme_mods_{theme-name} Array key (in the option): setting_id  option: Option key: setting_id 18
  • 20. © 2015 Rick Radko, r3df.com The settings code for the plugin Note:  The pseudo array notation, for the setting id, stores the options as an array. 19
  • 21. © 2015 Rick Radko, r3df.com Step 4. Add control(s)  $control_id - A unique ID for the control.  If you set it to the value of a setting id, it will control that setting. (instead of setting the settings arg)  $args: array  label - a label for the control  description - a description below the label  section - the section for the control  type - basic types include: text, checkbox, radio, select, dropdown-pages, textarea… 20
  • 22. © 2015 Rick Radko, r3df.com The controls code for the plugin 21
  • 23. © 2015 Rick Radko, r3df.com The controls code for the plugin 22
  • 24. © 2015 Rick Radko, r3df.com The plugin display so far in customizer 23
  • 25. © 2015 Rick Radko, r3df.com The plugin - expanded 24
  • 26. © 2015 Rick Radko, r3df.com Where’s the copyright message? 25
  • 27. © 2015 Rick Radko, r3df.com Using saved option values Setting type:  theme_mod:  option:  Can use with standard WordPress options. ie: convert existing plugin 26
  • 28. © 2015 Rick Radko, r3df.com The plugin's output code 27
  • 29. © 2015 Rick Radko, r3df.com The complete result in the customizer 28
  • 30. © 2015 Rick Radko, r3df.com The result on the frontend 29
  • 31. © 2015 Rick Radko, r3df.com Beyond the basics - Conditional actions Conditional display – dependent on radio button 30
  • 32. © 2015 Rick Radko, r3df.com Beyond the basics - Transport By default, when a customizer setting is changed:  The preview is updated with a page refresh.  This has a notable lag… But, we can fix that… 31
  • 33. © 2015 Rick Radko, r3df.com Beyond the basics - Transport Add some javascript… …and the page will update “instantly”. Note:  Preview javascript is loaded on the "customize_preview_init" action 32
  • 34. © 2015 Rick Radko, r3df.com Beyond the basics - Sanitizing values Input data can be sanitized by adding callbacks to the add_setting() definition:  Built in WordPress functions can often be used.  sanitize_key() checks that the data looks like an internal identifier (key). 33
  • 35. © 2015 Rick Radko, r3df.com Beyond the basics - Panels 34 2 Items
  • 36. © 2015 Rick Radko, r3df.com Beyond the basics - Panels 35 New top level
  • 37. © 2015 Rick Radko, r3df.com Beyond the basics - Panels 36
  • 38. © 2015 Rick Radko, r3df.com Beyond the basics - Panels  Panel with 2 sections 37
  • 39. © 2015 Rick Radko, r3df.com Beyond the basics - Modifying existing sections  get_panel() for panels, get_setting() for settings, and get_control() for controls 38 Section Id title_tagline colors header_image background_image nav_menus widgets static_front_page r3df_copyright_message_settings
  • 40. © 2015 Rick Radko, r3df.com Beyond the basics - Advanced controls Advanced Controls:  Color picker: WP_Customize_Color_Control()  Media uploader: WP_Customize_Upload_Control()  Image uploader: WP_Customize_Image_Control()  Background image control: WP_Customize_Background_Image_Control()  Header image control: WP_Customize_Header_Image_Control() Custom controls:  ottopress.com/2012/making-a-custom-control-for- the-theme-customizer/ 39
  • 41. © 2015 Rick Radko, r3df.com How does preview update without saving? The customizer preview intercepts calls to:  get_theme_mod  get_option Replaces them with the "live" content from the customizer controls. Note:  This only seems to work on or after the action "parse_request". 40
  • 42. © 2015 Rick Radko, r3df.com Learn More…  codex.wordpress.org/Theme_Customization_API  developer.wordpress.org/themes/advanced-topics/customizer-api/  developer.wordpress.org/reference/classes/wp_customize_manager/  ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own- themes/  ottopress.com/2012/theme-customizer-part-deux-getting-rid-of-options- pages/  ottopress.com/2012/making-a-custom-control-for-the-theme-customizer/  ottopress.com/2015/whats-new-with-the-customizer/  gavick.com/blog/contextual-controls-theme-customizer  gavick.com/blog/using-javascript-theme-customization-screen  make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api- for-the-customizer/  make.wordpress.org/core/2015/07/27/site-icon/ 41
  • 43. © 2015 Rick Radko, r3df.com Contact Rick Radko  email: wpinfo@r3df.com  twitter: @r3designforge Websites:  r3df.com  lumostech.training Slides at:  www.slideshare.net/r3df 42