I’m trying to figure out a way to let admins easily copy the activation link (i.e. UsersActivations->url) after they add new users. Ideally, this would look something like the screenshot below.
This way, the admin can send a personal email, which is less likely to end up in a junk folder. I like the idea of adding it to the flash message since it makes for a simple workflow, but I could also see adding this option for any existing users who have not been activated, as shown below.
So my question is whether filtering or appending to that flash message is supported or even possible to do cleanly using the API?
I think I could accomplish this in a messy way using the admin_users_browse hook, just looping through all the users and appending content using regex matching and some JavaScript. But that feels a little gross.
Does anyone have ideas for the best way to accomplish the general goal (if not the specifics)?
(PS: I would need to do this in a plugin; editing core is not helpful for my case)
A little progress, I found that I can add a message like so, but that it doesn’t accept HTML.
public function hookAdminUsersBrowse($args){
if($somecondition = true){
$message = __('lorem ipsum <a href="">this is not a link</a>');
$flash = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
$flash->addMessage($message, 'success');
}
}
Also, as far as I can see, there’s no data available via $args that says which user was just added.
I would consider using $flash->getCurrentMessages() and/or $flash->hasMessages() but I’m not sure how to do so. Those seem to be returning an empty array or false, respectively, so I guess I’m doing something wrong.
I now see some weirdness in the results that I missed earlier on my dev site. On an actual production site (which goes back to 2011), it looks like the users_activations table stores rows both for users that have been deleted and also for users that have already been activated. It also stores multiple rows for a single user_id for some reason.
I modified the code a little to account for the duplicates and the already active users.
Changes
1: get only the most recent activation url for each inactive user
let user_delete_button = jQuery('.inactive li a[href="/admin/users/delete-confirm/'+user['id']+'"]');
Remaining question
The odd thing is that now I have a bunch of inactive users without activation links. Can someone explain why this is? Do old activation links get removed? If so, how and why does that not always happen (as with the active users found in the table)? Is this something that was fixed long ago and the age of my site is just throwing off the expected results?
I think I was thrown most by the activation records for active users and the presence of multiple records for the same user. In the end, it was easy to work around, but I wonder if there was a bug at some point.
The user activation system is also used for forgotten passwords, so it doesn’t align 1:1 with active/inactiveness.
Multiple, the database setup allows for it, but generally issuance of new activation codes should delete an existing one. Probably you’re seeing the result of the site being as old as it is there, from when that wasn’t done perhaps.