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

ブロックエディターカスタマイズことはじめ #wpshinshu / 2023-06-17 Sh...

ブロックエディターカスタマイズことはじめ #wpshinshu / 2023-06-17 Shinshu WordPress Meetup vol.24

More Decks by Toro_Unit (Hiroshi Urabe)

Other Decks in Programming

Transcript

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

    Plugin and Theme Developer Github: @torounit Twitter: @Toro_Unit 3
  2. 7

  3. 8

  4. 9

  5. 12

  6. register_block_style( 'core/heading', array( 'name' => 'with-border', 'label' => 'With Border',

    'inline_style' => <<< CSS .is-style-with-border { border-left: 6px blue solid; padding-left: 4px; } CSS, ) ); 14
  7. 15

  8. • Ϋϥε͕෇༩͞ΕΔ͚ͩͳͷͰɺCSS͸ผ్༻ҙ͢Δ͜ͱ΋ Խɻ • wp_enqueue_style ͱ͔ɺadd_editor_style Ͱಥͬࠐ Ήɻ • inline_style

    Ͱ CSS Λ௥Ճ͢Δͷ͕ख͚ܰͩͲɺϓϨϏϡʔ ͰελΠϧ͕ར͔ͳ͍όά͕͋Δɻ • https://github.com/WordPress/gutenberg/issues/39944 16
  9. 18

  10. 19

  11. 21

  12. 23

  13. 26

  14. 27

  15. 35

  16. WordPress Playground for VS Code • VSCode Ͱ WordPress ։ൃΛ͢ΔͨΊͷ֦ுػೳ

    • PHP ͱ͔ɹMySQL ͱ͔ Apache ͱ͔Կ΋ͤͣʹɺWordPress ؀ڥ ΛखݩͰҰൃͰ্ཱͪ͛ΒΕΔ • Windows Ͱ΋ಈ͘ɻ • ಺෦తʹ͸ WASM + Node.js (express) • ͨ·ʹյΕͨΓͨ͠ͱ͖͸ɺ$HOME/.wp-now/wordpress-versions ͷத਎ফͤ͹ͳ͓Δɻ 36
  17. local • Docker ϕʔεɻGUI ͍ͭͯΔɻ • ৭ʑศརػೳ͕ೖͬͯΔɻ • Flywheel ͕։ൃ͚ͯͨ͠ͲɺWP

    Engine ʹങऩ͞Εͨɻ • ྑ͘ղΜͳ͔ͬͨΒͱΓ͋͑ͣ͜Ε ࢖͏ͷ͕͍͍͔΋ɻ https://localwp.com/ 38
  18. 39

  19. 40

  20. 41

  21. 43

  22. 44

  23. ϑΝΠϧ໊ ֓ཁ {ϓϥάΠϯ໊}.php WordPress ϓϥάΠϯϑΝΠϧ block.json ϒϩοΫͷઃఆɺϝλσʔλ index.js ϒϩοΫ༻ͷεΫϦϓτ edit.js

    ؅ཧը໘ͰͷϒϩοΫͷUI save.js ࣮ࡍʹอଘ͞Εɺදࣔ͞ΕΔϒϩοΫͷUI style.scss ϒϩοΫͷελΠϧ editor.scss ؅ཧը໘ઐ༻ͷελΠϧ 45
  24. edit.js import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; export default

    function Edit() { return ( <div {...useBlockProps({ className: "my-class" })}> <div {...useInnerBlocksProps({ className: "my-class__children" })} /> </div> ); } 49
  25. save.js import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor'; export default

    function save() { return ( <div {...useBlockProps.save({ className: "my-class" })}> <div {...useInnerBlocksProps.save({ className: "my-class__children" })} /> </div> ); } 50
  26. ͦͷଞ Tip • ΧελϜϑΟʔϧυͱ͔΋औΓѻ͑Δ • ը૾ͷΞοϓϩʔυͱ͔΋10ߦ͘Β͍Ͱग़དྷΔ • React ͷࢿ࢈͕࢖͑Δɻ •

    React ྗΛ஁͑ΔͱΊͪΌͪ͘Ό͍Ζ͍Ζग़དྷΔ͚Ͳɺͦ͜ ·Ͱෳࡶͳͷ͸࡞Βͳ͍͜ͱଟ͍͔ͳ͊ɻ 55