Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

block css not loading (wrong path) in roots bedrock environment (fix included) #526

Open
lemon3 opened this issue Apr 13, 2020 · 8 comments

Comments

@lemon3
Copy link

lemon3 commented Apr 13, 2020

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;
}
@kienstra
Copy link
Collaborator

Hi @lemon3,
Thanks for bringing this up, I'll look at this.

@Zyles
Copy link

Zyles commented Jul 29, 2020

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:
soflyy/oxygen-bugs-and-features#1380

@Zyles
Copy link

Zyles commented Jul 29, 2020

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;
        }

@kienstra
Copy link
Collaborator

Hi @Zyles,
Thanks a lot for your snippet!

@lemon3
Copy link
Author

lemon3 commented Jul 29, 2020

@Zyles,
i have tested your code in my environment, but it doesn't work ...

@Zyles
Copy link

Zyles commented Jul 29, 2020

Why not?

@lemon3
Copy link
Author

lemon3 commented Jul 29, 2020

as „wordpress“ is in it's own subdir
see here: https://roots.io/bedrock/

@Zyles
Copy link

Zyles commented Jul 30, 2020

I use Oxygen not bedrock. I think it depends on your webserver config too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants