Skip to content
Merged
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
26 changes: 22 additions & 4 deletions content/bones-console/bones-console.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Great! You are quite ready to start developing.
Since `v2.0.10` every command exits with a non-zero status when it fails, and with `1` when you answer "no" to a confirmation or nothing answers it, as in a script; errors are written to stderr. To confirm from a script, pipe the answer: `echo y | php bones version 1.2.0`.
</Callout>

<Callout type="info">
Since `v2.1.0` bones works from any folder: `php my-plugin/bones make:controller Cart` writes into `my-plugin`, and a custom command still finds WordPress. A relative `deploy` path means the folder you typed it in. Up to `v2.0.12` bones had to be run from the plugin root: from anywhere else it could not read the plugin's `namespace` file and stopped with a `TypeError`.
</Callout>

### `deploy`

When your plugin is ready, you can use the `deploy` bones command in order to create a new folder useful to submit your plugin to the wordpress.org repository.
Expand Down Expand Up @@ -168,6 +172,8 @@ The `rename` command is used to rename the plugin namespace. You can use the `re
php bones rename "My First WP Bones Plugin"
```

Since `v2.1.0` the rename writes only the files whose content changes, and leaves binary files alone. Up to `v2.0.12` it rewrote every file of the plugin, and a compiled `.mo` catalogue came out corrupted, because a longer plugin id shifts its strings while the offset table stays put.

→ See more about [Naming your Plugin](../getting-started/naming-your-plugin).

### `require`
Expand Down Expand Up @@ -208,12 +214,18 @@ A value you `return` is printed, variables live until the session ends, and an e

### `update`

The `update` command is used to update the WP Bones framework. You can use the `update` command by running:
The `update` command updates the WP Bones framework and the packages it depends on:

```sh copy
php bones update
```

Since `v2.1.0` it runs `composer update wpbones/wpbones --with-dependencies` and exits with Composer's status. To update every package of your plugin, run `composer update`.

<Callout type="warning">
Up to `v2.0.12` the command deleted `vendor/wpbones/wpbones` first and then ran a full `composer update`: when Composer failed, without a network for example, the plugin was left with no framework at all.
</Callout>

→ After updating the WP Bones framework, have a look at the [Changelog](../release-notes) to see what's new.<br/>
→ And you may also check the [Core Plugin Files](../core-plugin-files/overview) to see if there are any changes.

