Load CodeIgniter Instance in WordPress

The problem I had with using WordPress was wanting to incorporate CodeIgniter functionality into WordPress theme files. For example, there are a header and footer that I include in many of my CodeIgniter view files. That same header and footer also needed to be included in the WordPress theme.

The idea is to load CI instance and use it on WordPress.
Any help would be appreciated!

Read More

I have tried this.

https://github.com/falexandrou/Codeigniter-Wordpress-Integration

The file path to load CI bootstrap is correct already.
Its result was Error

Your system folder path does not appear to be set correctly. Please open the following file and correct this: index.php

the sites step:
1. Include this in the following template files at the top:

 - 404.php - index.php- archive.php- archives.php
 - links.php -page.php - search.php - single.php */

 <?php
  $wp_ci['return'] = true;
 require('codeigniter.php');
  1. put codeigniter file along the template dir
    This is supposed to load CI instance so it can be used in WordPress.

    https://github.com/falexandrou/Codeigniter-Wordpress-Integration/blob/master/ci-wp-thedaylightstudio/codeigniter.php

CI index.php

 <?php
 $wp_did_header = true;         
 require_once dirname( __FILE__ ) .'/blog/wp-blog-header.php';
 define('WP_USE_THEMES', true);
 require_once BASEPATH.'core/CodeIgniter.php';
 ?>

UPDATE:

wp-blog-header

  if ( !isset($wp_did_header) ) {
$wp_did_header = true;
require_once( dirname(__FILE__) . '/wp-load.php' );
wp();
require_once( ABSPATH . WPINC . '/template-loader.php' );
 }

I successfully load the codeigniter view on wordpress but
all my ci_site_url function returns website.com/blog/application
when it should be website.com/application
I put this code on one of WP theme index.php

  define('STDIN', TRUE);
  $_SERVER['argv'] = array();
  ob_start();
  require('../index.php');
  $GLOBALS['wp_ci_output'] = ob_get_contents();
  ob_end_clean();
  $GLOBALS['CI'] = get_instance();
  require_once(APPPATH.'helpers/wordpress_helper.php');

Code Reference:

http://thedaylightstudio.com/blog/2010/06/16/codeigniter-and-wordpress-integration

wordpress-helper.php

/**
* Print codeigniter view file in wordpress content
*
* @access   public
* @param    string view file name
* @param    array array of variables to be rendered
* @param    boolean true to return, false to return
* @return   mixed
*/

function wp_ci_load_view($view, $vars = array(), $return = FALSE){
 extract($vars);
  $file = APPPATH.'/views/'.$view.'.php';
  $contents = file_get_contents($file);
  //echo $contents;
  $CI =& get_instance();
  $check_funcs = array('ci_site_url(', '$this->');

  $replace_funcs = array('site_url_wp_safe(', '$CI->');
  $contents = str_replace($check_funcs, $replace_funcs, $contents);
  $contents = eval('?>'.preg_replace("/;*s*?>/", "; ?>", 
  str_replace('<?=', '<?php echo ', $contents)).'<?php ');

   if ($return === TRUE){
   return $contents;
   }
 }

https://github.com/falexandrou/Codeigniter-Wordpress-Integration/blob/master/ci-wp-thedaylightstudio/wordpress_helper.php

The writer did say an issue:
The only issue with this version is that it always renders the same CI page to get the CI object and you can’t manipulate which page it renders.
Thanks.

MY_url_helper

function ci_site_url: to differ CI site_url and WP site url function

 if ( ! function_exists('ci_site_url')){
   function ci_site_url($uri = '')
   {
    $CI =& get_instance();
    return $CI->config->site_url($uri);
    }
  }

Related posts

Leave a Reply

1 comment

  1. look I have added below code in my helper file of codeigniter and add this helper in config/autoload.php file to autoload it automatically.

    /**
     * return CI header to home page cms for 
     */
    if (!function_exists('ci_header')) {
    
        function ci_header() {
            $CI = & get_instance();
            $header = $CI->load->view('includes/header.php', '', true);
    
            return $header;
        }
    
    }
    
    /**
     * return CI footer to home page cms for 
     */
    if (!function_exists('ci_footer')) {
    
        function ci_footer() {
            $CI = & get_instance();
            $footer = $CI->load->view('includes/footer_homepage.php', '', true);
    
            return $footer;
        }
    
    }
    

    and put below code in wordpress wp-content/themes/my_theme/header.php

    <?php
        echo ci_header();
    ?>
    

    and put below code in wordpress wp-content/themes/my_theme/footer.php

    <?php
    echo ci_footer();
    ?>
    

    you can use any helper function in wordpress theme templete directly as i am calling ci_header() and ci_footer();

    Go ahead… and summarize me what else you need to do for your project…