AI Verified

Name

Custom Wordpress Register by User with Shortcode

About

This script allows you to create an advanced and customizable registration form for your WordPress website. It includes fields for entering first name, last name, and email address, with the email address used as the username. The password must meet certain security requirements, and upon successful registration, the user receives a custom email notification. The script can be inserted in the functions.php file of your theme or in a custom plugin, and the form can be displayed on a page or post using the shortcode [registrierungsformular].

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

jbeer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

16/04/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Potential vulnerability found : Insecure E-mail
Found on line : -1
Code : mail(= sanitize_email($_POST['email'])

Potential vulnerability found : Insecure E-mail
Found on line : 166
Code : mail($user->user_email, $email_data['subject'], $email_data['message'], $email_data['headers'])
Vulnerable line : 166
Code : $email_data = custom_wp_new_user_notification_email(array(), $user, get_bloginfo('name')));

Potential vulnerability found : Insecure E-mail
Found on line : 166
Code : mail($user->user_email, $email_data['subject'], $email_data['message'], $email_data['headers'])
Vulnerable line : 166
Code : $email_data = custom_wp_new_user_notification_email(array(), $user, get_bloginfo('name')));

Potential vulnerability found : Insecure E-mail
Found on line : 166
Code : mail($user->user_email, $email_data['subject'], $email_data['message'], $email_data['headers'])
Vulnerable line : 166
Code : $email_data = custom_wp_new_user_notification_email(array(), $user, get_bloginfo('name')));

Found 4 vulnerabilities

Custom Wordpress Register by User with Shortcode

 
                    
