Created
April 29, 2013 16:07
-
-
Save ShinichiNishikawa/5482614 to your computer and use it in GitHub Desktop.
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 | |
// エディタの下にテキストエリアを追加 | |
add_action( 'edit_form_after_editor', 'nskw_postMetaAfterEditor' ); | |
function nskw_postMetaAfterEditor() { | |
global $post; | |
$metaKey = 'afterEditor'; | |
if ( empty ( $post ) || 'post' !== get_post_type( $GLOBALS['post'] ) ) { | |
return; | |
} | |
if ( ! $content = get_post_meta( $post->ID, $metaKey, TRUE ) ) { | |
$content = ''; | |
} | |
printf( | |
'<p><label for="%1$s_id">お問い合わせ先</p> | |
<textarea name="%1$s" id="%1$s_id" cols="60" rows="5">%2$s</textarea>', | |
$metaKey, | |
esc_attr( $content ) | |
); | |
} | |
// テキストエリアの内容を保存 | |
add_action( 'save_post', 'nskw_savePostMeta2' ); | |
function nskw_savePostMeta2( $post_id ) | |
{ | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
return; | |
} | |
if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
return; | |
} | |
$metaKey = 'afterEditor'; | |
if ( isset ( $_POST[ $metaKey ] ) ) { | |
return update_post_meta( $post_id, $metaKey, $_POST[ $metaKey ] ); | |
} | |
delete_post_meta( $post_id, $metaKey ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment