Skip to content

Commit fec7052

Browse files
authored
Merge pull request #516 from wpengine/hwp-previews-docs
docs(previews): Add how-to guides, tutorials and an explanation
2 parents 085c9a1 + 92e71eb commit fec7052

File tree

18 files changed

+1060
-27
lines changed

18 files changed

+1060
-27
lines changed

docs/plugins/hwp-previews/explanation/core-concepts/index.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,101 @@ title: "Core Concepts"
33
description: "Deep dive explanations of the HWP Previews plugin's core concepts, architecture, and systems."
44
---
55

6-
@TODO
6+
## Overview
7+
8+
This article provides an in-depth exploration of the fundamental concepts that power the HWP Previews plugin, covering the template-based URL system that enables framework-agnostic preview generation, the parameter registry that makes URLs dynamic and context-aware, the flexible post type configuration system, solutions for WordPress hierarchical content challenges, and the different preview modes available to content creators.
9+
10+
## Core Architectural Concepts
11+
12+
### 1. Preview URL Templates with Dynamic Parameters
13+
14+
At the heart of HWP Previews is the concept of URL templates. Instead of hardcoding preview URLs, administrators define templates using placeholder tokens that get dynamically replaced with actual post data.
15+
16+
For example, a template like:
17+
```
18+
https://mysite.com/preview?p={ID}&type={type}&status={status}
19+
```
20+
21+
When previewing a draft post with ID 42 of type "page", this becomes:
22+
```
23+
https://mysite.com/preview?p=42&type=page&status=draft
24+
```
25+
26+
This template approach ensures framework agnosticity, whether you're using Next.js with `/api/preview?slug={slug}`, a custom React app with `/preview/{ID}`, or any other front-end architecture. The system generates context-rich URLs that can pass any information your front-end needs to handle previews intelligently, from basic post data to complex hierarchical relationships.
27+
28+
#### The Parameter Registry System
29+
30+
HWP Previews maintains a parameter registry, a centralized collection of available dynamic parameters. Out of the box, it provides:
31+
32+
- `{ID}` – Post ID
33+
- `{author_ID}` – Post author's user ID
34+
- `{status}` – Post status (draft, pending, etc.)
35+
- `{slug}` – Post slug
36+
- `{parent_ID}` – Parent post ID (for hierarchical types)
37+
- `{type}` – Post type slug
38+
- `{template}` – Template filename
39+
40+
This registry is extensible through WordPress filters, allowing developers to add custom parameters (e.g., `{category}`, `{custom_field}`, or `{locale}` for multilingual sites).
41+
42+
### 2. Post Type-Specific Configuration
43+
44+
WordPress sites often have diverse content types (posts, pages, custom post types) each potentially requiring different preview handling. To address this challenge, HWP Previews provides per-post-type configuration.
45+
46+
For each public post type, you can independently configure:
47+
- Whether previews are enabled at all
48+
- The preview URL template
49+
- Whether to display previews in an iframe within the editor
50+
- Whether to allow non-published posts as parents (for hierarchical types)
51+
52+
### 3. Hierarchical Post Types and Parent Status
53+
54+
WordPress supports hierarchical post types (like pages) where posts can have parent-child relationships. By default, WordPress only allows published posts to be parents. This creates a workflow problem: when building a site, you often want to establish page hierarchies while everything is still in draft.
55+
56+
HWP Previews solves this with the "Allow All Statuses as Parent" option. When enabled for a post type, draft, pending, or private posts can serve as parents.
57+
58+
### 4. Iframe vs. New Tab Preview Modes
59+
60+
HWP Previews offers two preview rendering modes, each suited to different workflows:
61+
62+
#### Iframe Mode
63+
When enabled, previews load directly within the WordPress editor in a sandboxed `<iframe>`. This provides an integrated experience, so you can see your changes alongside the preview, similar to the WordPress theme customizer.
64+
65+
#### New Tab Mode
66+
When disabled, clicking "Preview" opens the preview URL in a new browser tab.
67+
68+
### 5. Faust Integration
69+
70+
When Faust.js is detected, HWP Previews automatically configures itself to work seamlessly with Faust's preview system. This provides Faust users with an upgrade path that maintains their existing workflows while gaining access to additional features like iframe mode, custom parameters, and per-post-type control.
71+
72+
The integration removes potential conflicts by disabling Faust's native preview handling and pre-configuring preview URLs to match Faust's expected structure. This **compatibility without compromise** approach minimizes adoption barriers for users with existing Faust investments.
73+
74+
## The Hook System and Extensibility
75+
76+
HWP Previews provides a comprehensive system of WordPress actions and filters for extending functionality.
77+
78+
### Key Extension Points
79+
80+
`hwp_previews_register_parameters`: Add custom dynamic parameters
81+
`hwp_previews_filter_available_post_types`: Control which post types appear in settings
82+
`hwp_previews_filter_available_post_statuses`: Modify available post statuses
83+
`hwp_previews_template_path`: Replace the iframe preview template
84+
85+
## Security Considerations
86+
87+
While HWP Previews focuses on preview URL generation rather than authentication, its design acknowledges security concerns:
88+
89+
1. **No token generation**: The plugin intentionally doesn't handle authentication tokens, that's the front-end's responsibility
90+
2. **URL encoding**: All parameter values are properly encoded to prevent injection attacks
91+
3. **Capability checks**: Admin settings pages require appropriate WordPress capabilities
92+
4. **Nonce verification**: AJAX requests (like dismissing notices) include nonce verification
93+
94+
## Performance Characteristics
95+
96+
HWP Previews is designed for minimal performance impact:
97+
98+
- **Settings caching**: Configuration is cached and only loaded when needed
99+
- **Lazy initialization**: Services instantiate only when actually used
100+
- **Selective hooks**: Post-type-specific hooks only register for enabled post types
101+
- **No frontend overhead**: The plugin only activates for authenticated users in admin/preview contexts
102+
103+
These choices reflect an understanding that preview functionality should never degrade the public site's performance.
557 KB
Loading
30.4 KB
Loading
162 KB
Loading
153 KB
Loading

