WordPress.org

Ready to get started?Download WordPress

Forums

Problem in integrating Cake Php and WP:Auto Plogin Plugin (1 post)

  1. nishant.nightcrawler
    Member
    Posted 4 years ago #

    Hi friends,

    I have a cakePHP application housing a WP blog. I am using an auto-login plugin to log my users into WP when they sign in to my cake application. This works perfectly fine. But the trouble is, I need this to work the other way round too. That is a) I need my users to get logged in to cake when they log in using WP and b) I need to log users out of WP if they log out of cake and vice versa. I know I can probably achieve this by destroying the wp_auth cookie when I destroy my cake session upon logout. But I am not able to call any WP functions from inside of cake. I tried including the wp-blog-header.php in order to load the WP environment so that I can use the WP variable in Cake but that doesn't work either"

    Below is the autologin plugin code -

    /*
    Plugin Name: Auto Login
    Description: This is a Auto Login plugin works on the Intialization of the WordPress.
    Author: Nishant Shrivastava
    Version: 1.0
    Author URI: http://www.phpgeekz.com/
    */
    
    session_name("XXXX");
    session_start();
    
    function auto_login() {
        if (!is_user_logged_in()) {
    
            //get username
            $user_name = $_SESSION['User']['username']; 
    
            //get user password
    		$user_pass = md5($_SESSION['User']['password']); 		
    
    		// Get User's data based on Username to initialize the User session
    		$User = get_userdatabylogin($user_name);
    		$wp_UserID = $User->ID;
    
    		// Process auto-login
    		wp_set_current_user($wp_UserID, $user_name);
    		wp_set_auth_cookie($wp_UserID);
    		do_action('wp_login', $user_name);
    
        }
    }
    add_action('init', 'auto_login');

    Any help here from you guys is highly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by nishant.nightcrawler
  • This topic is not resolved
  • WordPress version: 2.9.1

Tags