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
5 changes: 0 additions & 5 deletions .changeset/headless-documents-initial.md

This file was deleted.

6 changes: 3 additions & 3 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ updates:

# composer (plugins)
- package-ecosystem: "composer"
directory: "/plugins/headless-documents"
directory: "/plugins/hwp-documents"
schedule:
interval: "weekly"
ignore:
Expand Down Expand Up @@ -60,7 +60,7 @@ updates:

# docker (Dockerfiles)
- package-ecosystem: "docker"
directory: "/plugins/headless-documents/.docker"
directory: "/plugins/hwp-documents/.docker"
schedule:
interval: "weekly"
ignore:
Expand All @@ -85,7 +85,7 @@ updates:

# docker (docker-compose)
- package-ecosystem: "docker"
directory: "/plugins/headless-documents"
directory: "/plugins/hwp-documents"
schedule:
interval: "weekly"
ignore:
Expand Down
1 change: 1 addition & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"plugins/hwp-documents": "0.0.0",
"plugins/hwp-previews": "1.0.2",
"plugins/wpgraphql-debug-extensions": "0.0.4",
"plugins/wpgraphql-logging": "1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The toolkit includes several WordPress plugins to enhance the headless experienc
| Plugin | Description |
|--------|-------------|
| [wpgraphql-logging](../plugins/wpgraphql-logging/) | Logging for WPGraphQL requests with granular lifecycle events and Monolog integration. |
| [headless-documents](../plugins/headless-documents/) | Store your app's JSON documents in WordPress over REST, with versioned writes that reject stale updates. |
| [hwp-documents](../plugins/hwp-documents/) | Store your app's JSON documents in WordPress over REST, with versioned writes that reject stale updates. |
| [hwp-previews](../plugins/hwp-previews/) | Headless Previews solution for WordPress: fully configurable preview URLs via the settings page which is framework agnostic. |

## Examples
Expand Down
2 changes: 1 addition & 1 deletion llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

WordPress plugins for the Headless WordPress Toolkit. Each plugin is paired with an NPM package.

