Filter uncanny-automator-pro

automator_pro_auto_login_link_expires_in

Filters the expiration time in days for automatically generated login links.

add_filter( 'automator_pro_auto_login_link_expires_in', $callback, 10, 2 );

Description

Filters the number of days before an auto-login link expires. Developers can use this hook to dynamically change the expiration duration for auto-login links, tailoring it based on the user ID or other custom logic. The default is 7 days.


Usage

add_filter( 'automator_pro_auto_login_link_expires_in', 'your_function_name', 10, 2 );

Parameters

$days_expired_in (mixed)
This parameter specifies the number of days after which an auto-login link will expire.
$user_id (mixed)
This parameter contains the number of days before an auto-login link expires.

Return Value

The filtered value.


Examples

<?php
/**
 * Example: Modify the expiration days for auto-login links.
 *
 * This filter allows you to change the default number of days an auto-login link
 * generated by Uncanny Automator Pro will remain valid.
 *
 * @param int $days_expired_in The current number of days the link will expire in.
 * @param int $user_id The ID of the user for whom the auto-login link is generated.
 * @return int The modified number of days the link will expire in.
 */
add_filter( 'automator_pro_auto_login_link_expires_in', function( $days_expired_in, $user_id ) {
	// For premium users, extend the expiration to 7 days.
	if ( user_can( $user_id, 'manage_options' ) ) {
		return 7;
	}

	// For regular users, keep the default expiration.
	return $days_expired_in;
}, 10, 2 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

uncanny-automator-pro/src/integrations/advanced/tokens/autologin-link-token.php:57

public function parse_integration_token( $return, $pieces, $recipe_id, $trigger_data, $user_id, $replace_args ) {

		$user_is_admin_or_editor = user_can( $user_id, 'editor' ) || user_can( $user_id, 'administrator' );

		$disable_security_check = apply_filters( 'automator_pro_auto_login_link_disable_security_check', false, $user_id );

		if ( false === $disable_security_check && $user_is_admin_or_editor ) {
			return esc_attr__( 'For security reasons, automatic login links cannot be generated for Administrator or Editor users.', 'uncanny-automator-pro' );
		}

		$unix_day = 24 * 60 * 60;

		$days_expired_in = 7;

		$days_expired_in = apply_filters_deprecated(
			'AUTOLOGINLINK_expires_in',
			array(
				$days_expired_in,
				get_user_by( 'ID', $user_id ),
			),
			'4.3',
			'automator_pro_auto_login_link_expires_in'
		); //phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase

		$days_expired_in = apply_filters( 'automator_pro_auto_login_link_expires_in', $days_expired_in, $user_id ); //phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase

		$hash = $this->generate_magic_hash();

		update_user_meta( $user_id, $hash, time() + ( $unix_day * $days_expired_in ) );

		return add_query_arg( 'ua_login', $hash, wp_login_url() );
	}


Scroll to Top