getShortcodes($attributes); $this->handleAlreadyLoggedIn($attributes); $app = App::getInstance(); $assets = $app['url.assets']; wp_enqueue_style('fluent_support_login_style', $assets . 'admin/css/all_public.css'); wp_enqueue_script('fluent_support_login_helper', $assets . 'portal/js/login_helper.js'); $return = '
'; $loginArgs = apply_filters('fluent_support/login_form_args', [ 'echo' => false, 'redirect' => Helper::getPortalBaseUrl(), 'remember' => true, 'value_remember' => true ]); $return .= wp_login_form($loginArgs); if ($attributes['show-signup'] == 'true') { $return .= '

' . __('Not registered?', 'fluent-support') . ' ' . __('Create an Account', 'fluent-support') . '

'; } $return .= '
'; return $return; } public function registrationForm($attributes) { $attributes = $this->getShortcodes($attributes); $this->handleAlreadyLoggedIn($attributes); $app = App::getInstance(); $assets = $app['url.assets']; wp_enqueue_style('fluent_support_login_style', $assets . 'admin/css/all_public.css'); wp_enqueue_script('fluent_support_login_helper', $assets . 'portal/js/login_helper.js'); wp_localize_script('fluent_support_login_helper', 'fluentSupportPublic', [ 'signup' => rest_url($app->config->get('app.rest_namespace') . '/' . $app->config->get('app.rest_version')) . '/signup', 'nonce' => wp_create_nonce('wp_rest'), 'hide' => $attributes['hide'] ]); $registrationFields = static::getSignupFields(); $hide = $attributes['hide'] == 'true' ? 'hide' : ''; $registrationForm = '
'; foreach ($registrationFields as $fieldName => $registrationField) { $registrationForm .= $this->renderField($fieldName, $registrationField); } $registrationForm .= ''; $registrationForm .= ''; $registrationForm .= '
'; if ($hide) { $registrationForm .= '

' . __('Already have an account?', 'fluent-support') . ' ' . __('Login', 'fluent-support') . '

'; } $registrationForm .= '
'; return $registrationForm; } public function authForm($attributes) { $authForm = '
'; $authForm .= do_shortcode('[fluent_support_login show-signup=true]'); $authForm .= do_shortcode('[fluent_support_signup hide=true]'); $authForm .= '
'; return $authForm; } private function renderField($fieldName, $field) { $fieldType = Arr::get($field, 'type'); $isRequired = Arr::get($field, 'required'); $isRequired = $isRequired ? 'is-required' : ''; $textTypes = ['text', 'email', 'password']; $html = '
'; if ($label = Arr::get($field, 'label')) { $html .= '
'; } if (in_array($fieldType, $textTypes)) { $inputAtts = array_filter([ 'type' => esc_attr($fieldType), 'id' => esc_attr(Arr::get($field, 'id')), 'placeholder' => esc_attr(Arr::get($field, 'placeholder')), 'name' => esc_attr($fieldName) ]); $atts = ''; foreach ($inputAtts as $attKey => $att) { $atts .= $attKey . '="' . $att . '" '; } if (Arr::get($field, 'required')) { $atts .= 'required'; } $html .= '
'; } else { return ''; } return $html . '
'; } public static function getSignupFields() { return apply_filters('fluent_support/registration_form_fields', [ 'first_name' => [ 'required' => true, 'type' => 'text', 'label' => __('First name', 'fluent-support'), 'id' => 'fst_first_name', 'placeholder' => __('First name', 'fluent-support') ], 'last_name' => [ 'type' => 'text', 'label' => __('Last Name', 'fluent-support'), 'id' => 'fst_last_name', 'placeholder' => __('Last name', 'fluent-support') ], 'username' => [ 'required' => true, 'type' => 'text', 'label' => __('Username', 'fluent-support'), 'id' => 'fst_username', 'placeholder' => __('Username', 'fluent-support') ], 'email' => [ 'required' => true, 'type' => 'email', 'label' => __('Email Address', 'fluent-support'), 'id' => 'fst_email', 'placeholder' => __('Your Email Address', 'fluent-support') ], 'password' => [ 'required' => true, 'type' => 'password', 'label' => __('Password', 'fluent-support'), 'id' => 'fst_password', 'placeholder' => __('Password', 'fluent-support') ] ]); } protected function submitBtnLoadingSvg() { $loadingIcon = ' '; return apply_filters('fluent-support/signup_loading_icon', $loadingIcon); } protected function getShortcodes($attributes) { $shortCodeDefaults = apply_filters('fluent-support/auth_shortcode_defaults', [ 'auto-redirect' => false, 'redirect-to' => Helper::getPortalBaseUrl(), 'hide' => false, 'show-signup' => false ]); return shortcode_atts($shortCodeDefaults, $attributes); } protected function handleAlreadyLoggedIn($attributes) { if (get_current_user_id() && !wp_is_json_request() && is_singular()) { if ($attributes['auto-redirect'] === 'true') { $redirect = $attributes['redirect-to']; ?>