SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
The Customizer
Konstantin Obenland
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Konstantin Obenland
Theme Wrangler at Automattic
@obenland
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
What’s The Customizer?
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Customizer Anatomy
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Customizer Anatomy
Section Title
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Customizer Anatomy
Section Description
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Customizer Anatomy
Control
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Relationships within the Customizer
Control
Control
Control
Control
Section
Setting
Setting
Setting
Setting
DatabaseSection
Section
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Theme Mods & Options
Digression
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Options
“The Options API is a simple and standardized way of storing data in
the database.” — WordPress Codex
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Theme Modifications
• Options API for themes.
• Introduced in 2.1 (!)
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Theme Mods API
set_theme_mod( $name, $value );
get_theme_mod( $name, $default = false );
remove_theme_mod( $name );
get_theme_mods();
remove_theme_mods();
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Theme Mods API
// Function simplified for brevity and clarity.
function get_theme_mod( $name, $default = false ) {
	 $mods = get_option( 'theme_mods_' . get_option( 'stylesheet' ) );
	 if ( isset( $mods[ $name ] ) )
	 	 return $mods[ $name ];
	 return $default;
}
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
The Customizer API
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Get Started
/**
* Registers the theme setting controls with the Customizer.
*
* @param WP_Customize_Manager $wp_customize
*/
function prefix_customize_register( $wp_customize ) {
	 // Code
}
add_action( 'customize_register', 'prefix_customize_register' );
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Adding a Section
$wp_customize->add_section( 'unique_section_id', array(
	 'title' => __( 'Title', 'textdomain' ),
	 'priority' => 10,
	 'description' => __( 'Description', 'textdomain' ),
	 'theme_supports' => '',
	 'capability' => 'edit_theme_options',
) );
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Adding a Setting
$wp_customize->add_setting( 'settings_name', array(
	 'type' => 'theme_mod', // 'option'
	 'capability' => 'edit_theme_options',
	 'theme_supports' => '',
	 'default' => '',
	 'transport' => 'refresh', // 'postMessage'
	 'sanitize_callback' => '',
	 'sanitize_js_callback' => '',
) );
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Adding a Control
$wp_customize->add_control( 'unique_control_id', array(
	 'label' => __( 'Label', 'textdomain' ),
	 'section' => 'unique_section_id',
	 'priority' => 10,
	 'settings' => 'unique_settings_id',
	 'type' => 'radio', // 'text','checkbox','select','dropdown-pages'
	 'choices' => array(
	 	 'value' => __( 'Choice', 'textdomain' ),
	 ),
) );
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Customizer Anatomy
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
$this->add_section( 'title_tagline', array(
	 'title' => __( 'Site Title & Tagline' ),
	 'priority' => 20,
) );
$this->add_setting( 'blogname', array(
	 'default' => get_option( 'blogname' ),
	 'type' => 'option',
	 'capability' => 'manage_options',
) );
$this->add_control( , array(
	 'label' => __( 'Site Title' ),
	 'section' => ,
) );
A Complete Setting
'title_tagline'
'blogname'
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
$this->add_section( 'title_tagline', array(
	 'title' => __( 'Site Title & Tagline' ),
	 'priority' => 20,
) );
$this->add_setting( 'blogname', array(
	 'default' => get_option( 'blogname' ),
	 'type' => 'option',
	 'capability' => 'manage_options',
) );
$this->add_control( , array(
	 'label' => __( 'Site Title' ),
	 'section' => ,
) );
A Complete Setting
'title_tagline'
'blogname'
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
$this->add_section( 'title_tagline', array(
	 'title' => __( 'Site Title & Tagline' ),
	 'priority' => 20,
) );
$this->add_setting( 'blogname', array(
	 'default' => get_option( 'blogname' ),
	 'type' => 'option',
	 'capability' => 'manage_options',
) );
$this->add_control( , array(
	 'label' => __( 'Site Title' ),
	 'section' => ,
) );
A Complete Setting
'title_tagline'
'blogname'
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Validation & Sanitization
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
function prefix_customize_register( $wp_customize ) {
$wp_customize->add_setting( 'prefix_layout', array(
'default' => 'content-sidebar',
'sanitize_callback' => 'prefix_sanitize_layout', // 'is_email', 'esc_url_raw'
) );
$wp_customize->add_control( 'prefix_layout', $args );
}
add_action( 'customize_register', 'prefix_customize_register' );
function prefix_sanitize_layout( $value ) {
if ( ! in_array( $value, array( 'content-sidebar', 'sidebar-content' ) ) )
$value = 'content-sidebar';
return $value;
}
Validation & Sanitization
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
function prefix_customize_register( $wp_customize ) {
$wp_customize->add_setting( 'prefix_theme_options[layout]', array(
'default' => 'content-sidebar',
'type' => 'option',
) );
$wp_customize->add_control( 'prefix_theme_options[layout]', $args );
}
add_action( 'customize_register', 'prefix_customize_register' );
function prefix_sanitize_customizer( $option ) {
if ( ! isset( $option['prefix_layout'] ) ||
! in_array( $option['prefix_layout'], array( 'content-sidebar', 'sidebar-content' ) ) )
$option['prefix_layout'] = 'content-sidebar';
return $option;
}
register_setting( 'prefix_theme_options', 'prefix_theme_options', 'prefix_sanitize_customizer' );
Validation & Sanitization
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Transport Methods
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
$wp_customize->add_setting( 'unique_settings_id', array(
	 'default' => '',
	 'transport' => 'postMessage', // 'refresh'
) );
Transport Methods
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Saturday, September 21, 13
/**
* Add postMessage support for site title and description for the Customizer.
*
* @since Twenty Thirteen 1.0
*
* @param WP_Customize_Manager $wp_customize Customizer object.
* @return void
*/
function twentythirteen_customize_register( $wp_customize ) {
	 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
	 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
	 $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
}
add_action( 'customize_register', 'twentythirteen_customize_register' );
In Twenty Thirteen
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
/**
* Binds JavaScript handlers to make Customizer preview reload changes
* asynchronously.
*
* @since Twenty Thirteen 1.0
*/
function twentythirteen_customize_preview_js() {
	 wp_enqueue_script(
	 	 'twentythirteen-customizer',
	 	 get_template_directory_uri() . '/js/theme-customizer.js',
	 	 array( 'customize-preview' ),
	 	 '20130226',
	 	 true
	 );
}
add_action( 'customize_preview_init', 'twentythirteen_customize_preview_js' );
In Twenty Thirteen
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
/**
* Theme Customizer enhancements for a better user experience.
* Contains handlers to make Theme Customizer preview reload changes asynchronously.
*/
( function( $ ) {
	 // Site title and description.
	 wp.customize( 'blogname', function( value ) {
	 	 value.bind( function( to ) {
	 	 	 $( '.site-title' ).text( to );
	 	 } );
	 } );
	 wp.customize( 'blogdescription', function( value ) {
	 	 value.bind( function( to ) {
	 	 	 $( '.site-description' ).text( to );
	 	 } );
	 } );
} )( jQuery );
In Twenty Thirteen
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
wp.customize( 'header_textcolor', function( value ) {
	 value.bind( function( to ) {
	 	 if ( 'blank' == to ) {
	 	 	 if ( 'remove-header' == _wpCustomizeSettings.values.header_image )
	 	 	 	 $( '.home-link' ).css( 'min-height', '0' );
	 	 	 $( '.site-title, .site-description' ).css( {
	 	 	 	 'clip': 'rect(1px, 1px, 1px, 1px)',
	 	 	 	 'position': 'absolute'
	 	 	 } );
	 	 } else {
	 	 	 $( '.home-link' ).css( 'min-height', '230px' );
	 	 	 $( '.site-title, .site-description' ).css( {
	 	 	 	 'clip': 'auto',
	 	 	 	 'color': to,
	 	 	 	 'position': 'relative'
	 	 	 } );
	 	 }
	 } );
} );
In Twenty Thirteen
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Custom Controls
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Built-in Controls
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
class Prefix_Customize_Textarea_Control extends WP_Customize_Control {
	 public $type = 'textarea';
	 public function render_content() {
	 	 ?>
	 	 <label>
	 	 	 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
	 	 	 <textarea rows="5" <?php $this->link(); ?>>
	 	 	 	 <?php echo esc_textarea( $this->value() ); ?>
	 	 	 </textarea>
	 	 </label>
	 	 <?php
	 }
}
Custom Controls
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Built-in Custom Controls
WP_Customize_Color_Control
WP_Customize_Upload_Control
WP_Customize_Image_Control
WP_Customize_Background_Image_Control
WP_Customize_Header_Image_Control
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
WP_Customize_Image_Control
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
WP_Customize_Color_Control
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array(
	 'label' => __( 'Accent Color', 'twentyfourteen' ),
	 'section' => 'colors',
	 'settings' => 'accent_color',
) ) );
Custom Controls
 The Customizer Konstantin Obenland 
