username_whitelisted( $username ) { return $this->local_lockout->is_username_whitelisted( $username ); } public function is_ip_blacklisted( $ip = null ) { return $this->ip_resolver->is_ip_blacklisted( $ip ); } public function is_username_blacklisted( $username ) { return $this->local_lockout->is_username_blacklisted( $username ); } /** * Filter: allow login attempt? (called from wp_authenticate()) * * @param $user WP_User * @param $password * * @return WP_Error|WP_User */ public function wp_authenticate_user( $user, $password ) { return $this->auth_handler->wp_authenticate_user( $user, $password ); } /** * Filter: add this failure to login page "Shake it!" * * @param $error_codes * * @return array */ public function failure_shake( $error_codes ) { $error_codes[] = 'too_many_retries'; $error_codes[] = 'username_blacklisted'; return $error_codes; } /** * Keep track of if user or password are empty, to filter errors correctly * * @param $user * @param $username * @param $password */ public function track_credentials( $user, $username, $password ) { return $this->auth_handler->track_credentials( $user, $username, $password ); } /** * Construct informative error message * * @param string $username Optional username from the auth hook. * @return string * @throws Exception */ public function error_msg( $username = '' ) { return $this->error_presenter->error_msg( $username ); } /** * When returning from MFA with llar_mfa_error, inject an error so WordPress outputs the red #login_error block. * * @param \WP_Error $errors WP_Error object passed to login_header(). * @param string $redirect_to Redirect URL. * @return \WP_Error */ public function inject_mfa_return_login_error( $errors, $redirect_to ) { return $this->error_presenter->inject_mfa_return_login_error( $errors, $redirect_to ); } /** * Fix up the error message before showing it * * @param $content * * @return string */ public function fixup_error_messages( $content ) { return $this->error_presenter->fixup_error_messages( $content ); } public function fixup_error_messages_wc( \WP_Error $error ) { return $this->error_presenter->fixup_error_messages_wc( $error ); } /** * Get correct remote address * * @return string * */ public function get_address() { return $this->ip_resolver->get_address(); } /** * Clean up old lockouts and retries, and save supplied arrays * * @param null $retries * @param null $lockouts * @param null $valid */ public function cleanup( $retries = null, $lockouts = null, $valid = null ) { $this->local_lockout->cleanup( $retries, $lockouts, $valid ); } /** * Render admin options page */ public function options_page() { $this->admin_ui->options_page(); } /** * Render an admin notice view by key (e.g. 'auto-update', 'mfa-no-ssl'). * * @param string $notice_key Notice identifier. * @param array $args Variables to pass to the notice view. * @return void */ public function render_admin_notice( $notice_key, array $args = array() ) { if ( null === $this->admin_notices_controller ) { $this->admin_notices_controller = new AdminNoticesController(); } $this->admin_notices_controller->render( $notice_key, $args ); } /** * Show warning when MFA is enabled and rescue links need attention: no rescue payload transients, * or latest payload expiry is within RESCUE_NOTICE_THRESHOLD. Uses a short-lived cache for the * max-expiry query to avoid scanning wp_options on every admin page load. * * @return bool */ public function should_show_mfa_recovery_links_expired_notice() { if ( ! (bool) Config::get( 'mfa_enabled' ) ) { return false; } $seconds_left = $this->mfa_controller->get_rescue_links_seconds_left(); if ( null === $seconds_left ) { return true; } return $seconds_left <= MfaConstants::RESCUE_NOTICE_THRESHOLD; } public function show_message( $msg, $is_error = false ) { $this->pending_admin_message = array( 'msg' => $msg, 'is_error' => $is_error, ); } private function plan_name_match( $plan = 'default' ) { if ( ! array_key_exists( $plan, $this->plans ) ) { $plan = 'default'; } return $this->plans[ $plan ]['name']; } public function array_name_plans() { $plans = array(); foreach ( $this->plans as $plan ) { $plans[ $plan['name'] ] = $plan['rate']; } return $plans; } /** * Free trial length in days — the single source of truth for every * trial string in the plugin (titles, buttons, banners, plan name). */ const TRIAL_DAYS = 7; /** * Canonical (untranslated) trial plan name. Doubles as the logic key * compared against plan_name_match() output, so it must stay literal. * * @return string */ public static function trial_plan_name() { return sprintf( '%d Day Trial', self::TRIAL_DAYS ); } /** * Translated trial label for display (buttons, badges, banners). * * @return string */ public static function trial_label() { /* translators: %d: trial length in days. */ return sprintf( __( '%d Day Trial', 'limit-login-attempts-reloaded' ), self::TRIAL_DAYS ); } private function info() { if ( $this->info_attempted ) { return $this->info_data; } if ( self::$cloud_app ) { $this->info_attempted = true; $this->info_data = self::$cloud_app->info(); } return $this->info_data; } /** * Drop the per-request /info memo so the next call reflects updated config. */ public function reset_info_cache() { $this->info_data = array(); $this->info_attempted = false; } public function info_is_exhausted() { if ( Config::get( Config::OPTION_ACTIVE_APP ) !== 'custom' || ! self::$cloud_app ) { return false; } if ( is_array( $this->info_data ) && ! empty( $this->info_data ) ) { return $this->parse_mc_exhausted( $this->info_data ); } $cached = $this->is_plugin_ui_request() ? false : get_transient( self::mc_exhausted_cache_key() ); if ( false !== $cached ) { return '1' === $cached; } $info = $this->info(); if ( is_array( $info ) && ! empty( $info ) ) { return $this->parse_mc_exhausted( $info ); } return false; } private function parse_mc_exhausted( $info ) { $exhausted = isset( $info['requests']['exhausted'] ) ? filter_var( $info['requests']['exhausted'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) : false; $exhausted = null === $exhausted ? false : (bool) $exhausted; $this->cache_mc_exhausted( $exhausted ); return $exhausted; } private function cache_mc_exhausted( $exhausted ) { $key = self::mc_exhausted_cache_key(); $value = $exhausted ? '1' : '0'; if ( get_transient( $key ) === $value ) { return; } set_transient( $key, $value, $exhausted ? 12 * HOUR_IN_SECONDS : 15 * MINUTE_IN_SECONDS ); } /** * Drop the cached MC-exhausted flag (e.g. after the cloud app config changed). * * @param array|null $app_config Config to build the key for; the current one by default. */ public static function clear_mc_exhausted_cache( $app_config = null ) { delete_transient( self::mc_exhausted_cache_key( $app_config ) ); } private static function mc_exhausted_cache_key( $app_config = null ) { $app_config = is_array( $app_config ) ? $app_config : Config::get( 'app_config' ); $app_id = is_array( $app_config ) && ! empty( $app_config['id'] ) ? (string) $app_config['id'] : 'unknown'; return 'limit_login_mc_exhausted_' . md5( $app_id . '|' . get_current_blog_id() ); } private function is_plugin_ui_request() { if ( ! is_admin() || ! $this->has_capability ) { return false; } if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] === $this->_options_page_slug ) { return true; } global $pagenow; return 'index.php' === $pagenow && ! Config::get( 'hide_dashboard_widget' ); } /** * Whether /info reports the Micro Cloud quota as almost exhausted. * * @return bool */ public function info_is_almost_exhausted() { $info = $this->info(); return isset( $info['requests']['almost_exhausted'] ) ? filter_var( $info['requests']['almost_exhausted'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) : false; } /** * Whether /info returned usable quota and plan data for the dashboard UI. * * @return bool */ public function info_has_valid_data() { $info = $this->info(); if ( empty( $info ) || ! is_array( $info ) ) { return false; } if ( empty( $info['requests'] ) || ! is_array( $info['requests'] ) ) { return false; } return array_key_exists( 'quota', $info['requests'] ) && '' !== (string) $info['requests']['quota']; } /** * Cloud API responded to /info but access is denied (e.g. quota exhausted or unpaid domain). * * @return bool */ public function info_is_cloud_unavailable() { if ( ! self::$cloud_app ) { return false; } if ( $this->info_has_valid_data() ) { return false; } return ! self::$cloud_app->is_info_network_failure(); } public function info_requests() { $info = $this->info(); return ( ! empty( $info ) && ! empty( $info['requests'] ) ) ? $info['requests'] : ''; } public function info_sub_group() { $info = $this->info(); $data = ( ! empty( $info ) && ! empty( $info['sub_group'] ) ) ? $info['sub_group'] : ''; return $this->plan_name_match( $data ); } public function info_upgrade_url() { $info = $this->info(); return ( ! empty( $info ) && ! empty( $info['upgrade_url'] ) ) ? $info['upgrade_url'] : ''; } public function info_block_by_country() { $info = $this->info(); return ( ! empty( $info ) && ! empty( $info['block_by_country'] ) ) ? $info['block_by_country'] : ''; } /** * Public wrapper for llar_api_response to allow integrations to use it * Only allows calls from integration classes within this plugin * * @param string $user_data User data to check * @param BaseIntegration|null $integration Integration instance (optional, for security validation) * @return array API response */ public function check_registration_api( $user_data, $integration = null ) { return $this->registration_limiter->check_registration_api( $user_data, $integration ); } /** * Register new user standard WP */ public function llar_submit_login_form_register() { $this->registration_limiter->llar_submit_login_form_register(); } /** * Correcting errors in the presence of a registration prohibition marker * @param $errors * @param $sanitized_user_login * @param $user_email * * @return mixed */ public function llar_submit_registration_errors( $errors, $sanitized_user_login, $user_email ) { return $this->registration_limiter->llar_submit_registration_errors( $errors, $sanitized_user_login, $user_email ); } /** * Debug tab: foreign authenticate filter callbacks. * * @return array */ public static function get_foreign_authenticate_hooks() { return AuthenticateHooksInspector::get_foreign_authenticate_hooks(); } /** * Admin notice: leave a review (dashboard/plugins/LLAR screens). * * @return void */ public function render_leave_review_admin_notice() { $screen = get_current_screen(); if ( isset( $_COOKIE['llar_review_notice_shown'] ) ) { Config::update( 'review_notice_shown', true ); @setcookie( 'llar_review_notice_shown', '', time() - 3600, '/' ); } if ( ! $this->has_capability || Config::get( 'review_notice_shown' ) || ! $screen || ! in_array( $screen->base, array( 'dashboard', 'plugins', 'toplevel_page_limit-login-attempts' ), true ) ) { return; } $activation_timestamp = Config::get( 'activation_timestamp' ); if ( ! $activation_timestamp || $activation_timestamp >= strtotime( '-1 month' ) ) { return; } $this->admin_notices_controller->render( 'leave-review' ); } }