name="_wu_force_elements_loading" />
post_name, $url); } return $url; } /** * Get an error message. * * @since 2.0.0 * * @param string $error_code The error code. * @param string $username The username. * @return string */ public function get_error_message($error_code, $username = '') { $messages = array( 'incorrect_password' => sprintf(__('Error: The password you entered is incorrect.', 'wp-ultimo')), // From here we are using the same messages as WordPress core. 'expired' => __('Your session has expired. Please log in to continue where you left off.'), 'confirm' => sprintf(__('Check your email for the confirmation link, then visit the login page.'), wp_login_url()), 'registered' => sprintf(__('Registration complete. Please check your email, then visit the login page.'), wp_login_url()), 'loggedout' => __('You are now logged out.'), 'registerdisabled' => __('Error: User registration is currently not allowed.'), 'empty_username' => __('Error: The username field is empty.'), 'empty_password' => __('Error: The password field is empty.'), 'invalid_email' => __('Unknown email address. Check again or try your username.'), 'invalid_username' => sprintf(__('Error: The username %s is not registered on this site. If you are unsure of your username, try your email address instead.'), $username), 'invalidcombo' => __('Error: There is no account with that username or email address.'), 'password_reset_empty_space' => __('The password cannot be a space or all spaces.'), 'password_reset_mismatch' => __('Error: The passwords do not match.'), 'invalidkey' => __('Error: Your password reset link appears to be invalid. Please request a new link below.'), 'expiredkey' => __('Error: Your password reset link has expired. Please request a new link below.'), ); /** * Filter the error messages. * * @since 2.1.1 * @param array $messages The error messages. * @return array */ $messages = apply_filters('wu_checkout_pages_error_messages', $messages); return wu_get_isset($messages, $error_code, __('Something went wrong', 'wp-ultimo')); } /** * Handle password reset errors. * * We redirect users to our custom login URL, * so we can add an error message. * * @since 2.0.0 * * @param \WP_Error $errors The error object. * @return void */ public function maybe_handle_password_reset_errors($errors) { if ($errors->has_errors()) { $url = add_query_arg( array( 'action' => wu_request('action', ''), 'user_login' => wu_request('user_login', ''), 'error' => $errors->get_error_code(), ), wp_login_url() ); wp_redirect($url); exit; } } /** * Maybe redirects users to the confirm screen. * * If we are successful in resetting a password, * we need to prevent the user from reaching the empty * wp-login.php message, so we redirect them to the passed * redirect_to query argument. * * @since 2.0.0 * @return void */ public function maybe_redirect_to_confirm_screen() { if (wu_request('redirect_to')) { wp_redirect(wu_request('redirect_to')); exit; } } /** * Replace the reset password link, if necessary. * * @since 2.0.0 * * @param string $message The email message. * @param string $key The reset key. * @param string $user_login The user login. * @param array $user_data The user data array. * @return string */ public function replace_reset_password_link($message, $key, $user_login, $user_data) { if ( ! is_main_site()) { return $message; } $results = array(); preg_match_all('/.*\/wp-login\.php.*/', $message, $results); $switched_locale = false; if (isset($results[0][0])) { // Localize password reset message content for user. $locale = get_user_locale($user_data); $switched_locale = switch_to_locale($locale); $new_url = add_query_arg( array( 'action' => 'rp', 'key' => $key, 'login' => rawurlencode($user_login), 'wp_lang' => $locale, ), wp_login_url() ); $new_url = set_url_scheme($new_url, null); $message = str_replace($results[0], $new_url, $message); } if ($switched_locale) { restore_previous_locale(); } return $message; } /** * Redirect logged users when they reach the login page. * * @since 2.0.0 * @return void */ public function maybe_redirect_to_admin_panel() { global $post; if ( ! is_user_logged_in()) { return; } $custom_login_page = $this->get_signup_page('login'); if (empty($custom_login_page) || empty($post)) { return; } if ($custom_login_page->ID !== $post->ID) { return; } /** * Create an exclusion list of parameters that prevent the auto-redirect. * * This is needed because otherwise page builder won't be able to * edit the login page once it is defined. * * @since 2.0.4 * @return array */ $exclusion_list = apply_filters( 'wu_maybe_redirect_to_admin_panel_exclusion_list', array( 'preview', // WordPress Preview 'ct_builder', // Oxygen Builder 'fl_builder', // Beaver Builder 'elementor-preview', // Elementor 'brizy-edit', // Brizy 'brizy-edit-iframe', // Brizy ), $custom_login_page, $post, $this ); foreach ($exclusion_list as $exclusion_param) { if (wu_request($exclusion_param, null) !== null) { return; } } $user = wp_get_current_user(); $active_blog = get_active_blog_for_user($user->ID); $redirect_to = $active_blog ? get_admin_url($active_blog->blog_id) : false; if (isset($_GET['redirect_to'])) { $redirect_to = $_GET['redirect_to']; } elseif (is_multisite() && ! get_active_blog_for_user($user->ID) && ! is_super_admin($user->ID)) { $redirect_to = user_admin_url(); } elseif (is_multisite() && ! $user->has_cap('read')) { $redirect_to = get_dashboard_url($user->ID); } elseif ( ! $user->has_cap('edit_posts')) { $redirect_to = $user->has_cap('read') ? admin_url('profile.php') : home_url(); } if ( ! $redirect_to) { return; } wp_redirect($redirect_to); exit; } /** * Adds the unverified email account error message. * * @since 2.0.0 * * @param \WP_Ultimo\Models\Payment $payment The current payment. * @param \WP_Ultimo\Models\Membership $membership the current membership. * @param \WP_Ultimo\Models\Customer $customer the current customer. * @return void */ public function add_verify_email_notice($payment, $membership, $customer) { if ($payment->get_total() == 0 && $customer->get_email_verification() === 'pending') { $html = '
%s
'; $message = __('Your email address is not yet verified. Your site will only be activated after your email address is verified. Check your inbox and verify your email address.', 'wp-ultimo'); $message .= sprintf('
%s', __('Resend verification email →', 'wp-ultimo')); printf($html, $message); } } /** * Check if we should obfuscate the login URL. * * @since 2.0.0 * @return void */ public function maybe_obfuscate_login_url() { $use_custom_login = wu_get_setting('enable_custom_login_page', false); if ( ! $use_custom_login) { return; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { return; } if (wu_request('interim-login')) { return; } if (wu_request('action') === 'logout') { return; } $new_login_url = $this->get_page_url('login'); if ( ! $new_login_url) { return; } $should_obfuscate = wu_get_setting('obfuscate_original_login_url', 1); $bypass_obfuscation = wu_request('wu_bypass_obfuscation'); if ($should_obfuscate && ! $bypass_obfuscation) { status_header(404); nocache_headers(); global $wp_query; $wp_query->set_404(); include get_404_template(); die; } else { wp_redirect($new_login_url); exit; } } /** * Redirects the customers to the registration page, when one is used. * * @since 2.0.0 * @return void */ public function redirect_to_registration_page() { $registration_url = $this->get_page_url('register'); if ($registration_url) { wp_redirect($registration_url); exit; } } /** * Filters the login URL if necessary. * * @since 2.0.0 * * @param string $login_url Original login URL. * @param string $redirect URL to redirect to after login. * @param bool $force_reauth If we need to force reauth. * @return string */ public function filter_login_url($login_url, $redirect, $force_reauth = false) { /** * Fix incompatibility with UIPress, making sure we only filter after wp_loaded ran. */ if ( ! did_action('wp_loaded')) { return $login_url; } $function_caller = wu_get_function_caller(5); if ($function_caller === 'wp_auth_check_html') { return $login_url; } $params = array(); $old_url_params = wp_parse_url($login_url, PHP_URL_QUERY); wp_parse_str($old_url_params, $params); $new_login_url = $this->get_page_url('login'); if ( ! $new_login_url) { return $login_url; } if ($params) { $new_login_url = add_query_arg($params, $new_login_url); } if ($redirect) { $new_login_url = add_query_arg('redirect_to', urlencode($redirect), $new_login_url); } if ($force_reauth) { $new_login_url = add_query_arg('reauth', 1, $new_login_url); } return $new_login_url; } /** * Returns the ID of the pages being used for each WP Multisite WaaS purpose. * * @since 2.0.0 * @return array */ public function get_signup_pages() { return array( 'register' => wu_guess_registration_page(), 'update' => wu_get_setting('default_update_page', false), 'login' => wu_get_setting('default_login_page', false), 'block_frontend' => wu_get_setting('default_block_frontend_page', false), 'new_site' => wu_get_setting('default_new_site_page', false), ); } /** * Returns the WP_Post object for one of the pages. * * @since 2.0.0 * * @param string $page The slug of the page to retrieve. * @return \WP_Post|false */ public function get_signup_page($page) { $pages = $this->get_signup_pages(); $page_id = wu_get_isset($pages, $page); if ( ! $page_id) { return false; } return get_blog_post(wu_get_main_site_id(), $page_id); } /** * Returns the URL for a particular page type. * * @since 2.0.0 * * @param string $page_slug The signup page to get. * @return string|false */ public function get_page_url($page_slug = 'login') { $page = $this->get_signup_page($page_slug); if ( ! $page) { return false; } return wu_switch_blog_and_run(fn() => get_the_permalink($page)); } /** * Tags the WP Multisite WaaS pages on the main site. * * @since 2.0.0 * * @param array $states The previous states of that page. * @param \WP_Post $post The current post. * @return array */ public function add_wp_ultimo_status_annotation($states, $post) { if ( ! is_main_site()) { return $states; } $labels = array( 'register' => __('WP Multisite WaaS - Register Page', 'wp-ultimo'), 'login' => __('WP Multisite WaaS - Login Page', 'wp-ultimo'), 'block_frontend' => __('WP Multisite WaaS - Site Blocked Page', 'wp-ultimo'), 'update' => __('WP Multisite WaaS - Membership Update Page', 'wp-ultimo'), 'new_site' => __('WP Multisite WaaS - New Site Page', 'wp-ultimo'), ); $pages = array_map('absint', $this->get_signup_pages()); if (in_array($post->ID, $pages, true)) { $key = array_search($post->ID, $pages, true); $states['wp_ultimo_page'] = wu_get_isset($labels, $key); } return $states; } /** * Renders the confirmation page. * * @since 2.0.0 * * @param array $atts Shortcode attributes. * @param null|string $content The post content. * @return string */ public function render_confirmation_page($atts, $content = null) { return wu_get_template_contents( 'checkout/confirmation', array( 'errors' => Checkout::get_instance()->errors, 'membership' => wu_get_membership_by_hash(wu_request('membership')), ) ); } }