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

admin-ajax.php not working properly on subdomains

Don’t bother with the complicated cookie/ajax nonsense, use a REST API! We’ll use dependency injection and RESTful APIs to remove the cookies and simplify your AJAX code. First things first, lets turn this into a REST API: class Stuff { public function __construct() { add_action( ‘rest_api_init’, function () { register_rest_route( ‘soothsayer/v1’, ‘/current_rate/’, array( ‘methods’ => … 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

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