WordPress.org

Ready to get started?Download WordPress

Forums

Integrating WordPress into my site: Global blues and many non-objects (6 posts)

  1. michael.heuberger
    Member
    Posted 1 year ago #

    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

  2. SirChunkington
    Member
    Posted 1 year ago #

    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');
    ?>
  3. michael.heuberger
    Member
    Posted 1 year ago #

    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 :/

  4. 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.

  5. SirChunkington
    Member
    Posted 1 year ago #

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

  6. 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!

Topic Closed

This topic has been closed to new replies.

About this Topic