Ciao @lamorfini, hai controllato nel repository se c’è un plugin che può esserti utile? Ecco il link al repository https://it.wordpress.org/plugins/ io ti consiglio di usare la parola chiave “city”.
Facci sapere
niente, non trovo .. mi protesti dirmi come devo cercare su google in inglese perché in italiano non trovo nulla.
Grazie mille.
ok, risolto .. lo fatto da solo con gli esempi di codice che ho trovato online..
e ora vi incollo per voi :
<?php
/*
**==========================================================================
** http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/
** http://stackoverflow.com/questions/24417651/how-to-display-comments-meta-fields-value-in-admin-comment-section
**==========================================================================
*/
add_filter( 'comment_form_defaults', 'change_comment_form_defaults');
function change_comment_form_defaults( $default ) {
$commenter = wp_get_current_commenter();
$default[ 'fields' ][ 'email' ] .= '<p class="comment-form-author">' .
'<label for="city">'. __('City') . '</label>
<span class="required">*</span>
<input id="city" name="city" size="30" type="text" /></p>';
return $default;
}
add_action( 'comment_post', 'save_comment_meta_data_city' );
function save_comment_meta_data_city( $comment_id ) {
add_comment_meta( $comment_id, 'city', $_POST[ 'city' ] );
}
add_filter( 'preprocess_comment', 'verify_comment_meta_data_city' );
function verify_comment_meta_data_city( $commentdata ) {
if ( ! isset( $_POST['city'] ) )
wp_die( __( 'Error: please fill the required field (city).' ) );
return $commentdata;
}
add_filter( 'get_comment_author_link', 'attach_city_to_author' );
function attach_city_to_author( $author ) {
$city = get_comment_meta( get_comment_ID(), 'city', true );
if ( $city )
$author .= " ($city)";
return $author;
}
add_action( 'add_meta_boxes_comment', 'comment_add_meta_box' );
function comment_add_meta_box()
{
add_meta_box( 'comment-extra-info', __( 'Exta info' ), 'comment_extra_info', 'comment', 'normal', 'high' );
}
function comment_extra_info( $comment )
{
$title = get_comment_meta( $comment->comment_ID, 'city', true );
?>
<p>
<label for="city"><?php _e('city'); ?></label>
<input type="text" name="city" value="<?php echo esc_attr( $title ); ?>" class="widefat" />
</p>
<?php
}
add_action( 'edit_comment', 'comment_edit_city' );
function comment_edit_city( $comment_id )
{
if( isset( $_POST['city'] ) )
update_comment_meta( $comment_id, 'city', esc_attr( $_POST['city'] ) );
}
per visualizzare nel comments.php:
<?php $meta_values = get_comment_meta( $comment->comment_ID, 'city', true ); ?>
vorrei sapere se è corretto .
Buona domenica.