Slide 1

Slide 1 text

ϒϩοΫΤσΟλʔ ͷΧελϚΠζํ๏Λ Ϛελʔͯ͠ϥΠόϧʹ ࠩΛ͚ͭΑ͏ʂʂʂʂ 1

Slide 2

Slide 2 text

ϥΠόϧͬͯͳΜ΍ͶΜ 2

Slide 3

Slide 3 text

Block Editor ΧελϚΠζೖ໳ Toro_Unit @Kansai WP Meetup in Osaka 3

Slide 4

Slide 4 text

$ whoami 4

Slide 5

Slide 5 text

Toro_Unit ઎෦ ߛ (͏Β΂ ͻΖ͠) • Frontend Developer • WordPress Plugin and Theme Developer Github: @torounit Twitter: @Toro_Unit 5

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

Plugins and Themes • Custom Post Type Permalinks • Advanced Posts Blocks • Simple Post Type Permalinks • Powerful Posts Per Page (PPPP) • Vanilla • and more... 7

Slide 8

Slide 8 text

8

Slide 9

Slide 9 text

WordPress Meetup Map • React Ͱग़དྷͯ·͢ɻ • https://github.com/torounit/wp-meetup-map • ϓϧϦΫ͍ͩ͘͞ɻ 9

Slide 10

Slide 10 text

10

Slide 11

Slide 11 text

௕໺ݝদຊࢢ͔Β͖·ͨ͠ • Shinshu WordPress Meetup • ຖճϐβ৯ͬͯ·͢ɻ • ߚ༿͕ݟ͝Ζɻ৽ͦ͹ɻ 11

Slide 12

Slide 12 text

ຊηογϣϯʹ͍ͭͯ ϞμϯJSͷ࿩͕͍Ζ͍Ζग़͖ͯ·͢ɻͦͪΒͷղઆ ͸ಛʹ͠·ͤΜɻ ʢ͍ͯ͏͔ऴΘΒΜʣ ࢀߟʹͳΔࢿྉ • https://speakerdeck.com/likr/re-introduction-to- modern-javascript • https://jsprimer.net/ • https://developer.mozilla.org 12

Slide 13

Slide 13 text

αϯϓϧίʔυʹ͍ͭͯ ΊͪΌͪ͘Όίʔυ͕ग़͖ͯ·͢ɻ https://github.com/torounit/my-first-block ʹࠓճͷσϞ͸ެ։͍ͯ͠·͢ɻ tag / branch Ͱɺ͍Ζ͍Ζ෼͚ͯ·͢ɻ 13

Slide 14

Slide 14 text

࣭໰ʹ͍ͭͯ • ղΒͳ͍͜ͱ͕͋ͬͨΒͦͷ৔Ͱฉ͍ͯ΋Βͬͯେৎ෉Ͱ͢ɻ • ͨͩ͠ɺ࣌ؒͱମྗͷؔ܎Ͱͦͷ৔Ͱ͓౴͑ग़དྷͳ͍৔߹͕͋Γ· ͢ɻ • 120ϖʔδ͘Β͍͋ΔͷͰɺؾʹͳͬͨ͜ͱͳͲ͸ɺπΠʔτ͢Δ ͳΓ͍͚ͯͨͩ͠Ε͹ɺޙͰ౴͑Δ͔΋͠Ε·ͤΜɻ 14

Slide 15

Slide 15 text

ϒϩοΫΤσΟλʔΧελϚΠζೖ໳ 15

Slide 16

Slide 16 text

ͷ·͑ʹ 16

Slide 17

Slide 17 text

ͦ΋ͦ΋ WordPress ʹ͓͚ΔΤσΟλͷ໾ׂͱ͸ 17

Slide 18

Slide 18 text

WordPress ͱ͍͏ CMS ͷ HTML؅ཧ • post_content ͷΧϥϜʹ HTML ΛอଘɻͦΕΛग़ྗ͢Δ૷ஔɻ • HTML Λԣஅతʹ؅ཧ͢Δ࢓૊ΈͰ͋Γɺ୯Ұͷϖʔδͦͷ΋ͷΛ؅ཧ͢Δ ࢓૊ΈͰ͸ͳ͍ɻਤॻؗɻ • σʔλΛݩʹ HTML Λੜ੒͢ΔΘ͚Ͱ͸ͳ͍ɻ΄΅׬੒඼ͷ HTML ʹςʔ Ϛͱ͍͏෰Λணͤͯ഑৴͢Δ૷ஔɻ • ͍ͬͯ͏͔࠷ॳ (0.71)͸ɺςʔϚ͢Βແ͔ͬͨɻ • https://github.com/mt8/wbkobe77/blob/master/index.php 18

Slide 19

Slide 19 text

19

Slide 20

Slide 20 text

• ͨͱ͑͹ɺconcrete5 ͱ͍͏ CMS ͸ɺϒϩοΫ͝ͱʹσʔλϕʔε ͷ table ͕ଘࡏ͢ΔΒ͍͠ɻ༷ʑͳ table ͔ΒσʔλΛҾͬுͬͯ ͖ͯ̍ͭͷ HTML Λੜ੒͢Δɻ 20

Slide 21

Slide 21 text

