Skip to content

Commit

Permalink
Adding the bulk of the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Jul 6, 2023
1 parent 8994e6d commit b5024a7
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 431 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/unit-test.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/update-changelog.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/upgrade-wordpress-plugin.yml

This file was deleted.

1 change: 1 addition & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<property name="prefixes" type="array">
<element value="alleyinteractive" />
<element value="wp_environment_switcher" />
<element value="alley" />
</property>
</properties>
</rule>
Expand Down
88 changes: 22 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,44 @@
# WordPress Environment Switcher

Contributors: srtfisher

Tags: alleyinteractive, wp-environment-switcher

Stable tag: 0.1.0

Requires at least: 5.9

Tested up to: 6.1

Requires PHP: 8.0

License: GPL v2 or later

[![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)
[![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)

Easily switch between different site environments from the WordPress admin bar..
Easily switch between different site environments from the WordPress admin bar.

> Props to [WordPress Stage Switcher](https://github.com/roots/wp-stage-switcher) for the inspiration.
## Installation

You can install the package via composer:
You can install the package via Composer:

```bash
composer require alleyinteractive/wp-environment-switcher
```

## Usage

Activate the plugin in WordPress and use it like so:

```php
$plugin = Alley\WP\WordPress_Environment_Switcher\WordPress_Environment_Switcher\WordPress_Environment_Switcher();
$plugin->perform_magic();
```
<!--front-end-->
## Testing

Run `npm run test` to run Jest tests against JavaScript files. Run
`npm run test:watch` to keep the test runner open and watching for changes.

Run `npm run lint` to run ESLint against all JavaScript files. Linting will also
happen when running development or production builds.

Run `composer test` to run tests against PHPUnit and the PHP code in the plugin.

### The `entries` directory and entry points

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.

#### Enqueuing Entry Points

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.

### Scaffold a dynamic block with `create-block`

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.
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`.

### Updating WP Dependencies
Activate the plugin in WordPress and you will see the switcher appear in the top right admin bar:

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.
![Screenshot of plugin](https://github.com/alleyinteractive/wp-environment-switcher/assets/346399/83684c99-4f74-4969-b302-a0c617c17190)

To update `@wordpress` dependencies to their latest version use the packages-update command:
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:

```sh
npx wp-scripts packages-update
```php
add_filter(
'wp_environment_switcher_environments',
fn () => [
'production' => 'https://example.org',
'staging' => 'https://staging.example.org',
'local' => 'https://example.test',
]
);
```

This script provides the following custom options:

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

```sh
npx wp-scripts packages-update --dist-tag=wp-WPVERSION`
```
The plugin will automatically detect the current environment and highlight it in
the switcher.

Where `WPVERSION` is the version of WordPress you are targeting. The version
must include both the major and minor version (e.g., `6.1`). For example:
## Testing

```sh
npx wp-scripts packages-update --dist-tag=wp-6.1`
```
Run `composer test` to run tests against PHPUnit and the PHP code in the plugin.

## Changelog

Expand All @@ -94,9 +50,9 @@ This project is actively maintained by [Alley
Interactive](https://github.com/alleyinteractive). Like what you see? [Come work
with us](https://alley.co/careers/).

- [Sean Fisher](https://github.com/Sean Fisher)
- [Sean Fisher](https://github.com/srtfisher)
- [All Contributors](../../contributors)

## License

The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.
The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.
20 changes: 3 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
"authors": [
{
"name": "Sean Fisher",
"email": "srtfisher@gmail.com"
"email": "sean@alley.com"
}
],
"require": {
"php": "^8.0",
"alleyinteractive/composer-wordpress-autoloader": "^1.0"
"php": "^8.0"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0",
"mantle-framework/testkit": "^0.11",
"szepeviktor/phpstan-wordpress": "^1.1"
},
"config": {
Expand All @@ -31,27 +29,15 @@
},
"sort-packages": true
},
"extra": {
"wordpress-autoloader": {
"autoload": {
"Alley\\WP\\WordPress_Environment_Switcher": "src"
},
"autoload-dev": {
"Alley\\WP\\WordPress_Environment_Switcher\\Tests": "tests"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"phpcbf": "phpcbf .",
"phpcs": "phpcs .",
"phpunit": "phpunit",
"phpstan": "phpstan --memory-limit=512M",
"test": [
"@phpcs",
"@phpstan",
"@phpunit"
"@phpstan"
]
}
}
3 changes: 0 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ parameters:
level: max

paths:
- blocks/
- entries/
- src/
- wp-environment-switcher.php

# ignoreErrors:
Expand Down
18 changes: 0 additions & 18 deletions phpunit.xml

This file was deleted.

15 changes: 0 additions & 15 deletions src/class-wordpress-environment-switcher.php

This file was deleted.

Loading

0 comments on commit b5024a7

Please sign in to comment.