첫 번째 WordPress 플러그인을 만드는 방법? 샘플 코드가 포함된 단계별 가이드 투어
게시 됨: 2017-04-27
WordPress 플러그인을 만들고 WordPress 플러그인 개발을 시작하는 방법은 무엇입니까?
당신은 새로운 WordPress 개발자입니까? 최근에 WordPress 작업을 시작하셨습니까? 새로운 WordPress 플러그인을 만들고 싶으십니까?
WordPress 플러그인을 처음부터 만드는 방법은 무엇입니까? 글쎄, 당신은 바로 이곳에 있습니다.
이 튜토리얼에서는 처음부터 Hello World WordPress Plugin
을 만드는 방법을 살펴보겠습니다. 이것은 WordPress 플러그인 개발 튜토리얼에 대한 단계별 가이드입니다.
시작하기 전에 WordPress 플러그인 디자인과 우리가 할 일은 다음과 같습니다.
- 우리는 간단한 Hello World WordPress 플러그인을 만들 것입니다.
- 모든 플러그인 코드가 포함된
crunchify-hello-world.php
파일 생성 - 기본 정보가 포함된
readme.txt
파일 생성- 플러그인 메타데이터
- 설명
- 설치 단계
- 자주 묻는 질문 섹션
- 스크린샷
- 변경 로그
- 플러그인에는 아래 기능이 있습니다.
-
Settings
메뉴에서 새 메뉴Crunchify Plugin
- 새 플러그인
admin page
- 사용자는 하나의
Textfield
add value
할 수 있습니다. - 설정을 저장하려면
Save button
- 플러그인은
every post
의 하단에append saved text
.
-
시작하자:
Step-1 플러그인 메타데이터를 생성합니다.
crunchify-hello-world.php
파일을 만들고 아래 코드를 먼저 넣습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
< ? php /** * Crunchify Hello World Plugin is the simplest WordPress plugin for beginner. * Take this as a base plugin and modify as per your need. * * @package Crunchify Hello World Plugin * @author Crunchify * @license GPL-2.0+ * @link https://crunchify.com/tag/wordpress-beginner/ * @copyright 2017 Crunchify, LLC. All rights reserved. * * @wordpress-plugin * Plugin Name: Crunchify Hello World Plugin * Plugin URI: https://crunchify.com/tag/wordpress-beginner/ * Description: Crunchify Hello World Plugin is the simplest WordPress plugin for beginner. Take this as a base plugin and modify as per your need. * Version: 3.0 * Author: Crunchify * Author URI: https://crunchify.com/ * Text Domain: crunchify-hello-world * Contributors: Crunchify * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ |
아래 필드는 절대적으로 필요하며 플러그인에 고유해야 합니다.
- 플러그인 이름
- 플러그인 URI
- 설명
- 버전
- 작가
- 작성자 URI
- 텍스트 도메인
- 기여자
2단계 하위 메뉴 섹션 추가
1 2 3 4 |
function crunchify_add_menu ( ) { add_submenu_page ( "options-general.php" , "Crunchify Plugin" , "Crunchify Plugin" , "manage_options" , "crunchify-hello-world" , "crunchify_hello_world_page" ) ; } add_action ( "admin_menu" , "crunchify_add_menu" ) ; |
플러그인의 하위 메뉴를 추가하기 위해 add_action
WordPress 후크를 사용하고 있습니다.
Step-3 플러그인 설정 페이지 생성
우리의 경우 Settings -> Crunchify Plugin
.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
function crunchify_hello_world_page ( ) { ? > < div class = "wrap" > < h1 > Hello World Plugin Template By < a href = "https://crunchify.com/optimized-sharing-premium/" target = "_blank" > Crunchify < / a > < / h1 > < form method = "post" action = "options.php" > <?php settings_fields ( "crunchify_hello_world_config" ) ; do_settings_sections ( "crunchify-hello-world" ) ; submit_button ( ) ; ?> < / form > < / div > <?php } function crunchify_hello_world_settings ( ) { add_settings_section ( "crunchify_hello_world_config" , "" , null , "crunchify-hello-world" ) ; add_settings_field ( "crunchify-hello-world-text" , "This is sample Textbox" , "crunchify_hello_world_options" , "crunchify-hello-world" , "crunchify_hello_world_config" ) ; register_setting ( "crunchify_hello_world_config" , "crunchify-hello-world-text" ) ; } add_action ( "admin_init" , "crunchify_hello_world_settings" ) ; function crunchify_hello_world_options ( ) { ?> < div class = "postbox" style = "width: 65%; padding: 30px;" > < input type = "text" name = "crunchify-hello-world-text" value = " <?php echo stripslashes_deep ( esc_attr ( get_option ( 'crunchify-hello-world-text' ) ) ) ; ?> " / > Provide any text value here for testing < br / > < / div > < ? php } |

4단계 저장된 텍스트 필드 값을 각 게시물에 추가
1 2 3 4 |
add_filter ( 'the_content' , 'crunchify_com_content' ) ; function crunchify_com_content ( $ content ) { return $ content . stripslashes_deep ( esc_attr ( get_option ( 'crunchify-hello-world-text' ) ) ) ; } |

완전한 코드:
다음은 완전한 Hello World WordPress Plugin
코드입니다. 아래에 복사하여 crunchify-hello-world.php
파일에 저장하십시오.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
<?php /** * Crunchify Hello World Plugin is the simplest WordPress plugin for beginner. * Take this as a base plugin and modify as per your need. * * @package Crunchify Hello World Plugin * @author Crunchify * @license GPL-2.0+ * @link https://crunchify.com/tag/wordpress-beginner/ * @copyright 2017 Crunchify, LLC. All rights reserved. * * @wordpress-plugin * Plugin Name: Crunchify Hello World Plugin * Plugin URI: https://crunchify.com/tag/wordpress-beginner/ * Description: Crunchify Hello World Plugin is the simplest WordPress plugin for beginner. Take this as a base plugin and modify as per your need. * Version: 3.0 * Author: Crunchify * Author URI: https://crunchify.com/ * Text Domain: crunchify-hello-world * Contributors: Crunchify * License: GPL-2.0+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt */ /** * Adding Submenu under Settings Tab * * @since 1.0 */ function crunchify_add_menu ( ) { add_submenu_page ( "options-general.php" , "Crunchify Plugin" , "Crunchify Plugin" , "manage_options" , "crunchify-hello-world" , "crunchify_hello_world_page" ) ; } add_action ( "admin_menu" , "crunchify_add_menu" ) ; /** * Setting Page Options * - add setting page * - save setting page * * @since 1.0 */ function crunchify_hello_world_page ( ) { ?> < div class = "wrap" > < h1 > Hello World Plugin Template By < a href = "https://crunchify.com/optimized-sharing-premium/" target = "_blank" > Crunchify < / a > < / h1 > < form method = "post" action = "options.php" > <?php settings_fields ( "crunchify_hello_world_config" ) ; do_settings_sections ( "crunchify-hello-world" ) ; submit_button ( ) ; ?> < / form > < / div > <?php } /** * Init setting section, Init setting field and register settings page * * @since 1.0 */ function crunchify_hello_world_settings ( ) { add_settings_section ( "crunchify_hello_world_config" , "" , null , "crunchify-hello-world" ) ; add_settings_field ( "crunchify-hello-world-text" , "This is sample Textbox" , "crunchify_hello_world_options" , "crunchify-hello-world" , "crunchify_hello_world_config" ) ; register_setting ( "crunchify_hello_world_config" , "crunchify-hello-world-text" ) ; } add_action ( "admin_init" , "crunchify_hello_world_settings" ) ; /** * Add simple textfield value to setting page * * @since 1.0 */ function crunchify_hello_world_options ( ) { ?> < div class = "postbox" style = "width: 65%; padding: 30px;" > < input type = "text" name = "crunchify-hello-world-text" value = " <?php echo stripslashes_deep ( esc_attr ( get_option ( 'crunchify-hello-world-text' ) ) ) ; ?> " / > Provide any text value here for testing < br / > < / div > <?php } /** * Append saved textfield value to each post * * @since 1.0 */ add_filter ( 'the_content' , 'crunchify_com_content' ) ; function crunchify_com_content ( $content ) { return $content . stripslashes_deep ( esc_attr ( get_option ( 'crunchify-hello-world-text' ) ) ) ; } |
5단계 readme.txt 파일 생성
다음은 샘플 WordPress 플러그인 readme.txt
파일입니다.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
=== Crunchify Hello World Plugin === Contributors : Crunchify Donate link : https : //www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8ZF6WATLYFELQ Tags : Hello World Plugin , Crunchify Plugins , Beginner WordPress , WordPress Plugin Requires at least : 4.5 Tested up to : 4.7.4 Stable tag : 3.0 License : GPLv2 or later License URI : http : //www.gnu.org/licenses/gpl-2.0.html Create your fist plugin . Crunchify Hello World Plugin is the simplest WordPress plugin for beginner . Take this as a base plugin and modify as per your need . == Description == Crunchify Hello World Plugin is the simplest WordPress plugin for beginner if you want to start creating fresh new plugin . Take this as a base plugin and modify as per your need . == Installation == 1. Unpack the ` download - package ` . 2. Upload the file to the ` / wp - content / plugins / ` directory . 3. Activate the plugin through the ` Plugins ` menu in WordPress . 4. Done and Ready . == Frequently Asked Questions == = How to add FAQ question = * just add your FAQ questions here == Screenshots == 1. This is a text label for your first screenshot 2. Add more screenshot labels as new line == Changelog == = 3.0 = * Initial release |
이제 뭐?
-
/plugins folder
아래에 폴더crunchify-hello-world
를 만들고 거기에 두 파일 복사를 추가하기만 하면 됩니다.

- 관리 콘솔 -> 플러그인으로 이동합니다.
- 플러그인 활성화

그게 다야
첫 번째 WordPress 플러그인 작성 시작
이 코드 as a sample
필요에 따라 수정합니다. 다음 튜토리얼에서는 더 많은 기능을 위해 좀 더 복잡한 배열 필드를 살펴보겠습니다.
계속 지켜봐 주시고 행복한 블로깅하십시오.