blic function dismiss_onboarding_popup_callback() { $this->check_user_capabilities(); check_ajax_referer( 'llar-dismiss-onboarding-popup', 'sec' ); Config::update( 'onboarding_popup_shown', true ); wp_send_json_success(); } public function get_remaining_attempts_message_callback() { check_ajax_referer( 'llar-get-remaining-attempts-message', 'sec' ); if ( ! session_id() ) { session_start(); } $remaining = ! empty( $_SESSION['login_attempts_left'] ) ? (int)$_SESSION['login_attempts_left'] : 0; if ( ! empty( $remaining ) && $remaining > 0 ) { $message = sprintf( _n( "%d attempt remaining.", "%d attempts remaining.", $remaining, 'limit-login-attempts-reloaded' ), $remaining ); wp_send_json_success( $message ); } else { wp_send_json_error(); } } public function onboarding_reset_callback() { if ( ! LimitLoginAttempts::$instance->has_capability ) { wp_send_json_error( array() ); } check_ajax_referer( 'llar-action-onboarding-reset', 'sec' ); if ( Config::get( 'active_app' ) !== 'local' || ! empty( Config::get( 'app_setup_code' ) ) ) { wp_send_json_error( array() ); } Config::update( 'onboarding_popup_shown', 0 ); wp_send_json_success(); } public function close_premium_message() { check_ajax_referer( 'llar-close-premium-message', 'sec' ); Config::update( 'notifications_message_shown', strtotime( '+1 day' ) ); wp_send_json_success(); } public function activate_micro_cloud_callback() { if ( ! LimitLoginAttempts::$instance->has_capability ) { wp_send_json_error( array('msg' => 'Wrong country code.') ); } check_ajax_referer( 'llar-activate-micro-cloud', 'sec' ); $email = sanitize_text_field( trim( $_POST['email'] ) ); if ( ! empty( $email ) && is_email( $email ) ) { $url_api = defined( 'LLAR_MC_URL' ) ? LLAR_MC_URL : 'https://api.limitloginattempts.com/checkout/network'; $data = [ 'group' => 'free', 'email' => $email ]; $response = Http::post( $url_api, array( 'data' => $data ) ); if ( ! empty( $response['error'] ) ) { wp_send_json_error( $response['error'] ); } else { $response_body = json_decode( $response['data'], true ); if ( ! empty( $response_body['setup_code'] ) ) { if ( $key_result = CloudApp::activate_license_key( $response_body['setup_code'] ) ) { if ( $key_result['success'] ) { wp_send_json_success( array( 'msg' => ( $key_result ) ) ); } else { wp_send_json_error( array( 'msg' => ( $key_result ) ) ); } } else { wp_send_json_error( array( 'msg' => $key_result['error'] ) ); } } } } wp_send_json_error( array() ); } public function toggle_auto_update_callback() { $this->check_user_capabilities(); if ( Helpers::is_block_automatic_update_disabled() ) { wp_send_json_error( array( 'msg' => 'Can\'t turn auto-updates on. Please ask your hosting provider or developer for assistance.') ); } check_ajax_referer( 'llar-toggle-auto-update', 'sec' ); $value = sanitize_text_field( $_POST['value'] ); $auto_update_plugins = get_site_option( 'auto_update_plugins', array() ); if( $value === 'yes' ) { $auto_update_plugins[] = LLA_PLUGIN_BASENAME; Config::update( 'auto_update_choice', 1 ); } else if ( $value === 'no' ) { if ( ( $key = array_search( LLA_PLUGIN_BASENAME, $auto_update_plugins ) ) !== false ) { unset($auto_update_plugins[$key]); } Config::update( 'auto_update_choice', 0 ); } update_site_option( 'auto_update_plugins', $auto_update_plugins ); wp_send_json_success(); } public function test_email_notifications_callback() { $this->check_user_capabilities(); check_ajax_referer('llar-test-email-notifications', 'sec'); $to = sanitize_email( $_POST['email'] ); if( empty( $to ) || !is_email( $to ) ) { wp_send_json_error( array( 'msg' => __( 'Wrong email format.', 'limit-login-attempts-reloaded' ), ) ); } if( wp_mail( $to, __( 'LLAR Security Notifications [TEST]', 'limit-login-attempts-reloaded' ), __( 'Your email notifications for Limit Login Attempts Reloaded are working correctly. If this email is going to spam, please be sure to add this address to your safelist.', 'limit-login-attempts-reloaded' ) ) ) { wp_send_json_success(); } else { wp_send_json_error(); } } /** * Access capabilities checks */ private function check_user_capabilities() { if ( ! LimitLoginAttempts::$instance->has_capability ) { wp_send_json_error( array() ); } } }