| 1 |
<?php |
| 2 |
|
| 3 |
class AF_Admin_Emails { |
| 4 |
|
| 5 |
function __construct() { |
| 6 |
|
| 7 |
add_action( 'acf/render_field/type=text', array( $this, 'add_email_field_inserter' ), 20, 1 ); |
| 8 |
|
| 9 |
add_filter( 'acf/load_field/name=recipient_field', array( $this, 'populate_email_field_choices' ), 10, 1 ); |
| 10 |
add_filter( 'af/form/settings_fields', array( $this, 'email_acf_fields' ), 10, 1 ); |
| 11 |
|
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
/** |
| 16 |
* Add an "Insert field" button to recipient, subject, and from fields |
| 17 |
* |
| 18 |
* @since 1.0.1 |
| 19 |
* |
| 20 |
*/ |
| 21 |
function add_email_field_inserter( $field ) { |
| 22 |
|
| 23 |
global $post; |
| 24 |
|
| 25 |
if ( ! $post ) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
$form = af_form_from_post( $post ); |
| 31 |
|
| 32 |
if ( ! $form ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
$fields_to_add = array( |
| 37 |
'field_form_email_recipient_custom', |
| 38 |
'field_form_email_subject', |
| 39 |
'field_form_email_from', |
| 40 |
); |
| 41 |
|
| 42 |
|
| 43 |
if ( in_array( $field['key'], $fields_to_add ) ) { |
| 44 |
|
| 45 |
_af_field_inserter_button( $form, 'regular', true ); |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
/** |
| 53 |
* Populates the email recipient field select with the current form's fields |
| 54 |
* |
| 55 |
* @since 1.0.0 |
| 56 |
* |
| 57 |
*/ |
| 58 |
function populate_email_field_choices( $field ) { |
| 59 |
|
| 60 |
global $post; |
| 61 |
|
| 62 |
if ( $post && 'af_form' == $post->post_type ) { |
| 63 |
|
| 64 |
$form_key = get_post_meta( $post->ID, 'form_key', true ); |
| 65 |
|
| 66 |
$field['choices'] = _af_form_field_choices( $form_key, 'regular' ); |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
return $field; |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
/** |
| 76 |
* Add fields for setting up emails to the form settings |
| 77 |
* |
| 78 |
* @since 1.0.0 |
| 79 |
* |
| 80 |
*/ |
| 81 |
function email_acf_fields( $field_group ) { |
| 82 |
|
| 83 |
$field_group['fields'][] = array ( |
| 84 |
'key' => 'field_form_notifications_tab', |
| 85 |
'label' => '<span class="dashicons dashicons-email-alt"></span>' . __( 'Notifications', 'advanced-forms' ), |
| 86 |
'name' => '', |
| 87 |
'type' => 'tab', |
| 88 |
'instructions' => '', |
| 89 |
'required' => 0, |
| 90 |
'conditional_logic' => 0, |
| 91 |
'wrapper' => array ( |
| 92 |
'width' => '', |
| 93 |
'class' => '', |
| 94 |
'id' => '', |
| 95 |
), |
| 96 |
'placement' => 'left', |
| 97 |
'endpoint' => 0, |
| 98 |
); |
| 99 |
|
| 100 |
$field_group['fields'][] = array ( |
| 101 |
'key' => 'field_form_emails', |
| 102 |
'label' => __( 'Emails', 'advanced-forms' ), |
| 103 |
'name' => 'form_emails', |
| 104 |
'type' => 'repeater', |
| 105 |
'instructions' => __( 'The emails defined here will be sent upon successful submission.', 'advanced-forms' ), |
| 106 |
'required' => 0, |
| 107 |
'conditional_logic' => 0, |
| 108 |
'wrapper' => array ( |
| 109 |
'width' => '', |
| 110 |
'class' => '', |
| 111 |
'id' => '', |
| 112 |
), |
| 113 |
'collapsed' => 'field_form_email_name', |
| 114 |
'min' => '', |
| 115 |
'max' => '', |
| 116 |
'layout' => 'block', |
| 117 |
'button_label' => __( 'Add new email', 'advanced-forms' ), |
| 118 |
'sub_fields' => array ( |
| 119 |
array ( |
| 120 |
'key' => 'field_form_email_name', |
| 121 |
'label' => __( 'Name', 'advanced-forms' ), |
| 122 |
'name' => 'name', |
| 123 |
'type' => 'text', |
| 124 |
'instructions' => '', |
| 125 |
'required' => 1, |
| 126 |
'conditional_logic' => 0, |
| 127 |
'wrapper' => array ( |
| 128 |
'width' => '66', |
| 129 |
'class' => '', |
| 130 |
'id' => '', |
| 131 |
), |
| 132 |
'default_value' => '', |
| 133 |
'placeholder' => 'Name this email for your reference', |
| 134 |
'prepend' => '', |
| 135 |
'append' => '', |
| 136 |
'maxlength' => '', |
| 137 |
), |
| 138 |
array ( |
| 139 |
'key' => 'field_form_email_active', |
| 140 |
'label' => __( 'Active?', 'advanced-forms' ), |
| 141 |
'name' => 'active', |
| 142 |
'type' => 'true_false', |
| 143 |
'instructions' => '', |
| 144 |
'required' => 0, |
| 145 |
'conditional_logic' => 0, |
| 146 |
'wrapper' => array ( |
| 147 |
'width' => '33', |
| 148 |
'class' => '', |
| 149 |
'id' => '', |
| 150 |
), |
| 151 |
'message' => 'Yes', |
| 152 |
'default_value' => 1, |
| 153 |
), |
| 154 |
array ( |
| 155 |
'key' => 'field_form_email_recipient_type', |
| 156 |
'label' => __( 'Send to', 'advanced-forms' ), |
| 157 |
'name' => 'recipient_type', |
| 158 |
'type' => 'radio', |
| 159 |
'instructions' => '', |
| 160 |
'required' => 0, |
| 161 |
'conditional_logic' => 0, |
| 162 |
'wrapper' => array ( |
| 163 |
'width' => '', |
| 164 |
'class' => '', |
| 165 |
'id' => '', |
| 166 |
), |
| 167 |
'choices' => array ( |
| 168 |
'field' => __( 'Select from field', 'advanced-forms' ), |
| 169 |
'custom' => __( 'Custom recipient', 'advanced-forms' ), |
| 170 |
), |
| 171 |
'allow_null' => 0, |
| 172 |
'other_choice' => 0, |
| 173 |
'save_other_choice' => 0, |
| 174 |
'default_value' => '', |
| 175 |
'layout' => 'horizontal', |
| 176 |
'return_format' => 'value', |
| 177 |
), |
| 178 |
array ( |
| 179 |
'key' => 'field_form_email_recipient_field', |
| 180 |
'label' => __( 'Recipient field', 'advanced-forms' ), |
| 181 |
'name' => 'recipient_field', |
| 182 |
'type' => 'select', |
| 183 |
'instructions' => '', |
| 184 |
'required' => 0, |
| 185 |
'conditional_logic' => array ( |
| 186 |
array ( |
| 187 |
array ( |
| 188 |
'field' => 'field_form_email_recipient_type', |
| 189 |
'operator' => '==', |
| 190 |
'value' => 'field', |
| 191 |
), |
| 192 |
), |
| 193 |
), |
| 194 |
'wrapper' => array ( |
| 195 |
'width' => '', |
| 196 |
'class' => '', |
| 197 |
'id' => '', |
| 198 |
), |
| 199 |
'choices' => array ( |
| 200 |
), |
| 201 |
'default_value' => array ( |
| 202 |
), |
| 203 |
'allow_null' => 0, |
| 204 |
'multiple' => 0, |
| 205 |
'ui' => 0, |
| 206 |
'ajax' => 0, |
| 207 |
'return_format' => 'value', |
| 208 |
'placeholder' => '', |
| 209 |
), |
| 210 |
array ( |
| 211 |
'key' => 'field_form_email_recipient_custom', |
| 212 |
'label' => __( 'Custom recipient', 'advanced-forms' ), |
| 213 |
'name' => 'recipient_custom', |
| 214 |
'type' => 'text', |
| 215 |
'instructions' => '', |
| 216 |
'required' => 0, |
| 217 |
'conditional_logic' => array ( |
| 218 |
array ( |
| 219 |
array ( |
| 220 |
'field' => 'field_form_email_recipient_type', |
| 221 |
'operator' => '==', |
| 222 |
'value' => 'custom', |
| 223 |
), |
| 224 |
), |
| 225 |
), |
| 226 |
'wrapper' => array ( |
| 227 |
'width' => '', |
| 228 |
'class' => '', |
| 229 |
'id' => '', |
| 230 |
), |
| 231 |
'default_value' => '', |
| 232 |
'placeholder' => '', |
| 233 |
'prepend' => '', |
| 234 |
'append' => '', |
| 235 |
'maxlength' => '', |
| 236 |
), |
| 237 |
array ( |
| 238 |
'key' => 'field_form_email_from', |
| 239 |
'label' => __( 'From', 'advanced-forms' ), |
| 240 |
'name' => 'from', |
| 241 |
'type' => 'text', |
| 242 |
'instructions' => 'Must be either an email address or on the form "Name <Email address>".', |
| 243 |
'required' => 0, |
| 244 |
'conditional_logic' => 0, |
| 245 |
'wrapper' => array ( |
| 246 |
'width' => '', |
| 247 |
'class' => '', |
| 248 |
'id' => '', |
| 249 |
), |
| 250 |
'default_value' => '', |
| 251 |
'placeholder' => '', |
| 252 |
'prepend' => '', |
| 253 |
'append' => '', |
| 254 |
'maxlength' => '', |
| 255 |
), |
| 256 |
array ( |
| 257 |
'key' => 'field_form_email_subject', |
| 258 |
'label' => __( 'Subject', 'advanced-forms' ), |
| 259 |
'name' => 'subject', |
| 260 |
'type' => 'text', |
| 261 |
'instructions' => '', |
| 262 |
'required' => 0, |
| 263 |
'conditional_logic' => 0, |
| 264 |
'wrapper' => array ( |
| 265 |
'width' => '', |
| 266 |
'class' => '', |
| 267 |
'id' => '', |
| 268 |
), |
| 269 |
'default_value' => '', |
| 270 |
'placeholder' => '', |
| 271 |
'prepend' => '', |
| 272 |
'append' => '', |
| 273 |
'maxlength' => '', |
| 274 |
), |
| 275 |
array ( |
| 276 |
'key' => 'field_form_email_content', |
| 277 |
'label' => __( 'Content', 'advanced-forms' ), |
| 278 |
'name' => 'content', |
| 279 |
'type' => 'wysiwyg', |
| 280 |
'instructions' => '', |
| 281 |
'required' => 0, |
| 282 |
'conditional_logic' => 0, |
| 283 |
'wrapper' => array ( |
| 284 |
'width' => '', |
| 285 |
'class' => '', |
| 286 |
'id' => '', |
| 287 |
), |
| 288 |
'default_value' => '', |
| 289 |
'tabs' => 'all', |
| 290 |
'toolbar' => 'full', |
| 291 |
'media_upload' => 1, |
| 292 |
), |
| 293 |
), |
| 294 |
); |
| 295 |
|
| 296 |
|
| 297 |
$field_group = apply_filters( 'af/form/notification_settings_fields', $field_group ); |
| 298 |
|
| 299 |
|
| 300 |
return $field_group; |
| 301 |
|
| 302 |
} |
| 303 |
|
| 304 |
} |
| 305 |
|
| 306 |
return new AF_Admin_Emails(); |