• ࡶʹݴ͏ͱɺHTMLͰॻ͔ΕͨจॻୡΛΧςΰϦʔͱ͔೔෇ͱ͔Λ ͚ͭͯ؅ཧग़དྷΔΑ͏ʹ͠Α͏ʂ͕ WordPress ͷίϯςϯπ؅ཧɻ ͭ·Γϒϩάɻ • ͍͍ͤͥ ϔομͱϑολ͘Β͍͸ڞ௨Խͯ͠΍Ζ͏ɻఔ౓ɻ 21

Slide 22

Slide 22 text

ͦΜͳ WordPress ʹ͓͚ΔΤσΟλʔͷ໾ׂͱ͸ 22

Slide 23

Slide 23 text

HTMLΘ͔Βͳ͍ͻͱͰ΋ɺ HTMLΛ࡞ΕΔΑ͏ʹ͢Δʂ 23

Slide 24

Slide 24 text

ʮHTMLΘ͔Βͳ͍ͻͱͰ΋ HTMLΛ࡞ΕΔΑ͏ʹ͢Δʂʯ • HTML Θ͔Βͳ͍ਓ͕৮ͬͯ΋ɺpost_content ʹ HTML ΛอଘͰ͖ ΔΑ͏ʹ͢Δɺͱ͍͏͜ͱɻ • DBʹอଘ͢Δ΋ͷ͸ɺ׬੒͞Εͨ HTML 24

Slide 25

Slide 25 text

͍ͬͯ͏͔΋ͱ΋ͱϒϩάιϑτʂ since 2003.05.27 25

Slide 26

Slide 26 text

ϒϩοΫΤσΟλʔͷΧελϚΠζ 26

Slide 27

Slide 27 text

ςʔϚʹ͍ͭͯ ࠓճ͸࣌ؒͱମྗͷؔ܎ͰऔΓѻΘͳ͍ͷͰɺެࣜυΩϡϝϯτಡΜͰ Լ͍͞ɻ https://developer.wordpress.org/block-editor/developers/themes/ ςʔϚʹهड़͢΂͖ CSSͷ࿩ɺΧϥʔύϨοτɺจࣈαΠζઃఆɺetc.. ౳͕ॻ͍ͯ͋Γ·͢ɻ ςʔϚϢχοτςετͷ࠷৽൛ʢ೔ຊޠ൛͸຋༁தͳͷͰͱΓ͋͑ͣӳ ޠ൛ʣಥͬࠐΜͰݟΔͱͳΜͱͳ͘΍Δ΂͖͜ͱ͸ݟ͑·͢ɻ 27

Slide 28

Slide 28 text

ͱΓ͋͑ͣɺeditor-styles ͸ඞͣઃఆ͢ΔΑ͏ʹ͠·͠ΐ͏ɻ

Slide 29

Slide 29 text

editor-style ΛΘ͟Θ͟࡞ΔͷΊΜͲ͘͞ ͍ͬͯਓ͸ɺ ࢖͍΍͍͢WordPressͷͨΊ ͷCSSͷͭ͘Γ͔ͨ ͬͯ࿩Λɺ2015೥ͷ WordBench Osaka Ͱ΍ͬͯΔͷͰͦΕಡΜ ͰԼ͍͞ɻ https://www.slideshare.net/Toro_Unit/ wordpresscss ݹ͍৘ใ΋͋Γ·͕͢ɺ͋Μ·Γߟ͑ํม Θͬͯ·ͤΜɻ๻͸ SMACSS + BEM ͬͯײ ͡Ͱ CSSॻ͍ͯ·͢ɻ 29

Slide 30

Slide 30 text

ΤσΟλΛΧελϚΠζ͢Δํ๏ @wordpress/blocks registerBlockStyle, registerBlockType @wordpress/plugins registerPlugin @wordpress/hooks addFilter, addAction 30

Slide 31

Slide 31 text

ΤσΟλΛΧελϚΠζ͢Δํ๏ @wordpress/blocks registerBlockStyle, registerBlockType @wordpress/plugins registerPlugin @wordpress/hooks addFilter, addAction ʹ͍ͭͯ࿩͠·͢ɻ 31

Slide 32

Slide 32 text

طଘͷϒϩοΫͷ֦ு • ·ͣ͸ɺ৽͍͠ϒϩοΫΑΓ΋طଘͷϒϩοΫͷ֦ுͰͲ͏ʹ͔Ͱ ͖ͳ͍͔ʁΛߟ͑Δɻ • ͭ·Γ class ଐੑΛ෇༩͠ɺCSS ͰσβΠϯΛΧελϚΠζ͢Δɻ 32

Slide 33

Slide 33 text

33

Slide 34

Slide 34 text

ϒϩοΫελΠϧ GUI ͰɺϒϩοΫʹΫϥεΛઃఆग़དྷΔɻ͍ͭͰʹϓϨϏϡʔ΋͍ͭͯ ͘Δɻඇৗʹศརɻ ઃఆ͞ΕΔ஋͸ɺis-style-hoge ͷΑ͏ͳܗࣜɻ "ߴ౓ͳઃఆ" ύωϧ಺ͷ "௥ՃCSS Ϋϥε" Λૢ࡞͍ͯ͠Δ͚ͩɻ Documentation : https://developer.wordpress.org/block-editor/ developers/filters/block-filters/#block-style-variations 34

Slide 35

Slide 35 text

࣮૷ํ๏ɻ ΤσΟλʔʹಡ·ͤΔ js ͷઃఆɻwp-blocks Λґଘؔ܎ʹࢦఆ

Slide 36

Slide 36 text

