Changeset 1509658
- Timestamp:
- 10/07/2016 01:01:03 AM (9 years ago)
- Location:
- wp-emfluence/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
widget.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-emfluence/trunk/readme.txt
r1428611 r1509658 2 2 Tags: email, email marketing, emailmarketing, emfluence, api, marketing automation, widget, email widget, email signup, mailing list, newsletter, form, automation 3 3 Requires at least: 3.0.1 4 Tested up to: 4. 5.25 Stable tag: 2. 04 Tested up to: 4.6.1 5 Stable tag: 2.1 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 52 52 == Changelog == 53 53 54 = 2.1 = 55 * Admins can choose to have submissions also sent to a notification email address. 56 54 57 = 2.0 = 55 58 * Contacts are added to any groups selected by the admin. Private groups can be selected. -
wp-emfluence/trunk/widget.php
r1421095 r1509658 234 234 } else { 235 235 // SUCCESS! 236 $this->send_notification($instance, $data); 236 237 if(!empty($instance['success'])) $message = nl2br(wp_kses_post($instance['success'])); 237 238 if(empty($message)) { … … 329 330 ); 330 331 return; 332 } 333 334 /** 335 * If a notification target has been provided, send the submission data to it. 336 * @param $instance 337 * @param $data 338 */ 339 protected function send_notification($instance, $data) { 340 if(empty($instance['notify'])) return; 341 $message = 'This is an automated notification. The following submission was received:' . "\n\n"; 342 foreach($data as $field=>$val) { 343 if($field == 'customFields') { 344 foreach($val as $custom_id=>$custom_val) { 345 $instance_key = str_replace('custom', 'custom_', $custom_id); 346 $label = $instance['fields'][$instance_key]['label']; 347 if($instance['fields'][$instance_key]['type'] === 'true-false') { 348 $custom_val['value'] = $custom_val['value'] ? 'Yes' : 'No'; 349 } 350 if($instance['fields'][$instance_key]['type'] === 'textarea') { 351 $label .= "\n"; 352 } 353 $message .= $label . ' ' . $custom_val['value'] . "\n"; 354 } 355 continue; 356 } 357 $message .= $field . ': ' . $this->recursively_convert_to_string($val); 358 } 359 wp_mail( 360 $instance['notify'], 361 'New email signup form submission for "' . $instance['title'] . '"', 362 $message 363 ); 364 } 365 366 /** 367 * Format an array for use in a plain text message. 368 * For use in the email notification. 369 * @param $data 370 * @param int $level 371 * @return string 372 */ 373 protected function recursively_convert_to_string($data, $level = 0) { 374 375 if(is_string($data)) return $data . "\n"; 376 if(!is_array($data)) return ''; 377 $out = "\n"; 378 foreach($data as $key=>$val) { 379 $out .= str_repeat('-', $level) . ' ' . $key . ': ' . $this->recursively_convert_to_string($val, $level + 1); 380 } 381 return $out; 382 383 } 384 385 /** 386 * Convert a potential CSV of email addresses to an array of trimmed email addresses. 387 * @param string $address_string 388 * @return array 389 */ 390 protected function explode_emails($address_string) { 391 $emails = explode(',', $address_string); 392 foreach($emails as &$email) { 393 $email = trim($email); 394 } 395 return array_filter($emails); 331 396 } 332 397 … … 390 455 <textarea id="' . $this->get_field_id( 'success' ) . '" name="' . $this->get_field_name( 'success' ) . '" style="width:100%;" >' . $instance['success'] . '</textarea> 391 456 NOTE: If you set the success message here, any theme template file emfluence/success.php will be ignored. 457 </p> 458 </div>' . "\n"; 459 return $output; 460 } 461 462 /** 463 * @param $instance 464 * @return string 465 */ 466 protected function form_template_notification($instance) { 467 $validation = ''; 468 if(!empty($instance['notify'])) { 469 $emails = $this->explode_emails($instance['notify']); 470 foreach($emails as $email) { 471 if(!is_email($email)) { 472 $validation = '<div class="validation error">The email address you entered is not valid</div>'; 473 } 474 } 475 } 476 $output = ' 477 <h3>' . __('Notification') . '</h3> 478 <div class="text_display"> 479 <p> 480 <label for="' . $this->get_field_id( 'notify' ) . '">' . __('Email Address') . ':</label> 481 <input type="text" id="' . $this->get_field_id( 'notify' ) . '" name="' . $this->get_field_name( 'notify' ) . '" value="' . $instance['notify'] . '" style="width:100%;" /> 482 (Leave blank to disable notification) 483 ' . $validation .' 392 484 </p> 393 485 </div>' . "\n"; … … 630 722 'submit' => __('Signup'), 631 723 'fields' => array(), 724 'notify' => '' 632 725 ); 633 726 … … 776 869 $output .= $this->form_template_basic_fields($defaults, $instance); 777 870 $output .= $this->form_template_custom_variables($defaults, $instance); 871 $output .= $this->form_template_notification($instance); 778 872 779 873 // Output the datalist for groups just once … … 863 957 $instance['submit'] = stripslashes($new_instance['submit']); 864 958 $instance['success'] = stripslashes($new_instance['success']); 959 $instance['notify'] = stripslashes($new_instance['notify']); 865 960 866 961 // If the current user isn't allowed to use unfiltered HTML, filter it
Note: See TracChangeset
for help on using the changeset viewer.