Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2013-05-16 10:57:53
- MattE
- New Member
- Registered: 2008-06-04
- Posts: 7
Send a custom registration email without modifying Textpattern
Does any plugin exist or is anyone aware of a method that a plugin could be written to replace the email the textpattern sends out after a author has been added?
I’m currently working on a site with front end auth where users are added by the site admins but the textpattern auto generated email points to textpattern rather than the section of the site protected by front auth.
I release the solution could be simple by just modifying textpattern but It’d be better not to have to remember to modify textpattern after each update.
Offline
Re: Send a custom registration email without modifying Textpattern
Plugins do not have access to the password emails Textpattern sends. The only option you have through a plugin would be to hackishly overwrite the whole callback steps, which update user details and are responsible of sending emails. The plugin would have to be updated each time any of the steps is altered, basically it could break on any Textpattern update similarly to a mod.
You will at least have to replace events admin > author_save_new
, admin > change_pass
and admin > admin_multi_edit
when HTTP query string contains ?edit_method=resetpassword
. Small code template:
class Abc_Password_Email
{
/**
* Constructor.
*
* Hooks to the callback events.
*/
public function __construct()
{
register_callback(array($this, 'authorSaveNew'), 'admin', 'author_save_new', 1);
register_callback(array($this, 'changePass'), 'admin', 'change_pass', 1);
register_callback(array($this, 'resetPassword'), 'admin', 'admin_multi_edit');
}
/**
* Saves a new author.
*
* This should contain same code as the default
* handler.
*/
public function authorSaveNew()
{
// The handler code here.
$this->endPage();
}
/**
* Change user password.
*/
public function changePass()
{
// The handler code here.
$this->endPage();
}
/**
* Reset user password.
*/
public function resetPassword()
{
if (ps('edit_method') === 'resetpassword')
{
// The handler code here.
$this->endPage();
}
}
/**
* Returns the footer and kills the panel.
*
* Prevents the normal handler code from
* executing.
*/
protected function endPage()
{
end_page();
exit;
}
}
new Abc_Password_Email();
If you also use the password reset functionality found on the login form, that is sandboxed and can not be altered by plugins at all.
Last edited by Gocom (2013-05-16 13:21:33)
Offline
Re: Send a custom registration email without modifying Textpattern
Hi Matt
what if you use smd_user_manager and then modify it to send email thrue a custom function rathe that the internal one do you think that can work? (i did it for one site but i cant remember wich one to see how i did :( )
Offline
#4 2013-05-16 13:46:16
- MattE
- New Member
- Registered: 2008-06-04
- Posts: 7
Re: Send a custom registration email without modifying Textpattern
Dragondz wrote:
Hi Matt what if you use smd_user_manager and then modify it to send email thrue a custom function rathe that the internal one do you think that can work? (i did it for one site but i cant remember wich one to see how i did :( )
That’s precisely what I’ve ended up doing, there’s a line in smd_user_manager that calls the send_password function. By replacing it with a copy of the function instead I was able to modify the email text.
If Textpattern undergoes changes to user account creation, the plugin will need to be updated, like Dragondz’ post suggests, but this will at least save having to alter/avoid replacing the send_password function after each minor update.
Thank You both for your help.
Last edited by MattE (2013-05-16 13:46:31)
Offline
Re: Send a custom registration email without modifying Textpattern
MattE wrote:
there’s a line in smd_user_manager that calls the send_password function. By replacing it with a copy of the function instead I was able to modify the email text.
I could add a callback to the plugin right there if you preferred. Less hacking, although you would have to have the plugin installed of course. Let me know if that would suit you and I’ll add it into the version that has yet to be released.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online
Re: Send a custom registration email without modifying Textpattern
Bloke wrote:
I’ll add it into the version that has yet to be released.
I added it anyway. Please download the beta 0.20 and let me know how you get on. Callback is documented in the plugin help file, but here’s a three-liner to get you started:
register_callback('abc_reset_pw', 'smd_user_manager', 'password.reset');
function abc_reset_pw($evt, $stp, $data) {
// Do some custom reset skulduggery here with $data array
...
return 'Password intercepted'; // Returning something bypasses the internal reset
}
Doesn’t get around the fact that the plugin itself is a monumental hack due to current inadequacies in the user API, but hopefully from 4.6.0 onwards the plugin can be made less intrusive.
Last edited by Bloke (2013-05-16 21:20:40)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Online