wp.blocks.registerBlockStyle ͰɺελΠϧͷઃఆΛهड़ɻ const { registerBlockStyle } = wp.blocks; registerBlockStyle( 'core/quote', { name: 'hoge', label: '΄͛' } ); 36

Slide 37

Slide 37 text

ελΠϧ͕௥Ճ͞ΕΔɻeditor-style ΛͪΌ Μͱઃఆ͍ͯ͠Ε͹ϓϨϏϡʔʹ΋ద༻͞Ε Δɻ • Ϙλϯͷؙ֯ελΠϧ • ςʔϒϧͷελΠϧ ͳͲ΋ಉ͡࢓૊Έɻ ԼखʹΧελϜϒϩοΫΛ࡞ΔΑΓɺ͜ΕΛ ֮͑Δํ͕༗༻ੑߴ͍ɻ ϒϩοΫΛࣗ࡞͢Δࡍ΋ɺσβΠϯͷόϦ ΤʔγϣϯΛ૿΍͢ͳΒ͜ΕΛ࢖͏ɻ 37

Slide 38

Slide 38 text

ΧελϜϒϩοΫ։ൃ 38

Slide 39

Slide 39 text

֓ཁ • wp_register_script Ͱ js ϑΝΠϧΛಡΈࠐΉɻͦͷ͋ͱ͸ɺJSͰ ʢͱ͍͏ΑΓɺReact ͰʣΰϦΰϦ͢Δɻ • PHPͰͷϨϯμϦϯάΛهड़͢Δ͜ͱͰಈతͳཁૉ (γϣʔτίʔ υɺ΢ΟδΣοτͷΑ͏ͳ) Λఏڙग़དྷΔɻ • ex. WP_Query Ͱ౤ߘͷ৘ใΛදࣔɻ • JSʢ React ʣ ͸ඞͣ࢖͏ɺPHP ͸ͨ·ʹ࢖͏ఔ౓ɻ 39

Slide 40

Slide 40 text

Note: JSX ͱ͔ϞμϯJSͱ͔Ϗϧυͨ͠Γͬͯ೉͍͠ͱ͔Α͘ ฉ͚͘Ͳ • ެࣜͷαϯϓϧʹɺਃ͠༁ఔ౓ʹ ES5 ͷαϯϓϧ͕͋Δ͚Ͳɺ։ൃ ͸ɺϞμϯJSͰߦΘΕ͍ͯΔɻ • ೴಺ʹ Babel ੵΜͰͳ͍ਓ͸ɺJSX + ϞμϯJS ॻ͍ͨ΄͏͕͍͍ɻ • ๻͸ੵΜͰͳ͍Ͱ͢ɻ 40

Slide 41

Slide 41 text

React Ή͔͍ͭ͠ ? • React ΋ษڧ͠Α͏ɻ͋Μͳͷ HTML Έ͍ͨͳ΋ͷͩʢચ೴ • ΧελϜϒϩοΫ։ൃͳΒɺHTML ʹໟ͕ੜ͑ͨҐͰ৐Γ੾ΕΔέʔε ΋݁ߏ͋Δɻ • ͪΐͬͱͨ͠ϞϊΛ࡞Δͷ͸͞΄Ͳ೉͘͠ͳ͍ɻߴػೳͳϞϊͭ͘Ζ͏ͱ ͢Δͱ೉͍͠ɻ • ͱ͍͏͔ɺঢ়ଶ؅ཧ / ඇಉظ / ௨৴ / GUIͰΰϦΰϦ΍Δͷ͕ͦ΋ͦ΋೉ ͍͠ɻͦͷ೉͠͞Λղܾ͢ΔϞϊͷ͕̍ͭ React. 41

Slide 42

Slide 42 text

ΧελϜϒϩοΫ։ൃͳΒׂͱͳΜͱ͔ͳΔɻ • WordPress ͔ΒσʔλΛऔಘ͢ΔύοέʔδͳͲ΋͋ΔͷͰɺͦ͜ ·Ͱ React ྗແͯ͘΋͍͚Δɻ • ΋ͪΖΜ React ྗɺJS ྗ͕͋Ε͹໓஡ۤ஡͍Ζ͍Ζग़དྷΔ • ex. ֎෦ͷಠࣗAPIΛ༻͍ͯΰϦΰϦ΍Δͱ͔ɻ 42

Slide 43

Slide 43 text

αΠτ੍࡞ͷ৔߹ େ఍ɺσβΠϯΛ࣮ݱ͢ΔͨΊͷ div ΛϒϩοΫʹ͍ͨ͠έʔεͱ͔ ͕ଟ͍ͷͰ͸ɻ ͍͍ͩͨ͜Μͳײ͡ͷίʔυɻ 43

Slide 44

Slide 44 text

import { registerBlockType } from '@wordpress/blocks'; import { InnerBlocks } from '@wordpress/block-editor'; const edit = ( { className } ) => (
); const save = ( { className } ) => (
); 44

Slide 45

Slide 45 text

registerBlockType( 'my-block/section', { title: 'section', description: 'section', icon: 'text-page', category: 'layout', supports: { align: [ 'wide', 'full' ], anchor: true, }, edit, save, } ); 45

Slide 46

Slide 46 text

͜Μ͚ͩɻ ͳΜͱ͔ͳΔɻ 46

Slide 47

Slide 47 text

