Forums

Using spl_autoload causes errors when I include wp-load.php (3 posts)

  1. aswitzer
    Member
    Posted 5 months ago #

    I am trying to show blog posts outside of my WP blog install folder on my website - something I have done numerous times before.

    I'm using the simple bit of PHP code:

    define('WP_USE_THEMES', false);
    include('wp-load.php');
    query_posts('showposts=1');

    However, with this website I have also been using the PHP5 feature of spl_autoload and it appears to be the cause of this error as soon as I attempt to include wp-load.php as shown above:

    Fatal error: Uncaught exception 'LogicException' with message 'Class Translation_Entry could not be loaded' in /mnt/domains/nobigdiffpool.com/html/blog/wp-includes/pomo/entry.php:10 Stack trace: #0 [internal function]: spl_autoload('Translation_Ent...')

    I've experimented with various things to try and fix this - namely adding to my include path for WP, but am completely stuck. Any ideas?

  2. tobiasbeuving
    Member
    Posted 3 months ago #

    Same here (only in wp-admin, in the frontend it works fine):

    Fatal error: Uncaught exception 'LogicException' with message 'Class WP_User_Search could not be loaded' in /domains/.../DEFAULT/wp-admin/includes/deprecated.php:291 Stack trace: #0 [internal function]: spl_autoload('WP_User_Search') #1 /domains/..../DEFAULT/wp-admin/includes/deprecated.php(291): class_exists('WP_User_Search') #2 /domains/.../DEFAULT/wp-admin/includes/admin.php(59): require_once('/domains/...') #3 /domains/.../DEFAULT/wp-admin/admin.php(64): require_once('/domains/...') #4 /domains/.../DEFAULT/wp-admin/index.php(10): require_once('/domains/...') #5 {main} thrown in /domains/.../DEFAULT/wp-admin/includes/deprecated.php on line 291

    I agree with Ketwaroo that wordpress should use spl_autoload:
    http://wordpress.org/support/topic/use-spl_autoload-to-load-classes?replies=1

    Did you get to find a way around this?

  3. tobiasbeuving
    Member
    Posted 3 months ago #

    @aswitzer: I managed to hack around it by editing wp-included/pomo/entry.php and changing the line into:

    if ( !isset($imlikewhatever)):/*!class_exists( 'Translation_Entry' ) ):*/

    Be aware, after the next WP update you'll have to find the lines that try to instantiate inline classes and change them again!

    Anyhow, now I can spl_autoload my custom classes!

Reply

You must log in to post.

About this Topic