简体   繁体   中英

Call to undefined function __() in wp-db.php

I have a standalone script in my WordPress installation and I have used the following to load the wpdb object:

define( 'SHORTINIT', true );
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

However, my error log outputs the following when I call the script:

PHP Fatal error:  Call to undefined function __() in /wp-includes/wp-db.php on line 1297

When I go to line 1297 in wp-db.php, I see

_doing_it_wrong( 'wpdb::prepare', sprintf( __( 'The query argument of %s must have a placeholder.' ), 'wpdb::prepare()' ), '3.9.0' );

If I comment out that line, the script doesn't crash, but being a core WordPress file, I don't think that's the best solution.

I do use the prepare method in a separate class, however it is only at the standalone script file that I get this error. When I re-use that same separate class by creating an object in a file that WordPress "recognizes", I don't get the error.

According to WP docs, __ is located in wp-includes/l10n.php - so you could try and include that as well (and hope that that then does not itself refer to stuff that in turn needs other files ;-)


Apparently it does work, so I'll just add it as an answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM