Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I guess WP uses a PHP session (or a cookie) to save login data, right?

I have a website, which uses WP as a CMS, but display (and create) content from outside. I allow anonymous posts, by simply not passing $post['post_author'] to wp_insert_post()

However, I also want to make users (that are registered in WP) to be able to login in mysite/wp/wp-login.php, than redirect to mysite/mypage.php, and get the user id from session or cookie.

How do I do that?

Edit

The code:

include( 'wp/wp-load.php');  
global $current_user;
get_currentuserinfo();
print_r($current_user);

this prints an empty WP_User Object:

WP_User Object ( [data] => [ID] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [filter] => ) 

Although I'm logged in in WP.

P.S.
Now that I saw wp-login-form in tags, which gave me a better idea.

Can I put a login form to my page (outside wp) ? This would surely be better, since it wouldn't require the users to redirect.

I want minimum (ideally zero) interaction between mysite/wp and visitors (including Google Bot).

share|improve this question
    
Something like this? wpengineer.com/1038/embed-wordpress-functions-outside-wordpress –  Pat J Jul 8 '13 at 18:24
    
@PatJ yes, but I'm already doing that. However, I couldn't manage to get the login data. –  Cengiz Frostclaw Jul 8 '13 at 23:07
    
It will help us help you if you post the code you are using to try to get the login data. –  Pat J Jul 8 '13 at 23:20
    
I pasted the code. –  Cengiz Frostclaw Jul 9 '13 at 10:59
add comment

1 Answer 1

up vote 1 down vote accepted

I solved my problem, and it could definitely help others too.

The problem was with cookies since my folder structure was like this :

  • mysite.com
  • mysite.com/mypage.php
    • mysite/wordpress/

the cookies were only valid for wordpress folder, and it's subdirectories.

In order to activate the cookies outside wordpress, I installed the root Cookie plugin, and everything works fine now.

P.S.

Do NOT change the configuration of root Cookie. Just leave the Domain Name setting as empty.

share|improve this answer
    
You can do it without a plugin. In Your wp-config.php add before require_once(ABSPATH . 'wp-settings.php'); define('SITECOOKIEPATH','/');define('ADMIN_COOKIE_PATH','/'); to set the cookie in all domain –  Pablo Martinez Feb 10 at 20:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.