I’ve developed a php app and I’d like that it’s restricted to WP users (use WP like a private area).
Is there a way to use WP is_user_logged_in
function in a custom file (i.e. www.mysite.com/app.php
)? where should I put the folder with the app ?
I tried but the page is not recognized.. (.htaccess
?)
Leave a Reply
You must be logged in to post a comment.
This is impossible to answer definitively without a better description, but I am assuming that
app.php
is a completely distinct piece of code. In which case, WordPress can’t really manage access to it. You will need to incorporate it into WordPress. While this is not the only way to do it I would advise:include
it.To control access you can include
if ( is_user_logged_in()) {
logic directly in the template. Do this if you want to provide some kind of “Must be logged message”Or, hook to
template_redirect
. This will let you redirect to some other pageYou’ll need to bring your code into the WordPress realm. Easiest way to do it is to create a new template (a standard .php file that will reside inside
wp-content/themes/your-theme-name
directory) and assign that template to a page (check this page for instructions). Look around this series of guides for more help on templates and how to build one. Your simplest template would look something like this:Once you have a working page with a template, you can incorporate your code into that template and use
is_user_logged_in
function to do what you need to do.