WordPress Login to close the landing page and set the user's invisible column _php skills

Source: Internet
Author: User
Tags php programming wordpress default login wordpress login

Close the login page after the user logs in
wordpress Default Login page is: Http://WP directory/wp-login.php, login will automatically jump to: Http://WP directory/wp-admin. Now the question is, if the user is logged in, but it opens the wp-login.php page, what will happen? The answer is, WordPress will not do any processing, or directly to show you the login window:

The face of such a cold login box, users will be confused, I have not just been logged in? How do you want me to enter a username and password? So, after the user login, we should not let the user see the Login box again. There are two ways to resolve this problem:

Remove Login Link

Make sure that the wp-login.php link no longer appears on the page. If the user is not logged in, we can be prompted in this page:

After the user logs in, we remove the login and registration links above and replace them with the following:

This will not only allow users to have logged in at a glance, and will not mistakenly click wp-login.php into the login interface. PHP programming only needs to use the WordPress is_user_logged_in () function to judge whether the user has already logged in can realize.

wp-login.php do jump

Sometimes, users will accidentally click on the wp-login.php login link, such as the browser's address bar. We should do some remedial action at this time, do not let the login box appear in front of the user. The method introduced here is, when the user has logged in, but also open the wp-login.php link, we let him jump to the back page wp-admin, the specific method is, in the current topic functions.php Add the following PHP code:

function Redirect_logged_user () {
 if (is_user_logged_in () && Empty ($_get[' action ') | | $_get[' action '] = = ' login ') {
  wp_redirect (Admin_url ());
  Exit;
 }
}
Add_action (' Login_init ', ' redirect_logged_user ');


Create a custom column that is not visible to the user
If you are a plugin or a theme developer, you should often use custom columns (or custom fields) to store the relevant parameters for your plugin or theme, and interestingly, when you edit the page in WordPress background or use the The_meta () template function, WordPress does not display a custom column with a name that starts with an _ (underscore).

To some people do not want to let users see, but do not want users to modify the custom column, we can use this technique, not only to make the article edit the custom column of the page is simpler, and will not let users see unfamiliar custom columns and feel confused, or even random modification. Here is a sample usage:

<?php Add_post_meta (, ' _ludou ', ' Lulu blog ', true);?>

This adds a unique custom column named _ludou to the article with ID 68, which is the value of the blog, and is not visible to users in the article edit page. Normally, we might be using this so that we can see the Ludou field in the custom column of the article edit page:

<?php Add_post_meta (, ' Ludou ', ' Lulu blog ', true);?>

Additionally, when the value of a custom column is an array, the column is not visible to the user in the article edit page, even if the custom column name is not underlined before.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.