Saturday, September 21, 13
Thanks!
Questions?
 The Customizer Konstantin Obenland 
Saturday, September 21, 13

Weitere ähnliche Inhalte

Andere mochten auch

Lessons Learned from Contributing to Default Themes
Lessons Learned from Contributing to Default ThemesLessons Learned from Contributing to Default Themes
Lessons Learned from Contributing to Default ThemesKonstantin Obenland
 
Twenty Thirteen - Ins and Outs of Developing a Default Theme
Twenty Thirteen - Ins and Outs of Developing a Default ThemeTwenty Thirteen - Ins and Outs of Developing a Default Theme
Twenty Thirteen - Ins and Outs of Developing a Default ThemeKonstantin Obenland
 
Pathosethoslogosreview
PathosethoslogosreviewPathosethoslogosreview
Pathosethoslogosreviewdarinjohn2
 
Can the City be Ethical?
Can the City be Ethical?Can the City be Ethical?
Can the City be Ethical?wdcrouch
 
Goat Collective // PPP Presentation
Goat Collective // PPP PresentationGoat Collective // PPP Presentation
Goat Collective // PPP PresentationPoppy Young
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3Poppy Young
 
Final storyboard
Final storyboardFinal storyboard
Final storyboardPoppy Young
 
PISA 2009 results
PISA 2009 resultsPISA 2009 results
PISA 2009 resultsOECD
 
