Support » Fixing WordPress » Integrating WordPress into my site: Global blues and many non-objects

  • Hello everyone

    I’ve been developing and coding sites for over 20 years and this is the first time I’m ingetraging WordPress to an existing site of mine. Installation went well.

    But now I’m having two issues when the real integration begins:
    a) Global variables aren’t initialised
    b) Null pointer in handle_404 (non-object)

    a) Global variables aren’t initialised
    Inside index.php I have this:

    // Load some other application stuff
    require 'core.php';
    
    //  Then integrate WP
    define('WP_USE_THEMES', false);
    define('WP_DIR',    WEB_ROOT . DIRECTORY_SEPARATOR . 'wordpress');
    
    require(WP_DIR . DIRECTORY_SEPARATOR . 'wp-blog-header.php');
    
    ...

    Like that the first error is:
    Fatal error: Call to a member function main() on a non-object in /[REMOVED]/httpdocs/wordpress/wp-includes/functions.php on line 1570

    I have to add this line before the integration to make this error disappear:
    global $wp, $wp_rewrite, $wp_the_query;

    In my opinion it’s not nice and bad code. Is there no other way around? Any better solutions?

    b) Null pointer in handle_404 (non-object)
    Depsite of my quick and dirty solution (above) I encouter another `error:
    MESSAGE: Trying to get property of non-object
    TYPE: Notice
    FILE: /[REMOVED]/httpdocs/wordpress/wp-includes/class-wp.php
    LINE: 477`

    After some debugging I can see $wp_query on line 477 is NULL.

    I do not want to hack WP otherwise any further updates will make it instable again. Are there any solutions out there?

    Thanks for your help!

    Cheers,
    Michael

Viewing 5 replies - 1 through 5 (of 5 total)
  • I had similar problems integrating WordPress into my site. Had to write a horrible auto-loader which maps WordPress class names to their respective files. WordPress sometimes has multiple classes in the same file so it wasn’t straightforward.

    The WordPress globals and constants need to be registered next, so adding the following before making any calls to WordPress seemed to do the trick:

    require 'blog/wp-config.php';

    You should then be able to add the following code on your page:

    <?php
    define('WP_USE_THEMES', false);
    require('/the/path/to/your/wp-blog-header.php');
    ?>

    yeah i figured that out myself too – but thanks anyways …

    while i reverse engineered the code i almost could not resist the need to vomit. the wordpress code really needs a complete makeover and rewrite :/

    Christine Rondeau

    (@crondeau)

    Volunteer Forum Moderator

    while i reverse engineered the code i almost could not resist the need to vomit. the wordpress code really needs a complete makeover and rewrite

    If you care to contribute, feel free to go to http://make.wordpress.org/core/ and learn how you can help.

    If WordPress implemented the PSR-0 Standard, that would be a good start.

    George Stephanis

    (@georgestephanis)

    Code Monkey

    Wouldn’t PSR-0 require PHP >= 5.3?

    Also, as Christine pointed out, we are always eager to welcome new contributors, if you’d be interested in pitching in!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Integrating WordPress into my site: Global blues and many non-objects’ is closed to new replies.