Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiled views path in wp-admin context #1

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion inc/class-compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,22 @@ class Compiler extends BladeCompiler {
* @return string
*/
public function getCompiledPath( $path ): string { // phpcs:ignore
// Get current working directory.
$cwd = getcwd();

// Handle case if the current working directory is /wp-admin and webroot is /wp.
// This scenario is common in local development environments.
if ( str_contains( $cwd, '/wp/wp-admin' ) ) {
junaidbhura marked this conversation as resolved.
Show resolved Hide resolved
$cwd = str_replace( '/wp/wp-admin', '', $cwd );
}

// Handle case if the current working directory is /wp-admin.
if ( str_contains( $cwd, '/wp-admin' ) ) {
$cwd = str_replace( '/wp-admin', '', $cwd );
}

// Get path.
$path = str_replace( getcwd(), '', $path );
$path = str_replace( $cwd, '', $path );

return $this->cachePath . '/' . sha1( 'v2' . Str::after( $path, $this->basePath ) ) . '.' . $this->compiledExtension; // phpcs:ignore
}
Expand Down