Expand Down Expand Up @@ -348,12 +360,16 @@ php bones migrate:to-v2
```

The command removes `gulpfile.js` and `package-lock.json`, creates
`webpack.config.js`, `tsconfig.json`, `.prettierrc`, and `jest.config.js`
`webpack.config.js`, `tsconfig.json`, `.prettierrc`, `.prettierignore` and `jest.config.js`
from the framework stubs, rewrites `package.json` scripts to the unified
`dev/build/test/format/lint` block, drops gulp-era devDependencies, and
installs the v2 set (`@wordpress/scripts ^31`, `typescript`, `glob`,
`less-loader`, `webpack-remove-empty-scripts`, `@types/react*`). Your
`resources/assets/` tree is left untouched — your code is preserved.
`less-loader`, `webpack-remove-empty-scripts`, `@types/react*`, and `prettier`
as `wp-prettier`). Your `resources/assets/` tree is left untouched — your code is preserved.

<Callout type="info">
Since `v2.1.0` the migrated `format:check` is `prettier --check`, and it writes nothing. Up to `v2.0.12` it was `wp-scripts format --check`, and `wp-scripts format` ignores `--check`: the "check" reformatted the plugin, compiled bundles included, and exited 0. The new `.prettierignore` also keeps `format` away from `public/`.
</Callout>

After migration, run:

Expand All @@ -379,6 +395,8 @@ php bones make:cpt MyCustomPostTypeClass
Every creator that writes a PHP class takes a class name or `Folder/ClassName` (`make:console` takes a class name only, since the kernel loads `plugin/Console/Commands/*.php`), and the namespace follows the folder: `php bones make:controller Shop/Cart` writes `plugin/Http/Controllers/Shop/Cart.php` in `…\Http\Controllers\Shop`. `make:app`, below, takes an app name instead.

<Callout type="info">
Since `v2.1.0` `make:widget Shop/RecentPosts` gives the widget the `id_base` `<plugin-id>-shop-recent-posts`, the name `<Plugin Name> Recent Posts` and a description. Up to `v2.0.12` every widget of a plugin got `<plugin-id>-demo-widget`, so a second widget shared the first one's settings, and the description never showed.

Since `v2.0.10` the class creators never overwrite a file that already exists: they stop and leave it as it is. Pass `--force` to overwrite it. A name that is not a PHP class name, or that climbs out of the folder with `..`, is refused. `make:app` refuses an existing app, `--force` or not.
</Callout>

Expand Down
5 changes: 3 additions & 2 deletions content/bones-console/writing-commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ public function handle()
<Callout type="info">
`$this->plugin` is available from WP Bones **v2.0.8**. When your plugin is active it is the very
instance WordPress created, so hooks are not registered twice; when it is not active,
`loadWordPress()` boots it for the command. Run the command from the plugin root: WordPress is
looked up three folders above it, and if it is not there `$this->plugin` stays `null`.
`loadWordPress()` boots it for the command. WordPress is looked up three folders above the plugin,
and if it is not there `$this->plugin` stays `null`. Since `v2.1.0` that works whatever folder
you run `php bones` from; up to `v2.0.12` only from the plugin root.
</Callout>

## Customizing Deploy
Expand Down
4 changes: 2 additions & 2 deletions content/core-plugin-files/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Callout, FileTree } from 'nextra/components'

# Core Plugin Files

This document explains how to update the WP Bones framework using the `php bones update` command, which executes a `composer update` along with other tasks. It highlights that only the framework is updated, not your plugin. The document provides an overview of the core plugin files included in the WP Bones boilerplate, noting that these files may undergo changes. It is advised checking for updates to these files if you have a plugin created with an earlier version of WP Bones.
This document explains how to update the WP Bones framework using the `php bones update` command, which runs `composer update wpbones/wpbones --with-dependencies`. It highlights that only the framework is updated, not your plugin. The document provides an overview of the core plugin files included in the WP Bones boilerplate, noting that these files may undergo changes. It is advised checking for updates to these files if you have a plugin created with an earlier version of WP Bones.

## Overview

Expand All @@ -13,7 +13,7 @@ You can update the WP Bones framework by using the bones command:
php bones update
```

Under the hood, the bones command will execute a `composer update` along with other tasks.
Under the hood, the bones command runs `composer update wpbones/wpbones --with-dependencies`; the `post-autoload-dump` hook in your [`composer.json`](./composer-json) then runs `php bones rename --update`, which renames the new framework into your namespace.
Of course, you are updating just the framework, not your plugin.

In this section, you will find the latest versions of the files included in the WP Bones boilerplate. These files may undergo changes, including breaking changes.
Expand Down
7 changes: 4 additions & 3 deletions content/core-plugin-files/package-json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ auto-discovers everything under `resources/assets/`.
"test": "wp-scripts test-unit-js",
"test:watch": "wp-scripts test-unit-js --watch",
"format": "wp-scripts format",
"format:check": "wp-scripts format --check",
"format:check": "prettier --check --ignore-path .prettierignore \"**/*.{js,jsx,json,ts,tsx,yml,yaml}\"",
"lint": "wp-scripts lint-js resources/",
"lint:style": "wp-scripts lint-style 'resources/**/*.{css,scss}'",
"check-engines": "wp-scripts check-engines",
Expand All @@ -35,6 +35,7 @@ auto-discovers everything under `resources/assets/`.
"glob": "^11.0.0",
"less": "^4.6.4",
"less-loader": "^12.2.0",
"prettier": "npm:[email protected]",
"typescript": "^5.9.3",
"webpack-remove-empty-scripts": "^1.1.0"
}
Expand All @@ -49,8 +50,8 @@ auto-discovers everything under `resources/assets/`.
| `yarn build` | One-shot production build into `public/` |
| `yarn test` | Runs Jest via `wp-scripts test-unit-js` on files under `__tests__/` |
| `yarn test:watch` | Same as above, watch mode |
| `yarn format` | Prettier over `resources/` |
| `yarn format:check` | Prettier in check mode (CI-friendly) |
| `yarn format` | Prettier over the plugin's JS, TS, JSON and YAML, except what `.prettierignore` lists: `public/` and `build/`, `vendor/`, `composer.json` and `composer.lock`, and the translation JSON in `languages/` |
| `yarn format:check` | The same files, checked: exits 1 where `yarn format` would change something, and writes nothing |
| `yarn lint` | ESLint over JS/TS in `resources/` |
| `yarn lint:style` | stylelint over CSS/SCSS in `resources/` |

Expand Down
19 changes: 13 additions & 6 deletions content/core-plugin-files/webpack-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ const IGNORE_DECLARATIONS = { ignore: '**/*.d.ts' };

