block css not loading (wrong path) in roots bedrock environment (fix included)
Feature description
can you please update the function get_url_from_path() in class-util.php
Use case
roots bedrock environment (or when the WP_HOME !== WP_SITEURL)
Additional information
here is my „new“ get_url_from_path() function in class-util.php
public function get_url_from_path( $path ) {
// uri to current stylesheet directory
$uri = get_stylesheet_directory_uri();
// get the current (child-)theme name
$theme_name = substr($uri, strrpos($uri, '/')+1);
// relative path to the style file
$rel_path = substr($path, strrpos($path, $theme_name) + strlen($theme_name));
// stylesheet url
return $uri . $rel_path;
}
Hi @lemon3, Thanks for bringing this up, I'll look at this.
This fix does not work with Oxygen.
I stumbled upon this problem with Oxygen where you can not use a custom CSS file because it points to the wrong location (missing trailing slash on domain). I thought it was Oxygen being a problem.
See here: https://github.com/soflyy/oxygen-bugs-and-features/issues/1380
This fix worked for me:
public function get_url_from_path( $path ) {
$abspath = ABSPATH;
// Workaround for weird hosting situations.
if ( trailingslashit( ABSPATH ) . 'wp-content' !== WP_CONTENT_DIR && isset( $_SERVER['DOCUMENT_ROOT'] ) ) {
$abspath = sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) );
}
$stylesheet_url = str_replace( untrailingslashit( $abspath ), '', $path);
return get_site_url() . '/' . $stylesheet_url;
}
Hi @Zyles, Thanks a lot for your snippet!
@Zyles, i have tested your code in my environment, but it doesn't work ...
Why not?
as „wordpress“ is in it's own subdir see here: https://roots.io/bedrock/
I use Oxygen not bedrock. I think it depends on your webserver config too.