Support » Plugins » Failing to integrate WP with CakePHP

  • Hi everybody,

    I’m trying to integrate a WP blog inside a CakePHP website. So far I got both working together but now I want to share the user administration.

    I want to let WP do the heavy lifting, so basically I want to adapt Cake to WP. I’m following this to be able to call some WP functions from Cake:

    But it fails with this error:

    Fatal error: Call to undefined method stdClass::set_prefix() in /Applications/XAMPP/xamppfiles/htdocs/tsd/app/webroot/blog/wp-settings.php on line 268

    I’ve been doing some tests and this doesn’t happen if I try the same code from the tuto on a simple php page.

    I’ve gone trough wp-settings and wp-db.php (line 268 is calling a function in $wpdb) and there isn’t anything obvious that might be causing this problem. Can’t find anything meaningful in Apache’s log either.

    A search on Google for CakePHP integration didn’t bring anything related to this.

    PHP version is 5.2.9 under Apache 2.2 on OSX.

    Any help much appreciated.


Viewing 9 replies - 1 through 9 (of 9 total)
  • Got it.

    First I had to set DEBUG to true to get a meaningful error, and finally find out the problem.

    CakePHP defines its own __() function in cake/basics.php. The moment you include WP, wp-includes/l10n.php kicks in trying to define a function with the same name, thus the problem.

    I’ve solved the problem surrounding WP’s __ function with this:

    if ( !function_exists(‘__’) ) :
    // the function

    And I’m good to go.

    I don’t expect any conflict because what I’m planning to do with WP when inside Cake has nothing to do with text, so I’ll give Cake’s function precedence. Likewise, when on the blog, none of Cake’s code is going to be present, therefore WP won’t notice.

    If anyone sees a problem with this, please let me know.



    Too fast 😐

    Actually, nowhere near ok. It turns out I broke WP installation and when reverted the changes, I faced the same problem.

    I keep getting tons of errors I think because some objects haven’t been initialized or PHP can’t just find them. For example, in deprecated.php I was getting an error that I solved declaring $wpdb as global at the beginning of the file.

    Now I get a problem in widgets.php saying that $wp_widget_factory is not an object. If I comment the line I get a similar errors in other files, but it won’t be safe just ignoring all of them.

    Just for the record and if anyone wants to give it a go, this is the code I’m using in app/controllers/app_controller.php (before the class definition) to include WP’s files:

    [code]$pathToWP = $_SERVER[‘DOCUMENT_ROOT’].”/tsd/app/webroot/blog/wp-config.php”;

    define(‘WP_USE_THEMES’, false);

    Thanks a lot,


    I’m still having this problem, too, and I can’t get a good answer as to why.

    I’m going to try to integrate a wordpress inside a cakephp application, do you have any suggestion if this is truly possible, are you still experimenting errors?

    global $wpdb;

    $pathToWP = $_SERVER[‘DOCUMENT_ROOT’].”/app/webroot/blog/wp-config.php”;

    define(‘WP_USE_THEMES’, false);

    At the moment, there is no easy way to load the entire WordPress environment from other PHP scripts. The heavy use of global variables and non object-oriented design makes it difficult to integrate WordPress with other PHP based projects.

    I just spent the last few hours struggling with this exact bug (though in my case, I was doing some stuff of my own, not cakephp).

    Here’s what I figured out.

    It seems you can make a file, myfile.php, full of code and at the end or anywhere in the middle you can “call” WordPress using something like “chdir(‘blog’); include ‘index.php’;”

    HOWEVER… if you try to “call WordPress” from *inside a function*, everything blows up all to hell.

    Sort of supports what mp2300 said… if WP uses lots of global variables, then I could see how it would blow all to hell when you try to “call” it from within a function.


    Just wanted to reiterate Glowing Face Man’s observation. I started getting this error when I put require_once('PATH-TO-/wp-blog-header.php'); inside one of my class’s functions, and everything worked again when I moved it out.

    I’m not working with CakePHP, but it seems that the issue is the same.

    I’d like to third Glowing Face Man’s observation…


Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Failing to integrate WP with CakePHP’ is closed to new replies.