I'm trying to get the value similar to the WordPress site url to identify a certain WordPress installation.
Since the get_site_url
can get altered (with a plugin or directly) I came up with this:
untrailingslashit('http://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'],'', ABSPATH));
This gives me good result to identify the WordPress based on it address but I'm curios if this may cause troubles on some server installations?
Here's my answer based on the information you've provided.
Create a function. First check if the home url is defined as a constant in wp-config. If so there's the URL. It overrides any DB value so if not set correctly the site won't function.
If that's not set then run a manual DB query to get the value of home from the options table. By running it manually instead of using get_option there's no way this value can be changed by a plugin before you use it.
I hope this link might help you to better understand the implications of using
home_url() vs site_url()