You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run `npm run test` to run Jest tests against JavaScript files. Run
42
-
`npm run test:watch` to keep the test runner open and watching for changes.
43
-
44
-
Run `npm run lint` to run ESLint against all JavaScript files. Linting will also
45
-
happen when running development or production builds.
19
+
Activate the plugin in WordPress and you will see the switcher appear in the top right admin bar:
46
20
47
-
Run `composer test` to run tests against PHPUnit and the PHP code in the plugin.
21
+

48
22
49
-
### The `entries` directory and entry points
23
+
The plugin reads the current WordPress environment from `wp_get_environment_type()` which can be set by defining `WP_ENVIRONMENT_TYPE` in your `wp-config.php` file. You can define the available environments by using the `wp_environment_switcher_environments` filter:
50
24
51
-
All directories created in the `entries` directory can serve as entry points and will be compiled with [@wordpress/scripts](https://github.com/WordPress/gutenberg/blob/trunk/packages/scripts/README.md#scripts) into the `build` directory with an accompanied `index.asset.php` asset map.
52
-
53
-
#### Enqueuing Entry Points
54
-
55
-
You can also include an `index.php` file in the entry point directory for enqueueing or registering a script. This file will then be moved to the build directory and will be auto-loaded with the `load_scripts()` function in the `functions.php` file. Alternatively, if a script is to be enqueued elsewhere there are helper functions in the `src/assets.php` file for getting the assets.
56
-
57
-
### Scaffold a dynamic block with `create-block`
58
-
59
-
Use the `create-block` command to create custom blocks with [@alleyinteractive/create-block](https://github.com/alleyinteractive/alley-scripts/tree/main/packages/create-block) script and follow the prompts to generate all the block assets in the `blocks/` directory.
60
-
Block registration, script creation, etc will be scaffolded from the `create-block` script. Run `npm run build` to compile and build the custom block. Blocks are enqueued using the `load_scripts()` function in `src/assets.php`.
61
-
62
-
### Updating WP Dependencies
63
-
64
-
Update the [WordPress dependency packages](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/#packages-update) used in the project to their latest version.
65
-
66
-
To update `@wordpress` dependencies to their latest version use the packages-update command:
67
-
68
-
```sh
69
-
npx wp-scripts packages-update
25
+
```php
26
+
add_filter(
27
+
'wp_environment_switcher_environments',
28
+
fn () => [
29
+
'production' => 'https://example.org',
30
+
'staging' => 'https://staging.example.org',
31
+
'local' => 'https://example.test',
32
+
]
33
+
);
70
34
```
71
35
72
-
This script provides the following custom options:
36
+
The plugin will automatically detect the current environment and highlight it in
37
+
the switcher.
73
38
74
-
-`--dist-tag` – allows specifying a custom dist-tag when updating npm packages. Defaults to `latest`. This is especially useful when using [`@wordpress/dependency-extraction-webpack-plugin`](https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin). It lets installing the npm dependencies at versions used by the given WordPress major version for local testing, etc. Example:
0 commit comments