Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
140
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
750
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
600
ブロックテーマとこれからの WordPress サイト制作 / nishinomiya.dev@2025-12-21
torounit
1
290
ブロックテーマとこれからの WordPress サイト制作 / Toyama WordPress Meetup Vol.81
torounit
0
810
ブロックテーマ時代における、テーマの CSS について考える Toro_Unit / 2025.09.13 @ Shinshu WordPress Meetup
torounit
0
830
ブロックテーマでサイトリニューアルした話 / Toro_Unit / 2025.04.12 @ Shinshu WordPress Meetup
torounit
1
360
Cloudflare Meetup Nagano Vol.3
torounit
1
180
僕が考える 「HTML サイトを WordPress にする」話 / 2023-11-05 Kansai WordPress Meetup
torounit
9
8.9k
Other Decks in Technology
See All in Technology
AI時代におけるエンジニアの新たな役割──FDEとクオリアの探求/登壇資料(戸井田 裕貴)
hacobu
PRO
0
460
探索・可視化・自動化を一本化 Amazon Quickでデータ活用スピードを上げる方法
koheiyoshikawa
0
210
AI Agent を本番環境へ―― Microsoft Foundry × Azure Serverless で作る Enterprise-Ready な基盤
shibayan
PRO
1
500
「休む」重要さ
smt7174
7
1.7k
論語・武士道・産業革命から見る かわるもの、かわらないもの
ichimichi
7
1.1k
発表と総括 / Presentations and Summary
ks91
PRO
0
210
OPENLOGI Company Profile for engineer
hr01
1
75k
書籍セキュアAPIについて
riiimparm
0
330
CTOキーノート:AI時代の「つなぐ」を再定義 ― 真のIoTとリアルワールドAI【SORACOM Discovery 2026】
soracom
PRO
0
130
AI時代の開発生産性を捉え直す — 経営と現場をつなぐ「開発組織のオブザーバビリティ」— / AI Dev Ex Conference 2026
tkyowa
1
1.7k
AIとハーネスで育てるトランスコンパイラ / 20260722 Yasushi Katayama
shift_evolve
PRO
3
960
仕様駆動開発、導入半年。「本当に速くなってるの?」にデータで答える / AICon2026_hirakawa
rakus_dev
0
350
Featured
See All Featured
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
190
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
320
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.6k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Context Engineering - Making Every Token Count
addyosmani
9
1k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
57k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Design in an AI World
tapps
1
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