Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WordPressテーマ開発再入門 ~ Do you Know Customizer ~

WordPressテーマ開発再入門 ~ Do you Know Customizer ~

WordBench Nagoya 登壇資料です。

Toro_Unit (Hiroshi Urabe)

January 13, 2018
Tweet

More Decks by Toro_Unit (Hiroshi Urabe)

Other Decks in Technology

Transcript

  1. Toro_Unit ઎෦ ߛ (͏Β΂ ͻΖ͠) HAMWORKS • Frontend Engineer •

    Plugin and Theme Developer Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit Blog: https://torounit.com 2
  2. 4

  3. 5

  4. 6

  5. Plugins and Themes • Custom Post Type Permalinks • Simple

    Post Type Permalinks • Powerful Posts Per Page (PPPP) • Responsive Slide • Vanilla • and more... 7
  6. Contribution • WordBench ௕໺ ϞσϨʔλʔ • WordCamp Kyoto 2017 ࣮ߦҕһ

    • WordCamp Tokyo 2017 Speaker • WordBench.org • VCCW Team • etc... 8
  7. 10

  8. ྫ • Analytics·ͨ͸τϥοΩϯάͷαϙʔτ • SEOΦϓγϣϯ • ͓໰͍߹ΘͤϑΥʔϜ • ඇσβΠϯؔ࿈ͷϝλϘοΫε •

    ϦιʔεΩϟογϯά • ؅ཧྖҬͷμογϡϘʔυ΢ΟδΣοτ • ΧελϜ౤ߘλΠϓͱγϣʔτίʔυ • ιʔγϟϧϝσΟΞͷʮ޷͖ʯɺʮϑΥϩʔʯɺʮڞ༗ʯϘλϯ 19
  9. Theme Unit Test ςʔϚϢχοτςετ - WordPress Codex ೔ຊޠ൛ WYSIWYG ΤσΟλͰී௨ʹهࣄΛॻ͍ͨ

    Βී௨ʹදࣔ͞ΕΔΑ͏ʹͪΌΜͱCSSΛ ॻ͘ɻ • ճΓࠐΈ΍Ωϟϓγϣϯ෇͖ը૾ɺΪϟ ϥϦʔ౳݁ߏ๨Ε͕ͪɻ • ී௨ͷHTML͕class౳Λ෇͚ͣʹɺͪΌ Μͱදࣔग़དྷΕ͹ɺςʔϚΛม͑ͯ΋ ͪΌΜͱදࣔͰ͖Δ͸ͣɻ 20
  10. 29

  11. The Customize API Theme Options – The Customize API |

    Theme Developer Handbook | WordPress Developer Resources • ΧελϚΠβʔʹઃఆΛ௥Ճ͢ΔͨΊͷAPI. • WordPress 3.4 Ͱ௥Ճ͞Εͨػೳɻ • WordPress 4.5 ͰSelective Reflesh౳͕௥Ճɻ • WordPress 4.9 Ͱ༧໿ެ։ͳͲɺߋʹڧԽ͞ΕΔɻ 30
  12. function my_customize_register( WP_Customize_Manager $wp_customize ) { //ηΫγϣϯͷ௥Ճ $wp_customize->add_section( 'jumbotron', array(

    'title' => 'jumbotron', ) ); //ઃఆͷΦϓγϣϯ $wp_customize->add_setting( 'jumbotron_title', array( 'default' => 'Hello World!', 'sanitize_callback' => 'esc_html', )); // ϑΥʔϜͷ௥Ճ $wp_customize->add_control( 'jumbotron_title', array( 'section' => 'jumbotron', 'label' => 'Jumbotron Title', )); } add_action( 'customize_register', 'my_customize_register' ); 32
  13. 33

  14. 34

  15. ࣮૷ग़དྷΔϑΟʔϧυͷλΠϓ • ςΩετϑΟʔϧυ(σϑΥϧτ) • νΣοΫϘοΫε (checkbox) • ϥδΦϘλϯ (radio) •

    ηϨΫτϘοΫε (select) • ςΩετϘλϯ (textarea) • ݻఆϖʔδ (doropdown-pages) 38
  16. 39

  17. $wp_customize->add_control( 'sample_radio', array( 'label' => 'Radio', 'section' => 'sample', 'type'

    => 'radio', 'choices' => array( 'option1' => 'Option 1', 'option2' => 'Option 2', ), ) ); $wp_customize->add_setting( 'sample_select', array( 'sanitize_callback' => 'esc_html', 'default' => 'option1', ) ); 40
  18. type ʹ ͜ΕҎ֎ͷ஋Λ౉͢ͱɺinputλάͷtypeଐੑ͕ઃఆ ͞ΕΔɻ $wp_customize->add_setting( 'sample_date', array( 'sanitize_callback' => 'esc_html',

    'default' => '2018-01-31', ) ); $wp_customize->add_control( 'sample_date', array( 'label' => 'Date', 'section' => 'sample', 'type' => 'date', ) ); 41
  19. built-inͷ WP_Customize_Control ͷαϒΫϥεྫɻ • WP_Customize_Upload_Control • WP_Customize_Image_Control • WP_Customize_Cropped_Image_Control •

    WP_Customize_Color_Control • WP_Customize_Date_Time_Control • WP_Customize_Code_Editor_Control 43
  20. 44

  21. • Twentysevnteen ͷτοϓϖʔδͷΧελϚΠζ ΋ΧελϚ ΠβʔͰͷ࣮૷ɻ • Lightning • s56bouya/nishiki: WordPress

    theme Nishiki. • Snow Monkey – 100%GPL ͷϝσΟΞ/ϒϩά޲͚ WordPress ༗ྉςʔϚ 46
  22. Selective Refresh ͱ͸ • Ajax Λ࢖ͬͯ෦෼తʹHTMLΛߋ ৽ɻ • Selective Refresh

    in the Customizer – Make WordPress Core • ԖචͷϚʔΫ͕ग़Δͷ͕໨ҹɻ 52
  23. function my_jumbotron_lead() { echo get_theme_mod( 'jumbotron_lead' ); } function my_customize_register(

    WP_Customize_Manager $wp_customize ) { $wp_customize->add_setting( 'jumbotron_lead', array( 'sanitize_callback' => 'esc_html', 'transport' => 'postMessage', // JSͰߋ৽͢ΔΑ͏ʹɻ ) ); $wp_customize->add_control( 'jumbotron_lead', array( 'section' => 'jumbotron', )); //Selective Refresh $wp_customize->selective_refresh->add_partial( 'jumbotron_lead', array( 'selector' => '.jumbotron .lead', 'render_callback' => 'my_jumbotron_lead', //ςϯϓϨʔτλάΛࢦఆɻ ) ); } add_action( 'customize_register', 'my_customize_register' ); 53
  24. ྫɿJavaScriptͰૢ࡞ͯ͠ɺߋʹߴ଎ʹɻ (function( $ ) { wp.customize( 'jumbotron_lead', function( value )

    { value.bind( function( to ) { $( '.jumbotron .lead' ).text( to ); } ); } ); })( jQuery ); 58
  25. JavaScript API Λ࢖͏΂͖έʔε • Selective Refresh ͕ਏ͍ɻ • ଐੑͳͲɺHTMLΛͦͷ··ஔ͖׵͑ΔΘ͚Ͱ͸ແ͍έʔε. •

    Selective Refresh ͚ͩͩͱਏ͍ɻ • ίϯςϯπεϥΠμʔͳͲ͕ೖ͍ͬͯΔέʔεɻ • JSͷঢ়ଶΛ࠶ߋ৽ɺ࠶ॳظԽͳͲ͕ඞཁͳέʔεɻ • DRY ͳײ͡ͰJSΛॻ͘ʹ͸͍Ζ͍Ζࢼߦࡨޡ͕ඞཁɻ 59
  26. ݁ߏେมɻ • ಘʹ Serective Refresh ΍ JavaScript Λ৮Γग़͢ͱେมɻ • ͪΌΜͱ࡞ͬͨϞϊΛίϯϙʔωϯτతʹ࢖͍ճ͢ͷ͕ϕ

    λʔɻ • ΧελϚΠβʔ൛ͷACFΈ͍ͨͳϠπ͕ग़Δؾ͸͢Δɻ • ࠓ͕νϟϯε͔΋͠Εͳ͍ɻ 64
  27. WordPress ͕ࡢ೥ྗΛೖΕͨϙΠϯτͷͻͱͭɻ • Gutenberg ΋ͦ͏͚ͩͲɺWordPressͷUX͕େ͖͘มΘΖ͏ͱ ͍ͯ͠Δɻ • ϏδϡΞϧͰΈͨ··࿔ΕΔͷ͸ͭΑ͍ɻ • Ϣʔβʔ͕ΧελϚΠβʔΛ৮Δػձ΋૿͑Δ͸ͣɻ

    • ṖͷઃఆϖʔδΛ࡞ͬͨΓɺṖͷΧελϜϑΟʔϧυΛ࡞ͬͯ ͍ΔͱɺʮσϑΥϧτςʔϚͱ͔ͳΒͰ͖Δͷʹɾɾɾʯͬ ͯͳΔ೔͸ͦ͏ԕ͘ͳ͍ʁ 65
  28. ·ͱΊɻ • ·ͣຊମͷػೳΛͪΌΜͱ࢖͍౗ͦ͏ɻ • ͍͍ͩͨͷ͜ͱ͸ɺTheme Developer Handbook ʹࡌͬͯ ΔͷͰɺಡ΋͏ɻ •

    ಡॻձͱ͔ʹͨ͠Βָ͍͠Μ͡Όແ͍Ͱ͠ΐ͏͔ʁ • _s ΍ σϑΥϧτςʔϚ ( Twenty γϦʔζ ) ΛಡΉͱ͍Ζ͍Ζ ൃݟ͕ଟ͍ɻTheme Development Examples 67