- [Headless Documents](https://github.com/wpengine/hwptoolkit/blob/main/plugins/headless-documents/README.md)
- [HWP CLI Plugin](https://github.com/wpengine/hwptoolkit/blob/main/plugins/hwp-cli/README.md)
- [HWP Documents](https://github.com/wpengine/hwptoolkit/blob/main/plugins/hwp-documents/README.md)
- [HWP Previews](https://github.com/wpengine/hwptoolkit/blob/main/plugins/hwp-previews/README.md)
- [WPGraphQL Debug Extensions](https://github.com/wpengine/hwptoolkit/blob/main/plugins/wpgraphql-debug-extensions/README.md)
- [WPGraphQL Logging](https://github.com/wpengine/hwptoolkit/blob/main/plugins/wpgraphql-logging/README.md)
Expand Down
2 changes: 1 addition & 1 deletion plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WordPress plugins for the Headless WordPress Toolkit. Each plugin is paired with

| Plugin | Description |
|--------|-------------|
| [headless-documents](./headless-documents/README.md) | Store your app's JSON documents in WordPress over REST, with versioned writes that reject stale updates. |
| [hwp-documents](./hwp-documents/README.md) | Store your app's JSON documents in WordPress over REST, with versioned writes that reject stale updates. |
| [hwp-previews](./hwp-previews/README.md) | Headless Previews solution for WordPress: fully configurable preview URLs via the settings page which is framework agnostic. |
| [wpgraphql-webhooks](./wpgraphql-webhooks/README.md) | Extends WPGraphQL to support webhook subscriptions and dispatching for headless WordPress environments. |
| [wpgraphql-logging](./wpgraphql-logging/README.md) | Logging for WPGraphQL requests with granular lifecycle events and Monolog integration. |
Expand Down
86 changes: 0 additions & 86 deletions plugins/headless-documents/headless-documents.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PLUGIN_SLUG=headless-documents
PLUGIN_SLUG=hwp-documents

# Configure these to match your existing testing environment or the one you want to create with Docker.
## Usually, these values should match the ones in the `wp-config.php` file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Pre-configured WordPress Installation w/ Headless Documents Plugin
# Pre-configured WordPress Installation w/ HWP Documents Plugin
# For testing only, use in production not recommended. #
###############################################################################

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PLUGIN_SLUG=headless-documents
PLUGIN_SLUG=hwp-documents

# Configure these to match your existing testing environment or the one you want to create with Docker.
## Usually, these values should match the ones in the `wp-config.php` file.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Headless Documents
# HWP Documents

Store your app's JSON documents in WordPress over REST. Every write names the version it was based on, and WordPress rejects a write based on an old version with `409 Conflict` instead of silently overwriting the newer one.

Expand All @@ -7,7 +7,7 @@ Store your app's JSON documents in WordPress over REST. Every write names the ve

-----

[![Version](https://img.shields.io/github/v/release/wpengine/hwptoolkit?include_prereleases&label=prerelease&filter=%40wpengine%2Fheadless-documents-wordpress-plugin-*)](https://github.com/wpengine/hwptoolkit/releases)
[![Version](https://img.shields.io/github/v/release/wpengine/hwptoolkit?include_prereleases&label=prerelease&filter=%40wpengine%2Fhwp-documents-wordpress-plugin-*)](https://github.com/wpengine/hwptoolkit/releases)
[![License](https://img.shields.io/badge/license-GPLv2%2B-green)](https://www.gnu.org/licenses/gpl-2.0.html)
[![Testing Integration](https://github.com/wpengine/hwptoolkit/actions/workflows/codeception.yml/badge.svg)](https://github.com/wpengine/hwptoolkit/actions/workflows/codeception.yml)
[![Code Quality](https://github.com/wpengine/hwptoolkit/actions/workflows/code-quality.yml/badge.svg)](https://github.com/wpengine/hwptoolkit/actions/workflows/code-quality.yml)
Expand All @@ -18,10 +18,10 @@ Store your app's JSON documents in WordPress over REST. Every write names the ve

Documents are grouped into collections, such as `preferences` or `drafts`. Each document has an ID that's unique within its collection, a version number, and data that's a JSON object or array. Use it for app data such as settings, structured drafts or form submissions, without adding a second database.

- Documents live in their own table, `wp_headless_documents` (with your site's table prefix).
- Documents live in their own table, `wp_hwp_documents` (with your site's table prefix).
- Writes and deletes use compare-and-swap on the version, so of two writers sending the same version, only one succeeds.
- WordPress users and capabilities control access.
- **Tools → Headless Documents** lists what your app has stored. The screen is read-only.
- **Tools → HWP Documents** lists what your app has stored. The screen is read-only.

Realtime updates, complex queries and high write volume are out of scope.

Expand All @@ -34,7 +34,7 @@ Realtime updates, complex queries and high write volume are out of scope.
Deactivating or deleting the plugin keeps your documents. To also drop the table, and every document in it, on every site when you delete the plugin, add this to `wp-config.php` first:

```php
define( 'HEADLESS_DOCUMENTS_UNINSTALL_PLUGIN', true );
define( 'HWP_DOCUMENTS_UNINSTALL_PLUGIN', true );
```

### Permissions
Expand All @@ -43,13 +43,13 @@ Users who can `manage_options` (administrators) can read and write documents. To

| Capability | Allows |
|---|---|
| `read_headless_documents` | Reading and listing documents |
| `read_headless_documents` and `edit_headless_documents` | Creating, updating and deleting documents |
| `read_hwp_documents` | Reading and listing documents |
| `read_hwp_documents` and `edit_hwp_documents` | Creating, updating and deleting documents |

Writers need both, because a rejected write returns the current document. These capabilities don't grant access to anything else in WordPress.

```php
get_role( 'editor' )->add_cap( 'read_headless_documents' );
get_role( 'editor' )->add_cap( 'read_hwp_documents' );
```

## REST API
Expand Down Expand Up @@ -83,7 +83,7 @@ GET /wp-json/headless/v1/collections/preferences/documents/site-settings
}
```

`created` and `modified` are UTC timestamps. A document that doesn't exist returns `404` with the code `headless_document_not_found`.
`created` and `modified` are UTC timestamps. A document that doesn't exist returns `404` with the code `hwp_document_not_found`.

### Create or update a document

Expand All @@ -102,7 +102,7 @@ If the document has changed since the version you sent, or a create finds that t

```json
{
"code": "headless_document_conflict",
"code": "hwp_document_conflict",
"message": "The document has changed since the version this write was based on.",
"data": {
"status": 409,
Expand Down Expand Up @@ -162,23 +162,23 @@ DELETE /wp-json/headless/v1/collections/waitlist/documents/3f9c2a7e1b0d4c6a8e5f?
|---|---|---|
| `400` | `rest_invalid_json`, `rest_missing_callback_param`, `rest_invalid_param` | The body isn't valid JSON, or `version` or `data` is missing or invalid. `data` must be a JSON object or array. |
| `401`, `403` | `rest_forbidden` | The request isn't authenticated, or the user lacks the capability. |
| `404` | `headless_document_not_found` | The document doesn't exist. |
| `409` | `headless_document_conflict` | The version is stale. |
| `413` | `headless_document_too_large` | The document is larger than the maximum size. |
| `404` | `hwp_document_not_found` | The document doesn't exist. |
| `409` | `hwp_document_conflict` | The version is stale. |
| `413` | `hwp_document_too_large` | The document is larger than the maximum size. |

## Actions and filters

| Hook | Type | Arguments |
|---|---|---|
| `headless_document_saved` | Action | `array $document`, `bool $created` |
| `headless_document_deleted` | Action | `array $previous` |
| `headless_document_max_bytes` | Filter | `int $max_bytes`, default 100 KB of encoded JSON |
| `hwp_document_saved` | Action | `array $document`, `bool $created` |
| `hwp_document_deleted` | Action | `array $previous` |
| `hwp_document_max_bytes` | Filter | `int $max_bytes`, default 100 KB of encoded JSON |

For example, to send an email for each waitlist signup:

```php
add_action(
'headless_document_saved',
'hwp_document_saved',
function ( $document, $created ) {
if ( $created && 'waitlist' === $document['collection'] ) {
wp_mail( get_option( 'admin_email' ), 'New waitlist signup', $document['data']->email );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Activation Hook
*
* @package Headless\Documents
* @package HWP\Documents
*
* @since 0.1.0
*/

declare(strict_types=1);

use Headless\Documents\Store\Document_Table;
use HWP\Documents\Store\Document_Table;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -21,7 +21,7 @@
* Creates the documents table for the current site. On a network activation,
* each other site creates its table on its first request.
*/
function headless_documents_activation_callback(): void {
function hwp_documents_activation_callback(): void {
Document_Table::maybe_install();
do_action( 'headless_documents_activate' );
do_action( 'hwp_documents_activate' );
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Exit if any command fails.
set -e

# Headless Documents doesn't depend on other plugins, so there's nothing to
# HWP Documents doesn't depend on other plugins, so there's nothing to
# install. Add install functions here if the tests ever need one.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ configure_wordpress() {
# Install WordPress.
echo -e "$(status_message "Installing WordPress...")"

SITE_TITLE=${WORDPRESS_SITE_TITLE:-"Headless Documents Tests"}
SITE_TITLE=${WORDPRESS_SITE_TITLE:-"HWP Documents Tests"}

wp core install --title="$SITE_TITLE" --admin_user="$WORDPRESS_ADMIN_USER" --admin_password="$WORDPRESS_ADMIN_PASSWORD" --admin_email="$WORDPRESS_ADMIN_EMAIL" --skip-email --url="$WORDPRESS_URL" --allow-root

Expand Down Expand Up @@ -144,12 +144,12 @@ setup_file_permissions() {

setup_plugin() {
if [ "${SKIP_WP_SETUP}" = "true" ]; then
echo -e "$(warning_message "Skipping headless-documents installation...")"
echo -e "$(warning_message "Skipping hwp-documents installation...")"
return 0
fi

# Add this repo as a plugin to the repo
if [ ! -d $WORDPRESS_ROOT_DIR/wp-content/plugins/headless-documents ]; then
if [ ! -d $WORDPRESS_ROOT_DIR/wp-content/plugins/hwp-documents ]; then
echo -e "$(status_message "Symlinking the plugin to the WordPress plugins directory...")"

cd "$ORIGINAL_PATH"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Running Unit Tests for the Headless Documents Plugin
# Running Unit Tests for the HWP Documents Plugin

# Usage:
## - sh bin/local/run-unit-tests.sh
Expand All @@ -24,4 +24,4 @@ if [[ "$1" == "coverage" ]]; then
fi
fi

docker exec $COVERAGE_ARG $COVERAGE_OUTPUT_ARG -e SUITES=wpunit -w /var/www/html/wp-content/plugins/headless-documents headless-documents-wordpress-1 bin/run-codeception.sh
docker exec $COVERAGE_ARG $COVERAGE_OUTPUT_ARG -e SUITES=wpunit -w /var/www/html/wp-content/plugins/hwp-documents hwp-documents-wordpress-1 bin/run-codeception.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ else
echo -e "${YELLOW}⚠ readme.txt not found${NC}"
fi

# Update headless-documents.php
PLUGIN_FILE="headless-documents.php"
# Update hwp-documents.php
PLUGIN_FILE="hwp-documents.php"

if [ -f "$PLUGIN_FILE" ]; then
echo "Updating main plugin file: $PLUGIN_FILE..."

# Update WordPress plugin header version (handles beta versions)
sed -i.bak -E "s/(\* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?/\1$VERSION/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak"

# Update HEADLESS_DOCUMENTS_VERSION define statement
sed -i.bak -E "s/(define\([[:space:]]*['\"]HEADLESS_DOCUMENTS_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak"
# Update HWP_DOCUMENTS_VERSION define statement
sed -i.bak -E "s/(define\([[:space:]]*['\"]HWP_DOCUMENTS_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak"

echo -e "${GREEN}✓ Updated $PLUGIN_FILE${NC}"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extensions:
coverage:
enabled: true
remote: false
c3_url: "%WORDPRESS_URL%/wp-content/plugins/headless-documents/headless-documents.php"
c3_url: "%WORDPRESS_URL%/wp-content/plugins/hwp-documents/hwp-documents.php"
include:
- src/*
- /activation.php
Expand Down Expand Up @@ -94,7 +94,7 @@ modules:
adminEmail: "%WORDPRESS_ADMIN_EMAIL%"
title: 'Test'
plugins:
- headless-documents/headless-documents.php
- hwp-documents/hwp-documents.php
activatePlugins:
- headless-documents/headless-documents.php
- hwp-documents/hwp-documents.php
configFile: 'tests/_data/config.php'
Loading