# Feedback_Author Class
**[→ Class Reference](feedback-author-class.md)** | **[← Back to Index](README.md)**
The `Feedback_Author` class manages submitter information for form submissions. It handles name, email, URL, and avatar data with automatic integration into WordPress comment filters.
## Overview
The `Feedback_Author` class:
- Stores author name, email, and URL
- Supports separate first/last name fields
- Provides display name fallback logic
- Integrates with WordPress comment filters
- Generates Gravatar URLs
## Creating Author Objects
### From Form Submission
```php
$author = Feedback_Author::from_submission( $_POST, $form );
```
This method:
- Extracts name, email, and URL from form data
- Applies WordPress comment filters
- Handles first-name and last-name fields if present
### Manual Creation
```php
$author = new Feedback_Author(
'John Doe', // name
'john@example.com', // email
'https://johndoe.com', // url
'John', // first_name (optional)
'Doe' // last_name (optional)
);
```
All parameters are optional and default to empty strings.
## Getting Author Information
### Display Name
Get the best available name for display:
```php
$name = $author->get_display_name();
```
**Behavior:**
- Returns the full name if available
- Falls back to email if name is empty
- Never returns empty string (unless both name and email are empty)
**Examples:**
```php
// With name
$author = new Feedback_Author( 'John Doe', 'john@example.com' );
echo $author->get_display_name(); // "John Doe"
// Without name
$author = new Feedback_Author( '', 'john@example.com' );
echo $author->get_display_name(); // "john@example.com"
```
### Name
Get the author's full name:
```php
$name = $author->get_name();
```
**Behavior:**
- If first_name and last_name are both set, combines them with `pre_comment_author_name` filter
- Otherwise returns the stored name value
- Name is filtered through WordPress comment filters during construction
**Example:**
```php
$author = new Feedback_Author( '', '', '', 'John', 'Doe' );
echo $author->get_name(); // "John Doe" (filtered through pre_comment_author_name)
```
### Email
```php
$email = $author->get_email();
```
Returns the author's email address.
### URL
```php
$url = $author->get_url();
```
Returns the author's website URL.
### First and Last Name
```php
$first_name = $author->get_first_name();
$last_name = $author->get_last_name();
```
Returns individual name components if provided separately in the form.
### Avatar
Get the Gravatar URL:
```php
$avatar_url = $author->get_avatar_url();
```
Returns empty string if no email is set.
**Example:**
```php
if ( $author->get_avatar_url() ) {
echo '';
echo '' . esc_html( $author->get_display_name() ) . '';
}
```
## WordPress Filter Integration
The class automatically applies WordPress comment filters during creation:
### Applied Filters
- `pre_comment_author_name` - Applied to name field
- `pre_comment_author_email` - Applied to email field
- `pre_comment_author_url` - Applied to URL field
### Customizing Author Data
```php
// Capitalize names
add_filter( 'pre_comment_author_name', function( $name ) {
return ucwords( strtolower( $name ) );
} );
// Normalize emails to lowercase
add_filter( 'pre_comment_author_email', function( $email ) {
return strtolower( $email );
} );
// Ensure URLs have protocol
add_filter( 'pre_comment_author_url', function( $url ) {
if ( ! empty( $url ) && ! preg_match( '~^https?://~i', $url ) ) {
return 'https://' . $url;
}
return $url;
} );
```
## Complete Examples
### Display Author Card
```php
$author = $feedback->get_author_data();
echo '