/** * While this may seem a little complex as an example, it * is intended to give you an idea of the values that are * passed to this filter. Since some of the data pieces * are dependent on the custom fields you have created * in your installation, the values may differ from * site to site based on your settings. * * What this example does is take the three arrays that come * through the filter (one required, two optional), puts the * data in those arrays into a readable format, and replaces * the default email body with the values in these arrays. * * If you test register with this filter in place, you should * receive an email containing the values in these arrays * when you completed the registration - that will give you an * idea of what data is available to you to be used in * your own filter functions. */ add_filter( 'wpmem_email_filter', 'my_email_filter', 10, 3 ); function my_email_filter( $email, $wpmem_fields, $field_data ){ /* * Use some of the settings in $email to turn off some * things we don't need for this: * * do_shortcodes = false (otherwise when display the * keys for the last array, the key values would be * parsed by the shortcode parser. * * add_footer = false (we don't need it for the * example; besides, this is a good example of * toggleing one of the settings. */ $email['do_shortcodes'] = false; $email['add_footer'] = false; // Give our email a new subject. $email['subj'] = 'Test Registration Email (arrays)'; // Start with an empty variable for our new body content. $body = ''; /* * This parses through the main $arr array and puts the contents * into a format for reading in the resulting email. */ $body .= 'MAIN $arr CONTAINS THE FOLLOWING: ' . "\r\n\r\n"; foreach ( $email as $key => $val ) { $body .= '[' . $key . '] => ' . $val . "\r\n"; } /* * This parses through the contents of the $wpmem_fields array * and adds this content to the email body. Each of the values * is also an array, so this loops though those as well. * * Note that this array is passed optionally to the filter. It * is only there to provide possible data you may want to have * when filtering the main email array $arr. */ $body .= "\r\n\r\n" . 'WP-Members FIELDS $wpmem_fields CONTAINS THE FOLLOWING: ' . "\r\n\r\n"; foreach ( $wpmem_fields as $key => $val ) { $body .= '[' . $key . '] => array(' . "\r\n"; foreach ( $val as $sub_key => $sub_val ) { $body .= "\t" . '[' . $sub_key . '] => ' . $sub_val . "\r\n"; } $body .= ')' . "\r\n"; } /* * This parses through the contents of the $field_data array * and adds it to the new email body in a readable way. * * Note that this array is passed optionally to the filter. It * is only there to provide possible data you may want to have * when filtering the main email array $arr. This example tests * to see if this a new registration email and only adds this * if it is. */ if ( 'newreg' == $email['tag'] ) { $body .= "\r\n\r\n" . 'FIELD DATA ARRAY $field_data CONTAINS THE FOLLOWING: ' . "\r\n\r\n"; foreach ( $field_data as $key => $val ) { $body.= '[' . $key . '] => ' . $val . "\r\n"; } } // Make the body of the email our new body that we just built out of all the arrays. $email['body'] = $body; // Return our filtered results. return $email; }
Not sure what to do with this code?
You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.
Here are some free articles to get you started:
- Using Code Snippets from the Site
- The functions.php File
- Create a plugin file for custom functions
- Create a child theme
- Do not modify plugin files!
For "hands on" help, consider a plugin support subscription or the Pro Bundle.