Sometimes this is a bug in another plugin or the theme, outputting something when it shouldn’t and example may be a closing ?> in php followed by some blank lines of a blank line before and opening <?php
I’m assuming here that you dont have control over the client sites, access to debug, or knowledge of their plugins and themes ( e.g. like a plugin developer ? )
You could try a lower priority on the hook
Or try an use a much earlier hook in the hope that what ever is outputting is not doing it that early – depending on what you need youcould go as early as muplugins_loaded
add_action( 'init', 'my_cookie', -1 );
You could try using the “wp_headers” filter to add your own Set-Cookie: header to all of the other WP headers about to be sent. If some other code generated output before this, it’d break all other WP header functionality.
I’ve not tested this to ensure it’s feasible, but I’m reasonably confident it’ll work. Even if it works, IDK if it’s an acceptable practice for inclusion in the WP plugin repository.
N.B: this is only feasible from plugins, themes load too late for this to work.
Thread Starter
Guido
(@guido07111975)
Hi,
Thank you both!
Thought about it a little more. As BC may already know I was testing with setting a cookie that stores an unique ID for my sum-captcha session. With that ID I was retrieving the correct transient from database. But cookies might be blocked or other plugins might cause the “headers already send” issue, so maybe I should look for something else.
Guido
