Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .wp-env.tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"plugins": [
"."
],
"themes": [
"https://downloads.wordpress.org/theme/twentytwentytwo.zip"
],
"testsEnvironment": false,
"config": {
"WP_DEBUG": true
Expand Down
7 changes: 7 additions & 0 deletions bin/scaffold.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,15 @@ module.exports = {
marker: 'wp:example',
groups: [
// Content modeling.
// The example taxonomies attach to the example post types, so removing
// post types also strips that link from the kept taxonomies.
capability( 'post-types', 'Post Types', 'Content', {
module: 'PostTypes',
strip: [
'inc/Modules/Taxonomies/ExampleTaxonomy.php',
'inc/Modules/Taxonomies/ExampleTaxonomyTwo.php',
'tests/php/TaxonomiesTest.php',
],
} ),
capability( 'taxonomies', 'Taxonomies', 'Content', {
module: 'Taxonomies',
Expand Down
2 changes: 1 addition & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Every set is kept by default. Removing a set at init deletes its module, classes
| Init key | Source | What it demonstrates | How to see it |
| --- | --- | --- | --- |
| `post-types` | `Modules/PostTypes/ExamplePostType.php`, `ExamplePostTypeTwo.php` | `AbstractPostType`: slug, labels, menu icon | Admin menu **Post Type Labels**; `wp post-type list` includes `post-type-slug`. |
| `taxonomies` | `Modules/Taxonomies/ExampleTaxonomy.php`, `ExampleTaxonomyTwo.php` | `AbstractTaxonomy` attached to the example post types via `get_object_types()` | `wp taxonomy list` includes `taxonomy-slug`; it appears on the example post type's editor. |
| `taxonomies` | `Modules/Taxonomies/ExampleTaxonomy.php`, `ExampleTaxonomyTwo.php` | `AbstractTaxonomy` attached to the example post types via `get_object_types()`; removing `post-types` drops that link | `wp taxonomy list` includes `taxonomy-slug`; it appears on the example post type's editor. |
| `blocks` | `Modules/Blocks/ExampleDynamicBlock.php`, `src/blocks/example-block*`, `templates/block-templates/example-block-dynamic.php` | A static block, a dynamic block (`AbstractBlock` rendering a template) and an Interactivity API block (`render.php` + `view.js`) | After `npm run build:dev`, insert **Example Block**, **Example Dynamic Block** or **Example Block Interactive** in the editor. |
| `shortcodes` | `Modules/Shortcodes/ExampleShortcode.php` | `AbstractShortcode` with default attributes, sanitized input and escaped output | Add `[acme_content_example title="Hello" count="3"]` to a post. |
| `rest` | `Modules/REST/ExampleRESTController.php` | `AbstractRESTController` with a real `permission_callback` (`manage_options`) | `GET /wp-json/acme-content-features/v1/examples` as an administrator (see below). |
Expand Down
4 changes: 3 additions & 1 deletion docs/internal/maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ Modules\Cron::class,
// wp:example:cron:end
```

On removal the engine deletes the region; on keep it deletes only the two marker lines. Current marked files are `inc/Main.php` (every set), `inc/Core/Assets.php` (`blocks`: the `STATIC_BLOCKS` entries) and `inc/Core/PluginSetup.php` (`cron`: the `use` import and the unschedule call). CI workflows use `wp:ci:<key>`.
On removal the engine deletes the region; on keep it deletes only the two marker lines. Current marked files are `inc/Main.php` (every set), `inc/Core/Assets.php` (`blocks`: the `STATIC_BLOCKS` entries), `inc/Core/PluginSetup.php` (`cron`: the `use` import and the unschedule call), and the example taxonomies and their test (`post-types`: the link to the example post types). CI workflows use `wp:ci:<key>`.

Rules that keep init working for every downstream project:

- Keep marker pairs balanced and on their own lines. A broken pair breaks removal for everyone.
- End new markers with a full stop (`// wp:example:<key>.`) so PHPCS accepts them. Init still recognises them.
- Inside an array, keep one comment line outside the markers, so the array still passes PHPCS when init empties it.
- A capability's footprint must be complete: module file, class folder, test file, and every coupled region. Anything left behind references deleted classes.
- Markers are consumed by the first run, so removal is one-shot by design.

Expand Down
9 changes: 8 additions & 1 deletion inc/Modules/Taxonomies/ExampleTaxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace Project_Name\Features\Modules\Taxonomies;

// wp:example:post-types.
use Project_Name\Features\Modules\PostTypes\ExamplePostType;
// wp:example:post-types:end.
use rtCamp\WPPrimitives\Contracts\Abstracts\AbstractTaxonomy;

/**
Expand All @@ -28,7 +30,12 @@ public static function get_slug(): string {
* {@inheritDoc}
*/
public static function get_object_types(): array {
return [ ExamplePostType::get_slug() ];
return [
// Post types this taxonomy attaches to.
// wp:example:post-types.
ExamplePostType::get_slug(),
// wp:example:post-types:end.
];
}

/**
Expand Down
9 changes: 8 additions & 1 deletion inc/Modules/Taxonomies/ExampleTaxonomyTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace Project_Name\Features\Modules\Taxonomies;

// wp:example:post-types.
use Project_Name\Features\Modules\PostTypes\ExamplePostTypeTwo;
// wp:example:post-types:end.
use rtCamp\WPPrimitives\Contracts\Abstracts\AbstractTaxonomy;

/**
Expand All @@ -28,7 +30,12 @@ public static function get_slug(): string {
* {@inheritDoc}
*/
public static function get_object_types(): array {
return [ ExamplePostTypeTwo::get_slug() ];
return [
// Post types this taxonomy attaches to.
// wp:example:post-types.
ExamplePostTypeTwo::get_slug(),
// wp:example:post-types:end.
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"test": "npm-run-all --parallel test:js test:php",
"test:js": "wp-scripts test-unit-jest --config=tests/js/jest.config.js --passWithNoTests",
"test:js:watch": "npm run test:js -- --watch",
"pretest:php": "wp-env start --config=.wp-env.tests.json && wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- sh -c 'test -f vendor/autoload.php || composer install --no-interaction'",
"pretest:php": "(wp-env run --config=.wp-env.tests.json cli true >/dev/null 2>&1 || wp-env start --config=.wp-env.tests.json) && ([ vendor/autoload.php -nt composer.lock ] || wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- composer install --no-interaction)",
"test:php": "wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- vendor/bin/phpunit -c phpunit.xml.dist",
"pretest:php:coverage": "echo \"\\e[1m\\e[32mMake sure you have run npm run wp-env start -- --config=.wp-env.tests.json --xdebug=coverage before using this command\\e[0m\" && wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- sh -c 'test -f vendor/autoload.php || composer install --no-interaction'",
"test:php:coverage": "wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- vendor/bin/phpunit -c phpunit.xml.dist --coverage-html coverage",
Expand Down
8 changes: 8 additions & 0 deletions tests/php/TaxonomiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ public function test_examples_are_taxonomy_instances(): void {
*/
public function test_static_accessors_are_accessible(): void {
$this->assertSame( 'taxonomy-slug', ExampleTaxonomy::get_slug() );
// wp:example:post-types.
$this->assertSame( [ 'post-type-slug' ], ExampleTaxonomy::get_object_types() );
// wp:example:post-types:end.

$this->assertSame( 'taxonomy-slug-two', ExampleTaxonomyTwo::get_slug() );
// wp:example:post-types.
$this->assertSame( [ 'post-type-slug-two' ], ExampleTaxonomyTwo::get_object_types() );
// wp:example:post-types:end.
}

/**
Expand All @@ -78,7 +82,9 @@ public function test_example_taxonomy_registers(): void {
$this->assertTrue( $object->public );
$this->assertTrue( $object->show_in_rest );
$this->assertTrue( $object->hierarchical );
// wp:example:post-types.
$this->assertContains( 'post-type-slug', $object->object_type );
// wp:example:post-types:end.
$this->assertSame( 'Taxonomy Label', $object->labels->singular_name );
$this->assertSame( 'Taxonomy Labels', $object->labels->name );
}
Expand All @@ -95,7 +101,9 @@ public function test_example_taxonomy_two_registers(): void {
$object = get_taxonomy( 'taxonomy-slug-two' );
$this->assertNotFalse( $object );
$this->assertFalse( $object->hierarchical );
// wp:example:post-types.
$this->assertContains( 'post-type-slug-two', $object->object_type );
// wp:example:post-types:end.
$this->assertSame( 'Taxonomy Two Label', $object->labels->singular_name );
$this->assertSame( 'Taxonomy Two Labels', $object->labels->name );
}
Expand Down
Loading