20) { add_settings_error('authcode_settings', 'authcode_code', 'Authentication code cannot be longer than 20 characters.', $type = 'error'); return false; } elseif(strlen($options['code']) < 3) { add_settings_error('authcode_settings', 'authcode_code', 'Authentication code cannot be shorter than 3 characters.', $type = 'error'); return false; } else { add_settings_error('authcode_settings', 'authcode_code', 'Settings saved.', $type = 'updated'); } } else { add_settings_error('authcode_settings', 'authcode_code', 'Authentication code has been disabled.', $type = 'updated'); } } return $options; } add_action('admin_notices', 'authcode_admin_notices'); function authcode_admin_notices() { settings_errors(); } function authcode_page() { ?>

Authentication Code

'; } } add_action( 'wp_authenticate', 'authcode_check', 5 ); function authcode_check($username) { $options = get_option( 'authcode_settings' ); if(!empty($options['code'])) { global $wpdb; if ( !username_exists( $username ) ) { return; } $set_code = $options['code']; $submit_code = $_POST['auth_key']; if(empty($submit_code)) { wp_die( __( 'The authentication code was empty.', 'authcode' ) ); } elseif ( ! ( $set_code == $submit_code ) ) { wp_die( __( 'The authentication code was invalid.', 'authcode' ) ); } } } function authcode_css() { $options = get_option( 'authcode_settings' ); if(!empty($options['code'])) { ?>