For GitHub pull requests, detect any coding standard violations via PHP_CodeSniffer. Errors should prevent the pull request from being merged and displayed to the user.
? Implementation
A workflow file with GitHub Actions to set up PHP with Composer and to run PHP_CodeSniffer.
If the coding standard isn’t one of the defaults it need to be added as (dev) dependency in your project’s composer.json file.
Only 10 warning and 10 error annotations per step are currently supported (source). It’s recommended to fix all existing errors before publishing the workflow.
To exit with error codes if there are only warnings you can remove the --graceful-warnings flag in the last line.
To render the UI we extend Component and implement the render() method. For this example I used a PanelColor component which allows a user to select a color. We’ll save the hex value in the post meta my_color_one:
(Please ignore the incorrect syntax highlighting.)
Now we need a higher-order component which is used to fetch the data, in this case our post meta.
The second higher-order component is used to update the data.
Since we now have two higher-order components we have to combine them with compose:
Having a fully renderable component we can finally register our custom plugin:
And that’s it! ?
PS: Make sure to register the post meta properly with 'show_in_rest' => true.