Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
REST API な WordPress テーマについて考える。
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Toro_Unit (Hiroshi Urabe)
September 03, 2017
Technology
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
REST API な WordPress テーマについて考える。
Toro_Unit (Hiroshi Urabe)
September 03, 2017
More Decks by Toro_Unit (Hiroshi Urabe)
See All by Toro_Unit (Hiroshi Urabe)
WordPress のサイト制作について改めて考える Toro_Unit / 2026.07.25 @ Shinshu WordPress Meetup
torounit
0
200
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
800
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
630
ブロックテーマとこれからの WordPress サイト制作 / nishinomiya.dev@2025-12-21
torounit
1
300
ブロックテーマとこれからの WordPress サイト制作 / Toyama WordPress Meetup Vol.81
torounit
0
830
ブロックテーマ時代における、テーマの CSS について考える Toro_Unit / 2025.09.13 @ Shinshu WordPress Meetup
torounit
0
920
ブロックテーマでサイトリニューアルした話 / Toro_Unit / 2025.04.12 @ Shinshu WordPress Meetup
torounit
1
370
Cloudflare Meetup Nagano Vol.3
torounit
1
190
僕が考える 「HTML サイトを WordPress にする」話 / 2023-11-05 Kansai WordPress Meetup
torounit
9
8.9k
Other Decks in Technology
See All in Technology
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
4
1.6k
Microsoft 365 Copilot chat -tekoälypalvelun tietosuojaongelmat
hponka
0
840
20260912_スクフェス三河
kgnkhkr
0
330
The Agent Builder Loop from Daily Work to OSS
minorun365
PRO
3
150
2026_devsumi_ozono.pdf
o3
3
450
OpenTelemetryのメトリクスをCloudWatchに送ってPromQLで見てみた
ota1022
0
140
AIネイティブプロダクトで顧客価値を最大化するプロダクトエンジニアとFDEの協働
righttouch
PRO
0
270
なぜJMBC(Japan MCP Business Community)? MCPってどう活用できるの?
cdataj
0
110
山手線を徒歩で一周してわかった、 位置情報アプリは「足」が最強のデバッガー
hinakko
0
140
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
700
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1.1k
薬剤師(ドメインエキスパート)と一緒に育てる薬局向けAIアシスタント
kakehashi
PRO
2
160
Featured
See All Featured
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
660
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Google's AI Overviews - The New Search
badams
0
1.6k
Building Adaptive Systems
keathley
44
3.2k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
300
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
RailsConf 2023
tenderlove
30
1.5k
How to make the Groovebox
asonas
2
2.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Building Applications with DynamoDB
mza
96
7.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
Transcript
REST API ͳ WordPress ςʔϚʹͭ ͍ͯߟ͑Δɻ Toro_Unit @2017.09.03/RESTࡇΓ 1
Toro_Unit ෦ ߛ (͏Β ͻΖ͠) ϑϦʔϥϯε Frontend Engineer / Web
Designer Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit Blog: https://torounit.com 2
Plugin and Theme Developer. • Custom Post Type Permalinks •
Vanilla • and more... 3
Contribution • WordBench ϞσϨʔλʔ • WordCamp Kyoto 2017 ࣮ߦҕһ
• VCCW Team • etc... 4
ݝদຊࢢ͔Β͓ૹΓ͠· ͢ɻ1 • ϫΠϯ͓͍͍͠Αɻ • ͦΖͦΖڶഴ͓͍͍͠Αɻ 1 https://commons.wikimedia.org/wiki/File: 130608_Matsumoto_Castle_Matsumoto_Nagano_pref_Japan02bs4.jpg Author:
663highland. License: CC BY 2.5 5
ຊҰඒຯ͍͍͔͕͋͢͠Δͱ͔ແ͍ͱ͔ɻ 6
ຊͷऴిҊ 7
REST API Λ׆༻ͯ͠ɺWEBαΠτΛ ͭ͘Δɻ 8
9
10
11
طʹ࣮༻Խ͞Ε͍ͯΔέʔε͚ͬ͜ ͏͋Δɻ 12
13
• ಠཱͨ͠ΞϓϦέʔγϣϯ͕ɺWordPressΛόοΫΤϯυͱ ͯ͠ѻ͏ɻ • WordPressͷׂ = σʔλཧٴͼɺJSONͰͷσʔλग़ ྗɻ 14
WordPressͷςʔϚͰ࣮ݱͰ͖ͳ͍ ͩΖ͏͔ʁ 15
• WordPressͷςʔϚͰϦονͳϢʔβʔମݧ • ϦονͳϖʔδભҠɻ • ϦΞϧλΠϜͳσʔλߋ৽ɻ • REST API Λ׆༻͢Δ͜ͱͰɺPWAͷରԠεϜʔζʹɻ
• ΦϑϥΠϯϑΝʔετͷ࣮ݱɻ • طଘͷWordPress͔ΒͷҠߦɻ • ϓϨϏϡʔͰαΠτͷݟͨΛ֬ೝɻ 16
17
͍͠ͱݴΘΕ͍ͯΔɻ ςʔϚͷ߹ϧʔςΟϯάͳͲɺWordPressͰߦ͍ͬͯΔ͜ͱ Λ࡞Γ͢ඞཁ͕͋ΓɺͪΐͬͱτϦοΩʔͱίϝϯτɻ ΠϕϯτϨϙʔτɿWordPress Meetup Tokyo #34 - AMA Session
with Joe Hoyle and Bryce Adams - Capital P 18
Wallace Wallace WordPress Theme • A next-generation* WordPress theme built
with the Rest API and Angular 19
ࣗͬͯΈͨɻ 20
torounit/vuepress 21
DEMO 22
23
Ͱ͖ͯΔ! 24
ͦΜͳʹ͘ͳ͍ɻ ՝͕ࢁੵΈɻ 25
URLͷύʔεʹ͍ͭͯ 26
• WEBαΠτඞͣ͠TOPϖʔδ͔ΒΞΫηε͞ΕΔΘ͚Ͱ ͳ͍ɻ • URL͔Βදࣔ͢Δίϯςϯπɺঢ়ଶʢهࣄϖʔδʁΧςΰϦ ʔʁʣΛݕࡧ͢Δඞཁ͕͋Δɻ • ͦͯ͠ύʔϚϦϯΫཧը໘͔Βࣗ༝ʹઃఆՄೳ!!! 27
Vue Router Λ͏έʔεɻ URLͷύεϕʔεɻ 28
Category, Tag, Date λΫιϊϛʔɺURLͷϕʔεɺ/category/, /tag/ Λ WordPress͔Β͢ɻ ϕʔεͷURLɺURLߏΛ WP_Rewrite::get_date_permastruct ͔ΒऔಘɻJSʹ͠ਖ਼
نදݱʹมɻ 29
WordPress͔ΒJSʹΛ͢ wp_localize_script Λ͑ग़དྷΔɻʢຊདྷͷ༻๏ͱͣ ΕΔؾ͢Δ͚Ͳʣ wp_localize_script( 'vuepress-script', 'WPSettings', [ 'root' =>
esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'date_permastruct' => $wp_rewrite->get_date_permastruct(), 'page_on_front' => get_option('page_on_front'), 'page_for_posts' => get_option('page_for_posts'), 'category_base' => get_option('category_base') ? get_option('category_base') : 'category', 'tag_base' => get_option('tag_base') ? get_option('tag_base') : 'tag' ] ); 30
ߘܥ 31
http://example.com/sample-page/ (ݻఆϖʔδ) http://example.com/hello-world/ (ߘ) ΛͲ͏ͬͯ۠ผ͢Δʁ 32
ࠓճɻ 1. /wp-json/vuepress/v1/post/<URL> ͱ͍͏APIΛ࡞ɻ 2. category, tag, date, ͷ݅ʹϚον͠ͳ͔ͬͨશͯͷURL Λ͜ͷAPIʹ͛Δɻ
3. url_to_postid ͰURL͔Β postID Λݕࡧ 4. get_post ͰߘσʔλΛऔಘ͠ฦ٫ɻ 33
add_action( 'rest_api_init', function () { register_rest_route( 'vuepress/v1', '/post/(?P<url>.*)', array( 'methods'
=> 'GET', 'callback' => function ( $request ) { $post_id = url_to_postid( $request['url'] ); if ( ! $post_id ) { return []; } $post = get_post( $post_id ); $post_type = get_post_type_object( $post->post_type ); $request['id'] = $post_id; $response = new WP_REST_Posts_Controller( $post->post_type ); return $response->get_item( $request ); } ) ); } ); 34
ͳ͔ͳ͔ແཧཧͳ࣮ɻ 35
͔͜͠͠ΕͰΓͳ͍ɻ 36
σϑΥϧτͷ WordPressʹࡌ͞ ΕΔRewrite Rule 90ݸ 37
"Clean URL"Ͱͳ͍URLͷରԠ • /?s=hoge /search/hoge ͱՁͰ͋Δ͕ϦμΠϨΫτ͞Εͳ͍!!! • /?cat=1 ϦμΠϨΫτ͞ΕΔ͕ɺ/?cat=1&cat=2 •
/?p=123ͷɺ"Clean URL"Λ༻͍ͯ͠ͳ͍έʔεɻ • ৽نߘͷϓϨϏϡʔɺ/?p=123&preview=true ܗࣜʹͳΔɻ • URL ͔Β /caregory/ Λফ͍ͨ͠ͱ͔͍͏ෆಧ͖ऀଟ͍ 38
Ͳ͏͠Α͏ʁ • WP_Rewirte / WPΫϥεͷ Α͏ͳϞϊΛJavaScriptͰ࠶࣮ ͢Δʁ • ͦͦͬͱΑ͍Ξϓϩʔν͕͋Δʁ 39
Let's think together 40
Thanks! Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit Blog: https://torounit.com 41