Evaluation question 2
Evaluation question 2Evaluation question 2
Evaluation question 2Poppy Young
 
Poppy Young - Level - PPP Presentation
Poppy Young  - Level - PPP PresentationPoppy Young  - Level - PPP Presentation
Poppy Young - Level - PPP PresentationPoppy Young
 

Andere mochten auch (15)

The Theme Review Process
The Theme Review ProcessThe Theme Review Process
The Theme Review Process
 
Actions & Filters In WordPress
Actions & Filters In WordPressActions & Filters In WordPress
Actions & Filters In WordPress
 
Contributing to WordPress
Contributing to WordPressContributing to WordPress
Contributing to WordPress
 
Lessons Learned from Contributing to Default Themes
Lessons Learned from Contributing to Default ThemesLessons Learned from Contributing to Default Themes
Lessons Learned from Contributing to Default Themes
 
New Theme Directory
New Theme DirectoryNew Theme Directory
New Theme Directory
 
Twenty Thirteen - Ins and Outs of Developing a Default Theme
Twenty Thirteen - Ins and Outs of Developing a Default ThemeTwenty Thirteen - Ins and Outs of Developing a Default Theme
Twenty Thirteen - Ins and Outs of Developing a Default Theme
 
Pathosethoslogosreview
PathosethoslogosreviewPathosethoslogosreview
Pathosethoslogosreview
 
Can the City be Ethical?
Can the City be Ethical?Can the City be Ethical?
Can the City be Ethical?
 
Goat Collective // PPP Presentation
Goat Collective // PPP PresentationGoat Collective // PPP Presentation
Goat Collective // PPP Presentation
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
 
Final storyboard
Final storyboardFinal storyboard
Final storyboard
 
PISA 2009 results
PISA 2009 resultsPISA 2009 results
PISA 2009 results
 
Evaluation question 2
Evaluation question 2Evaluation question 2
Evaluation question 2
 
Poppy Young - Level - PPP Presentation
Poppy Young  - Level - PPP PresentationPoppy Young  - Level - PPP Presentation
Poppy Young - Level - PPP Presentation
 
Chap6
Chap6Chap6
Chap6
 

Ähnlich wie The Customizer

Customizer-ing Theme Options: A Visual Playground
Customizer-ing Theme Options: A Visual PlaygroundCustomizer-ing Theme Options: A Visual Playground
Customizer-ing Theme Options: A Visual PlaygroundDrewAPicture
 
Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012Mike Schinkel
 
Building secured wordpress themes and plugins
Building secured wordpress themes and pluginsBuilding secured wordpress themes and plugins
Building secured wordpress themes and pluginsTikaram Bhandari
 
WordPress customizer for themes and more
WordPress customizer for themes and moreWordPress customizer for themes and more
WordPress customizer for themes and moreSantosh Kunwar
 
