Skip to content

Commit

Permalink
Add section to README about WP global constants
Browse files Browse the repository at this point in the history
Global constants such as those for paths can't be stubbed because they need to be literal string paths to the actual locations of included/required files.
  • Loading branch information
mcaskill committed Aug 16, 2023
1 parent bd97269 commit 9f4fa7c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ If a directory is provided, the plugin will search for the following files:

The plugin expects a JSON representation of the hooks as per [wp-hooks/generator](https://github.com/wp-hooks/generator).

### WordPress paths

To help Psalm analyze your project you might need to define some of WordPress' default global constants such as those for paths.

```xml
<?xml version="1.0"?>
<psalm autoloader="tests/bootstrap.php" xmlns="https://getpsalm.org/schema/config">
<!-- project configuration -->
</psalm>
```

The following example bootstrap file is for a Bedrock installation:

```php
<?php

require_once dirname( __DIR__ ) . '/config/application.php';

define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' );

define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
```

You could require WordPress' default constants functions but that requires a lot more boilerplating to allow those functions to effectively define constants.

## Interested in contributing?

Expand Down

0 comments on commit 9f4fa7c

Please sign in to comment.