Skip to content

Instantly share code, notes, and snippets.

@ShinichiNishikawa
Created April 29, 2013 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShinichiNishikawa/5482614 to your computer and use it in GitHub Desktop.
Save ShinichiNishikawa/5482614 to your computer and use it in GitHub Desktop.
<?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