I have a partially completed plug in from another developer for WP that integrates the Codeigniter based Easy!Appointments scheduling utility into the WP database. I need to associate the Easy!Appointments user with the WP user.
STRUCTURE: The Easy!Appointments database is part of the WP database structure in mysql. Easy!Appointments is built in the Codeigniter Framework. The plugin will let Easy!Appointments run on a page with a short code but WP headers are missing. So, I am running it in an iframe within a WP page. The main part of the plug in is:
<?php
/**
* Plugin Name: Easy!Appointments - WordPress Plugin
* Plugin URI: http://easyappointments.org
* Description: Creates a bridge between Easy!Appointments and WordPress.
* Version: 1.0.0
* Author: A.Tselegidis
* Author URI: http://alextselegidis.com
* Text Domain: eawp
* License: GPLv3
*/
/** Base Plugin Path */
define('EAWP_BASEPATH', __DIR__);
/** Supported Versions */
define('EAWP_MIN_VERSION', '1.0');
define('EAWP_MAX_VERSION', '1.0');
/** Setup Autoloader */
require EAWP_BASEPATH . '/core/Autoload.php';
$loader = new EAWPCoreAutoload;
$loader->register();
$loader->addNamespace('EAWPCore', EAWP_BASEPATH . '/core');
$loader->addNamespace('EAWPCoreInterfaces', EAWP_BASEPATH . '/core/interfaces');
$loader->addNamespace('EAWPCoreExceptions', EAWP_BASEPATH . '/core/exceptions');
$loader->addNamespace('EAWPCoreValueObjects', EAWP_BASEPATH . '/core/value-objects');
$loader->addNamespace('EAWPLibraries', EAWP_BASEPATH . '/libraries');
/** Initialize Plugin */
global $wpdb;
$route = new EAWPCoreRoute();
$plugin = new EAWPCorePlugin($wpdb, $route);
$plugin->initialize();
I want to pass on the ID of the current user to Easy!Appointments. In the plug in I add this code:
if(!function_exists('wp_get_current_user')) {
include(ABSPATH . "wp-includes/pluggable.php");
}
$wp_id = get_current_user_id();
This tells me the current user. That is what I need. Now how do I now pass that on so codeigniter/Easy!Appointments can use it in my controller?
What I have tried:
In my codeigniter controller I have added
require_once( “/path to wp/wp-includes/user.php” );
and then
$wp_id = get_current_user_id();
Which then tells me I am not logged in.
I have also tried adding to the controller
require_once( “/path to wp/wp-includes/pluggable.php” );
and that just kills it.
So, how to I make these WP functions or at least the results of functions available to my codeigniter controller. Do I just make it a global? How?
The issue is that I am trying to run in an iFrame rather than propperly in WP with the short code. I fixed the issues with the shortcode with advice given here:
How to integrate WordPress template with CodeIgniter.
Now all works fine.