0

I'm trying to prevent WP from loading all plug-ins when including wp-load.php, since I don't really need them nor the usual WP actions/filters. All I need is the WPDB class to query the database easily.

I've only found an (old) solution that involves defining WP_INSTALLING to trick WP into not loading plug-ins, but I'm not sure if it still works on current versions and/or if there's a better way.

(Background: I'm trying to optimize a simple autocomplete PHP script that serves JSON results via AJAX by doing some simple queries after initializing $wpdb via wp-load.php)

2 Answers 2

3

WordPress 3.4+ Method: Just define this define( 'SHORTINIT', true ); before you call wp-load.php

2

WordPress is heavy out-of-the-box. If you only need the database, you'd be so much better off using mysqli or PDO and just connecting directly.

Not to mention (in my opinion) PDO beats hell out of wpdb anyway, win win.

the idea is to make use of the DB defines in wp-config.php without needing to store the username/password somewhere else

Create wp-config-db.php with just your database constants, then swap them out in wp-config.php for require './wp-config-db.php';

Now you can just load wp-config-db.php in your handler and hey presto.

2
  • That could work, but the idea is to make use of the DB defines in wp-config.php without needing to store the username/password somewhere else, and I cannot include just wp-config.php: it also includes wp-settings.php with WP functions that wouldn't work. I could normally add an if() to skip wp-settings in wp-config.php, but I don't have much control over wp-config.php on this particular production instance so I would prefer to avoid it.
    – guidod
    Commented Jan 19, 2015 at 17:12
  • See my revision :) Commented Jan 19, 2015 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.