SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette

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
Konstantin Obenland
 
Pathosethoslogosreview
PathosethoslogosreviewPathosethoslogosreview
Pathosethoslogosreview
darinjohn2
 
Can the City be Ethical?
Can the City be Ethical?Can the City be Ethical?
Can the City be Ethical?
wdcrouch
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
Poppy Young
 
Final storyboard
Final storyboardFinal storyboard
Final storyboard
Poppy Young
 
PISA 2009 results
PISA 2009 resultsPISA 2009 results
PISA 2009 results
OECD
 
Evaluation question 2
Evaluation question 2Evaluation question 2
Evaluation question 2
Poppy Young
 
Poppy Young - Level - PPP Presentation
Poppy Young  - Level - PPP PresentationPoppy Young  - Level - PPP Presentation
Poppy Young - Level - PPP Presentation
Poppy Young
 

En vedette (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
 

Similaire à The Customizer

Stop Ember Time
Stop Ember TimeStop Ember Time
Stop Ember Time
cjwoodward
 
前端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 Jasmine
Paulo Ragonha
 

Similaire à 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
 

Plus de Konstantin Obenland

Plus de 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
 

Dernier

Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
ZurliaSoop
 

Dernier (20)

Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Buy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail AccountsBuy gmail accounts.pdf buy Old Gmail Accounts
Buy gmail accounts.pdf buy Old Gmail Accounts
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 
Putting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptxPutting the SPARK into Virtual Training.pptx
Putting the SPARK into Virtual Training.pptx
 
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Kalyan Call Girl 98350*37198 Call Girls in Escort service book now
Kalyan Call Girl 98350*37198 Call Girls in Escort service book nowKalyan Call Girl 98350*37198 Call Girls in Escort service book now
Kalyan Call Girl 98350*37198 Call Girls in Escort service book now
 
Falcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business PotentialFalcon Invoice Discounting: Unlock Your Business Potential
Falcon Invoice Discounting: Unlock Your Business Potential
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGParadip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Paradip CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTSJAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
 
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
 
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book nowGUWAHATI 💋 Call Girl 9827461493 Call Girls in  Escort service book now
GUWAHATI 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...
joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...joint cost.pptx  COST ACCOUNTING  Sixteenth Edition                          ...
joint cost.pptx COST ACCOUNTING Sixteenth Edition ...
 
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan CytotecJual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
Jual Obat Aborsi ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan Cytotec
 
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165Lucknow Housewife Escorts  by Sexy Bhabhi Service 8250092165
Lucknow Housewife Escorts by Sexy Bhabhi Service 8250092165
 

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