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の文法おさらい.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
echizenyayota
July 29, 2017
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
register_activation_hook関数の使い方でみるPHPの文法おさらい.pdf
echizenyayota
July 29, 2017
More Decks by echizenyayota
See All by echizenyayota
日本語話者と英語話者のためのIT技術者交流コミュニティ_事始め_日本語_英語_.pdf
echizenyayota
0
520
外出自粛期間のおすすめ! オンラインサービスで 自由気ままな英語学習
echizenyayota
0
600
Visual Studio CodeでJavaScriptプログラミング
echizenyayota
0
390
他人のソースコードをすばやく読むコツ 項とJavaScriptの演算子
echizenyayota
0
140
ドットインストールの質問回答サービスで身につくプログラミング学習法
echizenyayota
0
170
「Webパフォーマンス改善セミナー」 概要説明
echizenyayota
1
87
JavaScriptの正規表現で リファラースパムを退治した話
echizenyayota
0
160
JavaScriptの新しい文法を学習しよう
echizenyayota
1
360
さくらのVPSでプラグインを使わないWordPressのバックアップ
echizenyayota
0
1.5k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
420
The Pragmatic Product Professional
lauravandoore
37
7.5k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
BBQ
matthewcrist
90
10k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
Making Projects Easy
brettharned
120
6.8k
Ruling the World: When Life Gets Gamed
codingconduct
0
400
Transcript
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
ご清聴ありがとうございました!