我是插件mapsmarker的开发人员。com还提供了几个可以直接访问的API(例如www.mapsmarker.com/wp-content/plugins/fluel-maps-marker/fluel-geojson.php?marker=1)对于这些API,我最初编写了一个文件的绝对目录路径,该文件在插件安装时具有以下功能:
file_put_contents(dirname(__FILE__).\'/leaflet-wp-path.php\', \'<?php define(\\\'WP_PATH\\\',\\\'\'.ABSPATH.\'\\\'); ?>\');
在API文件中,文件传单wp路径。php包含在以下代码中:
include_once(dirname($_SERVER[\'SCRIPT_FILENAME\']).\'/leaflet-wp-path.php\');
include_once(WP_PATH.\'wp-config.php\');
include_once(WP_PATH.\'wp-includes/wp-db.php\');
global $wpdb;
...
然后我注意到,在一些托管提供商上,这种操作不受支持,导致插件安装失败。因此,我切换到另一种方法来确定wp config的目录路径。php:
//info: construct path to wp-config.php with fallback for subdirectory installations
$wp_path = $_SERVER["DOCUMENT_ROOT"];
if ( file_exists($wp_path . \'/wp-config.php\') ) {
include_once($wp_path.\'/wp-config.php\');
include_once($wp_path.\'/wp-includes/wp-db.php\');
} else {
$wp_plugin_path_modified = explode(DIRECTORY_SEPARATOR, dirname(__FILE__),-3);
$wp_path = implode(DIRECTORY_SEPARATOR, $wp_plugin_path_modified);
include_once($wp_path.\'/wp-config.php\');
include_once($wp_path.\'/wp-includes/wp-db.php\');
}
if ( !file_exists($wp_path . \'/wp-config.php\') ) {
echo __(\'Error: Could not construct path to wp-config.php - please check <a href="http://mapsmarker.com/path-error">http://mapsmarker.com/path-error</a> for more details.\',\'lmm\') . \'<br/>Path on your webhost: \' . $wp_path;
} else {
...
即使在不允许函数file\\u put\\u contents()的主机上,这也很好,因为目录路径是根据API文件的当前目录名确定的。
现在我从一个用户那里得到了一个bug报告,告诉我这个方法在他的主机上不起作用。他写道:
这是图标链接之一的示例。看起来整个插件链接都不正确。现在只有一件事在起作用,那就是管理面板配置。它也在做标记,但不在浏览器中显示。
在Windows Web主机上http://XXXXX/wordpress/wp-content/plugins/D:/Hosting/5465771/html/wordpress/wp-content/plugins/leaflet-maps-marker/img/logo-mapsmarker.png
在Linux Web主机上http://XXXXX/wordpress/wp-content/plugins/D:/inetpub/vhosts/XXXXX/httpdocs/wordpress/wp-content/plugins/leaflet-maps-marker/img/logo-mapsmarker.png
有谁知道更好的方法来确定wp config的目录路径吗。php是否支持这种托管配置?