0
votes

I am working on a WordPress plugin for a schedule software that is built in Codeigniter framework. The front end is running fine within the WP page now with some WP functions, CSS, and headers and footers that I want. But when I try to log into the back end of the codeigniter application when it is hooked into wordpress, it acts like the codeigniter login credentials are wrong. If I edit out the following from my codeigniter index.php:

require('../wp-blog-header.php');
add_filter('site_url', 'ci_site_url', 1);

function ci_site_url() {
    include(BASEPATH.'application/config/config.php');
    return $config['base_url'];
}

header("HTTP/1.0 200 OK");  

I can log into the backend view but the WP Headers and functions etc. are lost from the front end view.

I do NOT want want my Codigniter backend to be keyed to the WP login. They need to be separate.

How can I block the codeigniter login view from Wordpress hooks?

I have tried:

if( basename(__FILE__) !== '/application/views/user/login.php' ) {
    require('../wp-blog-header.php');

    add_filter('site_url', 'ci_site_url', 1);

    function ci_site_url() {
        include(BASEPATH.'application/config/config.php');
        return $config['base_url'];
    }

    header("HTTP/1.0 200 OK");
}

This does not work

STRUCTURE

/WordPress/CodeIgniter/

WordPress has its own index.php (WordPress/index.php) Codeigniter has its own index.php (/WordPress/CodeIgniter/index.php) in which the above code is contained.

Both have their own htaccess file.

WordPress:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /WordPress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /portal/index.php [L]
</IfModule>

# END WordPress

Codeigniter

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 

Server location of the CodeIgniter view I want to block from WordPress Headers: /WordPress/CodeIgniter/application/views/user/login.php Controler /WordPress/CodeIgniter/application/controllers/user.php

Url location of the view/page I want to block is https://www.MyWebsite.com/WordPress/CodeIgniter/index.php/user/login

1
"I am working on a WordPress plugin for a schedule software that is built in Codeigniter framework." ~ This does not even make any sense. I've never heard of using a PHP framework as the basis of a WordPress plugin. Are the entire CodeIgniter Application and System directories contained in the same directory as the plugin itself? You'll need to edit your OP to explain more about how you've set this up, where everything is located, etc. - Sparky
Thank you. Are you saying that codeigniter cannot be integrated into wordpress as a plugin? There has been a lot written on it here and elsewhere (eg stackoverflow.com/questions/1253906/…). I am not sure what is not clear. The code I have indicated above is how you set it up in index.php. This works great for the front end but I need to exclude it from the login.php file in codeigniter located in /application/views/user/login.php. - Craig Tucker
I'm sure it's been done. I'm simply saying that it doesn't make any sense to me to integrate a full-blown PHP framework with its dozens of classes for something as limited in functionality as a WordPress plugin. Whatever you need this plugin to do, there are multitudes of WP classes/functions you could use. What's not clear: your structure? ie - are WordPress and CodeIgniter installed in separate directories? Where is the WordPress index.php file located and where is the CodeIgniter index.php file located? What's inside your htaccess file? etc, etc, etc.... - Sparky
I have edited the above with the information you requested. I am wondering why my if statement does not work in this case. I am simply trying to say if the log in page from codeigniter is current don't use the wordpress headers. Is there something wrong with my structure of the if statement? - Craig Tucker

1 Answers

0
votes

The problem was in how I was identifying the page. basename($_SERVER["REQUEST_URI"] identifies the page. And the page that I was targeting was off. I thought that the issue was login but backend was where the conflict was. So the solution is:

if( basename($_SERVER["REQUEST_URI"]) !== 'backend') {
    require('../wp-blog-header.php');
    add_filter('site_url', 'ci_site_url', 1);
    function ci_site_url() {
        include(BASEPATH.'application/config/config.php');
        return $config['base_url'];
    }
    header("HTTP/1.0 200 OK");
}