Created
June 12, 2015 10:35
-
-
Save chwnam/f5287e31f14c77cb06d0 to your computer and use it in GitHub Desktop.
워드프레스 주요 진입점 (admin_menu, admin-post, ajax, redirect)에 대한 예제입니다. 소스는 실습용이므로 수정이 필요합니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: entry-points-<author> | |
*/ | |
// Menu entry points | |
add_action( 'admin_menu', 'i_need_your_callback_selection' ); | |
function <author>_entry_points_add_admin_menu() { | |
add_menu_page( | |
'<author>_menu', | |
'<author>_menu', | |
'read', | |
'<author>_menu', | |
'i_need_your_callback_selection' | |
); | |
add_submenu_page( | |
'<author>_menu', | |
'<author>_submenu', | |
'<author>_submenu', | |
'read', | |
'<author>_submenu', | |
'i_need_your_callback_selection' | |
); | |
} | |
// add_menu_page callback | |
function <author>_entry_points_add_menu_page_callback() { ?> | |
<div class="wrap"> | |
<h3>POST 방식 전송의 예제입니다.</h3> | |
<form method="post" action="<?=admin_url('admin-post.php')?>"> | |
<label for="item">Item</label> | |
<input type="text" id="item" name="item" value="" /> | |
<input type="hidden" name="action" value="<author>_admin_post_action" /> | |
<input class="button button-primary" type="submit" /> | |
</form> | |
</div> | |
<?php | |
} | |
// add_submenu_page callback | |
function <author>_entry_points_add_submenu_page_callback() { ?> | |
<script> | |
function send_form() { | |
jQuery.post( | |
'<?=admin_url( 'admin-ajax.php' )?>', | |
jQuery('form[name="item_form"]').serialize(), | |
function(data) { | |
jQuery('span#item_name').hide().html(data).fadeIn(200); | |
} | |
); | |
return false; | |
} | |
</script> | |
<div class="wrap"> | |
<h3>AJAX 방식 전송의 예제입니다.</h3> | |
<form name='item_form'> | |
<label for="item">Item</label> | |
<input type="text" id="item" name="item" value="" /> | |
<input type="hidden" name="action" value="<author>_ajax_action" /> | |
<input class="button button-primary" type="submit" onclick="return send_form();"/> | |
</form> | |
<div> | |
<span id="item_name"></span> | |
</div> | |
</div> | |
<?php | |
} | |
// admin-post | |
add_action( 'admin_post_<author>_admin_post_action', 'i_need_your_callback_selection' ); | |
function <author>_entry_points_admin_post_callback() { | |
echo $_REQUEST['item']; | |
die(); | |
} | |
// ajax | |
add_action( 'wp_ajax_<author>_ajax_action', 'i_need_your_callback_selection' ); | |
function <author>_entry_points_ajax_action_callback() { | |
echo $_REQUEST['item']; | |
die(); | |
} | |
add_action( 'template_redirect', 'i_need_your_callback_selection' ); | |
function <author>_entry_points_redirect_callback() { | |
if( $_GET['your-magic-parameter'] == 'your-magic-word' ) { | |
echo '<!DOCTYPE html><html><head><meta charset="utf-8" /></head><body>템플릿이 완전히 재정의되지요.</body></html>'; | |
die(); | |
} | |
} | |
add_shortcode( '<author>_shortcode', 'i_need_your_callback_selection' ); | |
function <author>_shorcode_callback() { | |
return "<author> shortcode successfully called!"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment