Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress - how detect if current page is the login page

Tags:

Is there a better way than using global variable $pagenow to detect current page if it is login page, like a is_admin() function?

if ($pagenow != 'wp-login.php' && !is_admin()) {     // Do something } 

There is a global variable $current_screen with a getter get_current_screen() (which is declared in /wp-admin/includes/template.php) but it's always equal to null.

On #15686 (Detect the current page template tag) – WordPress Trac it says $pagenow it is usually used, but I think is not a good way to compare non-dynamic pages against the file's name instead of the function (like admin page).

like image 848
mems Avatar asked Mar 10 '11 23:03

mems


People also ask

How do you check the WordPress is login in or not?

Then, use following code to check whether user has logged in or not. Show activity on this post. get_current_user_id() will return the current user id (an integer), or will return 0 if the user is not logged in. More details here get_current_user_id().

How do I get the current login of a WordPress user?

Getting all the information of current user in wordpress using the predefined function wp_get_current_user(); <? php $current_user = wp_get_current_user(); echo "Username :". $current_user->user_login; echo "Username :".

How do I check user status in WordPress?

The admin of the WordPress site will see a list of users from the User→All Users menu. There in the status column, they will find the status as Pending for the recently registered user. Hovering over it will show the Approve or Deny option. You can see the in-detailed documentation for more information.

How to check if a user is logged in WordPress?

This is easy using WordPress’ built-in is_user_logged_in () function. This quick tip will show you how to check if a user is logged in WordPress. To use this you’ll have to be familiar with programming in PHP.

How do I check if a WordPress User is an administrator?

Check if Current User is Administrator in WordPress If you want to add functionality only for logged in admins this can be done with the current_user_can () function. By using current_user_can (‘administrator’) in an if statement it’ll allow you to check if the current user is a site admin.

What is is_page () function in WordPress?

is_page () | Function | WordPress Developer Resources is_page (int|string|int []|string [] $page = '') Determines whether the query is for an existing single page.

What does the $page parameter do in a WordPress query?

Determines whether the query is for an existing single page. If the $page parameter is specified, this function will additionally check if the query is for one of the pages specified. For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.


1 Answers

While I tend to agree with others on the need for a function is_login_page() or something similar, I found what seems to be the best answer at https://wordpress.stackexchange.com/questions/12863/check-if-were-on-the-wp-login-page, which I used to make the following:

<?php function is_login_page() {     return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php')); } 
like image 57
Amereservant Avatar answered Oct 01 '22 10:10

Amereservant