Change WordPress user roles and capabilities › Forums › Bug Reports › Content View Restrictions Redirect to URL › Reply To: Content View Restrictions Redirect to URL
13/11/2018 at 06:10
#5269
Vladimir
Keymaster
Thanks for suggestion. It makes code more universal. I accept it with a little addition to remove a beginning slash from a resulting value, if it’s there:
private static function get_page_path_from_url() {
$url = substr( untrailingslashit( parse_url( $_SERVER['REQUEST_URI'] , PHP_URL_PATH) ), 1);
$home_url = basename( untrailingslashit( parse_url( home_url(), PHP_URL_PATH ) ) );
$path = substr( $url, strlen( $home_url ) );
if (substr( $path, 0, 1)==DIRECTORY_SEPARATOR) {
$path = substr( $path, 1);
}
return $path;
}
// end of get_page_path_from_url()