Skip to content

Commit da0e8ed

Browse files
authored
Merge pull request #5 from alleyinteractive/feature
Base feature of the plugin
2 parents 1f326cd + b26236c commit da0e8ed

15 files changed

+173
-432
lines changed

.github/workflows/unit-test.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/update-changelog.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/upgrade-wordpress-plugin.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<property name="prefixes" type="array">
3939
<element value="alleyinteractive" />
4040
<element value="wp_environment_switcher" />
41+
<element value="alley" />
4142
</property>
4243
</properties>
4344
</rule>

README.md

Lines changed: 23 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,44 @@
11
# WordPress Environment Switcher
22

3-
Contributors: srtfisher
4-
5-
Tags: alleyinteractive, wp-environment-switcher
6-
7-
Stable tag: 0.1.0
8-
9-
Requires at least: 5.9
10-
11-
Tested up to: 6.1
12-
13-
Requires PHP: 8.0
14-
15-
License: GPL v2 or later
16-
173
[![Coding Standards](https://github.com/alleyinteractive/wp-environment-switcher/actions/workflows/coding-standards.yml/badge.svg)](https://github.com/alleyinteractive/wp-environment-switcher/actions/workflows/coding-standards.yml)
18-
[![Testing Suite](https://github.com/alleyinteractive/wp-environment-switcher/actions/workflows/unit-test.yml/badge.svg)](https://github.com/alleyinteractive/wp-environment-switcher/actions/workflows/unit-test.yml)
194

20-
Easily switch between different site environments from the WordPress admin bar..
5+
Easily switch between different site environments from the WordPress admin bar.
6+
7+
> Props to [WordPress Stage Switcher](https://github.com/roots/wp-stage-switcher) for the inspiration.
218
229
## Installation
2310

24-
You can install the package via composer:
11+
You can install the package via Composer:
2512

2613
```bash
2714
composer require alleyinteractive/wp-environment-switcher
2815
```
2916

3017
## Usage
3118

32-
Activate the plugin in WordPress and use it like so:
33-
34-
```php
35-
$plugin = Alley\WP\WordPress_Environment_Switcher\WordPress_Environment_Switcher\WordPress_Environment_Switcher();
36-
$plugin->perform_magic();
37-
```
38-
<!--front-end-->
39-
## Testing
40-
41-
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:
4620

47-
Run `composer test` to run tests against PHPUnit and the PHP code in the plugin.
21+
![Screenshot of plugin](https://github.com/alleyinteractive/wp-environment-switcher/assets/346399/83684c99-4f74-4969-b302-a0c617c17190)
4822

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:
5024

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+
);
7034
```
7135

72-
This script provides the following custom options:
36+
The plugin will automatically detect the current environment and highlight it in
37+
the switcher.
7338

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:
75-
76-
```sh
77-
npx wp-scripts packages-update --dist-tag=wp-WPVERSION`
78-
```
79-
80-
Where `WPVERSION` is the version of WordPress you are targeting. The version
81-
must include both the major and minor version (e.g., `6.1`). For example:
39+
## Testing
8240

83-
```sh
84-
npx wp-scripts packages-update --dist-tag=wp-6.1`
85-
```
41+
Run `composer test` to run tests against PHPStan/PHPCS.
8642

8743
## Changelog
8844

@@ -92,11 +48,11 @@ Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed re
9248

9349
This project is actively maintained by [Alley
9450
Interactive](https://github.com/alleyinteractive). Like what you see? [Come work
95-
with us](https://alley.co/careers/).
51+
with us](https://alley.com/careers/).
9652

97-
- [Sean Fisher](https://github.com/Sean Fisher)
53+
- [Sean Fisher](https://github.com/srtfisher)
9854
- [All Contributors](../../contributors)
9955

10056
## License
10157

102-
The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.
58+
The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.

composer.json

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
"authors": [
1212
{
1313
"name": "Sean Fisher",
14-
"email": "srtfisher@gmail.com"
14+
"email": "sean@alley.com"
1515
}
1616
],
1717
"require": {
18-
"php": "^8.0",
19-
"alleyinteractive/composer-wordpress-autoloader": "^1.0"
18+
"php": "^8.0"
2019
},
2120
"require-dev": {
2221
"alleyinteractive/alley-coding-standards": "^1.0",
23-
"mantle-framework/testkit": "^0.11",
2422
"szepeviktor/phpstan-wordpress": "^1.1"
2523
},
2624
"config": {
@@ -31,27 +29,15 @@
3129
},
3230
"sort-packages": true
3331
},
34-
"extra": {
35-
"wordpress-autoloader": {
36-
"autoload": {
37-
"Alley\\WP\\WordPress_Environment_Switcher": "src"
38-
},
39-
"autoload-dev": {
40-
"Alley\\WP\\WordPress_Environment_Switcher\\Tests": "tests"
41-
}
42-
}
43-
},
4432
"minimum-stability": "dev",
4533
"prefer-stable": true,
4634
"scripts": {
4735
"phpcbf": "phpcbf .",
4836
"phpcs": "phpcs .",
49-
"phpunit": "phpunit",
5037
"phpstan": "phpstan --memory-limit=512M",
5138
"test": [
5239
"@phpcs",
53-
"@phpstan",
54-
"@phpunit"
40+
"@phpstan"
5541
]
5642
}
5743
}

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ parameters:
66
level: max
77

88
paths:
9-
- blocks/
10-
- entries/
11-
- src/
129
- wp-environment-switcher.php
1310

1411
# ignoreErrors:

phpunit.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/class-wordpress-environment-switcher.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)