Wordpress plugin development from Scratch
Wordpress plugin development from ScratchWordpress plugin development from Scratch
Wordpress plugin development from ScratchOcaka Alfred
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First WidgetChris Wilcoxson
 
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDBMongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDBMongoDB
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011Alessandro Nadalin
 
Stop Ember Time
Stop Ember TimeStop Ember Time
Stop Ember Timecjwoodward
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringIngo Schommer
 
Connecting Custom Post Types
Connecting Custom Post TypesConnecting Custom Post Types
Connecting Custom Post TypesJoe Casabona
 
Gutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisablesGutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisablesRiad Benguella
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From IusethisMarcus Ramberg
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Codemotion
 

Ähnlich wie The Customizer (20)

Customizer-ing Theme Options: A Visual Playground
Customizer-ing Theme Options: A Visual PlaygroundCustomizer-ing Theme Options: A Visual Playground
Customizer-ing Theme Options: A Visual Playground
 
Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012Mastering Custom Post Types - WordCamp Atlanta 2012
Mastering Custom Post Types - WordCamp Atlanta 2012
 
Lithium Best
Lithium Best Lithium Best
Lithium Best
 
Codigo taller-plugins
Codigo taller-pluginsCodigo taller-plugins
Codigo taller-plugins
 
Building secured wordpress themes and plugins
Building secured wordpress themes and pluginsBuilding secured wordpress themes and plugins
Building secured wordpress themes and plugins
 
WordPress customizer for themes and more
WordPress customizer for themes and moreWordPress customizer for themes and more
WordPress customizer for themes and more
 
Wordpress plugin development from Scratch
Wordpress plugin development from ScratchWordpress plugin development from Scratch
Wordpress plugin development from Scratch
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDBMongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 
Stop Ember Time
Stop Ember TimeStop Ember Time
Stop Ember Time
 
SilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript RefactoringSilverStripe CMS JavaScript Refactoring
SilverStripe CMS JavaScript Refactoring
 
Connecting Custom Post Types
Connecting Custom Post TypesConnecting Custom Post Types
Connecting Custom Post Types
 
Gutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisablesGutenberg sous le capot, modules réutilisables
Gutenberg sous le capot, modules réutilisables
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
Building a theming system with React - Matteo Ronchi - Codemotion Amsterdam 2017
 

Mehr von Konstantin Obenland

Mehr von Konstantin Obenland (8)

Shiny Updates, A Feature Plugin in Two Acts
Shiny Updates, A Feature Plugin in Two ActsShiny Updates, A Feature Plugin in Two Acts
Shiny Updates, A Feature Plugin in Two Acts
 
Lessons from WordPress 4.3
Lessons from WordPress 4.3Lessons from WordPress 4.3
Lessons from WordPress 4.3
 
WordPress 4.1
WordPress 4.1WordPress 4.1
WordPress 4.1
 
Underscores DE
Underscores DEUnderscores DE
Underscores DE
 
Cain & Obenland — Episode 4
Cain & Obenland — Episode 4Cain & Obenland — Episode 4
Cain & Obenland — Episode 4
 
Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!
 
Organisation von Selbstorganisation
Organisation von SelbstorganisationOrganisation von Selbstorganisation
Organisation von Selbstorganisation
 
Self-Organizing Teams In Scrum
Self-Organizing Teams In ScrumSelf-Organizing Teams In Scrum
Self-Organizing Teams In Scrum
 

Kürzlich hochgeladen

Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckHajeJanKamps
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessSeta Wicaksana
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionMintel Group
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation SlidesKeppelCorporation
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...ictsugar
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...lizamodels9
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis UsageNeil Kimberley
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menzaictsugar
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...lizamodels9
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...lizamodels9
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCRashishs7044
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxMarkAnthonyAurellano
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfRbc Rbcua
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africaictsugar
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?Olivia Kresic
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Pereraictsugar
 

Kürzlich hochgeladen (20)

Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
 
Organizational Structure Running A Successful Business
Organizational Structure Running A Successful BusinessOrganizational Structure Running A Successful Business
Organizational Structure Running A Successful Business
 
Future Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted VersionFuture Of Sample Report 2024 | Redacted Version
Future Of Sample Report 2024 | Redacted Version
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
 
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In.../:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
/:Call Girls In Indirapuram Ghaziabad ➥9990211544 Independent Best Escorts In...
 
