Skip to content

Commit

Permalink
Read the HOST_PATH environment variable for zero-setup remote path …
Browse files Browse the repository at this point in the history
…mapping.
  • Loading branch information
johnbillion committed Jan 16, 2025
1 parent 6fee02e commit f414a4d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 9 additions & 3 deletions docs/help/clickable-stack-traces-and-function-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ If you use an editor other than VS Code or PhpStorm then you may first need to c

If you're debugging a remote site or using Docker or a virtual machine, you'll need to map the path on the server to its path on your local machine so your editor doesn't try to load a non-existent file. You can do this using a filter on the `qm/output/file_path_map` hook which accepts an array of remote paths and the local path they map to.

For example, if you use the Docker-based development environment that's built in to WordPress core, your path mapping needs to look like this:
Here are examples for various environments:

### Altis

No need to do anything, the path mapping is handled for you.

### WordPress core development environment

```php
add_filter( 'qm/output/file_path_map', function( $map ) {
Expand All @@ -31,7 +37,7 @@ add_filter( 'qm/output/file_path_map', function( $map ) {
} );
```

If you use VVV your path mapping needs to look like this:
### VVV

```php
add_filter( 'qm/output/file_path_map', function( $map ) {
Expand All @@ -40,7 +46,7 @@ add_filter( 'qm/output/file_path_map', function( $map ) {
} );
```

If you use Chassis or another Vagrant-based VM, your path mapping needs to look like this:
### Chassis or another Vagrant-based VM

```php
add_filter( 'qm/output/file_path_map', function( $map ) {
Expand Down
12 changes: 11 additions & 1 deletion output/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,16 @@ public static function get_file_link_format() {
* @return array<string, string>
*/
public static function get_file_path_map() {
$map = array();

$host_path = getenv( 'HOST_PATH' );

if ( ! empty( $host_path ) ) {
$source = rtrim( ABSPATH, DIRECTORY_SEPARATOR );
$replacement = rtrim( $host_path, DIRECTORY_SEPARATOR );
$map[ $source ] = $replacement;
}

/**
* Filters the file path mapping for clickable file links.
*
Expand All @@ -613,7 +623,7 @@ public static function get_file_path_map() {
*
* @param array<string, string> $file_map Array of file path mappings. Keys are the source paths and values are the replacement paths.
*/
return apply_filters( 'qm/output/file_path_map', array() );
return apply_filters( 'qm/output/file_path_map', $map );
}

/**
Expand Down

0 comments on commit f414a4d

Please sign in to comment.