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
WordPress Plugin 入門 #wpshinshu / 2019-06-22 Sh...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
210
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
840
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
870
ブロックテーマとこれからの 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
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
3
21k
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
170
プラットフォームを「作る」、 チームに「入り込む」
sansantech
PRO
0
410
セルフサービスのオブザーバビリティ基盤をOpenTelemetryで作る / Building a Self-Service Observability Platform with OpenTelemetry
ymotongpoo
3
500
猫でもわかるKiro Web
kentapapa
1
160
雪かき部 #7 もう怖くない!SELECT文!
foursue
0
270
Codex概要
ymiya55
0
140
覗いてみよう 関数型ビジュアル言語×2Dグラフィックスの世界
yohyamasaki
0
160
Argo CDとAtlantisで実現するインフラ管理のセルフサービス化──小規模SREチームで支えるプラットフォーム
cassius7
0
260
Snowflake Horizon Catalog と Apache Iceberg で作る オープンなデータ基盤
kitagawaz
0
360
Confitura 2026
logico_jp
0
120
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
0
120
Featured
See All Featured
The Curse of the Amulet
leimatthew05
3
15k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
260
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
380
Git: the NoSQL Database
bkeepers
PRO
432
67k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Designing for humans not robots
tammielis
254
26k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
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