The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
PHP: custom email shortcodes - email addresses of role
I would like to know how I can create my own email shortcode to use in Form Actions > Email Notifications > To. Similar to [admin_email]. Would it be just like creating any other WordPress shortcode? Or does that require a special type of shortcode?
Basically I would like to be able to get emails for all people in a particular role.
Example:
[emails_by_role role='sales']
Please point me to any documentation. Or let me know if what I want already exists somewhere. Thanks.
June 22, 2017 at 6:16 am
I never had a requirement from a client for a custom shortcode on the backend of a form. Shortcodes are shortcodes though. Creating a shortcode for Formidable is done the same way you would create any shortcode. What gives me pause is that Formidable made changes to the way 3rd party shortcodes are processed way back in version 2.0.9 around June 2015. They basically had to lock down the use of 3rd party shorcodes due to a discovered security vulnerability. There is a workaround that allows you to execute a 3rd party shortcode. Your custom shortcode would be considered a 3rd party shortcode. This article explains the details and has a code example that you can modify to make your shortcode work with Formidable, if it doesn't work out of the gate, that is. https://victorfont.com/formidable-pro-3rd-party-shortcodes/
June 22, 2017 at 9:59 pm
Cool. I added shortcode to get emails to my theme code and it seems to work well.
/**
* my_email shortcode
*
* attributes:
* role= Give role name
*
*/
function my_email($params)
{
$params = shortcode_atts(
array(
'role' => null,
), $params, 'my_email' );
$args = array();
if ($params['role'])
{
$args['role'] = $params['role'];
}
if ($args)
{
$emails = array();
$users = get_users( $args );
if ($users)
{
foreach ($users as $user)
{
$emails []= $user->user_email;
}
$email_list = implode(", ", array_unique($emails));
}
if ($email_list == null)
{
$email_list = get_bloginfo('admin_email');
}
}
return $email_list;
}
add_shortcode('my_email', 'my_email');
Discussion closed.