How to get session variables in wordpress plugins
php, wordpress
Solution
You need to add `<?php session_start(); ?>` at beginning of my_page.php
After that for destroying session you can use wp_logout action in wordpress. code is as follows
<?php function custom_unset_session() {
// your code
unset($_SESSION['tag']);
}
add_action('wp_logout', 'custom_unset_session');
?>
Problem
Hi iam new to wordpress and I have created a plugin at which I need to print all the session data.First I have created a file in plugin folder and added code like ``` function myplugin_classname() { print_r($_SESSION); } ``` And I put an click event for two button with class `tags` like ``` $('.tags').on('click',function(){ $.post('my_page.php',{val:$(this).val()}); }); ``` and in my_page.php I kept like ``` $_SESSION['tag'] = $_POST['val']; ``` but when it comes to printing the session variables at `myplugin_classname` (by refreshing the page)it doesnt prints the newly assigned session variable....How to solve this..??I have started session through `theme-my-login` login.