In last session we have learned about add_action() and add_filters() hooks , please go through the last session once if you have missed it click link below
Most of the beginners search for custom form creator plugins to create forms in your wordpress website, some of them may have different requirements , to full fill their requirement , they need to try to create their own wordpress custom plugins , today I want to show you a small and simple registration form , which creates users. Let’s create a function in my_demo_plugin.php.
Here in this function we are creating html form code to display in frontend, let’s check the function below.
To display form in your post or page we need to create shortcode for this form, to add Shortcode we need to create a function as below.
Now above function is registered to wordpress ,we can use form in any page or post by adding [ektree_registration].
Now we need to write code to insert form data to wordpress database, let’s check the function below.
Here in the above function, I am trying to insert the form data to ektreeuser table, before we are inserting the data we need to sanitize the user data using wordpress escaping functions, which helps in to avoid cross site scripting attacks. We can also add validations to avoid wrong inputs from users, for this we created a function as.
Above code helps us to check the unique username, email validation and password strength, by using validations we can avoid duplicate data entries from users.
Thanks for reading this article