Slide 1

Slide 1 text

Embracing The Customizer @luke_redroot red-root.com

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Then (April 2012)

Slide 4

Slide 4 text

Now

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

DEMO

Slide 7

Slide 7 text

Sections

Slide 8

Slide 8 text

Settings

Slide 9

Slide 9 text

Controls text text checkbox

Slide 10

Slide 10 text

# mytheme/functions.php require("lib/customizer.php"); # mytheme/lib/customizer.php add_action("customize_register",function($wpc){ // code here });

Slide 11

Slide 11 text

// PHP 5.3 add_action("customize_register",function($wpc){ // code here }); // equivalent to add_action("customize_register","named_function"); function named_function($wpc){ // code here }

Slide 12

Slide 12 text

add_action("customize_register",function($wpc){ $wpc->add_section(); $wpc->add_setting(); $wpc->add_control(); });

Slide 13

Slide 13 text

$wpc->add_section("heading_section",array( "title" => "My Heading Section", "priority" => 35, "capability" => "edit_theme_options" ));

Slide 14

Slide 14 text

$wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type" => "option", "capability" => "edit_theme_options" ));

Slide 15

Slide 15 text

# mytheme/lib/customizer.php $wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type" => "option" )); # mytheme/index.php $options = get_option("mytheme_options"); $heading = $options["heading"];

Slide 16

Slide 16 text

# mytheme/lib/customizer.php $wpc->add_setting("mytheme_options_heading",array( "default" => "Default Heading", "type" => "option", )); # mytheme/index.php $heading = get_option("mytheme_options_heading");

Slide 17

Slide 17 text

# mytheme/lib/customizer.php $wpc->add_setting("heading",array( "default" => "Default Heading", "type" => "theme_mod" )); # mytheme/index.php $heading = get_theme_mod("heading");

Slide 18

Slide 18 text

$wpc->add_control(“mytheme_options[heading]",array( "label" => "Custom Heading", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "text" ));

Slide 19

Slide 19 text

# text $wpc->add_control("mythemes_option[heading]",array( "label" => "Custom Heading", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "text" )); # checkbox $wpc->add_control("mytheme_options[heading]",array( "label" => "A Checkbox", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "checkbox" ));

Slide 20

Slide 20 text

# select $wpc->add_control("mytheme_options[heading]",array( "label" => "A Checkbox", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "select", "choices" => array( "value 1" => "text for 1", "value 2" => "text for 2" ) )); # radio $wpc->add_control("mytheme_options[heading]",array( "label" => "A Checkbox", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "radio", "choices" => array( "value 1" => "text for 1", "value 2" => "text for 2" ) ));

Slide 21

Slide 21 text

add_action("customize_register",function ($wpc){ $wpc->add_section("heading_section",array( "title" => "My Heading Section", "priority" => 0 )); $wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type" => "option", "capability" => "edit_theme_options" )); $wpc->add_setting("mytheme_options[blue]",array( "default" => "false", "type" => "option", "capability" => "edit_theme_options" )); $wpc->add_setting("mytheme_options[subheading]",array( "default" => "Hot Fuzz", "type" => "option", "capability" => "edit_theme_options" )); $wpc->add_control("mytheme_options[heading]",array( "label" => "Custom Heading", "section" => "heading_section", "setting" => "mytheme_options[heading]", "type" => "text" )); $wpc->add_control("mytheme_options[blue]",array( "label" => "Make It Blue?", "section" => "heading_section", "setting" => "mytheme_options[blue]", "type" => "checkbox" )); $wpc->add_control("mytheme_options[subheading]",array( "label" => "subheading?", "section" => "heading_section", "setting" => "mytheme_options[subheading]", "type" => "select", "choices" => array( "Hot Fuzz" => "Hot Fuzz", "Shaun of the Dead" => "Shaun of the Dead", "The World Ends" => "The World Ends" ) )); });

Slide 22

Slide 22 text

# Remove default sections $wpc->remove_section("title_tagline"); $wpc->remove_section("static_front_page");

Slide 23

Slide 23 text

$colour_control = new WP_Customize_Color_Control( $wpc, 'mytheme_options[blue]', array( 'label' => "Heading Color", 'section' => 'heading_section', 'settings' => 'mytheme_options[blue]', ) ); $wpc->add_control($colour_control);

Slide 24

Slide 24 text

$image_control = new WP_Customize_Image_Control( $wpc, 'mytheme_options[image]', array( 'label' => "Heading Image", 'section' => 'heading_section', 'settings' => 'mytheme_options[image]', ) ); $wpc->add_control($image_control);

Slide 25

Slide 25 text

class WP_Customize_Category_Control extends WP_Customize_Control { public $type = 'dropdown-category'; public function render_content() { $dropdown = wp_dropdown_categories(array( "selected" => $this->value(), "name" => $this->settings["default"]->id, "echo" => 0 )); $dropdown = str_replace( 'get_link(), $dropdown); ?>

label);?>

Slide 26

Slide 26 text

# use postMessage transport $wpc->add_setting("mytheme_options[heading]",array( "default" => "Default Heading", "type" => "option", "capability" => "edit_theme_options", "transport" => "postMessage" ));

Slide 27

Slide 27 text

# mytheme/lib/customizer.php if($wpc->is_preview() && !is_admin()){ add_action("wp_footer", function(){ get_template_part("lib/views/customize_preview_js.php"); }); } # mytheme/lib/views/customizer_previews_js.php (function($){ wp.customize('mytheme_options[heading]',function(value){ value.bind(function(to){ $('h1').html(to); }); }); })(jQuery);

Slide 28

Slide 28 text

CORESITES

Slide 29

Slide 29 text

Resources: https://github.com/redroot/wp-customizer-example http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in- your-own-themes/ http://ottopress.com/2012/theme-customizer-part-deux-getting-rid-of- options-pages/ http://ottopress.com/2012/making-a-custom-control-for-the-theme- customizer/ https://codex.wordpress.org/Theme_Customization_API

Slide 30

Slide 30 text

Thanks! @luke_redroot red-root.com