|
<?php |
|
/** |
|
* Core Functionality Plugin |
|
* |
|
* @package CoreFunctionality |
|
* @since 1.0.0 |
|
* @copyright Copyright (c) 2014, Bill Erickson & Jared Atchison |
|
* @license GPL-2.0+ |
|
*/ |
|
|
|
// Author Form |
|
define( 'EA_AUTHOR_FORM_ID', 5192 ); |
|
|
|
// Author Field, hidden field in the form above |
|
// In WPForms, set the default value to {query_var key="person"} |
|
define( 'EA_AUTHOR_FIELD_ID', 3 ); |
|
|
|
/** |
|
* Adds author photo and name at top of form |
|
* @author Bill Erickson |
|
* @link http://www.billerickson.net/contact-form-dynamic-notification/ |
|
* |
|
* @param array $form_data, form data |
|
*/ |
|
function ea_author_on_form( $form_data ) { |
|
|
|
// Only run on the 'Contact an Author' form, and if an author is specified in the URL |
|
if( !( EA_AUTHOR_FORM_ID == $form_data['id'] && isset( $_GET['person'] ) ) ) |
|
return; |
|
|
|
// Display author |
|
$person = intval( $_GET['person'] ); |
|
$name = get_the_author_meta( 'display_name', $person ); |
|
$photo = get_avatar( $person, 48 ); |
|
echo '<h2 class="author">Contacting: ' . $photo . $name . '</h2>'; |
|
|
|
} |
|
add_action( 'wpforms_frontend_output', 'ea_author_on_form', 9 ); |
|
|
|
/** |
|
* Use author email address |
|
* @author Bill Erickson |
|
* @link http://www.billerickson.net/contact-form-dynamic-notification/ |
|
* |
|
* @param array $email, contains all the information used to build email notification (address, message...) |
|
* @param array $fields, form fields |
|
* @param array $entry, form entry |
|
* @param array $form_data, form data |
|
* @return array $email |
|
*/ |
|
function ea_author_email_address( $email, $fields, $entry, $form_data ) { |
|
|
|
if( !( EA_AUTHOR_FORM_ID == $form_data['id'] ) ) |
|
return $email; |
|
|
|
$author_id = false; |
|
foreach( $fields as $field ) { |
|
if( EA_AUTHOR_FIELD_ID == $field['id'] ) { |
|
$author_id = intval( $field['value'] ); |
|
} |
|
} |
|
|
|
if( $author_id ) { |
|
$email['address'] = array( get_the_author_meta( 'email', $author_id ) ); |
|
} |
|
|
|
return $email; |
|
} |
|
add_filter( 'wpforms_entry_email_atts', 'ea_author_email_address', 10, 4 ); |