My First WordPress Plugin
- 워드프레스 미트업 서울 2015 -
강동혁
2015-02-28
WordPress Core
+
Theme
+
Plugins
Hooks!
Hollywood Principle
Don’t call us,
we’ll call you.
지나가는 행인 역할도 좋으니
자리가 나면 연락주세요.
Hooking
=
특정 상황에 호출될
함수를 정의
Filters & Actions
Filters
add_filter(‘<filter
name>’, 함수)
apply_filters(‘<filter
name>’, 기본값)
$lower =
apply_filters(‘to_lower’,
‘LOWER’);
echo $lower; // lower
add_filter(‘to_lower’,
‘my_to_lower’);
function my_to_lower($arg) {
return strtolower($arg);
}
Actions
add_action(‘<action
name>’, 함수)
do_action(‘<action
name>’)
do_action(‘print_lower’,
‘LOWER’);
----
lower
add_action(‘print_lower’,
‘my_print_lower’);
function my_to_lower($arg) {
echo strtolower($arg);
}
WordPress Core
Plugins
Themes
apply_filters()
do_action()
Plugins
Plugin Extensions
Child Themes
add_filter()
add_action()
apply_filters( 'the_title' )
apply_filters( 'the_author' )
apply_filters( 'the_content' )
do_action( 'comment_form_before' )
do_action( 'twentyfourteen_credits' )
apply_filters( 'update_footer' )
Plugin Packaging
/unique-plugin-name
–unique-plugin-name.php
–uninstall.php
–/js
–/css
–/includes
–/images
Plugin Header
<?php
/**
* Plugin Name: My First Plugin
* Plugin URI: http://www.mysite.com/my-first-plugin/
* Description: This is my first wordpress plugin.
* Version: 1.0.0
* Author: WordPress Meetup
* Author URI: http://www.mysite.com
* Text Domain: my-first-plugin
* Domain Path: /languages/
*/
다국어 지원
Hello Dolly
function hello_dolly_get_lyric() {
return "Some Text";
}
function hello_dolly() {
$chosen = hello_dolly_get_lyric();
echo "<p id='dolly'>$chosen</p>";
}
add_action( 'admin_notices', 'hello_dolly' );
Hello Dolly
function hello_dolly_get_lyric() {
return "Some Text";
}
function hello_dolly() {
$chosen = hello_dolly_get_lyric();
echo "<p id='dolly'>WordPress Meetup Seoul
2015</p>";
}
Add Filter
function hello_dolly() {
$chosen = hello_dolly_get_lyric();
echo "<p id='dolly'>" .
apply_filters(‘dolly_lyric’, $chosen) .
"</p>";
}
function dolly_lyric_uppercase($chosen) {
return strtoupper($chosen);
}
Add Shortcode
function meetup_func( $atts ) {
return "<h1>안녕하세요? 워드프레스 미트업
서울 2015에 오신 것을 환영합니다.</h1>";
}
add_shortcode( 'meetup', 'meetup_func’ );
에디터에 [meetup] 입력
Advanced Plugins
●Activating and Deactivating Functions
●Internalization
●Nonces (Security)
●Saving and Retrieving Plugin Options
●Options Page
●Menu and Submenus
●Meta Box
●Widgets
●Custom DB Tables
Q & A
감사합니다.

My first word press plugin