2017-07-17 114 views
0

我在我的服务器上的web服务目录中调用vanilla Wordpress函数时遇到了一些问题。在wordpress根目录以外的webservice中使用WordPress功能

我有这样的结构:

Root 

- webservice 
- - service.php 
- wordpress 
- - wordpress-root 

我开始与谷歌这个问题,并找到这样一些解决方案...

require($_SERVER['DOCUMENT_ROOT'].'/wordpress-root/wp-load.php'); 

require($_SERVER['DOCUMENT_ROOT'].'/wordpress-root/wp-blog-header.php'); 

我加入这些行放到我的service.php中。 现在我的浏览器开始我重定向到以下URL并抛出一个错误 wp-admin/install.php

The requested URL /wp-admin/install.php was not found on this server. 

难道有人有一个坚实的解决这个问题?

//编辑

调试后想通了,重定向是在function.php

/* 
* Loop over the WP tables. If none exist, then scratch install is allowed. 
* If one or more exist, suggest table repair since we got here because the 
* options table could not be accessed. 
*/ 
$wp_tables = $wpdb->tables(); 
foreach ($wp_tables as $table) { 
    // The existence of custom user tables shouldn't suggest an insane state or prevent a clean install. 
    if (defined('CUSTOM_USER_TABLE') && CUSTOM_USER_TABLE == $table) 
     continue; 
    if (defined('CUSTOM_USER_META_TABLE') && CUSTOM_USER_META_TABLE == $table) 
     continue; 
    // Error throw after this lines 
    if (! $wpdb->get_results("DESCRIBE $table;")) 
     continue; 
+0

因此,如果您导航到'/ WordPress的根/'会发生什么? – WheatBeak

+0

@WheatBeak'require($ _ SERVER ['DOCUMENT_ROOT']。'/ wordpress-root /');'抛出一个错误“Warning:require”... – Pommesloch

+0

您的WordPress安装必须是有效的,然后才能从另一个目录。 – WheatBeak

回答

0

重定向到install.php了发生的这行代码后扔在WordPress的认为这是一个新的安装。当wordpress无法在数据库中找到特定条目时,就会发生这种情况。 (选项表与option_name =='siteurl')

打开文件functions.php并搜索函数is_blog_installed。然后调试为什么这个函数认为wordpress没有安装。

我的猜测是配置文件无法读取或某些变量为空。检查是否有正确的文件权限。

您也可以尝试通过脚本设置变量。另请参阅site_url函数。

+0

谢谢。这是一个很好的暗示。重定向似乎在这行代码之后。 'if(!$ wpdb-> get_results(“DESCRIBE $ table;”)) \t \t \t继续;' – Pommesloch

0

尝试

define('WP_USE_THEMES', false); 
require($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php') 

define('WP_USE_THEMES', false); 
require($_SERVER['DOCUMENT_ROOT'].'/wp-load.php') 

https://wordpress.stackexchange.com/q/47049/10911

+0

谢谢您的帮助,但那并没有解决我的问题。 – Pommesloch