At Pressable, the WordPress Core files are symbolically linked to another location on the platform. In other words, they are not in the site root, as is the case with a standard WordPress install. Due to this, using ABSPATH
to locate files in the site can result in errors.
<?php
var_dump(ABSPATH);
Returns:
string(19) "/srv/htdocs/__wp__/"
ABSPATH vs. WP_CONTENT_DIR
ABSPATH
can be used when pointing to Core files, but it will not function correctly if used to locate files/folders within wp-content
.
For example, the following on Pressable:
$target_path = ABSPATH . 'wp-content/plugins/order-tracking/order-sheets/';
Could become:
$target_path = WP_CONTENT_DIR . '/plugins/order-tracking/order-sheets/';
With WP_CONTENT_DIR
, files/folders in the site root can be successfully accessed. Note that ABSPATH
has a trailing slash, whereas WP_CONTENT_DIR
does not.
If you are trying to access the site root on Pressable in various parts of your code and you’d also prefer for the implementation to be less brittle and readily modifidable, we’d recommend the use of a PHP constant to define the site root:
define('PRESSABLE_SITE_ROOT', str_replace( 'wp-content', '', WP_CONTENT_DIR));
This would define PRESSABLE_SITE_ROOT
as /srv/htdocs/
, and it should also be usable on other hosting platforms:
$target_path = PRESSABLE_SITE_ROOT . 'wp-content/plugins/order-tracking/order-sheets/';
This constant could be placed in a plugin or a theme. It is not recommended to use this constant in wp-config.php
because some hosting platforms often do not migrate wp-config.php
or allow it to be modified.
While not preferable, if a plugin ever requires you to set an option for your site root via wp-admin, you should use the following path: /srv/htdocs
If you have questions about this please contact support.