// @wordpress/scripts has loader rules for .css and .scss/.sass only: the .less rule
// reuses the scss loaders (CSS extraction, css-loader, PostCSS) with less-loader.
const sassRule = defaultConfig.module.rules.find((rule) => rule.test instanceof RegExp && rule.test.test('.scss'));
const sassRule = defaultConfig.module.rules.find(
(rule) => rule.test instanceof RegExp && rule.test.test('.scss')
);
if (!sassRule) {
throw new Error('webpack.config.js: no .scss rule in the @wordpress/scripts config to build the .less rule from.');
throw new Error(
'webpack.config.js: no .scss rule in the @wordpress/scripts config to build the .less rule from.'
);
}
const lessRule = {
test: /\.less$/,
Expand All @@ -42,10 +46,12 @@ function autoEntries() {
const entries = {};

// React/TS apps — folder-based (for apps with multiple files)
glob.sync('resources/assets/apps/*/index.{ts,tsx,js,jsx}', IGNORE_DECLARATIONS).forEach((file) => {
const name = path.basename(path.dirname(file));
entries[`apps/${name}`] = `./${file}`;
});
glob
.sync('resources/assets/apps/*/index.{ts,tsx,js,jsx}', IGNORE_DECLARATIONS)
.forEach((file) => {
const name = path.basename(path.dirname(file));
entries[`apps/${name}`] = `./${file}`;
});

// React/TS apps — single-file (for lightweight apps)
glob.sync('resources/assets/apps/*.{ts,tsx,js,jsx}', IGNORE_DECLARATIONS).forEach((file) => {
Expand Down Expand Up @@ -82,6 +88,7 @@ module.exports = {
},
plugins: [
...defaultConfig.plugins,
// Strips the empty `.js` that webpack would generate for pure-CSS entries.
new RemoveEmptyScriptsPlugin(),
],
};
Expand Down
2 changes: 2 additions & 0 deletions content/getting-started/naming-your-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ php bones rename --update
Probably, you won't need to do that as the update flow is already in the composer file
</Callout>

Since `v2.1.0` `rename --update` renames `vendor/` only, which is what Composer has just installed: your plugin's own files are left alone. Up to `v2.0.12` it went through the whole rename again, and in a renamed plugin with an `index.php` in its root it moved that `index.php` over your main plugin file.


```json copy
...
Expand Down
6 changes: 3 additions & 3 deletions content/migrating-to-v2.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ constraint to `^2.0.0` after running the migrator.

- `webpack.config.js` — a single file that scans `resources/assets/` and builds everything.
- `tsconfig.json` — TypeScript ready out of the box (JS still works).
- `.prettierrc`, `jest.config.js`.
- `.prettierrc`, `.prettierignore`, `jest.config.js`.
- `@wordpress/scripts ^31`, `typescript`, `glob`, `less-loader`, `webpack-remove-empty-scripts`,
`@types/react*`, `@wordpress/jest-preset-default` devDependencies.
`@types/react*`, `@wordpress/jest-preset-default` and `prettier` (as `wp-prettier`) devDependencies.

### Unified scripts

Expand All @@ -53,7 +53,7 @@ constraint to `^2.0.0` after running the migrator.
"test": "wp-scripts test-unit-js",
"test:watch": "wp-scripts test-unit-js --watch",
"format": "wp-scripts format",
"format:check": "wp-scripts format --check",
"format:check": "prettier --check --ignore-path .prettierignore \"**/*.{js,jsx,json,ts,tsx,yml,yaml}\"",
"lint": "wp-scripts lint-js resources/",
"lint:style": "wp-scripts lint-style 'resources/**/*.{css,scss}'"
}
Expand Down
8 changes: 4 additions & 4 deletions content/services-provider/widgets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You may create your own widget service provider by following the steps below:
php bones make:widget MyWidget
```

By default, the new provider will be created in the `plugin/Widgets` directory. Of course, you may create your Service Provider manually and in any directory you prefer. You have to change the namespace accordingly.
By default, the new provider will be created in the `plugin/Widgets` directory. Its base ID, name and description come from the class name: `MyWidget` in a plugin named "WP Kirk" gets `wp-kirk-my-widget`, "WP Kirk My Widget" and "The My Widget widget of WP Kirk" (since `v2.1.0`; before, every widget got the same base ID, and so the same settings). Of course, you may create your Service Provider manually and in any directory you prefer. You have to change the namespace accordingly.

```php filename="plugin/Widgets/MyWidget.php" copy
<?php
Expand Down Expand Up @@ -49,14 +49,14 @@ class MyWidget extends Widget
*
* @var string
*/
public $id_base = 'wpkirk-demo-widget';
public $id_base = 'wp-kirk-my-widget';

/**
* Name for the widget displayed on the configuration page.
*
* @var string
*/
public $name = 'WP Kirk Widget';
public $name = 'WP Kirk My Widget';

/**
* Optional. Passed to wp_register_sidebar_widget()
Expand All @@ -67,7 +67,7 @@ class MyWidget extends Widget
* @var array
*/
public $widget_options = [
'description' => 'WP Kirk Demo Widget Description'
'description' => 'The My Widget widget of WP Kirk'
];

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@
"test": "yarn next typegen && yarn format:test && yarn lint && yarn typecheck && yarn jest",
"typecheck": "tsc --noEmit"
},
"version": "2.0.12"
"version": "2.1.0"
}
Binary file added public/newsletter/wpbones-2.1.0-bones-update.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/wpkirk-api-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-blade-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-cpt-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-cron-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-database-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-hooks-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-internationalization-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-mantine-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-options-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-packages-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-reactjs-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-routes-boilerplate.zip
Binary file not shown.
Binary file modified public/wpkirk-typescript-boilerplate.zip
Binary file not shown.