Code Monkey home page Code Monkey logo

wordpress_ci's Introduction

Wordpress/Codeigniter Integration

Version 0.1, February 3, 2013

This repository will allow you to place a CodeIgniter Application within a Wordpress directory and use Wordpress functions in your CodeIgniter app. A common use is to have consistent navigation within the CI app and Wordpress site. The helper file “namespaces” CIs site_url function (ci_site_url) to avoid collisions with Wordpress’ site_url function.

If CI sessions are used, you can use the wp-load.php file so that Wordpress doesn’t mangle CodeIgniter’s cookies.

Most other solutions require you to place the application and system directories in the site root; this allows you to keep Wordpress and Codeigniter separate!

Setup

  • Include the Wordpress load file (wp-load.php) immediately before calling the CI bootstrap file in your CI/index.php directory (see below)
  • Add the application/helpers/MY_url_helper.php to your CodeIgniter App.
  • Important!: Change all instances of site_url() in your application directory to ci_site_url; do NOT update anything in the system directory
    • In general, updating application/views, application/controllers, application/models will do.
  • (OPTIONAL) If using CodeIgniter’s Session Library, update Wordpress per the instructions under the Sessions Section.

Add Wordpress Load file to CIs index.php

/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
//Load Wordpress file.
require_once('/Server/path/to/wp-load.php');
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */

Sessions

Unfortunately, Wordpress loops through your $COOKIE global and applies its "add_magicquotes" function, which renders CI’s COOKIE useless; one or more CI cookies will be created on each page load.

KLUDGE: At this point, my solution is to edit the core file wp-includes/load.php, but there is probably a more elegant solution.

In wp-includes/load.php

On about line 26, add your CI cookie to the no_unset array. I’m using the default ci_session key created by CI, but replace this with your own.

$no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix','ci_session' );

To prevent Wordpress from mangling your CI cookie, scroll down to about Line 520 and add this function

/**
* Applies Magic Quotes to the $_COOKIE global but ignores Codeigniter's Cookie
* @param string $value Value passed by array_walk function
* @param string $key Key passed by array_walk function
*/
function ci_ignore_magic_quotes($value,$key)
{
if($key != "ci_session")
{
stripslashes_deep($value);
}
}

Finally, comment out the following lines inside the wp_magic_quotes function and add a reference to the above ci_ignore_magic_quotes function.

array_walk($_COOKIE, 'ci_ignore_magic_quotes');
//$_COOKIE = add_magic_quotes( $_COOKIE );

wordpress_ci's People

Watchers

James Cloos avatar Amal Gamage avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.