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() {
?>
',
esc_html__( 'Authentication Code', 'authcode' )
);
} );
add_filter( 'authenticate', function( $user ) {
$options = get_option( 'authcode_settings' );
$submit_code = filter_input( INPUT_POST, 'authcode_auth_key',
FILTER_SANITIZE_STRING );
if ( is_wp_error( $user ) ) {
return $user;
}
$is_valid_auth_code = ! empty( $options['code'] )
&& ( $options['code'] === $submit_code );
if( ! $is_valid_auth_code )
$user = new WP_Error(
'invalid_auth_code',
sprintf(
'%s: %s',
esc_html__( 'ERROR', 'authcode' ),
esc_html__( 'Authentication code is invalid.', 'authcode' )
)
);
return $user;
}, 100 );
add_action( 'login_head', function() { echo ''; });
}
}
do_authcode();
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), function($link) {
return array_merge( $link, array('Donate') );
} );