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).
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().
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 :".
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.
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.
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.
is_page () | Function | WordPress Developer Resources is_page (int|string|int []|string [] $page = '') Determines whether the query is for an existing single page.
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.
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')); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With