docs/plugins/hwp-previews/how-to/configure-previews/index.md

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,114 @@ title: "Configure Previews"
33
description: "Learn how to configure preview functionality using the HWP Previews plugin in your headless WordPress application."
44
---
55

6-
@TODO
6+
## Overview
7+
8+
This guide shows you how to configure preview URLs for your headless WordPress site using HWP Previews. You'll set up preview links that redirect from WordPress to your front-end application with the necessary context data.
9+
10+
> [!TIP]
11+
> Want to see HWP Previews in action first? Check out the working examples in the `examples/` directory that demonstrate integration with WP GraphQL and REST API. You can run them locally using `wp-env` to test the plugin functionality before configuring your own setup.
12+
13+
## Prerequisites
14+
15+
- HWP Previews plugin installed and activated
16+
- A running front-end application with a preview endpoint
17+
18+
## 1. Access the settings page
19+
20+
1. Log into your WordPress admin dashboard
21+
2. Navigate to **Settings > HWP Previews**
22+
23+
![HWP Previews menu item in WordPress admin sidebar under Settings](hwp-previews-menu-item.png)
24+
25+
You'll see tabs for each public post type on your site (Posts, Pages, and any custom post types).
26+
27+
## 2. Configure a post type
28+
29+
### a. Enable previews for the post type
30+
31+
1. Click on the tab for the post type you want to configure (e.g., "Posts")
32+
2. Check the "Enable HWP Previews" box
33+
34+
> [!NOTE]
35+
> If you have Faust.js installed, this option will be enabled by default for all post types.
36+
37+
### b. Set the preview URL template
38+
39+
In the "Preview URL Template" field, enter your front-end preview endpoint URL with dynamic parameters:
40+
41+
```
42+
https://mysite.com/api/preview?id={ID}&type={type}&status={status}
43+
```
44+
45+
Available parameters:
46+
47+
- `{ID}` - Post ID
48+
- `{author_ID}` - Post author's user ID
49+
- `{status}` - Post status (draft, pending, etc.)
50+
- `{slug}` - Post slug
51+
- `{parent_ID}` - Parent post ID (for hierarchical types)
52+
- `{type}` - Post type slug
53+
- `{template}` - Template filename
54+
55+
The parameters sidebar shows descriptions for each available parameter.
56+
57+
![HWP Previews post settings page showing the Posts tab with Enable HWP Previews checkbox, Preview URL Template field with example URL, and parameters sidebar](hwp-previews-post-settings.png)
58+
59+
### c. Choose the preview mode
60+
61+
Select how you want previews to display:
62+
63+
- **Iframe mode**: Check "Load Previews in Iframe" to display previews within the WordPress editor
64+
- **New tab mode**: Leave unchecked to open previews in a new browser tab
65+
66+
For iframe mode to work, your front-end must not set restrictive `X-Frame-Options` headers.
67+
68+
### d. Optional: Configure hierarchical post types (Pages only)
69+
70+
For hierarchical post types like Pages, you can allow draft posts to be parents by checking "Allow All Statuses as Parent" and saving changes, which lets you build page hierarchies before publishing content.
71+
72+
![HWP Previews page settings showing the Pages tab with Enable HWP Previews checkbox, Preview URL Template field, and Allow All Statuses as Parent checkbox for hierarchical post types](hwp-previews-page-settings.png)
73+
74+
## 3. Save your settings
75+
76+
Click the "Save Changes" button at the bottom of the page.
77+
78+
## 4. Test the preview
79+
80+
1. Open any post of the configured type in the editor
81+
2. Make a change to the content
82+
3. Click the "Preview" button
83+
84+
If configured correctly:
85+
- **Iframe mode**: The preview loads within the editor
86+
- **New tab mode**: A new tab opens with your front-end preview URL
87+
88+
The URL will include the dynamic parameters you specified, for example:
89+
```
90+
https://mysite.com/api/preview?id=42&type=post&status=draft
91+
```
92+
93+
![HWP Previews iframe mode showing a preview of a post loaded within the WordPress editor interface](hwp-previews-iframe.png)
94+
95+
## Troubleshooting common issues
96+
97+
### Preview button doesn't redirect
98+
99+
Check that:
100+
- The "Enable HWP Previews" checkbox is checked for that post type
101+
- You've saved your settings
102+
- The Preview URL Template field is not empty
103+
104+
### Iframe preview shows a blank screen
105+
106+
Your front-end may be blocking iframe embedding. Either:
107+
- Make sure your front-end can properly handle authentication to show draft content
108+
- Configure your front-end to allow embedding from your WordPress domain
109+
- Switch to new tab mode by unchecking "Load Previews in Iframe"
110+
111+
### Dynamic parameters show "PARAMETER_NOT_FOUND"
112+
113+
This happens when you use a parameter that doesn't exist. Verify:
114+
- Parameter names are spelled correctly
115+
- Parameters are wrapped in curly braces: `{ID}` not `ID`
116+
- The parameter is available (check the parameters sidebar)
163 KB
Loading

