Kian Posted June 8, 2020 Share Posted June 8, 2020 (edited) I don't know if it's me or this hook doesn't work as it should. I would expect that $vars['mergefields'] contains an array of all variable declared in the email (eg. {$whmcs_link}, {$signature}, {$firstname}) but this parameter is always empty. When I print $vars this is what I get: {"messagename":"Password Reset Validation","relid":1} {"messagename":"Invoice Created","relid":1595} {"messagename":"Invoice Modified","relid":1595} {"messagename":"First Invoice Overdue Notice","relid":1595} {"messagename":"Credit Card Invoice Created","relid":1595} It happens with any email template so my question is: where the heck are mergefields? There are all parameters (messagename, relid) except mergefields. Edited June 8, 2020 by Kian 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 8, 2020 Share Posted June 8, 2020 16 minutes ago, Kian said: I don't know if it's me or this hook doesn't work as it should. I would expect that $vars['mergefield'] tell me that's a typo and you have actually used $vars['mergefields'] instead ? <?php function email_hook($vars) { $merge_fields = $vars['mergefields']; return array("brian" => $merge_fields); } add_hook("EmailPreSend",1,"email_hook"); 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 8, 2020 Author Share Posted June 8, 2020 I'm using mergefields. More in particular... <?php add_hook('EmailPreSend', 1, function($vars) { logActivity(json_encode($vars)); }); But... {"messagename":"Password Reset Validation","relid":1} 😞 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 8, 2020 Share Posted June 8, 2020 if I try that hook of yours, it returns all the mergefields correctly... works for me whether it's an invoice, password reset etc... i'm not sure what to suggest. 😕 1 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 8, 2020 Author Share Posted June 8, 2020 Thanks, it helps me a lot. At least now I know that there's something wrong... somewhere 🥶 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted June 8, 2020 Author Share Posted June 8, 2020 (edited) Got it! 😩 EmailPreSend hook point returns mergefields parameter starting from an unknown version of WHMCS. The most recent snapshot of documentation doesn't show "mergefields" section and it is dated 23 Aug 2018. I read all patch notes from v7.0 of 22 Jul 2016 but there's nothing about changes to EmailPreSend. I'm developing a feature where I need to use mergefields. Of course there's a workaround but this time I don't give a damn about backward compatibility since nobody cares. I'll place a warning link this: This feature doesn't work with your version of WHMCS. Please, upgrade to v.??? Now the problem is that I have no idea of what is this magic number @WHMCS ChrisD help? 🙏 7.what? It should be something between 7.6 and 7.10. Edit: found! 7.8.0 BETA 1 CORE-13261 - Provide mergefield data to EmailPreSend hook. Edited June 8, 2020 by Kian 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 9, 2020 Share Posted June 9, 2020 it might be worth keeping the GitHub Dev Docs page bookmarked... as that's where the dev docs content is generated and you can view historic versions of the docs etc. https://github.com/WHMCS/developer-docs that said, the quality of documentation that WHMCS provides to users is truly shocking... but twas ever thus. 😞 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.