Решение нашел тут:
http://www.smashingmagazine.com/
А именно вот это:
//Add an edit option in comment edit screen
add_action( 'add_meta_boxes_comment', 'extend_comment_add_meta_box' );
function extend_comment_add_meta_box() {
add_meta_box( 'title', __( 'Дополнительные поля' ), 'extend_comment_meta_box', 'comment', 'normal', 'high' );
}
function extend_comment_meta_box ( $comment ) {
$company = get_comment_meta( $comment->comment_ID, 'company', true );
$town = get_comment_meta( $comment->comment_ID, 'town', true );
$project = get_comment_meta( $comment->comment_ID, 'project', true );
wp_nonce_field( 'extend_comment_update', 'extend_comment_update', false );
?>
<p>
<label for="company"><?php _e( 'Компания' ); ?></label>
<input type="text" name="company" value="<?php echo esc_attr( $company ); ?>" class="widefat" />
</p>
<p>
<label for="town"><?php _e( 'Город' ); ?></label>
<input type="text" name="town" value="<?php echo esc_attr( $town ); ?>" class="widefat" />
</p>
<p>
<label for="project"><?php _e( 'Проект' ); ?></label>
<input type="text" name="project" value="<?php echo esc_attr( $project ); ?>" class="widefat" />
</p>
<?php
}
// Update comment meta data from comment edit screen
add_action( 'edit_comment', 'extend_comment_edit_metafields' );
function extend_comment_edit_metafields( $comment_id ) {
if( ! isset( $_POST['extend_comment_update'] ) || ! wp_verify_nonce( $_POST['extend_comment_update'], 'extend_comment_update' ) ) return;
if ( ( isset( $_POST['company'] ) ) && ( $_POST['company'] != '') ) :
$company = wp_filter_nohtml_kses($_POST['company']);
update_comment_meta( $comment_id, 'company', $company );
else :
delete_comment_meta( $comment_id, 'company');
endif;
if ( ( isset( $_POST['town'] ) ) && ( $_POST['town'] != '') ) :
$town = wp_filter_nohtml_kses($_POST['town']);
update_comment_meta( $comment_id, 'town', $town );
else :
delete_comment_meta( $comment_id, 'town');
endif;
if ( ( isset( $_POST['project'] ) ) && ( $_POST['project'] != '') ) :
$project = wp_filter_nohtml_kses($_POST['project']);
update_comment_meta( $comment_id, 'project', $project );
else :
delete_comment_meta( $comment_id, 'project');
endif;
}
// Add the comment meta (saved earlier) to the comment text
// You can also output the comment meta values directly in comments template
add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){
$plugin_url_path = WP_PLUGIN_URL;
if( $commenttown = get_comment_meta( get_comment_ID(), 'town', true ) ) {
$author = '<span>' . get_comment_author_link() . ', ';
$commentcompany = get_comment_meta( get_comment_ID(), 'company', true );
$commentcompany = esc_attr( $commentcompany ) . ',';
$commenttown = ' г.' . esc_attr( $commenttown ) . '</span><br>';
$commentproject = get_comment_meta( get_comment_ID(), 'project', true );
$commentproject = esc_attr( $commentproject );
$text = $author . $commentcompany . $commenttown . '<div class="comment-content">' . $text . '</div>' . '<br><div class="project_name">Проект: ' . $commentproject . '</div>';
return $text;
} else {
return $text;
}
}
А вот с оповещением об отправке проблема. Не гуглится что-то. Неужели в WP нет стандартной функции, которая скажет "Спасибо, Ваше сообщение было отправлено"?
update: а вопрос с сообщением решил с помощью ajax
http://wpcrux.com