简体   繁体   中英

Check if user is logged in when using wordpress together with slim framework?

i have installed slim under my wordpress root under wordpressroot/japi/

all calls that go there are dealt with by slim framework v3 . So are not visible to wordpress

Now I want to provide some admin functions where I have to get the current user id eg with: get_current_user_id() but i get returned 0 all the time. Is there a fix to this? do i have to call some sort of wordpress init function to be able to access these functions?

You can require the wordpress framework if you put this where you init the slim framework.

define('WP_USE_THEMES', false);

/** Loads the WordPress Environment and Template */
require( path-to-wp-root . '/wp-blog-header.php' );

This way it will load the wordpress framework, without initing the templates. Then you can use any wordpress function you need.

I think i accessed the login page using https, then tried to access my slimframework over http? i think that was the mistake.

btw import you wp-load.php in your slim index to get access to the functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM