Magic Links Filters

Available Filters

GravityView Magic Links provides a few filters to customize the plugin's behavior.

gk/gravityview/magic-links/email/subject

Filter to change the email subject.

Parameters

  • $subject  : The email subject.

Example

add_filter( 'gk/gravityview/magic-links/email/subject', function( $subject ) {
	return 'Your link to edit an entry';
} );

gk/gravityview/magic-links/email/headers

Filter to change the email headers.

Parameters

  • $headers  : The email headers.

gk/gravityview/magic-links/email/message  

Filter to change the email message.

Parameters

  • $message  : The email message.
  • $magic_link  : The magic link URL.
  • $expiration_hours  : The expiration time in hours.

Example

add_filter( 'gk/gravityview/magic-links/email/message', function( $message ) {
	return 'Your link to edit an entry';
} );

Additional customization

When Magic Links sends an email to the user that includes the magic link, it automatically expires after the defined amount of time based on the "Link Expiration" setting.

The default choices for the Link Expiration setting includes options ranging from 5 minutes to 12 hours. This is designed to allow for a balance of security and convenience.

The thinking is that if someone is requesting a link to edit an entry, they are likely able to click it at that time, and if they want to request access again, they can do so.

If you want to add additional Link Expiration choices, you can do so using the following code:

/**
 * Add additional default Magic Link expiration durations to GravityView View settings.
 *
 * @since 1.0.0
 *
 * @param array $default_settings The default settings for a GravityView View.
 * @return array The modified settings array with added expiration options.
 */
add_filter( 'gravityview/view/settings/defaults', function( $default_settings ) {

	// Ensure the Magic Link expiration options key exists and is an array.
	if ( ! isset( $default_settings['magic_link_expiration']['options'] )
	|| ! is_array( $default_settings['magic_link_expiration']['options'] ) 
	) {
		return $default_settings;
	}

	// Add standard expiration durations.
	$default_settings['magic_link_expiration']['options'] += [
		DAY_IN_SECONDS   => '1 day',
		WEEK_IN_SECONDS  => '1 week',
		MONTH_IN_SECONDS => '1 month',
		YEAR_IN_SECONDS  => '1 year',
	];

	return $default_settings;
}, 15 );

Before:

A dropdown showing 5 minutes to 12 hours
Before the filter is applied, the maximum is 12 hours.

After:

A dropdown showing 5 minutes to 12 hours…plus 1 day, 1 week, 1 month, and 1 year options.
After the filter is applied, day, week, month, and year options are shown.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us