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
register_activation_hook関数の使い方でみるPHPの文法おさらい
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
echizenyayota
July 28, 2017
Programming
1.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
register_activation_hook関数の使い方でみるPHPの文法おさらい
WordPress関数をよく知るためには、PHPの文法に慣れていないといけませんよーというお話です
echizenyayota
July 28, 2017
Transcript
23 slides
register_activation_hook関数の使い方で みるPHPの文法おさらい 2017年7月28日(金) in WordBench大阪
Who are you? 福井 洋(@echizenya_yota) https://twitter.com/echizenya_yota http://e-yota.com/ WordCamp Kyoto 2017
実行委員(スポンサーチーム担当) https://2017.kyoto.wordcamp.org/organizers/ http://e-yota.com/webservice/suponsors-organizer/ 普段はWordPressサイトのサーバー構築のお手伝いと個人レッスン、Web初心者向け にプログラミングの個人レッスンをしている個人事業主です。
WordCamp Kyoto 2017 コントリデイ 本日のネタはwckyoto2017の2日目に行われたコントリビュターデイで、WordPress Codexを編集したときの内容に基づいてお話します。
実際に自分が編集したところ
register_activation_hook関数とは プラグインが有効化されたときに実行される関数を登録する関数。
register_activation_hook関数の具体例 class WPWA_User_Manager { public function __construct() { // 初期化コード
register_activation_hook( __FILE__ , array( $this, 'add_application_user_roles' ) ); } public function add_application_user_roles() { add_role( 'follower', 'Follower', array( 'read' => true ) ); add_role( 'developer', 'Developer', array( 'read' => true ) ); add_role( 'member', 'Member', array( 'read' => true ) ); } } $user_manage = new WPWA_User_Manager(); 詳しくはこちら→ https://goo.gl/Y83PGS プラグインが有効化されたときに、 Follower、Developper、Memberと いうユーザーロールが追加される
register_activation_hook関数の2つの使い方 • 関数を使う場合(クラスメソッドを使わない場合) • 関数を使わない場合(クラスメソッドを使う場合) →今回は関数を使わない場合(クラスメソッドを使う場合)でPHP の文法について説明
オブジェクトとは? class Hoge { public function __construct() { wp_example(__FILE__, array(
$this, 'fuga' ) ); } public function fuga() { } } →データとデータの処理方法の定義書 (説明の便宜上、架空のWordPress関数、wp_exampleを使用します)
クラス定義 class Hoge { } →定義するクラス名を宣言
コンストラクタ(初期化処理) class Hoge { public function __construct() { wp_example(__FILE__, array(
$this, 'fuga' ) ); } } →Hogeクラスが実行されると必ず__construct()というメソッドが呼び出される
__FILE__(マジック定数) class hoge { public function __construct() { // 初期化コード
wp_example(__FILE__, array( $this, 'fuga' ) ); } } →ファイルのフルパスとファイル名。 自分の環境だと/var/www/wordpress/wp-content/plugins/wpwa-user-manager/class-wpwa-user-manager.php と言う意味。
配列 class Hoge { public function __construct() { // 初期化コード
wp_example(__FILE__, array( $this, 'fuga' ) ); } } →変数を複数入れられる「箱」のようなもの
擬似変数 class Hoge { public function __construct() { // 初期化コード
wp_example(__FILE__, array( $this, 'fuga' ) ); } } →クラスの中のメソッドやプロパティ(クラス変数)みたいにアクセスする時に使うキー ワード
メソッド class Hoge { public function __construct() { // 初期化コード
wp_example( __FILE__ , array( $this, ‘fuga’) ); } public function fuga() { echo “My Name is Wapuu!”; } } →クラス内で使う関数
インスタンス化とは? class Hoge { public function __construct() { wp_example(__FILE__, array(
$this, 'fuga' ) ); } public function fuga() { echo “My Name is Wapuu!”; } } $hogefuga = new Hoge(); →クラスに定義されているデータを実際に持たせたデータ
newキーワード class Hoge { public function __construct() { wp_example(__FILE__, array(
$this, 'fuga' ) ); } public function fuga() { echo “My Name is Wapuu!”; } } $hogefuga = new Hoge(); →クラスに定義されている内容を実際に持たせたデータを呼び出す時に使うキーワード
オブジェクト変数 class Hoge { public function __construct() { wp_example(__FILE__, array(
$this, 'fuga' ) ); } public function fuga() { echo “My Name is Wapuu”; } } $hogefuga = new Hoge(); →クラスに定義されている内容を実際に持つ変数
オブジェクトとインスタンスの使用例 class Hoge { public function __construct() { wp_example(__FILE__, array(
$this, 'fuga' ) ); } public function fuga() { echo “My Name is Wapuu!”; } } $hogefuga = new Hoge(); $hogefuga->fuga(); →出力結果: My Name is Wapuu!
意味の分からない変数はデバッグしよう! class Hoge { public function __construct() { var_dump(__FILE__) exit;
wp_example(__FILE__, array( $this, 'fuga' ) ); } public function fuga() { echo “My Name is Wapuu!”; } } $hogefuga = new Hoge(); $hogefuga->fuga(); →出力結果: /var/www/wordpress/wp-content/plugins/wpwa-user-manager/class-wpwa-user-manager.php
公式ドキュメントを読もう! http://php.net/
本で調べよう! https://bookmeter.com/books/11600128
それでも分からなければdotinstallを利用しよう http://dotinstall.com/lessons/basic_php_v2
ご清聴ありがとうございました!
More Decks by echizenyayota
See All by echizenyayota
日本語話者と英語話者のためのIT技術者交流コミュニティ_事始め_日本語_英語_.pdf
echizenyayota
0
540
外出自粛期間のおすすめ! オンラインサービスで 自由気ままな英語学習
echizenyayota
0
610
Visual Studio CodeでJavaScriptプログラミング
echizenyayota
0
400
他人のソースコードをすばやく読むコツ 項とJavaScriptの演算子
echizenyayota
0
150
ドットインストールの質問回答サービスで身につくプログラミング学習法
echizenyayota
0
180
「Webパフォーマンス改善セミナー」 概要説明
echizenyayota
1
88
JavaScriptの正規表現で リファラースパムを退治した話
echizenyayota
0
160
JavaScriptの新しい文法を学習しよう
echizenyayota
1
370
さくらのVPSでプラグインを使わないWordPressのバックアップ
echizenyayota
0
1.5k
Other Decks in Programming
See All in Programming
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
200
protojson における文字化けの扱い
kazuki1023
0
450
Distance field of Julia set
kinakomoti321
0
330
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
250
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
6.1k
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
690
AI-Powered Domain-Driven Design
ziobrando
0
470
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
620
あなたはMCPの機能を、まだ知らない。
4geru
1
700
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
360
Spec-driven Development with AI
simas
PRO
0
2.3k
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
170
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
630
Amusing Abliteration
ianozsvald
1
400
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
61k
Designing for Timeless Needs
cassininazir
1
570
Bash Introduction
62gerente
615
220k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
30 Presentation Tips
portentint
PRO
1
470
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
900
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
990
Designing for humans not robots
tammielis
254
26k