How to add/use a member like %Biography% or %SITE_NAME% or %FULLNAME% to email templates

Discussion in 'Subrion Open Source CMS Core' started by petermguwata, Oct 23, 2017.

  1. petermguwata

    petermguwata New Member

    Hi Intellians,

    I would like to know how to add and use a member field "companyid" to email template.
    1. Where should i edit in ia.core.users.php to make companyid available as %companyid% in the email templates?
  2. petermguwata

    petermguwata New Member

    I figured it out. I did the following modification to successfully enable an additional user-field to appear in the email whenever a user has been registered by the admin.


    1. Need to Edit /admin/members.php.
    Change
    PHP:
    protected function _modifyGridParams(&$conditions, &$values)
        {
            if (!empty($_GET['name']))
            {
                $conditions[] = "CONCAT(`username`, `fullname`, `email`) LIKE '%" . iaSanitize::sql($_GET['name']) . "%'";
            }
        }
    To
    PHP:
    protected function _modifyGridParams(&$conditions, &$values)
        {
            if (!empty($_GET['name']))
            {
                $conditions[] = "CONCAT(`username`, `fullname`, `email`, 'companyid') LIKE '%" . iaSanitize::sql($_GET['name']) . "%'";
            }
        }
    2. Now our user-field is 'companyid' and we need the mailing system to recognize it in form of %COMPANYID%, so we have to replace values.
    Change.
    PHP:
    $action = 'member_registration';
                if ($this->_iaCore->get($action))
                {
                    $iaMailer = $this->_iaCore->factory('mailer');

                    $iaMailer->loadTemplate($action . '_notification');
                    $iaMailer->addAddress($entry['email']);
                    $iaMailer->setReplacements(array(
                        'fullname' => $entry['fullname'],
                        'username' => $entry['username'],
                        'password' => $this->_password,
                        'email' => $entry['email']
                    ));

                    $iaMailer->send();
                }
    To
    PHP:
    $action = 'member_registration';
                if ($this->_iaCore->get($action))
                {
                    $iaMailer = $this->_iaCore->factory('mailer');

                    $iaMailer->loadTemplate($action . '_notification');
                    $iaMailer->addAddress($entry['email']);
                    $iaMailer->setReplacements(array(
                        'fullname' => $entry['fullname'],
                        'username' => $entry['username'],
                        'companyid' => $entry['companyid'],
                        'password' => $this->_password,
                        'email' => $entry['email']
                    ));

                    $iaMailer->send();
                }
    3. your user-field 'companyid' will automatically be corrected to UPPER-Case under /classes/ia.core.mailer.php (No need to convert to upper)
    PHP:
    if ($replacements)
            {
                foreach ($replacements as $key => $value)
                {
                    $keyPattern = '{%' . strtoupper($key) . '%}';
                    $this->_replacements[$keyPattern] = $value;
                }
            }
    Thank you. You may leave your comment down below.
    Vasily_B. likes this.

Share This Page