Skip to content

Instantly share code, notes, and snippets.

@zuramai
Created July 17, 2023 06:17
Show Gist options
  • Save zuramai/dc72f693eed92039307ce8305a1df314 to your computer and use it in GitHub Desktop.
Save zuramai/dc72f693eed92039307ce8305a1df314 to your computer and use it in GitHub Desktop.
Comment Phone Wordpress
<?php
/*
Plugin Name: Comment IP
Author: Ahmad Saugi
*/
add_action('plugin_init', 'ip_init');
function ip_init() {
}
function custom_extra_comment_field($field){
$field['comment_field'] .= '<label for="phone">Phone</label>
<input type="phone" id="phone" name="phone" placeholder="Your phone number">';
return $field;
}
add_filter('comment_form_defaults', 'custom_extra_comment_field');
function save_comment($comment) {
echo $_POST['phone'];
add_comment_meta($comment, 'phone', $_POST['phone']);
}
add_action('comment_post', 'save_comment');
add_action('manage_edit-comments_columns', 'edit_comments_columns');
function edit_comments_columns($cols) {
$cols['phone'] = 'Phone Number';
return $cols;
}
add_action('manage_comments_custom_column', 'display_comment_phone', 10, 2);
function display_comment_phone($col, $comment_id) {
if($col == 'phone') {
echo get_comment_meta($comment_id, 'phone', true);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment