1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Update Comment Author |
---|
4 | Plugin URI: http://qvister.se |
---|
5 | Description: Make sure your previous comments gets updated when you change your display name. |
---|
6 | Version: 0.1 |
---|
7 | Author: Anton Lindqvist |
---|
8 | Author URI: http://qvister.se |
---|
9 | */ |
---|
10 | |
---|
11 | function 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 | } |
---|
28 | add_action('profile_update', 'update_comment_author', 1, 2); |
---|
29 | ?> |
---|