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
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
210
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
850
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
880
ブロックテーマとこれからの 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
950
ブロックテーマでサイトリニューアルした話 / Toro_Unit / 2025.04.12 @ Shinshu WordPress Meetup
torounit
1
380
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
ビジネスを止めない技術的負債の返済のための戦略とその手法 - 技術的負債と向き合う / Complexity and Simplicity
soudai
PRO
3
510
AI感のないAWS構成図をAIエージェントに描かせたい!
sagochiko
2
500
MCPゲートウェイを作って運用してわかったこと — Agent時代の権限管理の現在地
mtpooh
10
3k
SREでアラート疲れを 解決しよう!
kairim0
1
120
『GOエコノミー 』(相乗りサービス) におけるスペック駆動開発
mot_techtalk
1
250
高負荷プロダクション環境におけるAWS Lambdaのリアル 〜スケールとコストを左右する実行ライフサイクルの技術仕様〜
maimyyym
2
850
行動するAIのためのオントロジー | DevRev — Encraft #26.pdf
dvrv_tknrszk
2
680
The seven pitfalls of AI (revised version)
ufried
0
230
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
180
BedrockとLambdaで作る リアルタイム進行型推理ゲーム
kawametho
0
170
IoTデバイスを繋げるプロトコルMatterをAndroidで使用する方法
harutiro
0
100
freeeらしさをAIとともに作る / Creating the freee Experience with AI
ymrl
0
130
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
530
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Claude Code のすすめ
schroneko
67
230k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
960
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
590
The SEO identity crisis: Don't let AI make you average
varn
0
570
How to make the Groovebox
asonas
2
2.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
510
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