├── .gitignore ├── screenshot-1.png ├── cf7-dynamic-mail-to.php ├── README.md ├── cf7-dynamic-mail-to-examples.php └── readme.txt /.gitignore: -------------------------------------------------------------------------------- 1 | _notes 2 | .DS_Store 3 | *.LCK 4 | *.svn 5 | -------------------------------------------------------------------------------- /screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hube2/contact-form-7-dynamic-mail-to/master/screenshot-1.png -------------------------------------------------------------------------------- /cf7-dynamic-mail-to.php: -------------------------------------------------------------------------------- 1 | properties; 28 | $properites = $form->get_properties(); 29 | //echo '
'; print_r($_POST); die;
30 | 			//echo '
'; print_r($properites); die;
31 | 			if (!isset($_POST['dynamic-mail-to-filter'])) {
32 | 				return;
33 | 			}
34 | 			$filter = $_POST['dynamic-mail-to-filter'];
35 | 			$args = array();
36 | 			if (isset($_POST['dynamic-mail-to-fields'])) {
37 | 				$fields = $_POST['dynamic-mail-to-fields'];
38 | 				$fields = str_replace(' ', '', $fields);
39 | 				if ($fields != '') {
40 | 					$fields = explode(',', $fields);
41 | 					foreach ($fields as $field) {
42 | 						$value = '';
43 | 						if (isset($_POST[$field])) {
44 | 							$value = $_POST[$field];
45 | 						}
46 | 						$args[$field] = $value;
47 | 					} // end foreach $fields
48 | 				} // end in fields
49 | 			} // end if fields
50 | 			$recipient = $properites['mail']['recipient'];
51 | 			$new_recipient = apply_filters($filter, $recipient, $args);
52 | 			$properites['mail']['recipient'] = $new_recipient;
53 | 			$form->set_properties($properites);
54 | 		} // end public function wpcf7_before_send_mail
55 | 	} // end class wpcf7_dynamic_mail_to
56 | 	
57 | ?>


--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
 1 | # contact-form-7-dynamic-mail-to
 2 | 
 3 | # Adopt my Contact Form 7 (CF7) Plugins
 4 | 
 5 | I am putting my 3 CF7 plugins up for adoption.
 6 | 
 7 | The reasons for this are:
 8 | * I no longer use CF7 for my clients.
 9 |   * It is too difficult to use for my average client
