Message composition/email notifications - hide real name?

Is it possible to hide user's real names when composing a message and in the email notification? I only want to display usernames across all instances where the name appears. See here: http://i.imgur.com/YpDtGm7.jpg

  • Jose

    Hello there Seth,

    I coded a solution for you. I've packaged the code into a mu-plugin so you can install it easily and without worrying about plugin updates.
    I did modified the plugin core a bit so we can hook in the notification and change the 'from' parameter. You will need to replace a file in the plugin now, but I'll be including it in the next release so it should work if you update in the future.

    Download the attached files and do the following:
    - Replace wp-content/plugins/private-messaging/app/controllers/notify-controller.php with the attached version.
    - Drop the file private_messaging_custom.php into the folder wp-content/mu-plugins/ (create the folder if it doesn't exists).

    Please let me know if it works fine for you with this customization.

    Just for reference, this is the code for the mu-plugin:

    if( !class_exists('Private_Messaging_Custom')):
    
        class Private_Messaging_Custom{
    
            function __construct(){
                add_filter('mm_suggest_users_result', array( $this, 'filter_suggested_names' ), 20, 1);
                add_filter('message_notification_params', array( $this, 'filter_notification_from' ), 20, 3);
            }
    
            function filter_suggested_names($data){
                foreach($data as $key => $user){
                    $user->name = explode(' - ', $user->name)[0];
                    $data[$key] = $user;
                }
    
                return $data;
            }
    
            function filter_notification_from($data, $controller, $model){
                $userdata = get_userdata($model->send_from);
                $data['FROM_NAME'] = $userdata->user_login;
    
                return $data;
            }
        }
    
        new Private_Messaging_Custom;
    
    endif;

    Cheers,
    José

  • Jose

    Hey Seth,

    I was not specific enough in the original request

    Actually, It makes sense and I figured you could be trying to hide it in all places. But believe me that whenever I assumed requirements in the past I got asked "why did you change this?" :slight_smile:

    That said, I improved the hooks and added a tweak in another core file. So, same as before, replace this other file with the one attached:
    wp-content/plugins/private-messaging/app/models/mm-message-model.php
    and, of course, replace the mu-plugin with the new version.

    For the records, I added the following to the mu-plugin:
    apply_filters( 'mm_get_name', $userdata->user_login, $userdata);

    function filter_message_get_name($name, $userdata){
                return $userdata->user_login;
            }

    Let me know if I missed something.

    Cheers,
    José

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.