1

This question is for Security.

I found this code here:

add_filter( 'request', 'wpse5742_request' );
function wpse5742_request( $query_vars )
{
    if ( array_key_exists( 'author_name', $query_vars ) ) {
        global $wpdb;
        $author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='nickname' AND meta_value = %s", $query_vars['author_name'] ) );
        if ( $author_id ) {
            $query_vars['author'] = $author_id;
            unset( $query_vars['author_name'] );    
        }
    }
    return $query_vars;
}

add_filter( 'author_link', 'wpse5742_author_link', 10, 3 );
function wpse5742_author_link( $link, $author_id, $author_nicename )
{
    $author_nickname = get_user_meta( $author_id, 'nickname', true );
    if ( $author_nickname ) {
        $link = str_replace( $author_nicename, $author_nickname, $link );
    }
    return $link;
}

It works, but only in Blog, not in:

  • Comments, meta, widgets, etc.
  • Neither for: buddypress (activity, groups, members, notifications, etc.) and bbpress forums.

If you Right Click on Public Name you can see the Username in:

  • www.yoursite.com/author/username (in Comments)
  • www.yoursite.com/members/username
  • www.yoursite.com/forums/profile/username

Also, If you go to a Buddypress Profile, you can see, for example:

  • John Doe
  • @johnstack (username)

==========================

The correct:

  • John Doe
  • @johndoe (nickname)

  • www.yoursite.com/author/nickname
  • www.yoursite.com/members/nickname
  • www.yoursite.com/forums/profile/nickname

Please, any solution for Forcing to Show the Nickname Only (based on your first name and last name) in Profile and all Links.

(Functions.php)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.