Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

of

My second word press plugin Slide 1 My second word press plugin Slide 2 My second word press plugin Slide 3 My second word press plugin Slide 4 My second word press plugin Slide 5 My second word press plugin Slide 6 My second word press plugin Slide 7 My second word press plugin Slide 8 My second word press plugin Slide 9 My second word press plugin Slide 10 My second word press plugin Slide 11 My second word press plugin Slide 12 My second word press plugin Slide 13 My second word press plugin Slide 14 My second word press plugin Slide 15 My second word press plugin Slide 16
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

1 Like

Share

Download to read offline

My second word press plugin

Download to read offline

MVC 기반 워드프레스 플러그인 개발 개요

Related Books

Free with a 30 day trial from Scribd

See all

My second word press plugin

  1. 1. My Second WordPress Plugin 강동혁 dongheok@shoplic.kr 2019-02-07
  2. 2. Problems • 워드프레스 플러그인 개발 방법론 부재 • Naming Conflicts
  3. 3. add_action(‘init’, ‘my_plugin_init’); if ( !function_exists(‘my_plugin_init’)) { function my_plugin_init() { echo ‘This is my plugin init.’; } }
  4. 4. add_action(‘my_plugin_action’, ‘my_plugin_action’); if ( !function_exists(‘my_plugin_action’)) { function my_plugin_action() { echo ‘This is my plugin action.’; } }
  5. 5. Solutions • MVC(Model, View, Controller) • CBD(Component Based Development)
  6. 6. M V C Component M V C Component M V C Component M V C Component M V C Component PLUGIN
  7. 7. Plugin Packaging plugin-name/ components/ comp1/ views/ models/ controller.php comp2/ plugin-name.php
  8. 8. Model • WordPress Models • Tables • wp_posts, wp_postmeta, wp_comments, wp_commentmeta, wp_users, wp_usermeta, … • Classes • WP_Post, WP_Comment, WP_User, … • Functions • get_posts(), get_comments(), get_users(), … • Query • WP_Query // Show Posts from Several Authors $query = new WP_Query( array( 'author' => '2,6,17,38' ) );
  9. 9. Simple ORM for Custom Tables CREATE TABLE `site_domain` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `site_id` bigint(20) DEFAULT NULL, `domain` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL, `primary` tinyint(1) DEFAULT NULL, `https` tinyint(1) DEFAULT NULL, `created_date` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `IDX_SITE_ID` (`site_id`) )
  10. 10. class Site_Domain extends SP_Entity { static $_database = 'sp_hosting'; static $_primary_key = 'id'; static $_column_formats = [ 'id' => '%d', 'site_id' => '%d', 'domain' => '%s', 'primary' => '%d', 'https' => '%d', 'created_date' => '%s', ]; static function get_table() { return 'site_domain'; } } SP_ORM::insert(new Site_Domain([ 'site_id' => $site->id, 'domain' => $_POST['domain’], 'https' => $_POST['https’], 'created_date' => current_time('mysql'), ])); SP_ORM::select(new Site_Domain([ 'site_id'=>$site->id ])); SP_ORM::delete(new Site_Domain([ 'site_id' => $site->id, 'domain' => $_POST['domain’] ]));
  11. 11. Controller • A set of actions, filters, and shortcodes Abstract_Controller $id init() add_action() add_filter() add_shortcode() view() My_Controller login() class My_Controller extends Absctract_Controller { $id = ‘shoplic’; function init() { $this->add_action(‘login’); } function login() { // 로그인 처리 } } => add_action(‘shoplic_login’, My_Controller::login)
  12. 12. // controller.php class My_Controller extends Absctract_Controller { $id = ‘shoplic’; function init() { $this->add_shortcode(‘login_form’); } function login_form() { // 로그인 폼 $this->view(‘login_form’, [ ‘message’ => ‘로그인‘ ]); } } add_shortcode(‘shoplic_login_form’, My_Controller::login_form) // login_form.php <h1><?php echo $message; ?></h1> <form> </form> // Editor [shoplic_login_form]
  13. 13. Communication between Components // comp1/controller.php class Comp1_Controller extends Absctract_Controller { $id = ‘shoplic’; function init() { $this->add_action(‘logout’); } function logout() { // 로그아웃 처리 } }  add_action(‘shoplic_logout’, Comp1_Controller::logout) // comp2/controller.php class Comp2_Controller extends Abstract_Controller { $id = ‘wordpress’; function logout() { do_action(‘shoplic_logout’); } }
  14. 14. Prevent Naming Conflicts • Don’t Do Naming • Use Anonymous Functions(5.3~) & Anonymous Classes(7~)
  15. 15. new class() extends Abstract_Controller { $id = ‘shoplic’; function init() { $this->add_action(‘login’, function() { // 로그인 처리 }); } }
  16. 16. 감사합니다. 강동혁 donghyeok@shoplic.kr
  • LorenMills

    Nov. 23, 2021

MVC 기반 워드프레스 플러그인 개발 개요

Views

Total views

312

On Slideshare

0

From embeds

0

Number of embeds

182

Actions

Downloads

2

Shares

0

Comments

0

Likes

1

×