Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Wordpress/php login

I'm building a Wordpress theme for a company that sells widgets. They want to have an area where their dealers can login into the website and get information like specifications, price, and ordering info that doesn't require a login to the backend of the wordpress site.

I was thinking of simply making php login form that goes to the one page that they need to be protected by the login.

I need some recommendations or good tutorials on how do to something like this. Thoughts?

1 Answer

Konrad Traczyk
Konrad Traczyk
22,287 Points

Hello Tyler,

To make login form for wordpress you should use wordpress built-in function wp_login_form()

Then restrict the content only for dealers with functions is_user_logged_in() and wp_get_current_user() Like that:

<?php if(is_user_logged_in() && in_array('dealer', wp_get_current_user()->roles)): ?>
  <!-- your code -->
<?php endif; ?>

Have you thought about registration form and restricting wp-admin area for such users like dealers?

Hope it helps, goodluck

Konrad