0

Being a programmer from a completely different background, I have some pretty novice questions about wordpress and PHP that I could not find the answers for on the internet, probably because they are too basic. Sorry if some you find these questions way too silly, but I could not find answers for these on the web. Hence asking

  1. I am trying to create a simple login/registration functionality to add to my wordpress site. I could not find a plugin doing that. All I found is plugins helping to customize the admin login page of wordpress (like CustomLogin). Is there one that can help me?

  2. I saw some functions named 'signon', and 'isusersignedin' and a table called wp_users in the database. Can these functions be used for my purpose or are they reserved only for the admin login of the wordpress website? I am also unlcear about what is the difference between wp-admin and wp-login. They both allow for the site to be edited byt the admin

  3. Trying to implement it on my own in PHP, I seem to be really confused about the PHP structure that wordpress uses. For example, while implementing a registration form, I will need a page that takes the input from the post method and writes a new row to the database table. For that I cannot use the regular template that I am using for all my pages. Do I have to create a new template page for just this one extra thing? Isn't there some way of just calling an extra function somewhere based on some condition

Thanks & Regards Rahul

0

WordPress Core provides a lot of helper functions to accomplish these types of tasks. If it's not a function, then there most often is a filter or action that you can hook into.

In the case of the WordPress login form, it's wp_login_form(). Here documentation on that: https://codex.wordpress.org/Function_Reference/wp_login_form

Regarding redirecting users after login, there's a filter for that. This code is a snippet I've used on many sites:

function wip_login_redirect( $url, $request, $user ){
 $slug = $_SERVER["REQUEST_URI"];
 $islogin = strpos($slug, 'log-in');

 if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {

 if(($user->has_cap('edit_users')) && ($islogin==true)) {
 $url = admin_url('index.php');
 } elseif ((!$user->has_cap('edit_users')) && ($islogin==true)) { 
 $url = home_url();
 } else {
 $url = $slug;
 }
 }
 return $url;
}

add_filter('login_redirect', 'wip_login_redirect', 10, 3 );

I go into detail about that in this article: https://wordimpress.com/conditional-custom-login-redirects-wordpress/

Hope that gets you going in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.