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
220
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
850
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
900
ブロックテーマとこれからの WordPress サイト制作 / nishinomiya.dev@2025-12-21
torounit
1
300
ブロックテーマとこれからの WordPress サイト制作 / Toyama WordPress Meetup Vol.81
torounit
0
840
ブロックテーマ時代における、テーマの CSS について考える Toro_Unit / 2025.09.13 @ Shinshu WordPress Meetup
torounit
0
970
ブロックテーマでサイトリニューアルした話 / 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
9k
Other Decks in Technology
See All in Technology
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
230
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
370
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
180
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
1.4k
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
660
子育てエンジニアの可処分時間が減っても成長を諦めない戦い方
sudoakiy
6
4.4k
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
5
1.3k
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
540
ファミコンでPHPを動かす / PHP on the Famicom side b
tomzoh
0
140
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
230
Getting Started with Google Antigravity
glaforge
0
150
今こそ知りたいAmplifyGen2
mkdev10
2
160
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
HDC tutorial
michielstock
2
950
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Statistics for Hackers
jakevdp
799
230k
ラッコキーワード サービス紹介資料
rakko
1
5.3M
Building Applications with DynamoDB
mza
96
7.2k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
590
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
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