wordpress - Laravel 5 覆盖辅助函数 __() 因为在 wordpress 中使用
问题描述
我已经阅读了几篇关于stackoverflow的帖子,但没有帮助,所以我希望有人能给出好的答案。
我正在将 Laravel 与 wordpress 一起使用。现在有一个错误。是否可以重命名或其他方法来改变它?
错误:
Fatal error: Cannot redeclare __() (previously declared in C:app\laravel\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php:821)
解决方案
在 de 文件 wp-blog-header.php 在 wp-load.php 之前加载 l110n.php
if ( !isset($wp_did_header) ) {
$wp_did_header = true;
// Load the WordPress library.
require_once( dirname(__FILE__).'/wp-includes/l10n.php' );
require_once( dirname(__FILE__) . '/wp-load.php' );
// Set up the WordPress query.
wp();
// Load the theme template.
require_once( ABSPATH . WPINC . '/template-loader.php' );
}
并在你的 LARAVEL 项目中创建一个自己的帮助文件,使用这个函数并使用自己的名称:
if (! function_exists('ownname')) {
/**
* Translate the given message.
*
* @param string $key
* @param array $replace
* @param string $locale
* @return \Illuminate\Contracts\Translation\Translator|string
*/
function ownname($key = null, $replace = [], $locale = null)
{
return app('translator')->getFromJson($key, $replace, $locale);
}
}
推荐阅读
- go - 如何使用 go 1.13 安装从 golang 中删除的静态内容
- python - os.system 在执行 pygame 代码时打开新窗口
- python - 在字典和列表上运行循环以检查字典值是否在列表值范围内
- .net - 使用 Superpower 解析列表列表
- corda - 在令牌选择模块中找不到方法
- python - 更新 git repo 所需的最少网络流量是多少?
- asp.net - 使用 ASP.Net 4.5 Webforms 中的子域和可选参数的路由重写 IIS URL
- javascript - 工作表对象的 Google 表格平等运算符测试 == 或 =?
- uwp - 提高 IXamlMetadataProvider 性能
- c# - 如何在没有导航页面的情况下更改状态栏颜色