Skip to main content
Code formatting, tags and question/title readability
Source Link

How tocan I return the result of wordpressmy custom function?

iI have used the following source code to add an extra CITYcity field to wordpressmy WordPress comment form:

<?php

/* Plugin Name: Comment meta data test Version: 1.0 Plugin URI: http://wpengineer.com Description: Comment meta data test Author: Latz Author URI: http://wpengineer.com */

add_filter( 'comment_form_defaults', 'change_comment_form_defaults');

function change_comment_form_defaults($default) {

/*
  Plugin Name: Comment meta data test
  Version: 1.0
  Plugin URI: http://wpengineer.com
  Description: Comment meta data test
  Author: Latz
  Author URI: http://wpengineer.com
 */

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>
        
                <input id="city" name="city" size="30" type="text" /></p>';
    
    return $default;
}

add_filter( 'preprocess_comment', 'verify_comment_meta_data' );
function verify_comment_meta_data($commentdata) {
  if ( ! isset( $_POST['city'] ) )
        wp_die( __('Error: please fill the required field (city).') );
        return $commentdata;
}

add_action( 'comment_post', 'save_comment_meta_data' );
function save_comment_meta_data( $comment_id ) {
    add_comment_meta( $comment_id, 'city', $_POST['city'] );
}

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_filter( 'preprocess_comment', 'verify_comment_meta_data' ); function verify_comment_meta_data($commentdata) { if ( ! isset( $_POST['city'] ) ) wp_die( __('Error: please fill the required field (city).') ); return $commentdata; }

add_action( 'comment_post', 'save_comment_meta_data' ); function save_comment_meta_data( $comment_id ) { add_comment_meta( $comment_id, 'city', $_POST['city'] ); }

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; }

?>

This shows the extra field and wordpress comment form, and its output is displayed alognalong with wordpressthe comment author name.

However, I want to Displaydisplay only the city name, without the author name how to. How can I do this?

How to return result of wordpress custom function

i have used following source code to add extra CITY field to wordpress comment form

<?php

/* Plugin Name: Comment meta data test Version: 1.0 Plugin URI: http://wpengineer.com Description: Comment meta data test Author: Latz Author URI: http://wpengineer.com */

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>
    
            <input id="city" name="city" size="30" type="text" /></p>';

return $default;

}

add_filter( 'preprocess_comment', 'verify_comment_meta_data' ); function verify_comment_meta_data($commentdata) { if ( ! isset( $_POST['city'] ) ) wp_die( __('Error: please fill the required field (city).') ); return $commentdata; }

add_action( 'comment_post', 'save_comment_meta_data' ); function save_comment_meta_data( $comment_id ) { add_comment_meta( $comment_id, 'city', $_POST['city'] ); }

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; }

?>

This shows the extra field and wordpress comment form and its output is displayed alogn with wordpress comment author name I want to Display only city name without author name how to do this?

How can I return the result of my custom function?

I have used the following source code to add an extra city field to my WordPress comment form:

<?php
/*
  Plugin Name: Comment meta data test
  Version: 1.0
  Plugin URI: http://wpengineer.com
  Description: Comment meta data test
  Author: Latz
  Author URI: http://wpengineer.com
 */

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>
        
                <input id="city" name="city" size="30" type="text" /></p>';
    
    return $default;
}

add_filter( 'preprocess_comment', 'verify_comment_meta_data' );
function verify_comment_meta_data($commentdata) {
  if ( ! isset( $_POST['city'] ) )
        wp_die( __('Error: please fill the required field (city).') );
        return $commentdata;
}

add_action( 'comment_post', 'save_comment_meta_data' );
function save_comment_meta_data( $comment_id ) {
    add_comment_meta( $comment_id, 'city', $_POST['city'] );
}

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;
}

?>

This shows the extra field and comment form, and its output is displayed along with the comment author name.

However, I want to display only the city name, without the author name. How can I do this?

Source Link

How to return result of wordpress custom function

i have used following source code to add extra CITY field to wordpress comment form

<?php

/* Plugin Name: Comment meta data test Version: 1.0 Plugin URI: http://wpengineer.com Description: Comment meta data test Author: Latz Author URI: http://wpengineer.com */

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>
    
            <input id="city" name="city" size="30" type="text" /></p>';

return $default;

}

add_filter( 'preprocess_comment', 'verify_comment_meta_data' ); function verify_comment_meta_data($commentdata) { if ( ! isset( $_POST['city'] ) ) wp_die( __('Error: please fill the required field (city).') ); return $commentdata; }

add_action( 'comment_post', 'save_comment_meta_data' ); function save_comment_meta_data( $comment_id ) { add_comment_meta( $comment_id, 'city', $_POST['city'] ); }

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; }

?>

This shows the extra field and wordpress comment form and its output is displayed alogn with wordpress comment author name I want to Display only city name without author name how to do this?