$text ) {
if ( isset( $strings[ $key ] ) && is_string( $strings[ $key ] ) && is_string( $text ) && '' !== trim( $text ) ) {
$strings[ $key ] = sanitize_text_field( $text );
}
}
}
$strings['titles'] = self::clean_map( isset( $args['titles'] ) ? $args['titles'] : array(), self::steps() );
$strings['subtitles'] = self::clean_map( isset( $args['subtitles'] ) ? $args['subtitles'] : array(), self::steps() );
$strings['placeholders'] = self::clean_map( isset( $args['placeholders'] ) ? $args['placeholders'] : array(), self::placeholder_fields() );
$config = array(
'rest' => esc_url_raw( rest_url( 'aslansheed-otp/v1/' ) ),
'redirect' => $redirect,
'accent' => '' !== (string) $accent ? (string) $accent : (string) Options::get( 'forms.accent_color' ),
'google' => isset( $args['google'] ) && ! $args['google'] ? '' : $google,
'captcha' => array() === $captcha || '' !== $preview ? null : $captcha,
'terms_url' => (string) Options::get( 'forms.terms_url' ),
'countries' => self::country_config(),
'i18n' => $strings,
);
if ( '' !== $preview ) {
$config['preview'] = $preview;
$config['preview_notice'] = isset( $args['preview_notice'] ) ? sanitize_key( $args['preview_notice'] ) : '';
$config['preview_fields'] = \Aslansheed\OTP\Auth\Register_Fields::for_type( 'phone' );
$config['preview_custom'] = \Aslansheed\OTP\Auth\Custom_Fields::for_client( 'phone' );
$config['preview_calendar'] = (string) Options::get( 'forms.date_calendar' );
}
$classes = 'aslansheed-otp' . ( ! isset( $args['auto_dark'] ) || $args['auto_dark'] ? ' aslo-auto-dark' : '' );
if ( isset( $args['class'] ) ) {
$classes .= ' ' . implode( ' ', array_map( 'sanitize_html_class', explode( ' ', (string) $args['class'] ) ) );
}
return '
';
}
/**
* Keeps only known keys with non-empty text.
*
* @param mixed $map Submitted map.
* @param string[] $allowed Allowed keys.
* @return array
*/
private static function clean_map( $map, array $allowed ) {
$out = array();
if ( ! is_array( $map ) ) {
return $out;
}
foreach ( $allowed as $key ) {
if ( isset( $map[ $key ] ) && is_string( $map[ $key ] ) && '' !== trim( $map[ $key ] ) ) {
$out[ $key ] = sanitize_text_field( $map[ $key ] );
}
}
return $out;
}
/**
* Returns the country list for the phone country selector, or null when it is off.
*
* The list holds the allowed countries, or every country when none is set.
*
* @return array{selected: string, list: array}|null
*/
public static function country_config() {
if ( ! Options::get( 'forms.country_selector' ) ) {
return null;
}
$allowed = Access_Control::allowed_countries();
$all = Phone_Countries::all();
$list = array();
foreach ( array() === $allowed ? array_keys( $all ) : $allowed as $iso ) {
$list[] = array( $iso, $all[ $iso ][0], $all[ $iso ][1] );
}
if ( count( $list ) < 2 ) {
return null;
}
return array(
'selected' => Access_Control::default_country(),
'list' => $list,
);
}
/**
* Builds the identifier label from the enabled input types.
*
* @return string
*/
private static function identifier_label() {
$parts = array();
if ( Options::get( 'forms.accept_phone' ) ) {
$parts[] = __( 'phone number', 'aslansheed-login' );
}
if ( Options::get( 'forms.accept_email' ) ) {
$parts[] = __( 'email', 'aslansheed-login' );
}
if ( Options::get( 'forms.accept_username' ) ) {
$parts[] = __( 'username', 'aslansheed-login' );
}
if ( array() === $parts ) {
return __( 'Account', 'aslansheed-login' );
}
$label = implode( ' / ', $parts );
return ucfirst( $label );
}
/**
* Returns every text the script needs.
*
* @return array
*/
public static function strings() {
return array_merge(
Two_Factor_Ui::strings(),
array(
'identifier' => self::identifier_label(),
'continue_label' => __( 'Continue', 'aslansheed-login' ),
'code' => __( 'Verification code', 'aslansheed-login' ),
'code_sent' => __( 'We sent you a code.', 'aslansheed-login' ),
'sent_to' => __( 'Enter the code sent to', 'aslansheed-login' ),
'change' => __( 'Change', 'aslansheed-login' ),
'verify' => __( 'Verify', 'aslansheed-login' ),
'choose_channel' => __( 'How would you like to receive your code?', 'aslansheed-login' ),
'other_method' => __( 'Send it another way', 'aslansheed-login' ),
'use_password' => __( 'Use password instead', 'aslansheed-login' ),
'use_code' => __( 'Send me a code instead', 'aslansheed-login' ),
/* translators: %s: number of seconds. */
'resend_in' => __( 'Resend code in %s s', 'aslansheed-login' ),
'resend' => __( 'Resend code', 'aslansheed-login' ),
'password' => __( 'Password', 'aslansheed-login' ),
'new_password' => __( 'Choose a password', 'aslansheed-login' ),
'sign_in' => __( 'Sign in', 'aslansheed-login' ),
'name' => __( 'Display name', 'aslansheed-login' ),
'country' => __( 'Country', 'aslansheed-login' ),
'verify_email_hint' => __( 'We sent a code to your email address. Enter it to finish.', 'aslansheed-login' ),
'skip_email' => __( 'Skip for now', 'aslansheed-login' ),
'email_sent' => __( 'We sent a code to your email.', 'aslansheed-login' ),
'finish' => __( 'Almost done. Tell us a little about you.', 'aslansheed-login' ),
'terms' => __( 'I accept the terms.', 'aslansheed-login' ),
'terms_link' => __( 'Read them', 'aslansheed-login' ),
'create_account' => __( 'Create account', 'aslansheed-login' ),
'welcome' => __( 'Signed in. Redirecting…', 'aslansheed-login' ),
'network' => __( 'Connection problem. Please try again.', 'aslansheed-login' ),
'optional' => __( '(optional)', 'aslansheed-login' ),
'first_name' => __( 'First name', 'aslansheed-login' ),
'last_name' => __( 'Last name', 'aslansheed-login' ),
'email' => __( 'Email address', 'aslansheed-login' ),
'username' => __( 'Username', 'aslansheed-login' ),
'password_confirm' => __( 'Repeat the password', 'aslansheed-login' ),
'national_id' => __( 'National ID', 'aslansheed-login' ),
'postal_code' => __( 'Postal code', 'aslansheed-login' ),
'birth_date' => __( 'Birth date', 'aslansheed-login' ),
'day' => __( 'Day', 'aslansheed-login' ),
'month' => __( 'Month', 'aslansheed-login' ),
'year' => __( 'Year', 'aslansheed-login' ),
'calendar' => __( 'Calendar', 'aslansheed-login' ),
'calendar_gregorian' => __( 'Gregorian', 'aslansheed-login' ),
'calendar_jalali' => __( 'Jalali (Persian)', 'aslansheed-login' ),
'strength_weak' => __( 'Weak password', 'aslansheed-login' ),
'strength_fair' => __( 'Fair password', 'aslansheed-login' ),
'strength_good' => __( 'Good password', 'aslansheed-login' ),
'strength_strong' => __( 'Strong password', 'aslansheed-login' ),
'months_gregorian' => array(
__( 'January', 'aslansheed-login' ),
__( 'February', 'aslansheed-login' ),
__( 'March', 'aslansheed-login' ),
__( 'April', 'aslansheed-login' ),
__( 'May', 'aslansheed-login' ),
__( 'June', 'aslansheed-login' ),
__( 'July', 'aslansheed-login' ),
__( 'August', 'aslansheed-login' ),
__( 'September', 'aslansheed-login' ),
__( 'October', 'aslansheed-login' ),
__( 'November', 'aslansheed-login' ),
__( 'December', 'aslansheed-login' ),
),
'months_jalali' => array(
__( 'Farvardin', 'aslansheed-login' ),
__( 'Ordibehesht', 'aslansheed-login' ),
__( 'Khordad', 'aslansheed-login' ),
__( 'Tir', 'aslansheed-login' ),
__( 'Mordad', 'aslansheed-login' ),
__( 'Shahrivar', 'aslansheed-login' ),
__( 'Mehr', 'aslansheed-login' ),
__( 'Aban', 'aslansheed-login' ),
__( 'Azar', 'aslansheed-login' ),
__( 'Dey', 'aslansheed-login' ),
__( 'Bahman', 'aslansheed-login' ),
__( 'Esfand', 'aslansheed-login' ),
),
'or' => __( 'or', 'aslansheed-login' ),
'captcha_needed' => __( 'Please complete the security check first.', 'aslansheed-login' ),
)
);
}
}