΍ͬͯΈΑ͏ɻ ࢀߟࢿྉ΋νϡʔτϦΞϧ΋͋Δɻ • https://developer.wordpress.org/block-editor/tutorials/block- tutorial/writing-your-first-block-type/ • ެࣜͷνϡʔτϦΞϧɻ • https://github.com/WordPress/gutenberg-examples • ެࣜͷαϯϓϧɻΑ͘ग़དྷͯΔɻ 47

Slide 48

Slide 48 text

ϒϩοΫΛͭͬͯ͘ΈΔ 48

Slide 49

Slide 49 text

४උɻ ͱΓ͋͑ͣద౰ʹ WordPress ͷϓϥάΠϯΛ࡞੒͠·͢ɻ ϑΝΠϧߏ੒ - my-first-block - package.json - my-first-block.php ( js ͷొ࿥ͱ͔ɺWordPressϓϥάΠϯຊମ ) - src/index.js ( ͜͜ʹΰϦΰϦ͢Δɻ) 49

Slide 50

Slide 50 text

package.json { "name": "my-first-block", "version": "0.0.1", "license": "GPL2.0+", "devDependencies": { "@wordpress/scripts": "^5.0.0" }, "scripts": { "start": "wp-scripts start", "build": "wp-scripts build", } } ͜Ε͚ͩͰ OK 50

Slide 51

Slide 51 text

@wordpress/scripts https://www.npmjs.com/package/@wordpress/scripts • JSͷࣗಈϏϧυͱ͔ɺBabel ͱ͔ɺWebpack ͱ͔ɺESLint ͱ͔ɺ WordPressϓϥάΠϯ։ൃ؀ڥͷߏஙʢཁ docker-compose ʣͱ͔ ͳΜͰ΋΍ͬͯ͘ΕΔ͍͢͝Ϡπɻ • PostCSS / SCSS ͷϏϧυ͸ࠓͷͱ͜Ζग़དྷͳ͍͚Ͳɺ௥Ճ͞ΕΔ͔ ΋ɻhttps://github.com/WordPress/gutenberg/issues/14801 51

Slide 52

Slide 52 text

wp-script start or wp-script build Λ͢Δͱ src/index.js ͔Βɺ • build/index.js • build/index.asset.php Λు͖ग़͢ɻ 52

Slide 53

Slide 53 text

• @wordpress/blocks -> wp.blocks ͷΑ͏ʹɺάϩʔόϧม਺Λࢀ র͢ΔΑ͏ʹม׵ͯ͘͠ΕΔɻ import { registerBlockStyle } from '@wprdpress/blocks' Λɺ const { registerBlockStyle } = wp.blocks; Έ͍ͨʹͯ͘͠ΕΔɻ • jQuery ౳ͷ WordPress ʹಉࠝ͞Ε͍ͯΔJS΋ಉ༷ɻ • ςʔϚ։ൃͳͲͰ΋ศརʹ࢖͑Δɻ 53

Slide 54

Slide 54 text

my-first-block.php function my_first_block_register_block() { $asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php'); wp_register_script( 'my-first-block', plugins_url( 'build/index.js', __FILE__ ), $asset_file['dependencies'], $asset_file['version'] ); // block ͷొ࿥ɻ register_block_type( 'my-first-block/hello', array( 'editor_script' => 'my-first-block', ) ); } add_action( 'init', 'my_first_block_register_block' ); 54

Slide 55

Slide 55 text

build/index.asset.php wp_register_script ͢Δͱ͖ͷɺґଘؔ܎ɺversion ౳ΛɺJS ͔Βࣗಈతʹ൑ผͯ͠࡞੒͞Ε Δɻࠓ·ͰखಈͰ΍ͬͯͨͷ͕ΞϗΈ͍ͨʹࢥ͑Δ͘Β͍ศརɻ array( 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose','wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill' ), 'version' => '3ba4a1cc34f9a198d6519b52f8622629' ); 55

Slide 56

Slide 56 text

register_block_type ϒϩοΫͷొ࿥Λߦ͏ɻࣄલʹ JS౳ͷొ࿥͕ඞཁͳͷͰɺwp_register_script Ͱ֤ࣗ΍ͬͯ ͍ͩ͘͞ɻ 'ొ࿥ͯ͋͠Δjsͷ໊લɺϑϩϯτ/؅ཧը໘༻', 'style' => 'ొ࿥ͯ͋͠ΔCSSͷ໊લɺϑϩϯτ/؅ཧը໘༻', 'editor_script' => 'ొ࿥ͯ͋͠Δjsͷ໊લɺ؅ཧը໘༻', 'editor_style' => 'ొ࿥ͯ͋͠ΔCSSͷ໊લɺ؅ཧը໘༻', ) ); editor_script ͚ͩ͋Ε͹OK. ϓϥάΠϯଆͰ༻ҙͨ͠CSSͱ͔Λಡ·ͤͨΓ΋Ͱ͖Δɻ 56

Slide 57

Slide 57 text

note: ଟݴޠԽͱ͔͸ެࣜͷexampleͱ͔ݟͯɻ https://make.wordpress.org/core/2018/11/09/new-javascript-i18n- support-in-wordpress/ 57

Slide 58

Slide 58 text

͓·ͨͤ͠·ͨ͠ʂ Α͏΍͘ϒϩοΫ։ൃʂ 58

Slide 59

Slide 59 text

