Reputation: 543
I am writing plugin that uses init() action and the_content() filter.
In init I would like to do some cookie checks and set some variables based on result (lets say $mycookieset = 1). In the_content filter I would like to modify article based on $mycookieset variable.
How to pass $mycookieset variable in safe way between these two hooks? I would prefer not to use sessions. It also should be multiple users safe (hundreds of people browsing the web same time).
Any ideas? Thanks
Upvotes: 3
Views: 969
Reputation: 6838
You can add the filter inside a function that is hooked into init, and use the cookie value as a variable in the $function_to_add
parameter:
add_action( 'init', 'my_init_function' );
function my_init_function(){
// do the cookie stuff
add_filter( 'the_content', 'my_variable_cookie_func_' . $mycookieset );
}
Of course, you should have an appropriate callback function for each possible cookie value.
Upvotes: 1