When creating a new node and using auto_nodetitle we get an error that $node->name is undefined.
we need to set this value before we try to use it. Simple short term fix around line 160 of modules/node/node.tokens.inc)
change:

case 'author':
          $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
          $replacements[$original] = $sanitize ? filter_xss($name) : $name;
          break;

to:

case 'author':
          if(!isset($node->name)) { $node->name = db_query("SELECT name FROM {users} WHERE uid = :d", array(':d' => $node->uid))->fetchField(); }
          $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
          $replacements[$original] = $sanitize ? filter_xss($name) : $name;
          break;

Comments

chrisjlock’s picture

#1185842: The [node:author] token does not use format_username()

case 'author':
- $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
- $replacements[$original] = $sanitize ? filter_xss($name) : $name;
+ $account = user_load($node->uid);
+ $name = format_username($account);
+ $replacements[$original] = $sanitize ? check_plain($name) : $name;
break;

This would also fix this issue, by loading the name using user_load().

damien tournoud’s picture

Status: Active » Closed (duplicate)

Thanks for your report. This is a duplicate of #1185842: The [node:author] token does not use format_username().