Make WordPress Core

Ticket #10653: update-comment-author.php

File update-comment-author.php, 904 bytes (added by mptre, 15 years ago)
Line 
1<?php
2/*
3Plugin Name: Update Comment Author
4Plugin URI: http://qvister.se
5Description: Make sure your previous comments gets updated when you change your display name.
6Version: 0.1
7Author: Anton Lindqvist
8Author URI: http://qvister.se
9*/
10
11function update_comment_author($user_id, $user) {
12    global $wpdb;
13    $display_name_new = (isset($_POST['display_name'])) ? $_POST['display_name'] : NULL;
14    $display_name_old = (isset($user->display_name)) ? $user->display_name : NULL;
15
16    if (isset($display_name_new) && isset($display_name_old) && $display_name_new != $display_name_old) {
17        $wpdb->update(
18            $wpdb->comments,
19            array('comment_author' => $display_name_new),
20            array('comment_author' => $display_name_old),
21            array('%s'),
22            array('%s')
23        );
24    }
25
26    return TRUE;
27}
28add_action('profile_update', 'update_comment_author', 1, 2);
29?>