import { registerBlockType } from '@wordpress/blocks'; // const { registerBlockType } = wp.blocks ʹม׵͞ΕΔ registerBlockType( 'my-first-block/hello', { title: 'hello', icon: 'palmtree', // Dashicons. ௚઀ ͷࢦఆ΋ग़དྷΔ category: 'common', // ΠϯαʔλʔͷͲͷύωϧʹදࣔ͢Δ͔ɻ edit({ className } ) { return (
ΤσΟλʔͩΑɻ
); }, save({ className } ) { return (
อଘ͞ΕΔσʔλɺ࣮ࡍʹදࣔ͞ΕΔςΩετɻ
); }, } ); 59

Slide 60

Slide 60 text

60

Slide 61

Slide 61 text

ΧελϜϒϩοΫ͕Ͱ͖ͨʂ 61

Slide 62

Slide 62 text

·͊ɺ͜Ε͚ͩͩͱͦ͜·Ͱ࢖͍ಓ͸ͳ͍ɻʢ࠶ར༻ϒϩοΫͰ͑͑΍ ΜͬͯͳΔʣ 62

Slide 63

Slide 63 text

ฤूՄೳྖҬΛͭ͘Δʂ 63

Slide 64

Slide 64 text

௕͘ͳΔͷͰɺίʔυΛ෼ׂɻ 64

Slide 65

Slide 65 text

import { registerBlockType } from '@wordpress/blocks'; import { RichText } from '@wordpress/block-editor'; const edit = ( { className, attributes: { text }, setAttributes } ) => { const onChange = ( value ) => { return setAttributes( { text: value } ); }; return (
); }; const save = ( { className, attributes: { text } } ) => { return (
{ text }
); }; 65

Slide 66

Slide 66 text

registerBlockType( 'my-first-block/hello', { title: 'hello', icon: 'palmtree', category: 'common', attributes: { text: { type: 'string', default: '', }, }, edit, save, } ); 66

Slide 67

Slide 67 text

registerBlockType( 'my-first-block/hello', { title: 'hello', icon: 'palmtree', category: 'common', attributes: { text: { type: 'string', default: '', }, }, edit, save, } ); 67

Slide 68

Slide 68 text

import { registerBlockType } from '@wordpress/blocks'; import { TextControl } from '@wordpress/components'; const edit = ( { className, attributes: { text }, setAttributes } ) => { const onChange = ( value ) => { return setAttributes( { text: value } ); }; return (
); }; const save = ( { className, attributes: { text } } ) => { return (
{ text }
); }; 68

Slide 69

Slide 69 text

const edit = ( { className, attributes: { text }, setAttributes } ) => { const onChange = ( value ) => { return setAttributes( { text: value } ); }; return (
); }; 69

Slide 70

Slide 70 text

• @wordpress/components ఏڙ͞ΕΔίϯϙʔωϯτɻinput λάΛ ు͖ग़͢ɻϑΥʔϜͷ෦඼ͳͲ͸ɺ΄΅શͯ༻ҙ͞Ε͍ͯΔɻ • ex. , @wordpress/components ʹ͸ଞʹ΋༷ʑͳίϯϙʔωϯτ͕͋Δɻ Component Reference: https://developer.wordpress.org/block- editor/components/ 70

Slide 71

Slide 71 text

attributes ϓϩύςΟ registerBlockType( 'my-first-block/hello', { title: 'hello', icon: 'palmtree', category: 'common', attributes: { text: { type: 'string', default: '', }, }, edit, save, } ); อଘ͢ΔσʔλͷܗࣜΛఆٛɻσʔλܕɺσϑΥϧτ஋ͳͲɻ഑ྻͳͲ΋ࢦఆՄೳɻ 71

Slide 72

Slide 72 text

attirubutes, setAttirubutes const edit = ( { className, attributes: { text }, setAttributes } ) => { const onChange = ( value ) => { return setAttributes( { text: value } ); }; return (
); }; TextControl ͷத਎͕มߋ͞ΕͨΒɺݱࡏͷ attributes Λ࠶ઃఆɻߋ৽͢Δ஋ͷΈ Λهड़ɻ https://developer.wordpress.org/block-editor/developers/block-api/block- attributes/ 72

Slide 73

Slide 73 text

Hello!!!
73

Slide 74

Slide 74 text

Hello!!!
attirbutes ͸ɺίϝϯτͱͯ͠อଘ͞Ε͍ͯΔɻ( the_cotent Ͱు͖ग़ ͢ࡍʹ͸ɺϑΟϧλʔͰ࡟আ͞ΕΔ) 74

Slide 75

Slide 75 text

΋ͬͱ;ͭ͏ͷϒϩοΫͬΆ͍ͨ͘͠ɻ ΤσΟλʹ input ͕͋Δͷ͸ͪΐͬͱɻɻɻ 75

Slide 76

Slide 76 text

ฤूग़དྷΔςΩετΛఏڙ͢ΔίϯϙʔωϯτɻίΞͷϒϩοΫ΋ςΩετฤू ग़དྷΔ΋ͷ͸͍͍ͩͨ͜ΕͰग़དྷͯΔɻվߦͱ͔΋औΓѻ͑Δɻ • : ΤσΟλը໘༻ɻ • : HTMLΛు͖ग़͢༻ɻ

hello

https://developer.wordpress.org/block-editor/developers/richtext/ 76

Slide 77

Slide 77 text

import { registerBlockType } from '@wordpress/blocks'; import { RichText } from '@wordpress/block-editor'; const edit = ( { className, attributes: { text }, setAttributes } ) => { const onChange = ( value ) => setAttributes( { text: value } ); return (
); }; const save = ( { className, attributes: { text } } ) => { return (
); }; 77

