Title: Custom New User Message (function replace_keywords)
Last modified: August 22, 2016

---

# Custom New User Message (function replace_keywords)

 *  [Petteri](https://wordpress.org/support/users/petteri-l/)
 * (@petteri-l)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/custom-new-user-message-function-replace_keywords/)
 * Hello,
 * Thank you for great plugin.
    I think that I found a problem from your code. At
   end of function `replace_keywords` you have loop which may cause problems.
 *     ```
       preg_match_all( '/%([^%]+)%/', (string) $message, $keys );
       if ( is_array( $keys ) && is_array( $keys[1] ) ) {
           foreach( $keys[1] as $key ) {
               $message = str_replace( "%$key%", get_user_meta( $user->ID, $key, TRUE ), $message );
           }
       }
       ```
   
 * If message body, %user_password% or any other field contains ‘%’ characters, 
   this loop will corrupt the email body. Instead of trying to find possible keywords(
   preg_match_all) from email body I suggest to match only real keywords and real
   meta. Something like this:
 *     ```
       $user_meta = get_user_meta( $user->ID );
       foreach ( $user_meta as $key => $value ) {
           if ( !is_array($value[0]) ) // skip arrays ... ?
               $message = str_replace( "%".$key."%", $value[0], $message);
       }
       ```
   
 * Best regards,
    petteri
 * [https://wordpress.org/plugins/register-plus-redux/](https://wordpress.org/plugins/register-plus-redux/)

The topic ‘Custom New User Message (function replace_keywords)’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/register-plus-redux.svg)
 * [Register Plus Redux](https://wordpress.org/plugins/register-plus-redux/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/register-plus-redux/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/register-plus-redux/)
 * [Active Topics](https://wordpress.org/support/plugin/register-plus-redux/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/register-plus-redux/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/register-plus-redux/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [Petteri](https://wordpress.org/support/users/petteri-l/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/custom-new-user-message-function-replace_keywords/)
 * Status: not resolved