เอา not verified ออกจากชื่อของผู้เยี่ยมชมเว็บเราบน drupal

drupal_3
ถ้าใครใช้งาน drupal ไปสักพักและปรับแต่งให้เว็บเรามีการให้ผู้ที่เยี่ยมชมเว็บเรา สามารถแสดงความคิดเห็นได้เลยโดยไม่ต้องสมัครสมาชิก ในระบบ drupal นั้นผู้เยี่ยมแบบนี้จะเรียกว่า Anonymous ซึ่งเมื่อเขามาทำการแสดงความคิดเห็นในบทความของเราเมื่อไร ชื่อของ user พวกนี้จะมีคำว่า not verified ต่อท้ายเสมอๆ เพื่อเป็นการบ่งบอกว่าบุคคลเหล้านั้นไม่ได้เป็นสมาชิกเว็บเราน่ะ แต่ผมก็เกิดความรำคาญคือมันดูไม่สวยงามเท่าไรที่จะมี not verified ตามหลังชื่อเขาครับ ดังรูปบน ผมก็มีวิธีการนำเอามันออกมาฝากเพื่อใครอยากจะเอาออกด้วยแบบผม

ให้เราสร้างไฟล์ชื่อ template.php ขึ้นมาไว้ใน theme ที่ตัวเองใช้งาน เช่น sites/all/themes/whitejazz (whitejazz เป็นชื่อ theme ที่ใช้งาน) หรือถ้า theme ใครมีไฟล์นี้อยู่แล้วก็ไม่เป็นไรครับไม่ต้องสร้างขึ้นมา
drupal

จากนั้นทำการเพิ่มโค็ดด้านล่างลงไปครับ

/*
 *
 * remove not verified
 *
 */
function phptemplate_username($object) {
  if ($object->uid && $object->name) {
    // Shorten the name when it is too long or it will break many tables.
    if (drupal_strlen($object->name) > 20) {
      $name = drupal_substr($object->name, 0, 15) .'...';
    }
    else {
      $name = $object->name;
    }

    if (user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array('attributes' => array('title' => t('View user profile.'))));
    }
    else {
      $output = check_plain($name);
    }
  }
  else if ($object->name) {
    // Sometimes modules display content composed by people who are
    // not registered members of the site (e.g. mailing list or news
    // aggregator modules). This clause enables modules to display
    // the true author of the content.
    if (!empty($object->homepage)) {
      $output = l($object->name, $object->homepage, array('attributes' => array('rel' => 'nofollow')));
    }
    else {
      $output = check_plain($object->name);
    }

    //$output .= ' ('. t('not verified') .')';
  }
  else {
    $output = check_plain(variable_get('anonymous', t('Anonymous')));
  }

  return $output;
}

จากนั้นทำการเซพแล้วไปล้าง cash ของเว็บที่ Administer >> Site configuration >> Performance ลงมาล่างสุดกดปุ่ม Clear cached data ครับ
drupal

แล้วลองกลับไปที่เว็บเรา refresh รอบหนึ่ง not verified ก็จะหายไปละครับ

บทความแนะนำ
    blog comments powered by Disqus