0

我已经为 X-Cart 4.6.4 Gold 站点安装并配置了“X-Cart 中的 WordPress”模块。当我从 X-Cart 管理员启用模块时,x-cart 前端崩溃,并显示“建立数据库连接时出错。无法使用 W3_Config 类型的对象作为 /home/[username]/public_html/include/ 中的数组” func/func.db.php 在第 517 行”消息,在空白页中。X-Cart 后端工作正常,当我禁用模块时,x-cart 前端再次工作。此外,当我直接进入 WordPress 站点时,WordPress 前端和管理员都可以正常工作。WP 站点位于 X-Cart 根目录中。

我找到了一个我不确定它是否完美的解决方案,但暂时它可以工作。我试图在本地开发人员中使用调试器跟踪代码。服务器,我发现在/wp-includes/ms-settings.php WP 脚本文件中,靠近第 57 行,代码通过浏览器中的输入路径查询 WP 数据库来搜索当前博客。这通过代码片段存储在$current_blog变量中:

if ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) {
            $current_blog = get_site_by_path( $domain, $path );
        } elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) {
            // If the current network has a path and also matches the domain and path of the request,
            // we need to look for a site using the first path segment following the network's path.
            $current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) );
        } else {
            // Otherwise, use the first path segment (as usual).
            $current_blog = get_site_by_path( $domain, $path, 1 ); // REPLACED LINE
        }

$current_blog 变量设置为 false,从而导致关于找到的当前 WP 站点的更多空对象并退出过程,显示“建立数据库连接时出错”消息。

据我所知,$path变量被设置为 x-cart 根目录的相对路径(例如,如果 xcart 安装在 /xcart 根目录中,而 WP 博客安装在 /xcart/blog/ 目录中,那么$path变量是设置为'/xcart/',省略博客路径部分,因此找不到博客。另一方面,$current_site->path 值包含博客的路径(/xcart/blog/),所以我替换了上面的行(注释:'REPLACED LINE')与下面的行:

 $current_blog = get_site_by_path($domain, $current_site->path);  

此外,我做了以下事情: - 我删除了 WordPress 根目录的 .htaccess 文件中的所有 mod_rewrite 规则,因为它们破坏了初始重定向 - 我试图删除我在此线程中发布的代码调整,但随后站点显示数据库连接错误,所以我把它找回来了。- 我停用了WordPress 中的W3 Total Cache插件,因为它不断破坏网站。

奇怪的是,我还需要对代码进行调整。无论如何,集成工作正常。

我的问题是我上面关于代码修改的方法是否正确,因为我实际上修改了原始的 WordPress 代码,在这个地方几乎不可能有错误。

4

0 回答 0