调用 wp-db.php 中未定义的函数 __() [英] Call to undefined function __() in wp-db.php

查看:19
本文介绍了调用 wp-db.php 中未定义的函数 __()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 WordPress 安装中有一个独立的脚本,我使用以下内容加载 wpdb 对象:

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

当我转到 wp-db.php 中的第 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' );

如果我注释掉该行,脚本不会崩溃,但作为核心 WordPress 文件,我认为这不是最佳解决方案.

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.

我确实在单独的类中使用了 prepare 方法,但是只有在独立脚本文件中才会出现此错误.当我通过在 WordPress 识别"的文件中创建一个对象来重新使用同一个单独的类时,我没有收到错误消息.

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.

推荐答案

根据 WP 文档, __ 位于 wp-includes/l10n.php - 所以你也可以尝试包含它(并希望它本身不会引用需要其他文件的东西;-)

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 ;-)

显然它确实有效,所以我将其添加为答案.

这篇关于调用 wp-db.php 中未定义的函数 __()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