From the course: WordPress Development: Coding Practice
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Store user meta - WordPress Tutorial
From the course: WordPress Development: Coding Practice
Store user meta
- [Instructor] Let's say we want to know the last time a user logged into our site. We don't necessarily have this information available to us by default, so we are going to store it upon login. Here are the requirements. Replace the "init" hook with the proper hook that you need. Store the date and time in the format year, month, date, and hour, minute, second, all as one string. Check to make sure that the meta field exists for the current user. If it doesn't create it, otherwise update it. And finally, the name of the field should be lil_last_logged_in. The output should only show for the currently logged in user. While you'll see our function is set up to accept arguments, our short code is not. So, you should use the ID of the currently logged in user. With that, let's go ahead and look at our starting code. We have the meta key defined and then we want to replace the admin "init" hook with the appropriate one. You…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Dynamic copyright year2m 50s
-
(Locked)
Randomize posts5m 37s
-
(Locked)
Get post meta3m 19s
-
(Locked)
Change admin colors based on the server5m 18s
-
(Locked)
Create your own block pattern5m 58s
-
(Locked)
Append a message to RSS content5m 31s
-
(Locked)
Sanitize input4m 39s
-
(Locked)
Sanitize output4m 4s
-
Add a sitewide banner to the top of the page3m 32s
-
(Locked)
Register a custom post type5m 37s
-
(Locked)
Store user meta5m 29s
-
(Locked)
Send an email to the admin when a plugin is activated6m 42s
-
(Locked)
When a user logs in, greet them by their name4m 44s
-
(Locked)
Create a transient5m 30s
-
(Locked)
Hide content based on a query string5m 49s
-
-