Slide 78

Slide 78 text

78

Slide 79

Slide 79 text

ྑ͍ײ͡ʹͳͬͨ!! 79

Slide 80

Slide 80 text

Ͱ΋ɻɻɻ
Hello!!!
ʮHello!!!ʯॏෳͯ͠Δɻίϝϯτ͔ΒͰ͸ͳ͘ɺHTML͔Β௚઀ɺ஋ ΛऔΓग़ͤͳ͍͔ʁ 80

Slide 81

Slide 81 text

attributes: { text: { type: 'string', default: '', }, }, 81

Slide 82

Slide 82 text

attributes: { text: { type: 'string', source: 'html', selector: '.text', default: '', }, }, 82

Slide 83

Slide 83 text

attributes: { text: { type: 'string', source: 'html', selector: '.text', default: '', }, }, 83

Slide 84

Slide 84 text

Hello!!!
{"text":"Hello!!!"} Λফͤͨɻ 84

Slide 85

Slide 85 text

attirbutes ͷ source Λઃఆ͢Δ͜ͱͰɺ͍Ζ͍ΖͳܗͰऔಘग़དྷ Δɻ ஋ʹΑͬͯ͸ɺͦͷଞͷઃఆ͕ඞཁɻ https://developer.wordpress.org/block-editor/developers/block-api/ block-attributes/ type: array ʹ͢Δ͜ͱͰɺෳ਺ͷཁૉΛऔಘग़དྷͨΓ͢Δɻ ϦετͳͲͱҰॹʹ࢖͏ͱඒຯ͍͠ɻ 85

Slide 86

Slide 86 text

source ʹࢦఆͰ͖Δ஋ • html: innerHTML Λऔಘɻෳ਺ߦͰ΋औಘͯ͠഑ྻʹग़དྷͨΓ͢ Δɻ • text: textContent Λऔಘ • attribute : ଐੑ஋Λऔಘ • query: ෳ਺ͷଐੑ΍ɺςΩετͳͲΛऔಘͯ͠ΦϒδΣΫτʹɻ 86

Slide 87

Slide 87 text

υΩϡϝϯςʔγϣϯʹॻ͍ͯແ͍΋ͷ • children : ࢠཁૉɻ • node / tag : ࢖͍Ͳ͜Ζ͕ྑ͘ղΒͳ͍ • property: ιʔείʔυʹ͚͋ͬͨͲͳΜ͔ͩղΒͳ͍ɻ 87

Slide 88

Slide 88 text

Note: ΧελϜϑΟʔϧυͱͷ࿈ܞ΋ग़དྷΔɻ register_post_meta( 'post', 'my_post_sub_title', array( 'show_in_rest' => true, 'single' => true, 'type' => 'string', ) ); attributes: { author: { type: 'string', source: 'meta', meta: 'my_post_sub_title' }, }, ΧελϜϑΟʔϧυͷΩʔΛ post_hoge ͱ͔ʹ͢Δͱಈ͔ͳ͍ͷͰ஫ҙɻ 88

Slide 89

Slide 89 text

ઃఆมߋग़དྷΔUIɻ https://developer.wordpress.org/block-editor/tutorials/block-tutorial/ block-controls-toolbar-and-sidebar/ InspectorControls, BlockControls αΠυόʔͷઃఆ߲໨(ΠϯεϖΫλ)ɺϒϩοΫͷπʔϧόʔʹ߲໨Λ ௥ՃͰ͖Δɻ 89

Slide 90

Slide 90 text

const edit = ( props ) => { // ஋ͷ४උͱ͔͍Ζ͍Ζ΍Δɻ return (
// ઃఆͱ͔
//ϒϩοΫຊମ
) }; 90

Slide 91

Slide 91 text

InnerBlocks ϒϩοΫͷதʹϒϩοΫΛೖΕΒΕΔϠπɻΧϥϜϒϩοΫɺάϧʔϓϒϩοΫɺJetpack ͷίϯλΫτ ϑΥʔϜ౳Ͱ༻͍ΒΕ͍ͯΔɻallowedBlocks Λࢦఆ͢ΔͱɺதʹೖΕΒΕΔϒϩοΫΛ੍ݶͰ͖Δɻ const edit = ( { className } ) => (
); const save = ( { className } ) => (
); 91

Slide 92

Slide 92 text

Dynamic Blocks https://developer.wordpress.org/block-editor/tutorials/block-tutorial/ creating-dynamic-blocks/ PHP Λ༻͍ͯɺαʔόʔαΠυͰಈతʹɺϨϯμϦϯά͢ΔϒϩοΫɻ 92

Slide 93

Slide 93 text

example: Advanced Posts Blocks https://www.wordpress.org/plugins/ advanced-posts-blocks/ • ΧςΰϦʔ/λά/λΫιϊϛʔͱ౤ߘλΠ ϓͰɺߜΓࠐ·Εͨ౤ߘΛදࣔ͢Δɻϒ ϩοΫͳͲΛఏڙɻ • TOPϖʔδͷ৽ண৘ใҰཡͱ͔Ͱ࢖͏ɻ 93

Slide 94

Slide 94 text

94

Slide 95

Slide 95 text