1function registrierungsformular() {
2 // Prüfen, ob der Benutzer bereits angemeldet ist
3 if (is_user_logged_in()) {
4 return 'Du bist bereits registriert und angemeldet.';
5 }
6 
7 // Formular-HTML
8 $form_html = '
9 <style>
10 .registrierungsformular {
11 font-family: "Nunito", sans-serif;
12 }
13 
14 .registrierungsformular p {
15 position: relative;
16 width: 100%;
17 }
18 
19 .registrierungsformular input[type="text"],
20 .registrierungsformular input[type="email"],
21 .registrierungsformular input[type="password"] {
22 color: black;
23 width: 100%;
24 }
25 
26 .registrierungsformular input[type="text"]::placeholder,
27 .registrierungsformular input[type="email"]::placeholder,
28 .registrierungsformular input[type="password"]::placeholder {
29 color: black;
30 opacity: 1;
31 }
32 
33 .registrierungsformular input[type="submit"] {
34 background-color: #662029;
35 border: none;
36 border-radius: 4px;
37 color: white;
38 cursor: pointer;
39 font-size: 16px;
40 margin: 0 auto;
41 padding: 10px;
42 text-align: center;
43 width: 100%;
44 }
45 
46 .registrierungsformular .errors {
47 color: red;
48 font-size: 14px;
49 margin-top: 5px;
50 }
51 
52 .toggle-password {
53 cursor: pointer;
54 height: 15px;
55 position: absolute;
56 right: 10px;
57 top: 50%;
58 transform: translateY(-50%);
59 width: 24px;
60 }
61 </style>
62 <script>
63 document.addEventListener("DOMContentLoaded", function() {
64 var toggles = document.querySelectorAll(".toggle-password");
65 
66 toggles.forEach(function(toggle) {
67 toggle.addEventListener("click", function() {
68 var input = this.previousElementSibling;
69 input.type = input.type === "password" ? "text" : "password";
70 });
71 });
72 });
73 </script>
74 <form id="registrierungsformular" class="registrierungsformular" action="' . esc_url($_SERVER['REQUEST_URI']) . '" method="post">
75 <p>
76 <input type="text" name="first_name" id="first_name" placeholder="Vorname" required>
77</p>
78<p>
79<input type="text" name="last_name" id="last_name" placeholder="Nachname" required>
80</p>
81<p>
82<input type="email" name="email" id="email" placeholder="E-Mail" required>
83</p>
84<p>
85<input type="password" name="password" id="password" placeholder="Passwort" required>
86<span class="toggle-password"></span>
87</p>
88<p>
89<input type="password" name="password_confirm" id="password_confirm" placeholder="Passwort bestätigen" required>
90<span class="toggle-password"></span>
91</p>
92<p>
93<input type="submit" name="submit" value="Registrierieren">
94</p>
95</form>';
96 
97// Registrierungsfunktion aufrufen
98if (isset($_POST['submit'])) {
99$first_name = sanitize_text_field($_POST['first_name']);
100$last_name = sanitize_text_field($_POST['last_name']);
101$email = sanitize_email($_POST['email']);
102$password = $_POST['password'];
103$password_confirm = $_POST['password_confirm'];
104 
105$errors = registrierungsformular_registrieren($first_name, $last_name, $email, $password, $password_confirm);
106 
107if (!empty($errors)) {
108 $form_html .= '<ul class="errors">';
109 foreach ($errors as $error) {
110 $form_html .= '<li>' . $error . '</li>';
111 }
112 $form_html .= '</ul>';
113} else {
114 $form_html = 'Vielen Dank für Ihre Registrierung. Sie können sich jetzt <a href="' . wp_login_url() . '">einloggen</a>.';
115}
116}
117return $form_html;
118 
119}
120 
121// Funktion, die die Registrierung durchführt
122function registrierungsformular_registrieren($first_name, $last_name, $email, $password, $password_confirm) {
123$errors = array();
124 
125if (email_exists($email)) {
126$errors[] = 'Die E-Mail-Adresse ist bereits vergeben.';
127}
128 
129if ($password !== $password_confirm) {
130$errors[] = 'Die Passwörter stimmen nicht überein.';
131}
132 
133// Passwortsicherheit überprüfen
134$min_length = 8;
135$has_upper = preg_match('/[A-Z]/', $password);
136$has_lower = preg_match('/[a-z]/', $password);
137$has_digit = preg_match('/\d/', $password);
138$has_special = preg_match('/[^a-zA-Z\d]/', $password);
139 
140if (strlen($password) < $min_length) {
141$errors[] = 'Das Passwort muss mindestens ' . $min_length . ' Zeichen lang sein.';
142}
143if (!$has_upper) {
144$errors[] = 'Das Passwort muss mindestens einen Großbuchstaben enthalten.';
145}
146if (!$has_lower) {
147$errors[] = 'Das Passwort muss mindestens einen Kleinbuchstaben enthalten.';
148}
149if (!$has_digit) {
150$errors[] = 'Das Passwort muss mindestens eine Ziffer enthalten.';
151}
152if (!$has_special) {
153$errors[] = 'Das Passwort muss mindestens ein Sonderzeichen enthalten.';
154}
155 
156if (empty($errors)) {
157$user_id = wp_create_user($email, $password, $email);
158if (is_wp_error($user_id)) {
159 $errors[] = 'Es gab einen Fehler bei der Registrierung. Bitte versuche es später erneut.';
160} else {
161 // Vor- und Nachnamen hinzufügen
162 wp_update_user(array('ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name));
163 
164 // Benutzerdefinierte Registrierungs-E-Mail senden
165 $user = get_userdata($user_id);
166 $email_data = custom_wp_new_user_notification_email(array(), $user, get_bloginfo('name'));
167 wp_mail($user->user_email, $email_data['subject'], $email_data['message'], $email_data['headers']);
168}
169}
170return $errors;
171 
172}
173 
174// Benutzerdefinierte Registrierungs-E-Mail
175function custom_wp_new_user_notification_email($wp_new_user_notification_email, $user, $blogname) {
176 $key = get_password_reset_key($user);
177 $message = sprintf(__('Hallo %s,'), $user->user_login) . "\r\n\r\n";
178 $message .= __('Vielen Dank für Ihre Registrierung bei') . ' ' . $blogname . ".\r\n\r\n";
179 $message .= __('Um die Registrierung abzuschließen und Ihr Konto zu aktivieren, klicken Sie bitte auf den folgenden Link:') . "\r\n\r\n";
180 $message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . "\r\n\r\n";
181 $message .= __('Wenn Sie Probleme beim Klicken auf den Aktivierungslink haben, kopieren Sie bitte die URL und fügen Sie sie direkt in die Adressleiste Ihres Browsers ein.') . "\r\n\r\n";
182 $message .= __('Sobald Ihr Konto aktiviert ist, können Sie sich mit Ihren Anmeldedaten anmelden und alle Funktionen unserer Website nutzen.') . "\r\n\r\n";
183 $message .= __('Mit freundlichen Grüßen,') . "\r\n";
184 $message .= $blogname . __(' Team');
185 
186 $wp_new_user_notification_email = array(
187 'to' => $user->user_email,
188 'subject' => '[' . $blogname . '] ' . __('Aktivieren Sie Ihr Konto'),
189 'message' => $message,
190 'headers' => ''
191 );
192 
193 return $wp_new_user_notification_email;
194}
195 
196add_filter('wp_new_user_notification_email', 'custom_wp_new_user_notification_email', 10, 3);
197 
198// Shortcode erstellen
199function registrierungsformular_shortcode() {
200 ob_start();
201 echo registrierungsformular();
202 return ob_get_clean();
203}
204 
205add_shortcode('registrierungsformular', 'registrierungsformular_shortcode');

0

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

0

WhatsApp and Call Icon

Added: 5 months ago

Last Updated: 5 months ago

Display Sticky WhatsApp and Call image/icon on website

General

AI Verified

0

FacetWp - Default featured Image

Added: 6 months ago

Last Updated: 6 months ago

General

AI Verified

0

What's My IP? Display the current users IP address with shortcode

Added: 4 months ago

Last Updated: 4 months ago

Display the users current IP address with shortcode [my-ip]

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

2

Confirm Password Field in Woocommerce

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

2

Bypass logout confirmation.

Added: 1 year ago

Last Updated: 1 month ago

WooCommerce

AI Verified

2

Add Product Picture to Orderlist

Added: 1 year ago

Last Updated: 1 year ago