I need to set a session value in my plugin, but session isn’t started when WordPress loads my plugin and I don’t want to run if (!session_id()) session_start();
manually, because other plugins might rely on setting cookies, etc and face a “headers already sent error”.
Is there any hook in WordPress that runs after session is started?
If not, how do you professionals handle such situations?
Advertisement
Answer
WordPress does not use session. There are actually a number of reasons for this outlined very well in this stackexchange post:
I would say if you are concerned about stepping on a plugin’s toes, try hooking into “plugins_loaded” and use that hook as an entry for your plugin (if you can, I know that will limit functionality somewhat). But because WordPress does not start a session itself it is really a coin toss whether you are interrupting another plugin or not.