Skip to content

Latest commit

 

History

History
122 lines (88 loc) · 2.75 KB

File metadata and controls

122 lines (88 loc) · 2.75 KB

Multi Email Field Type

The Multi Email field type provides a repeatable interface for collecting multiple email addresses with add/remove functionality and built-in email validation.

Field Type: multi_email

array(
	'type'  => 'multi_email',
	'label' => 'Email Addresses',
	'min'   => 1,
	'max'   => 5,
)

Properties

For Default Field Properties, see Field Types Definition.

Specific Properties

min (integer) — Optional

Minimum number of items. Users cannot remove items below this count.

max (integer) — Optional

Maximum number of items. Users cannot add items beyond this count.

buttons (array) — Optional

Custom button labels. Supports keys: add, remove, duplicate.

disabled_buttons (array) — Optional

Array of buttons to disable. Options: 'move', 'delete', 'duplicate'.

Stored Value

An array of email address strings.

Example Usage

Basic Multi Email Field

'notification_emails' => array(
	'type'        => 'multi_email',
	'label'       => 'Notification Emails',
	'description' => 'Add email addresses that should receive notifications',
),

With Default Values

'team_emails' => array(
	'type'    => 'multi_email',
	'label'   => 'Team Email Addresses',
	'default' => array(
		'manager@company.com',
		'support@company.com',
	),
),

Using Values in Your Theme

$notification_emails = get_post_meta( get_the_ID(), 'notification_emails', true );

if ( ! empty( $notification_emails ) && is_array( $notification_emails ) ) {
	echo '<ul>';

	foreach ( $notification_emails as $email ) {
		if ( ! is_email( $email ) ) {
			continue;
		}

		echo '<li><a href="mailto:' . esc_attr( $email ) . '">' . esc_html( $email ) . '</a></li>';
	}

	echo '</ul>';
}

With Conditional Logic

'enable_notifications' => array(
	'type'  => 'toggle',
	'id'    => 'enable_notifications',
	'label' => 'Enable Email Notifications',
),
'recipient_emails' => array(
	'type'       => 'multi_email',
	'label'      => 'Recipient Email Addresses',
	'conditions' => array(
		array( 'field' => 'enable_notifications', 'value' => true ),
	),
),

Field Factory

$f = new \Wpify\CustomFields\FieldFactory();

$f->multi_email(
	label: 'Email Addresses',
	min: 1,
	max: 5,
);

Notes

  • The stored value is always an array, even if only one email address is provided.
  • Each email address is validated for proper format (must include @ and a domain with a period).
  • When retrieving emails for sending, use WordPress's is_email() function to verify validity.
  • Items can be reordered by dragging unless the move button is disabled.
  • Ideal for collecting notification recipients, team contacts, or any scenario requiring multiple email addresses.