As a follow-up for #183120: Support Token module, the [simplenews-receiver-name] token is currently only useful for registered users. For non-registered (anonymous) users, this token resolves into "Anonymous" per default. That string should be changable into something configurable (like "subscriber"). Sutharsan mentioned

Token does not support conditional token replacement. You need to write a module for this or give 'anonymous' a new name (site wide)

Any ideas how the code for such a module could look like? How can the site-wide string "Anonymous" for non-logged-in users be changed?

Comments

sutharsan’s picture

Status: Active » Closed (won't fix)

I have no intention to include support for just a tag like [simplenews-receiver-name]. If something gets in it should be flexible and not limited to just a name. I deliberately keep the door closed for partial solutions. I know once I say yes to 'user name' the next question will be 'zip code' or 'age' or ... A solution should be flexible and for both anonymous and authenticated users. I have my plans for it, but I lack funds and time to build it.

You can build you own solution using a hook_mail_alter() implementation in which you replace your custom tokens by custom content.

roball’s picture

Status: Closed (won't fix) » Needs review
StatusFileSize
new1.74 KB

Why not just changing your code to not use variable_get('anonymous') but t('subscriber') instead? Patch attached.

sutharsan’s picture

Status: Needs review » Closed (won't fix)
Sepero’s picture

I came here looking for an answer, but I found a "sort-of" answer elsewhere, so I'll post it here.
The name used to indicate D6 anonymous users found here:
admin/settings/site-information

Sepero’s picture

I wrote my own little module to solve this problem for me. The caveat is that mymodule has to run before the simplenews module (and it does on my website). I think that which module runs first may be edited by weights? I still haven't figured out how drupal works 100%
Create the folder in sites/all/modules/mymodule, and create these files in it.

File: mymodule.info

; $Id: mymodule.info,v 1.0 2010/11/25 10:37:54
name = "My Custom Module"
description = "My custom module for any overrides"
core = 6.x
package = Other

File: mymodule.module

<?php
function mymodule_token_values($type, $object = NULL, $options = array()) {
  // Set name of Anonymous users to 'Subscriber' in newsletters.
  switch ($type) {
    case 'all':
    case 'simplenews':
      if(empty($object['account']->name))
        $object['account']->name = 'Subscriber';
      break;
  }
  return array();
}
?>

Enable the module just as you normally enable any drupal module.