10 |   * It does not support the features my clients want
11 |   * The authour of CF7 makes too many backwards compatibility breaking changes
12 |   * I simply do not have time to keep up with maintenence for plugins I no longer use
13 | 
14 | These plugins do have users and are usefull for those that use CF7 and I'd rather someone else takes them over than let them die.
15 | 
16 | The 3 plugins involved are:
17 | * At WP
18 |   * [Dynamic Select for Contact Form 7](https://wordpress.org/plugins/contact-form-7-dynamic-select-extension/)
19 |   * [Hidden Field for Contact Form 7](https://wordpress.org/plugins/contact-form-7-simple-hidden-field/)
20 |   * [Dynamic Recipient for Contact Form 7](https://wordpress.org/plugins/contact-form-7-dynamic-mail-to/)
21 | * On Github
22 |   * [Dynamic Select for Contact Form 7](https://github.com/Hube2/contact-form-7-dynamic-select-extension)
23 |   * [Hidden Field for Contact Form 7](https://github.com/Hube2/contact-form-7-simple-hidden-field)
24 |   * [Dynamic Recipient for Contact Form 7](https://github.com/Hube2/contact-form-7-dynamic-mail-to)
25 | 
26 | These plugins were built to work togther
27 | * The dynamic select to populate drop downs
28 | * The dynamic recipient send emails to different people
29 | * The hidden field to supply the fields that the recipient plugin needs to work
30 | 
31 | If you are interested in adopting all 3 of these plugins please open up an issue in any of the Github repos for any of these plugins. Below is how I would like to do this, if you have other ideas you can bring them up when you open the issue.
32 | 
33 | * You fork all of these repos
34 | * You maintian, update and improve these plugins as needed an send me pull requests
35 | * You take over supporting these plugins on Github and WP (answer questions etc)
36 | * I will, for a short time continue to update the WP repo with your changes
37 | * At some time in the future I will transfer ownership of the both the Github and WordPress repos to you.


--------------------------------------------------------------------------------
/cf7-dynamic-mail-to-examples.php:
--------------------------------------------------------------------------------
 1 | email_address_1;
35 | 				} elseif ($args['select-email'] == 'send to email 2') {
36 | 					$recipient = $this->email_address_2;
37 | 				} elseif ($args['select-email'] == 'sent to email 3') {
38 | 					$recipient = $this->email_address_3;
39 | 				}
40 | 			}
41 | 			return $recipient;
42 | 		} // end public function filter
43 | 		
44 | 	} // end class wpcf7_dynamic_mail_to_examples
45 | 	
46 | 	/*
47 | 	function wpcf7_dynamic_to_filter_example($recipient, $args=array()) {
48 | 		if (isset($args['select-email'])) {
49 | 			if ($args['select-email'] == 'send to email 1') {
50 | 				$recipient = 'email-01@email.com';
51 | 			} elseif ($args['select-email'] == 'send to email 2') {
52 | 				$recipient = 'email-02@email.com';
53 | 			} elseif ($args['select-email'] == 'send to email 3') {
54 | 				$recipient = 'email-03@email.com';
55 | 			}
56 | 		}
57 | 		return $recipient;
58 | 	} // end function wpcf7_dynamic_to_filter_example
59 | 	add_filter('wpcf7-dynamic-recipient-example-filter', 'wpcf7_dynamic_to_filter_example', 10, 2);
60 | 	*/
61 | 	
62 | 	
63 | ?>


--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
  1 | === Dynamic Recipient for Contact Form 7 ===
  2 | Contributors: Hube2
  3 | Tags: adopt-me, contact form 7, dynamic, mail to, recipient
  4 | Requires at least: 4.0
  5 | Tested up to: 4.9
  6 | Stable tag: 1.0.0
  7 | Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted
  8 | License: GPLv2 or later
  9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html
 10 | 
 11 | Set recipient email dynamically by useing a filter
 12 | 
 13 | 
 14 | == Description ==
 15 | 
 16 | Addopt this plugin. [Please see details on Github](https://github.com/Hube2/contact-form-7-dynamic-mail-to).
 17 | 
 18 | Dynamically set recipitent of mail using a filter.
 19 | 
 20 | How To Use
 21 | ----------
 22 | 
 23 | Create a filter that will return the recipient of mail. For more information see the example filter in
 24 | cf7-dynamic-mail-to-examples.php included with the plugin.
 25 | 
 26 | `function wpcf7_dynamic_to_filter_example($recipient, $args=array()) {
 27 |   if (isset($args['select-email'])) {
 28 |     if ($args['select-email'] == 'send to email 1') {
 29 |       $recipient = 'email-01@email.com';
 30 |     } elseif ($args['select-email'] == 'send to email 2') {
 31 |       $recipient = 'email-01@email.com';
 32 |     } elseif ($args['select-email'] == 'sent to email 3') {
 33 |       $recipient = 'email-01@email.com';
 34 |     }
 35 |   }
 36 |   return $recipient;
 37 | } // end function wpcf7_dynamic_to_filter_example
 38 | add_filter('wpcf7-dynamic-recipient-example-filter', 'wpcf7_dynamic_to_filter_example', 10, 2);`
 39 | 
 40 | Add special fields to your form, see screenshot of example fields.
 41 | 
 42 | Add a field to you form with the name "dynamic-mail-to-filter". This can be any type of field that holds
 43 | a single value. I would suggest trying out my other plugin
 44 | [Contact Form 7 - Simple Hidden Field](https://wordpress.org/plugins/contact-form-7-simple-hidden-field/). 
 45 | You can also use another hidden field extension for CF7. Set the value of this field to the name of your
 46 | filter hook. 
 47 | 
 48 | If you would like the values of other fields sent to your filter as arguments, add a field with the name of
 49 | "dynamic-mail-to-fields." Set the value of this field to a comma separated list of the fields values you 
 50 | want sent to your filter. Again, see the example filter supplied with this plugin.
 51 | 
 52 | == Installation ==
 53 | 
 54 | 1. Upload the files to the plugin folder of your site
 55 | 2. Activate it from the Plugins Page
 56 | 
 57 | 
 58 | == Screenshots ==
 59 | 
 60 | 1. Special Fields in CF7 Example
 61 | 
 62 | == Frequently Asked Questions ==
 63 | 
 64 | = Tell me how to use this thing again =
 65 | It seems that my instructions in the description are not exactly clear, so here's a step by step
 66 | 
 67 | 1. Add a hidden field to your form. This hidden field can be added using my other plugin [Hidden Field for Contact Form 7](https://wordpress.org/plugins/contact-form-7-simple-hidden-field/). I believe that there are other plugins available that will let you do this.
 68 | The name of this hidden field must be `dynamic-mail-to-filter` and the value of this hidden field should be the filter hook that this plugin should use to get your dynamic value. For example, if this is the code used to set up the filter and function:
 69 | ```
 70 | 
 71 | add_filter('my_dynamic_mailto_hook', 'my_dynamic_mailto_function', 10, 2);
 72 | 
 73 | ```
 74 | then the value of this hidden field should be `my_dynamic_mailto_hook`.
 75 | 
 76 | 2. Set up optional parameters. This allows you to pass the values of other fields in your form to your filter function so that they can be used in determining the mailto address to return.  
 77 | 
 78 | For example, you could pass the post ID value of the current page. First set up a hidden field that contains the post ID. This can also be done with my hidden field plugin and with other plugins. Let's say for example that you name this field `post-id`. To pass the value of this field to your filter you would then create another hidden field. The name of this hidden field must be `dynamic-mail-to-fields`. The value of this field would be `post-id`. The value of this field should be a comma seperated list of all the other field names that you want to pass to your filter. For example if we wanted to use 2 fields named `post-id` and `user-id` then the value of the hidden field named `dynamic-mail-to-fields` would be `post-id,user-id`. Now let's assume that this is the code of your function
 79 | ```
 80 | 
 81 | function my_dynamic_mailto_function($recipient, $args) {
 82 |   // the code of your function here
 83 | }
 84 | 
 85 | ```
 86 | and we have set up the `dynamic-mail-to-fields` field to have the value of `post-id,user-id`, in this case the value of `$args` would be
 87 | ```
 88 | 
 89 | Array (
 90 |   'post-id' => '10', // assuming the post id was 10
 91 |   'user-id' => '5',  // assuming the user id was 5
 92 | )
 93 | 
 94 | ```
 95 | 
 96 | 3. Complete your function that determines who the recipient (or recipients) of your form should be. You can return a single email address or a comma separated list of email addresses. For example
 97 |  * someone@somewhere.com
 98 |  * John Doe 
 99 |  * someone@somewhere.com, John Doe 
100 | 
101 | 
102 | = Why Filters? =
103 | 
104 | Many other plugins of this type use shortcodes. I'm not a real fan of shortcodes, but that's not the only
105 | reason. 
106 | 
107 | Filters are much more flexible that shortcodes. 
108 | 
109 | For example, a shortcode cannot return an array. A shortcode pretty much requires that only a text value is returned.
110 | 
111 | 
112 | == Changelog ==
113 | 
114 | = 1.0.0 =
115 | 
116 | * initial release


--------------------------------------------------------------------------------