options = $options; add_action( 'admin_init', [ $this, 'init' ] ); } /** * Option keys that only the Pro settings UI writes. * * @return string[] */ protected function get_pro_only_option_keys(): array { return [ 'lockout_time', 'lockout_count', 'hide_login_form' ]; } /** * Start the engine running * * @return void */ public function init() { $this->settings_options = [ [ 'option_group' => Block_Login::MENU_SLUG, 'option_name' => Block_Login::OPTION_NAME, 'args' => [ 'sanitize_callback' => [ $this, 'sanitize_settings' ] ], ], ]; $this->settings_sections = [ 'free' => [ 'id' => 'adminoptimizer-block-login', 'title' => '', 'description' => '', 'menu_slug' => Block_Login::MENU_SLUG, 'option_name' => Block_Login::OPTION_NAME, 'fields' => [ [ 'type' => 'number', 'title' => __( 'Failed Login Attempts', 'admin-optimizer' ), 'id' => 'failed-login-attempts', 'name' => 'failed_count', 'min' => '1', 'max' => '10', 'default' => '3', 'desc' => __( 'Number of failed login attempts before 15 minutes lockout.', 'admin-optimizer' ), ], ], ], ]; if ( $this->is_pro_active() ) { $this->settings_sections = $this->inject_pro_fields( $this->settings_sections, 'adminoptimizer-block-login', [ [ 'type' => 'number', 'title' => __( 'Lockout Time', 'admin-optimizer' ), 'id' => 'lockout-time', 'name' => 'lockout_time', 'min' => '1', 'max' => '100', 'default' => '15', 'desc' => __( 'The lock out time (in minutes) before the user can log in again. Allowed value is between 1 to 100', 'admin-optimizer' ), ], [ 'type' => 'number', 'title' => __( 'Total Lockout', 'admin-optimizer' ), 'id' => 'lockout-count', 'name' => 'lockout_count', 'min' => '1', 'max' => '10', 'default' => '3', 'desc' => __( 'Number of lockouts before activating a full login block for 24 hours.', 'admin-optimizer' ), ], [ 'type' => 'checkbox', 'title' => __( 'Hide Login form on Lockout', 'admin-optimizer' ), 'id' => 'hide-login-form', 'name' => 'hide_login_form', 'label' => __( 'Remove the login form from the page while an IP is locked out.', 'admin-optimizer' ), ], ] ); } else { $this->settings_sections['pro'] = [ 'id' => 'adminoptimizer-block-login-pro', 'title' => __( 'Pro Options', 'admin-optimizer' ), /* translators: %1$s is the anchor link to the Pro version. %2$s is the closing anchor tag */ 'description' => sprintf( __( 'Upgrade to the %1$sPro version%2$s to access these features', 'admin-optimizer' ), '', '' ), 'menu_slug' => Block_Login::MENU_SLUG . '_pro', 'option_name' => Block_Login::OPTION_NAME, 'args' => [ 'before_section' => '
', 'after_section' => '
', ], 'fields' => [ [ 'type' => 'number', 'title' => __( 'Lockout Time', 'admin-optimizer' ), 'id' => 'lockout-time', 'name' => 'lockout-time-free-disabled', 'min' => '1', 'max' => '100', 'default' => '15', 'disabled' => true, 'desc' => __( 'The lock out time (in minutes) before the user can log in again. Allowed value is between 1 to 100', 'admin-optimizer' ), ], [ 'type' => 'number', 'title' => __( 'Total Lockout', 'admin-optimizer' ), 'id' => 'lockout-count', 'name' => 'lockout-count-free-disabled', 'min' => '1', 'max' => '10', 'disabled' => true, 'desc' => __( 'Number of lockouts before activating a full login block for 24 hours.', 'admin-optimizer' ), ], [ 'type' => 'checkbox', 'title' => __( 'Hide Login form on Lockout', 'admin-optimizer' ), 'id' => 'hide-login-form', 'name' => 'hide-login-form-free-disabled', 'disabled' => true, 'desc' => '', ], ], ]; } $this->setup(); } /** * Render Settings page * * @return void */ public function render_settings_page() { ?>
render_settings_on_page( Block_Login::MENU_SLUG ); ?> is_pro_active() ) : ?> render_settings_on_page( Block_Login::MENU_SLUG . '_pro', [ 'remove_submit_button' => true ] ); ?>

prepare_items(); $lockout_table->display(); ?>
wp_create_nonce( 'adminoptim_block_login_action' ) ] ); wp_enqueue_style( 'adminoptim-modules-pro-settings' ); } /** * Callback function to sanitize settings before storing in database * * @param array|null $options Values to be sanitized. * * @return array */ public function sanitize_settings( $options ) { $sanitized_options = []; if ( is_array( $options ) ) { if ( isset( $options['failed_count'] ) ) { $sanitized_options['failed_count'] = absint( $options['failed_count'] ); } if ( $this->is_pro_active() ) { if ( isset( $options['lockout_time'] ) ) { $lockout_time = absint( $options['lockout_time'] ); if ( $lockout_time > 100 ) { $sanitized_options['lockout_time'] = 100; } elseif ( $lockout_time < 1 ) { $sanitized_options['lockout_time'] = 1; } else { $sanitized_options['lockout_time'] = $lockout_time; } } if ( isset( $options['lockout_count'] ) ) { $sanitized_options['lockout_count'] = absint( $options['lockout_count'] ); } if ( isset( $options['hide_login_form'] ) ) { $sanitized_options['hide_login_form'] = 1; } } } return $this->carry_forward_inactive_pro_keys( $sanitized_options ); } }