WordPress doesn’t use PHP session ($_SESSION
). If you want to use it you need to do at your own. For example:
add_action('init', 'wpse_session_start', 1);
function wpse_session_start() {
if(!session_id()) {
session_start();
}
}
But, if you want is to get the user id of the current user, you can use get_current_user_id()
:
<?php $user_ID = get_current_user_id(); ?>
Related Posts:
- How to log out everywhere else, destroy all sessions “all other devices”?
- Are there any drawbacks on opening a session_start in functions.php and header.php?
- Allow user to select location and then set cookie for location in WordPress
- How to call a function only once (global variable scope)
- Multiple is_page() in page.php
- Set media upload attachment link to none and hide it in WP v3.5
- Fatal error: Call to undefined function plugin_dir_path()
- Switching wp_get_sites to get_sites
- Display message once per session to users with a specific role
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- Why does $_SESSION only work when I am logged in?
- How to correct schedule my event weekly with wp_schedule_event()
- One button to change all settings in theme customizer?
- Add custom image sizes to media uploader
- Execute a shortcode when clicking on a image
- How can update custom meta for all posts
- How to add default images into theme customizer image control?
- Is $hook a global variable in WordPress
- Successful or Error Message after running mysql code in functions.php
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- wrong php date()?
- Include a php file from functions.php only to homepage
- How do I fetch all comments per post via WP REST API?
- Shortcode content output but not in correct place
- How to restrict page access to logged-in users?
- How do I display a user’s previous orders as a select box option on a product?
- Handling Body class based on Template
- Adding Default Settings to Theme My Login plugin
- How to combine wordpress_logged_in cookies in one cookie?
- Two Different Links for Same Product – WooCommerce [closed]
- Automatically adding new post categories to menu
- Get post id in a function when edit/add a post
- function to assign user role based on a field from usermeta
- get author_name from queried post
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- Pass php dynamic variable to shortcode
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Modify custom field input data before creating a new post
- Query Pages and post excerpts dynamically
- Run a code only on theme activation only during first activation
- Shortcode from a function not working
- Is it possible to return content, and then also continue to do other things?
- How to remove ?p= from wordpress short links
- Need php code’s output to display underneath a Divi Module
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- How to make function appear in sentence?
- How to define a variable already defined in a plugin function?
- woocommerce specific quantities for product
- My website is not showing Footer section
- How to use mysql LIKE with wpdb?
- woocommerce related product title length
- Custom query vars filters problem with pagination
- Query for user roles
- Use SCSSPHP to compile Theme Customizer Values into .SCSS files ready to compile to CSS
- Must filter functions receive all arguments passed to them?
- Displaying Event within two given time frames
- Displaying Slider in Front Page (home) using Customizr Theme
- How to add PHP pagination to wordpress
- How to call custom function outside from the admin page?
- Is there a way to create a “copy post” link?
- Taxonomy term description with style, only if the description exists?
- Use of antispambot with $curauth->email
- Restrict post to current user in postmeta
- Reject all malicious URL requests functions.php
- copy fields value to another field
- Like and Dislike Buttons on Post with Counter – Only allow one click per post per user session
- posts_per_page displays only 2 posts instead of 4 posts
- Get parent category name when only child category is applied to a product
- PHP session not staying alive. headers already sent
- Can an AJAX callback function access a PHP variable which was defined during initial page load?
- Notice: Undefined variable
- Adding product permalink on admin order page throwing error
- Before & After Content – After Content directly below Before Content when using require_once
- How to override WooCommerce Order Item Meta with data from Cart?
- Taxonomy Child Term, Counter is staying on 0
- Access to “My Site” is missing from the admin bar
- How to redirect (301) trashed post to it’s parent taxonomy TERM ARCHIVE instead of 404 page
- How to call WordPress PHP file using external js file
- Using get_theme_mod with checkbox to display content
- use system script advertising in wordpress multisite
- Use WP_Query Data In Cookie
- Styling admin page rows in order of importance (checkboxes)
- Insert wordpress tags below posts via functions.php
- Help with my first Metabox helper class
- Break a WordPress function to run in patches and re-continue
- Pagenav Not appearing on custom Template
- ISOTOPE – Missing/Invalid Arguement Get Terms
- Pagination not displaying
- My title is showing after the shortcode
- Load a Header in wordpress
- Trouble figuring out how to get my button to submit comment
- Setting WooCommerce currency programmatically
- Masking external links with internal link for member-only
- Adding multiple conditional tags in a function?
- How do I change the Go To Categories link in the term_updated_messages
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- Generate and upload screenshot as featured image for user-submitted post
- a problem in class in class-wp-hook.php
- change title of page dynamically
- Custom plugin doesn’t show in admin menu – when code added, displays an empty page