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

detect referr page

If I understand you correctly, a) a user goes to any website, b) user clicks on “random article”, c) user is redirected to a random article, d) user loads that random article. Am I correct thus far? In that case, you’ll see the site from a) as your http referrer in d), because an HTTP … Read more

When ever wordpress home page refreshes the code is not reading the cookie as set anymore

You cannot use setcookie() after you’ve already started outputting stuff to the body (in this case your javascript-debugging, but possibly something else outside that function). Are you suppressing PHP warnings? It should complain with “Cannot send headers; headers already sent” and tell you where the output was started. To get rid of the problem regarding … Read more

Automatically Log Out UserX when visiting WooCommerceStore

You should use one of the actions that occur after parse_query, because then the variables on which the conditional tags are based are set. Such action can be template_redirect. The conditional tag will allow you to check if the current page is a store page. To log out the user, use the wp_logout() function. add_action(‘template_redirect’, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)