تغییر نام کاربران در نظرات

با سلام
من میخوام که وقتی کاربری نظری در سایت ثبت کرد به جای اینکه نام کاربری اون شخص نمایش داده بشه که از لحاظ امنیت بده اینجوری
بتونم نام نمایشی اون شخص رو نمایش بده

سلام.
کد زیر رو بذار توی functions.php فولدر قالبت و مجدد یه چک کن!

add_filter('get_comment_author', 'name_beja_username', 10, 1);

function name_beja_username( $author = '' ) {
     $comment = get_comment( $comment_ID );
     if (!empty($comment->comment_author) ) {
          if($comment->user_id > 0){
                $user=get_userdata($comment->user_id);
                $author=$user->first_name.' '.$user->last_name //combine the name and lastname
          } else{
               $author = __('کاربر ناشناس');
          }
     } else{
          $author = $comment->comment_author;
     }
     return $author;
}
4 پسندیده

با سلام @Ershad
من این کد رو گذاشتم ولی یه ارور میده


توی عکس خطاش معلومه
از @Hosein و @arta و دیگر دوستان میخوام اگه میتونن کمک کنن
با تشکر

سلام خدمت شما
کدی که دوست عزیزمون جناب @Ershad قرار دادند تنها یک سمیکالن کم دارد که کد اصلاح شده به شرح ذیل هست

add_filter('get_comment_author', 'name_beja_username', 10, 1);

function name_beja_username( $author = '' ) {
     $comment = get_comment( $comment_ID );
     if (!empty($comment->comment_author) ) {
          if($comment->user_id > 0){
                $user=get_userdata($comment->user_id);
                $author=$user->first_name.' '.$user->last_name; //combine the name and lastname
          } else{
               $author = __('کاربر ناشناس');
          }
     } else{
          $author = $comment->comment_author;
     }
     return $author;
}
5 پسندیده