You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: plugins/hwp-previews/examples/hwp-preview-rest/README.md
+28-23Lines changed: 28 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,26 @@
1
-
# Example: Headless WordPress Previews with Nextjs App Router and REST API
1
+
---
2
+
title: "Headless WordPress Previews with Next.js App Router and REST API"
3
+
description: "This demonstrates the usage of HWP Previews with Next.js App Router and REST API. It uses JWT authentication to fetch posts in draft status and implements a login modal for front-end authentication, showcasing an alternative approach to the Draft Mode implementation."
4
+
---
5
+
6
+
# Example: Headless WordPress Previews with Next.js App Router and REST API
2
7
3
8
> [!NOTE]
4
-
> Check out [HWP Previews WPGraphQL example](../hwp-preview-wpgraphql) if you need the previews implementation with Nextjs pages router, Draft Mode or WordPress Application Passwords.
9
+
> Check out [HWP Previews WPGraphQL example](../hwp-preview-wpgraphql) if you need the previews implementation with Next.js pages router, Draft Mode or WordPress Application Passwords.
5
10
6
11
## Overview
7
12
8
-
The purpose of this example is to showcase different use cases of HWP Previews. The example demonstrates the usage of [HWP Previews](https://github.com/wpengine/hwptoolkit/tree/main/plugins/hwp-previews) with Nextjs App Router and REST API. Example uses credentials authentication to fetch the posts in draft status. Unlike [HWP Previews WPGraphQL example](../hwp-preview-wpgraphql) this example don't use [Draft Mode](https://nextjs.org/docs/pages/guides/draft-mode).
13
+
The purpose of this example is to showcase different use cases of HWP Previews. The example demonstrates the usage of [HWP Previews](https://github.com/wpengine/hwptoolkit/tree/main/plugins/hwp-previews) with Next.js App Router and REST API. Example uses credentials authentication to fetch the posts in draft status. Unlike [HWP Previews WPGraphQL example](../hwp-preview-wpgraphql) this example doesn't use [Draft Mode](https://nextjs.org/docs/pages/guides/draft-mode).
9
14
10
15
The example includes a wp-env setup, which will allow you to build and start this example quickly. With this wp-env setup, you don't need to have a separate WordPress instance or demo data to inspect the example.
11
16
12
-
> [!CAUTION]
13
-
> The HWP Previews plugin is currently in beta. While it's more stable than earlier versions, you may still encounter occasional bugs or incomplete features. Regular updates will continue as development progresses. Use with care and consider providing feedback to help improve the plugin.
17
+
## What does this example do
18
+
19
+
1. Preview posts, pages and custom post types using WordPress REST API
20
+
2. Use JWT authentication for secure access to draft content
21
+
3. Next.js App Router implementation without Draft Mode
22
+
4. Login modal for front-end authentication
23
+
5. Configured WordPress instance with demo data and required plugins, using wp-env.
14
24
15
25
## Screenshots
16
26
@@ -52,47 +62,42 @@ The example includes a wp-env setup, which will allow you to build and start thi
52
62
53
63
**Note** Please make sure you have all prerequisites installed as mentioned above and Docker running (`docker ps`)
54
64
55
-
### Setup Repository and Packages
65
+
### 1. Setup Repository and Packages
56
66
57
67
- Clone the repo `git clone https://github.com/wpengine/hwptoolkit.git`
> **Note:** The login details for the admin is username "admin" and password "password"
78
85
79
-
### Add environment variable to the Nextjs
80
-
81
-
Create a .env file under `examples/next/hwp-preview-rest/example-app` and add copy-paste the environment variable below:
86
+
### 3. Add environment variable to the Next.js application
82
87
88
+
Create a .env file under `plugins/hwp-previews/examples/hwp-preview-rest/example-app` and add the environment variable below:
83
89
84
90
```bash
85
91
NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8888
86
92
```
87
93
88
-
### Usage
94
+
> [!CAUTION]
95
+
> This setup is intended for demonstration purposes only. For production use, you should consider the security implications and implement appropriate measures based on your project's specific needs.
89
96
90
-
After completing this step, login to your [WordPress instance](http://localhost:8888) and preview the posts as usual. Since all of the settings are configured for this example, clicking the preview button should redirect you to the front-end URL. To see the draft posts and pages you will need to login your WordPress account on front-end website, using the same credentials.
91
97
92
-
If you want to learn more about the preview plugin, check out [the documentation](/plugins/hwp-previews/README.md).
98
+
After completing this step, clicking the preview button in wp-admin should open the preview in your front-end app. Login with your admin credentials on the frontend to enable draft preview functionality.
93
99
94
-
> [!CAUTION]
95
-
> This setup is intended for demonstration purposes only. For production use, you should consider the security implications and implement appropriate measures based on your project’s specific needs.
100
+
If you want to learn more about the preview plugin, check out [the documentation](../../../../docs/plugins/hwp-previews/index.md).
Copy file name to clipboardExpand all lines: plugins/hwp-previews/examples/hwp-preview-wpgraphql/README.md
+19-21Lines changed: 19 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,23 @@
1
+
---
2
+
title: "Headless WordPress Previews with Next.js Pages Router and WPGraphQL"
3
+
description: "This demonstrates the usage of HWP Previews with Next.js Pages Router and WPGraphQL. It uses WordPress Application Passwords for authentication and implements Draft Mode for secure preview functionality."
4
+
---
5
+
1
6
# Example: Headless WordPress Previews with Nextjs Draft Mode
2
7
3
8
## Overview
4
9
5
-
This example shows the HWP Previews plugin in action. Example implements the [Draft Mode](https://nextjs.org/docs/pages/guides/draft-mode) of Nextjs. It uses WordPress [Application Passwords](https://wordpress.com/support/security/two-step-authentication/application-specific-passwords/) for the authentication and WPGraphQL for data fetching.
10
+
This example shows the HWP Previews plugin in action. Example implements the [Draft Mode](https://nextjs.org/docs/pages/guides/draft-mode) of Next.js. It uses WordPress [Application Passwords](https://wordpress.com/support/security/two-step-authentication/application-specific-passwords/) for the authentication and WPGraphQL for data fetching.
6
11
7
12
The example includes a wp-env setup, which will allow you to build and start this example quickly. With this wp-env setup, you don't need to have a separate WordPress instance or demo data to inspect the example.
8
13
9
-
> [!CAUTION]
10
-
> The HWP Previews plugin is currently in an beta state. It's still under active development, so you may encounter bugs or incomplete features. Updates will be rolled out regularly. Use with caution and provide feedback if possible.
11
-
12
14
## What does this example do
13
15
14
-
1.`/api/preview/` route to enable Nextjs Draft Mode
15
-
2.`/api/disable-preview` route to disable Nextjs Draft Mode
16
+
1.`/api/preview/` route to enable Next.js Draft Mode
17
+
2.`/api/disable-preview` route to disable Next.js Draft Mode
16
18
3. Preview posts, pages and custom post types
17
19
4. Use WordPress Application Password as an authentication method
18
-
5. Configured WordPress instance with demo data and required plugins, using wp-env
20
+
5. Configured WordPress instance with demo data and required plugins, using wp-env.
19
21
20
22
## Screenshots
21
23
@@ -55,34 +57,30 @@ The example includes a wp-env setup, which will allow you to build and start thi
55
57
56
58
**Note** Please make sure you have all prerequisites installed as mentioned above and Docker running (`docker ps`)
57
59
58
-
### Setup Repository and Packages
60
+
### 1. Setup Repository and Packages
59
61
60
62
- Clone the repo `git clone https://github.com/wpengine/hwptoolkit.git`
> **Note:** The login details for the admin is username "admin" and password "password"
82
80
83
-
### Add environment variables to the Nextjs
81
+
### 3. Add environment variables to the Nextjs
84
82
85
-
In this step we will create an Application Password and a secret preview token for the previews. At the end we'll prepare a .env file for the Nextjs application and put it inside `examples/next/hwp-preview-wpgraphql/example-app` folder. Below are the step by step guide to achieve this.
83
+
In this step we will create an Application Password and a secret preview token for the previews. At the end we'll prepare a .env file for the Next.js application and put it inside `plugins/hwp-previews/examples/hwp-preview-wpgraphql/example-app` folder. Below are the step by step guide to achieve this.
86
84
87
85
1. Login to your newly created [wp-env instance](http://localhost:8888/wp-admin/). You can find the credentials above
88
86
2. a. Follow [these instructions](https://wordpress.com/support/security/two-step-authentication/application-specific-passwords/) to create an Application Password. At the end it should look like this:
@@ -95,7 +93,7 @@ In this step we will create an Application Password and a secret preview token f
0 commit comments