ID . ': ' . $e->getMessage()); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log } } } } } // Remove fcom_action and fcom_url_hash from the current url $currentUrl = home_url(add_query_arg($_GET, $GLOBALS['wp']->request)); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $url = remove_query_arg(['fcom_action', 'fcom_url_hash'], $currentUrl); wp_redirect($url, 302); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect exit(); } public function viewAuthPage() { add_filter('login_form_defaults', function ($defaults) { $defaults['label_username'] = __('Email Address', 'fluent-community'); return $defaults; }); add_filter('fluent_community/has_color_scheme', '__return_false'); $currentUserId = get_current_user_id(); // check if there has any invitation token $inivtationToken = Arr::get($_GET, 'invitation_token'); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $inviation = null; if ($inivtationToken) { $inviation = apply_filters('fluent_community/auth/invitation', null, $inivtationToken); if ($inviation && !$inviation->isValid()) { $inviation = null; } } if ($currentUserId && !$inviation) { $redirectUrl = null; if (!empty($_REQUEST['redirect_to'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $redirectUrl = sanitize_url(wp_unslash($_REQUEST['redirect_to'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } if (!$redirectUrl) { $redirectUrl = Helper::baseUrl(); } wp_safe_redirect($redirectUrl); exit(); } if ($currentUserId && $inviation) { /** @var BaseSpace|null $space */ $space = BaseSpace::withoutGlobalScopes()->find($inviation->post_id); if ($space) { if (Helper::isUserInSpace($currentUserId, $inviation->post_id)) { // let's redirect the user to the space $redirectUrl = $space->getPermalink(); wp_safe_redirect($redirectUrl); exit(); } if (!empty($_REQUEST['auto_accept'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $redirectUrl = (new InvitationHandler())->handleInvitationLogin(Helper::baseUrl(), get_user_by('ID', $currentUserId), $inviation->message_rendered); if (is_wp_error($redirectUrl) || !$redirectUrl) { $redirectUrl = Helper::baseUrl(); } wp_safe_redirect($redirectUrl); exit(); } } } do_action('fluent_community/auth/before_auth_page_process', $currentUserId, $inviation); $acceptedForms = ['login', 'register', 'reset_password']; $targetForm = Arr::get($_GET, 'form'); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $explicitForm = in_array($targetForm, $acceptedForms, true); if (!$explicitForm) { $targetForm = 'login'; } if ($inviation && !$explicitForm) { if ($inviation->message) { $isUserAvailable = get_user_by('email', $inviation->message); $targetForm = $isUserAvailable ? 'login' : 'register'; } else { $targetForm = 'register'; } } if ($inviation && $currentUserId && $inviation->isValid()) { if ($inviation->message) { $invitedUser = get_user_by('email', $inviation->message); if ($invitedUser && $invitedUser->ID == $currentUserId) { $targetForm = 'accept_invitation'; } } else { $targetForm = 'accept_invitation'; } } $isFluentAuth = AuthHelper::isFluentAuthAvailable(); if (!$isFluentAuth && $targetForm == 'reset_password') { wp_safe_redirect(wp_lostpassword_url(Helper::baseUrl())); exit(); } $portalSettings = Helper::generalSettings(); $titleVar = Arr::get($portalSettings, 'site_title'); $frameData = [ 'logo' => Arr::get($portalSettings, 'logo', ''), /* translators: %s is replaced by the title of the site */ 'title' => sprintf(__('Join %s', 'fluent-community'), $titleVar), 'description' => __('Login or Signup to join the community', 'fluent-community'), 'button_label' => __('Login', 'fluent-community'), ]; if ($targetForm == 'register') { $frameData['button_label'] = __('Signup', 'fluent-community'); if (!$inviation) { $customSignupUrl = Arr::get($portalSettings, 'custom_signup_url'); if ($customSignupUrl) { wp_safe_redirect($customSignupUrl); exit(); } } } $currentUrl = home_url(add_query_arg($_GET, $GLOBALS['wp']->request)); // phpcs:ignore WordPress.Security.NonceVerification.Recommended do_action('fluent_community/enqueue_global_assets', true); add_action('wp_enqueue_scripts', function () use ($isFluentAuth, $targetForm, $inviation) { wp_enqueue_style('fluent_auth_styles', Vite::getStaticSrcUrl('user_registration.css'), [], FLUENT_COMMUNITY_PLUGIN_VERSION); if(!$isFluentAuth || $targetForm == 'register' || $inviation) { wp_enqueue_script('fluent_auth_scripts', Vite::getStaticSrcUrl('user_registration.js'), [], FLUENT_COMMUNITY_PLUGIN_VERSION, true); wp_localize_script('fluent_auth_scripts', 'fluentComRegistration', array( 'ajax_url' => admin_url('admin-ajax.php'), 'is_logged_in' => is_user_logged_in(), 'redirecting_text' => __('Redirecting...', 'fluent-community') )); } }, 10); $pageVars = [ 'title' => $frameData['title'], 'og_title' => $frameData['title'], 'description' => $frameData['description'], 'url' => $currentUrl, 'featured_image' => '', 'css_files' => [], 'js_files' => [], 'js_vars' => [], 'scope' => 'user_registration', 'layout' => 'signup', 'portal' => [ 'logo' => Arr::get($portalSettings, 'logo', ''), /* translators: %s is replaced by the title of the site */ 'title' => \sprintf(__('Welcome to %s', 'fluent-community'), Arr::get($portalSettings, 'site_title')), 'description' => get_bloginfo('description') ] ]; if (Utility::isDev()) { $pageVars['js_files'] = [ Vite::getStaticSrcUrl('public/js/user_registration.js') ]; } $formType = ($targetForm == 'register') ? 'signup' : 'login'; $formSettings = AuthenticationService::getFormattedAuthSettings($formType); if ($formSettings) { $pageVars['portal'] = Arr::get($formSettings, 'banner'); $pageVars['portal']['form'] = Arr::get($formSettings, 'form'); } add_action('fluent_community/headless/content', function ($context) use ($targetForm, $currentUrl, $frameData, $inviation, $formSettings) { $preContent = apply_filters('fluent_community/auth/pre_content', '', $context, $targetForm, $frameData); if ($preContent) { return; } if ($targetForm == 'login') { $frameData['button_label'] = Arr::get($formSettings, 'form.button_label', __('Login', 'fluent-community')); $this->showLoginForm($frameData, $inviation); } else if ($targetForm == 'reset_password') { $frameData['title'] = __('Reset your password', 'fluent-community'); ?>
' . __('You have successfully registered to the community', 'fluent-community') . '
' . __('You have successfully logged in to the community', 'fluent-community') . '