࡞Γํ render_callback ͱɺඞཁͰ͋Ε͹ɺattributes Λࢦఆɻ௨ৗͷϒϩοΫͱҧ͍ɺattributes Ͱࢦఆ͠ͳ͍ͱɺclassName ΛҾͬுͬͯདྷΕͳ͍ɻ register_block_type( 'my-first-block/hello', array( 'editor_script' => 'my-first-block', 'attributes' => [ 'className' => [ 'type' => 'string', 'default' => '', ], ], 'render_callback' => 'my_first_block_render' ) ); 95

Slide 96

Slide 96 text

example.1 ୈ2Ҿ਺ʹ͸ɺsave ͞ΕͨHTML͕ͦͷ··౉͞ΕΔͷͰɺ͜ΕΛPHPଆͰɺද੍ࣔ ޚɻ function my_first_block_render( $attributes, $content ) { if ( get_current_user_id() ) { return $content; } return sprintf( '
login to see this content.
', $attributes['className'] ); } 96

Slide 97

Slide 97 text

JSଆ͸ී௨ʹॻ͘ɻ const edit = ( { className } ) => (
); const save = ( { className } ) => (
); 97

Slide 98

Slide 98 text

ͳ͍͠ΐ͹ͳ͠ɻ

98

Slide 99

Slide 99 text

࢖͍Ͳ͜Ζ • ϩάΠϯϢʔβʔʹͷΈݟ͍ͤͨίϯςϯπɻ • ظؒݶఆϞϊɻ • ͜ΕͰA/BςετΛϒϩοΫ୯ҐͰ΍ΔϠπ͕͋Δͱ͔ฉ͍ͨ͜ͱ ͋Δɻ • InnerBlocks ͱηοτͰ࢖͏ίτ͕ଟͦ͏ɻ 99

Slide 100

Slide 100 text

example.2 function my_first_block_render( $attributes, $content ) { if ( get_current_user_id() ) { return sprintf( '
Hello %2$s !!
', $attributes['className'], wp_get_current_user()->display_name ); } } 100

Slide 101

Slide 101 text

import { registerBlockType } from '@wordpress/blocks'; import { useSelect } from '@wordpress/data'; // JS ͰίΞͷσʔλΛҾͬுͬͯ͘Δɻ export const useCurrentUser = () => { return useSelect( ( select ) => { return select( 'core' ).getCurrentUser(); } ); }; const edit = ( { className } ) => { const { name } = useCurrentUser(); return (
Hello { name } !!
); }; // શͯ PHP ͰϨϯμϦϯά͢Δ৔߹͸ɺsave ͸ null. const save = () => null; 101

Slide 102

Slide 102 text

ͳײ͡Ͱอଘ͞ΕΔɻsave ͕ null ͳͷͰɺίϝϯτͷΈอଘ͞ΕΔɻ γϣʔτίʔυతɻ 102

Slide 103

Slide 103 text

Note: ΤσΟλ্Ͱ΋αʔόʔαΠυϨϯμϦϯάग़དྷΔ import { ServerSideRender } from '@wordpress/components'; const edit = ( { className } ) => ( ); 103

Slide 104

Slide 104 text

࢖͍Ͳ͜Ζ • ࠷৽ͷ౤ߘҰཡɻ • WP_Query ͱ͔ɻ • ࠓ·Ͱɺγϣʔτίʔυ΍ɺ΢ΟδΣοτͰද͍ࣔͯͨ͠Ϟϊɻ 104

Slide 105

Slide 105 text

σϝϦοτ • ϓϥάΠϯ͕ແޮͳΔͱ౰વػೳ͠ͳ͍ɻ • ϓϥάΠϯΛແޮʹ͢Δͱɺফ͑Δʂʂʂʂ • ௨ৗͷϒϩοΫ͸HTMLΛ DBʹอଘ͍ͯ͠ΔͷͰɺফ͑ͳ͍ɻ • ؅ཧը໘ͰϒϩοΫ͕؆୯ʹ࡞ΕΔΑʁతͳϓϥάΠϯ͸ɺDynamic Block ͳ ࣮૷͕ଟ͍ɻ ϓϥάΠϯΛແޮʹ͢Δɾ࢓༷͕มΘΔͱɺίϯςϯπ͕ফ͑Δ ϦεΫɻ • DB ʹೖ͍ͬͯͳ͍ͷͰɺݕࡧͳͲ΋ޮ͔ͳ͍ɻ 105

Slide 106

Slide 106 text

ϒϩοΫ։ൃͷֶͼํ 106

Slide 107

Slide 107 text

·ͣɺReact ͱ஥ྑ͘ͳΔɻ • ͱΓ͋͑ͣɺcreate-react-app ౳Ͱ؆ ୯ͳΞϓϦΛ࡞ͬͨΓ͢Δͷେࣄɻ • WordPress Meetup Map ΋ͦͷҰ؀ɻ • ͍ͭͰʹ Redux ͱ͔΋৮͓ͬͯ͘ͱ͍ ͍ɻʢ಺෦తʹ࢖ΘΕ·ͬͯ͘Δɻʣ 107

Slide 108

Slide 108 text

Block Editor Handbook • νϡʔτϦΞϧͳͲ΋ͦͦ͋͜͜Δͷ ͰɺͱΓ͋͑ͣಡΉɻ • ࠔͬͨΒಡΉɻ 108

Slide 109

Slide 109 text

Gutenberg ͷιʔείʔυ ·ͣ͸ɺpackages/block-library/src ͋ ͨΓΛআ͍ͯɺίΞͷϒϩοΫͷιʔεΛಡ Ήɺࣸܦ͢Δ͋ͨΓ͔Βɻ • issue ౳΋ௐ΂Δͱ͍Ζ͍Ζ৘ใग़ͯ͘ Δɻ 109

Slide 110

Slide 110 text

ਓͷϓϥάΠϯΛಡΉɻ • LIQUID BLOCKS: https://wordpress.org/plugins/liquid-blocks/ • Snow Monkey Blocks: https://wordpress.org/plugins/snow-monkey-blocks/ • Slide: https://github.com/WordPress/slides • ࠓ೥ͷ WordCamp US Ͱͷ matt ͰͷηογϣϯͷεϥΠυ͸͜ΕͰ࡞ΒΕ ͍ͯΔɻ* ίΞίϛολʔͰΤσΟλʔνʔϜͷɺElla ͞Μ࡞ɻͺͶ͐ɻ 110

Slide 111

Slide 111 text

• ࠓճ࿩ͨ͠಺༰͸΄ΜͷҰ෦ɻ ਂ෵͸ਂ͍ɻ • registerPlugin ౳Λ׆༻͢Δ͜ͱͰɺߋʹ෯͕޿͕Δɻ • ͱΓ͋͑ͣɺश͏ΑΓ׳ΕΖײ΋͋ΔͷͰɺखΛಈ͔͢ͷେࣄɻ • ίΞͷ։ൃͷϒϩά΋ಡ΋͏ɻ࢖͍ํͳͲ΋ॻ͍ͯ͋ͬͨΓ͢Δɻ • Making WordPress ͷ #core-editor νϟϯωϧͰ࣭໰ͯ͠ΈΑ͏ 111

Slide 112

Slide 112 text

ϒϩοΫΤσΟλͰมΘ ΔϫʔΫϑϩʔ 112

Slide 113

Slide 113 text

ϒϩοΫ͝ͱͷ࢓༷Λఆ͕ٛඞཁɻ • ϒϩοΫ͝ͱͷೖྗ߲໨ͷఆٛɻ • ͦΕ͸ɺߋ৽͢ΔϢʔβʔʹͱͬͯ࢖͍΍͍͢ͷ͔ʁ • Ϣʔβʔͷҙਤ͠ͳ͍ಈ࡞Λ͍ͯ͠ͳ͍͔ʁ • ΤσΟλͷࣗ༝౓͕ߴ͘GUIͰΰϦΰϦ࿔ΕΔɻΧελϚΠβʔ౳ ͱ੗Έ෼͚ɻ 113

Slide 114

Slide 114 text

ฐࣾͷ৔߹ • ՄೳͳݶΓΧελϚΠβʔ΋࢖ΘͣɺશͯϒϩοΫΤσΟλʔ্Ͱ ׬݁ɻ • σβΠϯ͔ΒϒϩοΫͷ࢓༷Λى͜͢৔߹΋͋Δ͠ɺϫΠϠʔϑ ϨʔϜ͔ΒϒϩοΫͷ࢓༷Λى͜͢৔߹΋͋ΔɻαΠτཁ݅࣍ୈɻ 114

Slide 115

Slide 115 text

ϒϩοΫ࡞Ε͹͍͍ͬͯ΋Μ͡Όͳ͍ɻ • ΧελϜϒϩοΫ͕େྔʹ͋ͬͯ΋࢖͍͜ͳͤͳ͍ɻແཧɻ • registerBlockStyle Λ্खʹ׆༻͠ɺγϯϓϧ͔ͭɺόϦΤʔ γϣϯΛ࣋ͨͤ΍͍͢ํʹ࢓༷Λ౗͢ɻCSSઃܭྗ͕ཁٻ͞ΕΔɻ • ίΞͷϒϩοΫͷ HTMLߏ଄Ͱ͸ɺෆՄೳͳσβΠϯΛͲ͏͢Δ͔ ͸͍ͭͰ΋ݕ౼ࣄ߲ɻ 115

Slide 116

Slide 116 text

σβΠφʔɾσΟϨΫλʔͱ΋ڠྗ͠ͳ͍ͱ͏·͍͔͘ͳ͍Α ࣗ෼Ͱ࡞Εͳͯ͘΋ɺ஌͓ͬͯ͘͜ͱ͸େࣄ 116

Slide 117

Slide 117 text

͍͞͝ʹ • ϒϩοΫΤσΟλʔόάͬͯΔ -> ϑΟʔυόοΫ͠·͠ΐ͏ɻhttps://github.com/WordPress/gutenberg/issues • ࢖͍ͮΒ͍ -> ϑΟʔυόοΫ͠·͠ΐ͏ɻhttps://github.com/WordPress/gutenberg/issues • ӳޠΘ͔ΒΜ -> Google ຋༁ • ͳΜ͔͜Θ͍ -> SNSͱ͔ͰݴͬͯΔํ͕͜Θ͍ͧ 117

Slide 118

Slide 118 text

118

Slide 119

Slide 119 text

ϒϩοΫΤσΟλʔ͕࢖͍΍͘͢ͳΔͷ͔ɺͦ͏Ͱͳ͍͔͸๻Β࣍ୈɻ • https://github.com/WordPress/gutenberg/issues/18362 ೔ຊޠೖ ྗͰͷม׵࣌ʹΧʔιϧ͕ҙਤ͠ͳ͍৔ॴʹҠಈ͢Δෆ۩߹ɻ 119

Slide 120

Slide 120 text

Thanks! • @Toro_Unit on Twitter and WordPress.org • @torounit on Github and Making WordPress 120