Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function conditional_email(&$WPCF7) {
- $url = parse_url($_SERVER['HTTP_REFERER']); // Get posted page
- $path = ltrim($url['path'], '/'); // Remove first slash
- $path = untrailingslashit($path); // Remove last slash
- $parts = explode('/', $path);
- // Validate parts isn't empty AND is an array AND that array has 2 or more values
- if(!empty($parts) && is_array($parts) && count($parts) > 1)
- {
- if($parts[0] == 'CPT'){ // Check parts to make sure that [0] contains our CPT
- $user = getUser($parts); // [0] => name [1] => email
- if(count($user) == 2) // Verify we've recieved the 2 indexes correctly, else Bail Out
- {
- $email = $user[0].' <'.$user[1].'>'; // Format email
- $WPCF7->mail['recipient'] = $email; // Set Email
- }
- }
- }
- // The Default Email would be set in the Contact Form 7 Form at the Wordpress Backend. Recommended.
- }
- add_action("wpcf7_before_send_mail", "conditional_email");
- // Use the path to get the Staff ID then the Staff info
- // Returns ARRAY[0] => title [1] => email
- function getUser($parts){
- $post = get_page_by_path($parts[1], OBJECT, $parts[0]); // Get post
- $title = $post->post_title; // Get Post Title
- $meta = get_post_meta($post->ID, 'email', true); // Get value of `email` meta
- $staff_cpt = array($title, $email);
- return $staff_cpt ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement