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); $this->redirectAndExit($url); } /** * Send a redirect and stop. * * Extracted only so it can be observed: a bare `exit()` terminates the PHP * process, which in a test run kills the whole suite with no result (see * FIX-PLAN item 22 for the same problem on PortalHandler). A test subclass * overrides this and the two methods below to record what was about to * happen and throw instead. Behaviour in production is unchanged — this is * the original call, moved. * * This one keeps the UNSAFE variant its single caller already used. That * caller builds its target with home_url(), so it is same-host by * construction rather than by validation. Kept as a separate method from * safeRedirectAndExit(), rather than a $safe flag, so the distinction stays * visible to anyone grepping for wp_redirect. */ protected function redirectAndExit($url, $status = 302) { wp_redirect($url, $status); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect exit(); } /** * Send a host-confined redirect and stop. See redirectAndExit(). */ protected function safeRedirectAndExit($url) { wp_safe_redirect($url); exit(); } /** * Render the headless page and stop. See redirectAndExit(). */ protected function renderPageAndExit($template, $pageVars) { status_header(200); App::make('view')->render($template, $pageVars); exit(200); } 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(); } $this->safeRedirectAndExit($redirectUrl); } 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(); $this->safeRedirectAndExit($redirectUrl); } 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(); } $this->safeRedirectAndExit($redirectUrl); } } } 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') { $this->safeRedirectAndExit(wp_lostpassword_url(Helper::baseUrl())); } $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) { $this->safeRedirectAndExit($customSignupUrl); } } } $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'), 'i18n' => [ 'generic_error' => esc_html__('Something went wrong. Please try again later', 'fluent-community'), 'network_error' => esc_html__('Could not reach the server. Please check your connection and try again.', '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') . '