'gmail',
'text' => '',
],
$atts,
'forwp_account_login'
);
$provider = sanitize_key( (string) $atts['provider'] );
if ( ! ProviderSettings::is_enabled( $provider ) ) {
return '';
}
$labels = ProviderSettings::get_button_labels();
$text = ! empty( $atts['text'] ) ? sanitize_text_field( $atts['text'] ) : ( $labels[ $provider ] ?? __( 'Sign in', '4wp-account' ) );
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
return '
' . esc_html__( 'You are logged in as:', '4wp-account' ) . ' ' . esc_html( $current_user->display_name ) . '
';
}
return sprintf(
'',
esc_attr( $provider ),
esc_html( $text )
);
}
/**
* Render enabled auth buttons only.
*
* @param array $atts Shortcode attributes.
* @return string
*/
public static function render_auth_buttons( $atts ) {
$atts = shortcode_atts(
[
'providers' => 'auto',
],
$atts,
'forwp_account_signin_buttons'
);
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
return '' . esc_html__( 'You are logged in as:', '4wp-account' ) . ' ' . esc_html( $current_user->display_name ) . '
';
}
return self::render_buttons_markup( ProviderSettings::parse_provider_list( (string) $atts['providers'] ) );
}
/**
* @param string[] $provider_ids Enabled provider IDs.
*/
public static function render_buttons_markup( array $provider_ids ): string {
$labels = ProviderSettings::get_button_labels();
$output = '';
foreach ( $provider_ids as $provider ) {
if ( ! isset( $labels[ $provider ] ) ) {
continue;
}
$output .= sprintf(
'',
esc_attr( $provider ),
esc_html( $labels[ $provider ] )
);
}
$output .= '
';
return $output;
}
}