A suite of page building content blocks for the ASU Web Standards Unity WordPress theme.
UnityBlocks is a WordPress block editor plugin that provides custom Gutenberg blocks for the ASU Web Standards Unity (UDS) WordPress theme. It is built with React 18, @wordpress/scripts, and a custom Webpack configuration. The plugin registers 10 content blocks under the unityblocks category.
- Plugin file:
unityblocks.php— registers blocks viaregister_block_type()from thebuild/directory. - Text domain:
unityblocks - WordPress: ≥ 6.6, PHP ≥ 7.4
- Node: ≥ 18.12.1, npm ≥ 9.2.0 (pinned via Volta)
src/ # Block source code (one folder per block)
hero/ # Example: block.json, index.js, edit.js, save.js, inspector.js, controls.js, frontend.js, icon.js
news-grid/
testimonial/
asu-events/
events-grid/
image-gallery/
anchor-menu/
ranking-card/
wchm/
resources/ # Shared libraries and utilities
unity/ # Local component library (Hero, Testimonial, Card, etc.)
components-core/ # Shared React components (used in edit.js and frontend.js)
component-news/ # News-specific display components (Grid, List, Carousel)
component-events/ # Events display component
component-ke-events/ # KE Events variant
asu-unity-stack/ # Git submodule → github.com/ASU/asu-unity-stack
utils/ # Utilities: hooks (SWR-based data fetching), transformers, helpers
build/ # Compiled output (generated, committed to repo)
webpack.config.js # Custom webpack extending @wordpress/scripts
unityblocks.php # Main WordPress plugin file
package.json # Project configuration
Each block in src/ follows a consistent 6–8 file pattern:
| File | Purpose |
|---|---|
block.json |
Block metadata, attributes, script/style registrations (WordPress Block API v2/v3) |
index.js |
Block registration via registerBlockType() — imports edit, save, and metadata |
edit.js |
Editor-side React component — renders Inspector + Controls + preview component |
save.js |
Serializes attributes as data-* attributes on a wrapper <div> |
frontend.js |
Client-side hydration — queries DOM, parses data-* attributes, creates React root |
inspector.js |
Sidebar panel controls (InspectorControls with PanelBody, TextControl, etc.) |
controls.js |
Toolbar controls (BlockControls, MediaUpload) |
icon.js |
Block icon SVG |
- Attribute flow: Attributes are defined in
block.json→ destructured fromprops.attributesin edit/save → passed tosetAttributes()for updates. - Save/Frontend pattern:
save.jsoutputs a<div>with all attributes as JSON-encodeddata-*attributes.frontend.jsreads these from the DOM and hydrates React components usingcreateRoot()(React 18). - Component sources: Some blocks import from the
@asu-unity-stackwebpack alias (git submodule), others from@asu/*npm packages, and others from localresources/unity/components.
Defined in webpack.config.js:
@resources→resources/@unity-components→resources/unity/component-news/src/components@asu-unity-stack→resources/asu-unity-stack/
Both src/ and resources/ are included in Babel transpilation.
| Command | Description |
|---|---|
npm run build |
Production build via wp-scripts build |
npm start |
Watch mode for development via wp-scripts start |
npm run manifest |
Generate build/blocks-manifest.php |
npm run format |
Format code via wp-scripts format |
npm run lint:js |
Lint JavaScript via wp-scripts lint-js |
npm run lint:css |
Lint styles via wp-scripts lint-style |
npm run plugin-zip |
Create distributable zip |
-
@asuscoped packages require authentication: The.npmrcpoints@asu:registrytohttps://npm.pkg.github.com/. Runningnpm installwill fail with a 401 error unless a valid GitHub token withread:packagesscope is configured. The packages affected are:@asu/component-carousel@asu/component-events@asu/components-core@asu/unity-react-core
Workaround: If you cannot authenticate, note that some blocks import directly from the
@asu-unity-stackgit submodule (aliased via webpack) rather than npm packages. For code-only changes that don't require a full build (e.g., editingblock.jsonattributes, modifying inspector controls, or updating text/labels), the build step can be skipped. -
Git submodule must be initialized: Run
git submodule update --initbefore building. Theresources/asu-unity-stacksubmodule provides source components used by several blocks (hero, anchor-menu). -
Node version: The project pins Node 18.12.1 and npm 9.2.0 via Volta. The build tooling (
@wordpress/scripts) is compatible with Node 18+.
- EditorConfig: tabs for PHP, 2-space indentation for JS/CSS/JSON/YAML.
- Linting: Uses
@wordpress/scriptsdefault ESLint and Stylelint configurations (no custom config files). - Formatting:
npm run formatapplies Prettier via@wordpress/scripts.
This project does not have unit or integration tests. There is no test infrastructure to run.
- GitHub Actions:
azure-devops-sync.ymlsyncs issues to Azure DevOps. There is a Copilot code review workflow and Dependabot updates. - No build/test CI pipeline — the build is run locally and the
build/directory is committed.
- Edit files in
src/<block-name>/. - Follow the existing file pattern (block.json, index.js, edit.js, save.js, inspector.js, controls.js, frontend.js, icon.js).
- Attributes must be defined in
block.jsonwith types and defaults. - The
save.jsmust serialize all attributes asdata-*attributes. - The
frontend.jsmust parse thosedata-*attributes and render the component.
- Create a new folder under
src/with the block name. - Create
block.jsonfollowing the WordPress Block API schema. Set"category": "unityblocks". - Implement the standard file set (index.js, edit.js, save.js, etc.).
- Run
npm run manifestto regeneratebuild/blocks-manifest.php. - Run
npm run buildto compile.
- Shared components live in
resources/unity/— changes here affect all blocks that import them. - Utility hooks are in
resources/utils/hooks/(e.g.,use-fetch-wp-rest-taxonomy.jsfor SWR-based REST API fetching). - Transformer functions are in
resources/utils/transformers/.
git submodule update --init
cd resources/asu-unity-stack
git pull
cd ../..
git add resources/asu-unity-stack- The
build/directory is committed to the repository — it must be rebuilt and committed after source changes. - React 18 is enforced via
overridesinpackage.json. - Some blocks use
deprecatedarrays in theirindex.jsfor backwards compatibility with older attribute schemas. - The
unityblocks.phpplugin file handles WordPress version compatibility (6.8+, 6.7, pre-6.7) for block registration.