WordPress keep logged in after browser close

You can use the following 2 filter hooks add_filter(‘auth_cookie_expiration’, ‘auth_cookie_expiration_filter_5587’); function auth_cookie_expiration_filter_5587() { return YEAR_IN_SECONDS * 5; } and: add_filter(‘auth_cookie_expiration’, function () { return YEAR_IN_SECONDS * 5; });

How to get the id dynamically to store cookies

If you want the ID of the current post outside of the loop, you can use get_queried_object_id(). Just make sure to check is_singular() first, or you could end up storing IDs of things other than posts. This could cause problems if there’s overlap with post IDs. I’d share the amended code with those changes, but … Read more

Why isn’t my cookie setting in my function?

Setting cookies is done via HTTP headers. This means you can’t set any cookies via serverside methods (PHP->WordPress) anymore after any content has been sent to the browser. A working example of setting cookies in WordPress (in one of my plugins): Cookie Manager: https://github.com/download-monitor/download-monitor/blob/e26022f9a96abf174a874873b8cd35a0db98882b/includes/class-dlm-cookie-manager.php Setting the actual cookie: https://github.com/download-monitor/download-monitor/blob/e26022f9a96abf174a874873b8cd35a0db98882b/includes/class-dlm-download-handler.php#L416 The cookie is set on the … Read more

Capture and display users name

Use wp_get_current_user to get the current user (if any) then check or update the display name – update_user_meta or wp_update_user. When you have a user, you’ll probably want to set a flag on the user’s meta for after they have filled out their name, or prompt otherwise. How/where all this would go is really a … Read more

Cookie is not set

This is the correct format for a cookie to expire in one hour (3600 seconds): setcookie(‘rma_member’, true, time() + 3600, COOKIEPATH, COOKIE_DOMAIN); setcookie Expire: The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. In other words, you’ll most likely set this with the time() function … Read more