2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage2024 Numerator Consumer Study of Cannabis Usage
2024 Numerator Consumer Study of Cannabis Usage
 
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu MenzaYouth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
Youth Involvement in an Innovative Coconut Value Chain by Mwalimu Menza
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
Call Girls In Connaught Place Delhi ❤️88604**77959_Russian 100% Genuine Escor...
 
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
8447779800, Low rate Call girls in New Ashok Nagar Delhi NCR
 
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptxContemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
Contemporary Economic Issues Facing the Filipino Entrepreneur (1).pptx
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdf
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africa
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?MAHA Global and IPR: Do Actions Speak Louder Than Words?
MAHA Global and IPR: Do Actions Speak Louder Than Words?
 
Kenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith PereraKenya Coconut Production Presentation by Dr. Lalith Perera
Kenya Coconut Production Presentation by Dr. Lalith Perera
 

The Customizer

  • 1. The Customizer Konstantin Obenland  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 2. Konstantin Obenland Theme Wrangler at Automattic @obenland  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 3. What’s The Customizer?  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 4.  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 5. Customizer Anatomy  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 6. Customizer Anatomy Section Title  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 7. Customizer Anatomy Section Description  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 8. Customizer Anatomy Control  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 9. Relationships within the Customizer Control Control Control Control Section Setting Setting Setting Setting DatabaseSection Section  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 10. Theme Mods & Options Digression  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 11. Options “The Options API is a simple and standardized way of storing data in the database.” — WordPress Codex  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 12. Theme Modifications • Options API for themes. • Introduced in 2.1 (!)  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 13. Theme Mods API set_theme_mod( $name, $value ); get_theme_mod( $name, $default = false ); remove_theme_mod( $name ); get_theme_mods(); remove_theme_mods();  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 14. Theme Mods API // Function simplified for brevity and clarity. function get_theme_mod( $name, $default = false ) { $mods = get_option( 'theme_mods_' . get_option( 'stylesheet' ) ); if ( isset( $mods[ $name ] ) ) return $mods[ $name ]; return $default; }  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 15. The Customizer API  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 16. Get Started /** * Registers the theme setting controls with the Customizer. * * @param WP_Customize_Manager $wp_customize */ function prefix_customize_register( $wp_customize ) { // Code } add_action( 'customize_register', 'prefix_customize_register' );  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 17. Adding a Section $wp_customize->add_section( 'unique_section_id', array( 'title' => __( 'Title', 'textdomain' ), 'priority' => 10, 'description' => __( 'Description', 'textdomain' ), 'theme_supports' => '', 'capability' => 'edit_theme_options', ) );  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 18. Adding a Setting $wp_customize->add_setting( 'settings_name', array( 'type' => 'theme_mod', // 'option' 'capability' => 'edit_theme_options', 'theme_supports' => '', 'default' => '', 'transport' => 'refresh', // 'postMessage' 'sanitize_callback' => '', 'sanitize_js_callback' => '', ) );  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 19. Adding a Control $wp_customize->add_control( 'unique_control_id', array( 'label' => __( 'Label', 'textdomain' ), 'section' => 'unique_section_id', 'priority' => 10, 'settings' => 'unique_settings_id', 'type' => 'radio', // 'text','checkbox','select','dropdown-pages' 'choices' => array( 'value' => __( 'Choice', 'textdomain' ), ), ) );  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 20. Customizer Anatomy  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 21. $this->add_section( 'title_tagline', array( 'title' => __( 'Site Title & Tagline' ), 'priority' => 20, ) ); $this->add_setting( 'blogname', array( 'default' => get_option( 'blogname' ), 'type' => 'option', 'capability' => 'manage_options', ) ); $this->add_control( , array( 'label' => __( 'Site Title' ), 'section' => , ) ); A Complete Setting 'title_tagline' 'blogname'  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 22. $this->add_section( 'title_tagline', array( 'title' => __( 'Site Title & Tagline' ), 'priority' => 20, ) ); $this->add_setting( 'blogname', array( 'default' => get_option( 'blogname' ), 'type' => 'option', 'capability' => 'manage_options', ) ); $this->add_control( , array( 'label' => __( 'Site Title' ), 'section' => , ) ); A Complete Setting 'title_tagline' 'blogname'  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 23. $this->add_section( 'title_tagline', array( 'title' => __( 'Site Title & Tagline' ), 'priority' => 20, ) ); $this->add_setting( 'blogname', array( 'default' => get_option( 'blogname' ), 'type' => 'option', 'capability' => 'manage_options', ) ); $this->add_control( , array( 'label' => __( 'Site Title' ), 'section' => , ) ); A Complete Setting 'title_tagline' 'blogname'  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 24. Validation & Sanitization  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 25. function prefix_customize_register( $wp_customize ) { $wp_customize->add_setting( 'prefix_layout', array( 'default' => 'content-sidebar', 'sanitize_callback' => 'prefix_sanitize_layout', // 'is_email', 'esc_url_raw' ) ); $wp_customize->add_control( 'prefix_layout', $args ); } add_action( 'customize_register', 'prefix_customize_register' ); function prefix_sanitize_layout( $value ) { if ( ! in_array( $value, array( 'content-sidebar', 'sidebar-content' ) ) ) $value = 'content-sidebar'; return $value; } Validation & Sanitization  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 26. function prefix_customize_register( $wp_customize ) { $wp_customize->add_setting( 'prefix_theme_options[layout]', array( 'default' => 'content-sidebar', 'type' => 'option', ) ); $wp_customize->add_control( 'prefix_theme_options[layout]', $args ); } add_action( 'customize_register', 'prefix_customize_register' ); function prefix_sanitize_customizer( $option ) { if ( ! isset( $option['prefix_layout'] ) || ! in_array( $option['prefix_layout'], array( 'content-sidebar', 'sidebar-content' ) ) ) $option['prefix_layout'] = 'content-sidebar'; return $option; } register_setting( 'prefix_theme_options', 'prefix_theme_options', 'prefix_sanitize_customizer' ); Validation & Sanitization  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 27. Transport Methods  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 28. $wp_customize->add_setting( 'unique_settings_id', array( 'default' => '', 'transport' => 'postMessage', // 'refresh' ) ); Transport Methods  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 30. /** * Add postMessage support for site title and description for the Customizer. * * @since Twenty Thirteen 1.0 * * @param WP_Customize_Manager $wp_customize Customizer object. * @return void */ function twentythirteen_customize_register( $wp_customize ) { $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; } add_action( 'customize_register', 'twentythirteen_customize_register' ); In Twenty Thirteen  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 31. /** * Binds JavaScript handlers to make Customizer preview reload changes * asynchronously. * * @since Twenty Thirteen 1.0 */ function twentythirteen_customize_preview_js() { wp_enqueue_script( 'twentythirteen-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20130226', true ); } add_action( 'customize_preview_init', 'twentythirteen_customize_preview_js' ); In Twenty Thirteen  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 32. /** * Theme Customizer enhancements for a better user experience. * Contains handlers to make Theme Customizer preview reload changes asynchronously. */ ( function( $ ) { // Site title and description. wp.customize( 'blogname', function( value ) { value.bind( function( to ) { $( '.site-title' ).text( to ); } ); } ); wp.customize( 'blogdescription', function( value ) { value.bind( function( to ) { $( '.site-description' ).text( to ); } ); } ); } )( jQuery ); In Twenty Thirteen  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 33. wp.customize( 'header_textcolor', function( value ) { value.bind( function( to ) { if ( 'blank' == to ) { if ( 'remove-header' == _wpCustomizeSettings.values.header_image ) $( '.home-link' ).css( 'min-height', '0' ); $( '.site-title, .site-description' ).css( { 'clip': 'rect(1px, 1px, 1px, 1px)', 'position': 'absolute' } ); } else { $( '.home-link' ).css( 'min-height', '230px' ); $( '.site-title, .site-description' ).css( { 'clip': 'auto', 'color': to, 'position': 'relative' } ); } } ); } ); In Twenty Thirteen  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 34. Custom Controls  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 35. Built-in Controls  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 36. class Prefix_Customize_Textarea_Control extends WP_Customize_Control { public $type = 'textarea'; public function render_content() { ?> <label> <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> <textarea rows="5" <?php $this->link(); ?>> <?php echo esc_textarea( $this->value() ); ?> </textarea> </label> <?php } } Custom Controls  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 38. WP_Customize_Image_Control  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 39. WP_Customize_Color_Control  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 40. $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'accent_color', array( 'label' => __( 'Accent Color', 'twentyfourteen' ), 'section' => 'colors', 'settings' => 'accent_color', ) ) ); Custom Controls  The Customizer Konstantin Obenland  Saturday, September 21, 13
  • 41. Thanks! Questions?  The Customizer Konstantin Obenland  Saturday, September 21, 13