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
WordPress Plugin 入門 #wpshinshu / 2019-06-22 Sh...
Search
Toro_Unit (Hiroshi Urabe)
June 22, 2019
Technology
280
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
WordPress Plugin 入門 #wpshinshu / 2019-06-22 Shinshu WordPress Meetup
Toro_Unit (Hiroshi Urabe)
June 22, 2019
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
790
ブロックテーマでサイトをリニューアルした話 / 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
910
ブロックテーマでサイトリニューアルした話 / 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
Nav2、Nav3 ... はたまた自作?〜 作って理解する Nav3 の設計意図 〜 / Nav2, Nav3 ... or Build Your Own? — Understanding Nav3's design intent by building it from scratch
yanzm
0
260
GoにおけるFFIのこれまでとこれから
goccy
4
1.3k
Benchmarking Vector Databases: pgvector vs. LanceDB
tsho
0
150
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1k
Webとヘルスデータ
yukukotani
1
200
Redmine 7.0で私が開発した新機能の狙いと背景
vividtone
1
130
こんなアーキテクチャ図は嫌だ BEYOND THE TIME: 半年後の自分へ贈る15のメッセージ / 15 of Anti-pattern in AWS Architecture Diagrams
naospon
3
270
Microsoft 365 Copilot chat -tekoälypalvelun tietosuojaongelmat
hponka
0
560
AIとペアプロを始める。人とのペアプロをやめる。ペアプロの良さを改めて知る。もっと好きになった。 / Rediscovering Pair Programming
honyanya
1
290
プロダクト思考 × 基盤思考を AIで実現する Compound Engineering
tkc66buzz
1
290
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
3
370
Bet AI Day 2026丨バクラク Autopilot、業務システムの再設計
layerx
PRO
2
1.6k
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
500
Agile that works and the tools we love
rasmusluckow
331
22k
The Invisible Side of Design
smashingmag
301
52k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Leo the Paperboy
mayatellez
8
2.2k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Abbi's Birthday
coloredviolet
3
9.8k
Evolving SEO for Evolving Search Engines
ryanjones
0
280
Amusing Abliteration
ianozsvald
1
290
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
510
Transcript
WordPress Plugin ೖ Toro_Unit @Shinshu WP Meetup vol.13 1
$ whoami 2
Toro_Unit ෦ ߛ (͏Β ͻΖ͠) • Frontend Engineer • WordPress
Plugin and Theme Developer Github: @torounit Twitter: @Toro_Unit 3
Contribution • WordPress 4.3 / 4.4 / 4.7 / 5.0
/ 5.1 / 5.2 • WordCamp Osaka 2019 • WordCamp Osaka 2018 Speaker. • etc... 4
Plugins and Themes • Custom Post Type Permalinks • Advanced
Posts Blocks • Simple Post Type Permalinks • Powerful Posts Per Page (PPPP) • Vanilla • and more... 5
Question. 6
Theme ࡞ͬͨ͜ͱ͋Δਓ 7
Plugin ࡞ͬͨ͜ͱ͋Δਓ 8
ͦͦ ϓϥάΠϯͱԿͳͷ͔ɻ 9
• WordPress Λ֦ு͢ΔػೳɻσϑΥϧτʹແ͍ػೳΛՃ͠ ͨΓɺಈ࡞Λվมͨ͠Γ͢Δɻ • wp-settings.php ͰಡΈࠐ·ΕΔɻ • PHPͷεΫϦϓτɻ͔ͦ͜ΒCSSͱ͔JSͱ͔ΛಡΈࠐΜͩΓ ͢Δ͜ͱɻ
10
foreach ( wp_get_active_and_valid_plugins() as $plugin ) { wp_register_plugin_realpath( $plugin );
include_once( $plugin ); /** * Fires once a single activated plugin has loaded. * * @since 5.1.0 * * @param string $plugin Full path to the plugin's main file. */ do_action( 'plugin_loaded', $plugin ); } 11
wp-content/plugins ͷதʹɺ • hogehoge.php • hogehoge/hugahuga.php ͳͲͷϑΝΠϧΛ࡞͠ɺઌ಄ʹίϝϯτΛॻ͚ϓϥάΠ ϯɻ <?php /**
* Plugin Name: Your Plugin */ 12
ΞΫγϣϯϑοΫɺϑΟϧλʔϑοΫ • WordPress ͷಛఆͷಈ࡞Λվม͢ΔͨΊͷػೳɻ 13
add_action ಛఆͷՕॴʹಈ࡞ΛՃ͢Δɻ // ϓϥάΠϯͷελΠϧγʔτΛొ function add_reading_minutes_styles() { wp_enqueue_style( 'plugin-hans-on-sample', plugin_dir_url(
__FILE__ ) . 'style.css' ); } // ΞΫγϣϯϑοΫΛొ add_action( 'wp_enqueue_scripts', 'add_reading_minutes_styles' ); 14
add_filter ಛఆͷՕॴʹಈ࡞Λվม͢Δɻ //ຊจͷલʹ͜ͷهࣄnͰಡΊ·͢Λදࣔɻ function add_reading_minutes_to_the_content( $content ) { $minutes =
count_reading_minutes( $content ); $text = sprintf( '͜ͷهࣄ%dͰಡΊ·͢ɻ', $minutes ); $before = '<span class="reading-minutes">' . esc_html( $text ) . '</span>'; return $before . $content; } //ϑΟϧλʔϑοΫΛొ add_filter( 'the_content', 'add_reading_minutes_to_the_content' ); 15
ࡶͳͨͱ͑ ࡶͳΧϨʔͷ࡞Γํ 1. ࡐྉΛ༻ҙ͢Δ: [ܲɺδϟΨΠϞɺʹΜ͡ΜɺλϚωΪ] 2. ࡐྉΛΔ 3. ᖱΊΔ 4.
ࣽΔ 5. ௐຯྉ(ϧ)ΛೖΕΔ 16
ΧϨʔͪΌΜͱΞΫΛऔͬͨํ͕ඒຯ͍ɻ ΞΫΛऔΓ·͘ΔΧϨʔVSҰऔΒͳ͍ΧϨʔ :: σΠϦʔϙʔ λϧZ 17
1. ࡐྉΛ༻ҙ͢Δ: [ܲɺδϟΨΠϞɺʹΜ͡ΜɺλϚωΪ] 2. ࡐྉΛΔ 3. ᖱΊΔ 4. ࣽΔ 5.
ΞΫΛऔΔ!!! 6. ௐຯྉ(ϧ)ΛೖΕΔ 18
ࡶͳϨγϐΛ PHP Ͱॻ͍ͯΈΔɻ $zairyo = [ 'ܲ', 'δϟΨΠϞ', 'ʹΜ͡Μ', 'λϚωΪ'
]; $zairyo = apply_filters( 'zairyo', $zairyo ); $cook->cut( $zairyo ); do_action( 'before_boil', $cook ); $cook->boil(); do_action( 'after_boiled', $cook ); $seasoning = apply_filters( 'seasoning', [ 'ΧϨʔϧ' ] ); $cook->add_seasoning( $seasoning ); 19
ΞΫΛऔΔ add_action( 'after_boiled', 'remove_aku' ); function remove_aku( $cook ) {
$cook->remove_aku(); } 20
1. ࡐྉΛ༻ҙ͢Δ: [ܲɺδϟΨΠϞɺʹΜ͡ΜɺλϚωΪ] 2. ࡐྉΛΔ 3. ᖱΊΔ 4. ࣽΔ 5.
ΞΫΛऔΔ!!! 6. ௐຯྉ(ϧ)ΛೖΕΔ 21
ϏʔϑΧϨʔʹม͑Δ add_filter( 'zairyo', 'beef_curry_zairyo' ); function beef_curry_zairyo( $zairyo ) {
return array_replace( $zairyo, [ 0 => 'ڇ'] ); } 22
1. ࡐྉΛ༻ҙ͢Δ: [ ڇ!! ɺδϟΨΠϞɺʹΜ͡ΜɺλϚωΪ] 2. ࡐྉΛΔ 3. ᖱΊΔ 4.
ࣽΔ 5. ௐຯྉ(ϧ)ΛೖΕΔ 23
͡Ό͕ʹม͑Δ add_filter( 'zairyo', function() { return ['ಲ', 'δϟΨΠϞ', 'ʹΜ͡Μ', '͠Β͖ͨ',
'λϚωΪ' ]; }); add_filter( 'seasoning', function() { return [ '͠ΐ͏Ώ', 'ΈΓΜ', '࠭' ]; }); add_action( 'before_boil', function( $cook ) { $cook->make_dashi('અ'); }); add_action( 'after_boiled', function( $cook ) { $cook->remove_aku(); $cook->set_otoshibuta(); }); 24
1. ࡐྉΛ༻ҙ͢Δ: [ಲɺδϟΨΠϞɺʹΜ͡Μɺ͠Β͖ͨɺλϚωΪ] 2. ࡐྉΛΔ 3. ᖱΊΔ 4. μγΛऔΔ 5.
ࣽΔ 6. փोΛऔΔ 7. མͱ֖͠ 8. ௐຯྉ(ে༉ɺΈΓΜɺ࠭)ΛೖΕΔ 25
ϑοΫͷ୳͠ํ Codex ΛݟΔ • ϓϥάΠϯ API/ΞΫγϣϯϑοΫҰཡ - WordPress Codex
ຊޠ൛ 26
27
• Code reference https://developer.wordpress.org/reference/ɹ Ͱ͕͢͞ɻ • ιʔεΛಡΉɻ • ϑΟϧλʔϑοΫϚδͰଟ͗͢ΔͷͰɺͦͷ୳ͯ͠ Δɻ͜ͷؔͱ͔ςϯϓϨʔτλάͲ͏ʹ͔ͳΒͳ͍͔
ͳʔͬͯײ͡ͰιʔεΛͦͷՕॴ͚ͩಡΉͱɺେɺ do_action, apply_filter ͕ݟ͔ͭΔɻ 28
Α͘͏ action • after_setup_theme: ςʔϚͷઃఆ͕ऴΘͬͨޙ • init : WordPress ͷॳظઃఆͳͲ͕ऴΘͬͨޙ
• admin_init : ཧը໘ͰͷॳظઃఆͳͲ͕ऴΘͬͨޙ • wp_enqueue_scripts : CSS ͱ͔ JS Λొ͢Δͱ͖ • pre_get_posts: ߘͷσʔλΛऔಘ͢Δલ 29
Α͘͏ filter • body_class: body_class() Ͱग़ྗ͞ΕΔ class Λվมɻ • get_the_archive_title:
ҰཡϖʔδͰͷλΠτϧɺ the_archive_title() ͷςΩετΛมߋɻ ͋Μ·Γͳ͍ɻͦͷඞཁʹԠͯ͡ɻɻɻ 30
functions.php ͱͳʹ͕͕ͪ͏ͷ͔ • ಡΈࠐ·ΕΔλΠϛϯά͕ҧ͏ɻϓϥάΠϯͷ100ߦԼ͘Β͍Ͱಡ Έࠐ·ΕΔɻ • ͦΕҎ֎ʹҧ͍ಛʹͳ͍ɻfunctions.php ͰՄೳͳ͜ͱશͯϓϥ άΠϯͰ࣮ݱͰ͖Δɻ foreach
( wp_get_active_and_valid_themes() as $theme ) { if ( file_exists( $theme . '/functions.php' ) ) { include $theme . '/functions.php'; } } 31
• άάΔͱ functions.php ʹɾɾɾΈ͍ͨͳهࣄ͕ࢁ΄Ͳग़ͯ ͘Δ͕ɺ΄΅શͯϓϥάΠϯͰಈ͘ɻ 32
ԿނϓϥάΠϯʁςʔϚͰಉ͜͡ͱ͕Ͱ͖Δͳ Βผʹྑ͘ͳ͍ʁ • ͪ·ͨͰଟػೳΛചΓʹͯ͠ΔςʔϚଟ͍Ͱ͕͢ɻɻɻ 33
ςʔϚʹػೳΛؚΊΔ͜ͱͷ • ςʔϚαΠτͷݟͨΛఆٛ͢ΔϞϊɻػೳΛؚΊΔͷ Ͱແ͍ɻ • ݟͨΛม͍͑ͨʂͱ͍͏ͱ͖ʹɺػೳ͕ࢮ͵ͷͰม͑ΒΕ ͳ͍ͳͲͷɻ • ଞͷϞϊͰରԠ͍ͨ͠ػೳΛOFFʹͰ͖ͳ͍ɻ 34
ϓϥάΠϯςϦτϦʔ Plugin Territory • ΞΫηεղੳ • SEO ͷͨΊͷػೳ • ͓͍߹ΘͤϑΥʔϜ
• ΧελϜߘλΠϓ • ΧελϜϒϩοΫɾγϣʔτίʔυ • etc.... 35
ʮϦχϡʔΞϧςʔϚͷมߋͰͿͬ ͱΜͩΒࠔΔͷϓϥάΠϯʯ Plugin Territory – WordPressͷͦͷॲཧςʔϚͰΔ͖͔ϓϥάΠϯͰΔ͖͔ʁ | Firegoby 36
ͲΜͳ;͏ʹࣄͰͬͯΔ͔ • Ҋ݅Ͱ࡞Δͱ͖ɺػೳ͝ͱʹผͷϓϥάΠϯʹׂ͍ͯ͠ Δɻ • 5ߦͷίʔυͱ͔Ͱɻ • γϯϓϧͳػೳ͍ճ͕͠ޮ͖͍͢͠ཧղ͍͢͠ɻ • functions.php
͕ _sʢελʔλʔςʔϚʣ ͦͷ··ͱ͍͏ ߹ଟ͍ɻ 37
Thanks! Github: @torounit Twitter: @Toro_Unit Facebook: fb.me/torounit Blog: https://torounit.com 38