docs/plugins/hwp-previews/how-to/integrate-with-faust/index.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,56 @@ title: "Integrate with Faust.js"
33
description: "Learn how to integrate the HWP Previews plugin with Faust.js in your headless WordPress application."
44
---
55

6-
@TODO
6+
## Overview
7+
8+
This guide shows you how to use HWP Previews with Faust.js. The integration happens automatically when both plugins are installed.
9+
10+
## Prerequisites
11+
12+
- [Faust.js](https://wordpress.org/plugins/faustwp/) plugin installed and activated
13+
14+
## 1. Install HWP Previews
15+
16+
1. Install and activate the HWP Previews plugin
17+
2. Navigate to **Settings > HWP Previews**
18+
19+
HWP Previews automatically detects Faust.js and configures itself to work with Faust's preview system.
20+
21+
### Automatic setup
22+
23+
When HWP Previews detects Faust.js, it:
24+
25+
1. Enables previews for all public post types
26+
2. Sets the preview URL template to match Faust's expected format:
27+
```
28+
{FAUST_FRONTEND_URI}/preview?p={ID}&preview=true&previewPathname=p{ID}&typeName={type}
29+
```
30+
3. Removes Faust.js's native preview link filter to prevent conflicts
31+
4. Disables Faust's redirect functionality for preview URLs
32+
5. Shows an admin notice on the settings page confirming the integration
33+
34+
The `{FAUST_FRONTEND_URI}` is automatically pulled from your Faust.js settings. If not configured, it defaults to `http://localhost:3000`.
35+
36+
### Authentication
37+
HWP Previews handles preview URL generation, but authentication remains the responsibility of your Faust front-end application. Continue using [Faust.js authentication](https://faustjs.org/docs/how-to/authentication/) to access draft content in previews.
38+
39+
## 2. Verify the integration
40+
41+
1. Go to **Settings > HWP Previews**
42+
2. Check any post type tab (Posts, Pages, etc.)
43+
3. Verify that:
44+
- "Enable HWP Previews" is checked
45+
- The Preview URL Template contains your Faust front-end URL
46+
47+
![HWP Previews settings page showing automatic Faust.js integration with enabled previews and configured preview URL template](hwp-previews-faust-integration.png)
48+
49+
## 3. Test previews
50+
51+
1. Open any post in the WordPress editor
52+
2. Click the "Preview" button
53+
3. You should be redirected to your Faust front-end preview endpoint
54+
55+
The preview URL will look like:
56+
```
57+
https://your-faust-site.com/preview?p=42&preview=true&previewPathname=p42&typeName=post
58+
```

0 commit comments

Comments
 (0)