Skip to content

Chore update wp env setup for nuxt gforms pr #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a496e09
Adds WP plugin example for the stylesheet exposure.
whoami-pwd Mar 24, 2025
4d3c0a5
Provides CLI command.
whoami-pwd Mar 25, 2025
9951d2c
Updates readme.
whoami-pwd Mar 25, 2025
831930a
docs: explanation about sitemaps in headless WordPress
theodesp Mar 26, 2025
9eea41e
chore: update sitemaps documentation based on feedback
theodesp Mar 31, 2025
2f32abd
chore: pr review update
theodesp Mar 31, 2025
c6d504e
Reverts pnpm-lock.yaml changes.
whoami-pwd Apr 3, 2025
e62df79
Updates JS example.
whoami-pwd Apr 3, 2025
671d3ba
Moves the plugin to the example folder.
whoami-pwd Apr 3, 2025
ac1d7b4
Merge branch 'main' into example-wp-theme-rendered-blocks
whoami-pwd Apr 3, 2025
72324e6
Fixes lock typo.
whoami-pwd Apr 3, 2025
7b73aa3
Moves plugin to the separate example folder.
whoami-pwd Apr 7, 2025
add904e
Restores original versions of the example.
whoami-pwd Apr 7, 2025
b40ab65
Provides example files.
whoami-pwd Apr 7, 2025
0760b8e
Resets files
whoami-pwd Apr 7, 2025
19073cd
chore: update proxy example
theodesp Apr 7, 2025
6753411
chore: move example into next folder
ahuseyn Apr 8, 2025
84af66a
feat: add wp-env, update package.json
ahuseyn Apr 8, 2025
56df61b
docs: update readme
ahuseyn Apr 8, 2025
0b160cc
docs: add screenshots
ahuseyn Apr 8, 2025
a54e0a1
chore: clarify updating the Site Address URL when proxying sitemaps
theodesp Apr 8, 2025
db8d5f5
chore: move example into next folder
ahuseyn Apr 8, 2025
6d6d001
feat: add proxied sitemap example
theodesp Apr 8, 2025
01a0c9f
chore: add wp-env
ahuseyn Apr 9, 2025
438636b
chore: add db
ahuseyn Apr 9, 2025
8597c22
chore: cleanup, package.json update
ahuseyn Apr 9, 2025
130bcf9
docs: update docs, add screenshots
ahuseyn Apr 9, 2025
bfc721a
docs: include independent setup guide
ahuseyn Apr 9, 2025
90ef0e7
docs: fix headings
ahuseyn Apr 9, 2025
7284aeb
initial: commit template hierarchy astro example with data fetching
moonmeister Apr 9, 2025
3e3cd0e
move stuff around and get wp-env fully working
moonmeister Apr 9, 2025
b4a77cf
add readme
moonmeister Apr 10, 2025
1a584cc
Merge pull request #138 from wpengine/wp-env-backport-nextjs-apollo-auth
ahuseyn Apr 10, 2025
56ebe4f
Merge pull request #135 from wpengine/wp-env-backport-nextjs-apollo-f…
ahuseyn Apr 10, 2025
fa1ff82
Merge pull request #116 from wpengine/docs-explanation-sitemaps
theodesp Apr 10, 2025
1d12b8c
Merge pull request #139 from wpengine/astro-template-hierarchy
moonmeister Apr 10, 2025
76e163c
feat: explanation document on rendering options
theodesp Apr 11, 2025
7b62e79
Provides the wp-env configuration.
whoami-pwd Apr 11, 2025
644ceba
Provides the wp-env configuration.
whoami-pwd Apr 11, 2025
5e491ff
Update examples/next/proxied-sitemap-apollo/README.md
theodesp Apr 14, 2025
4305a03
Update examples/next/proxied-sitemap-apollo/README.md
theodesp Apr 14, 2025
70669b3
Update docs/explanation/rendering-options.md
theodesp Apr 15, 2025
c8e5494
Update docs/explanation/rendering-options.md
theodesp Apr 15, 2025
71abfa9
Updates the README.md.
whoami-pwd Apr 15, 2025
fc905d3
Merge pull request #140 from wpengine/explanation-rendering-options
theodesp Apr 16, 2025
91b0d3d
Update README.md
theodesp Apr 16, 2025
1989cda
Merge pull request #136 from wpengine/example-proxied-sitemaps-next
theodesp Apr 17, 2025
d3ccc54
Created Security Policy
colinmurphy Apr 18, 2025
5032513
PR to update README's for the project
colinmurphy Apr 18, 2025
c87e415
Added screenshots as per @ahuseyn suggestion on our stand up call. Mo…
colinmurphy Apr 18, 2025
efdc07a
Merge pull request #142 from wpengine/chore-create-security-policy
colinmurphy Apr 18, 2025
5782928
Merge pull request #143 from wpengine/chore-update-readmes
colinmurphy Apr 22, 2025
93f0b17
chore: Update README
colinmurphy Apr 22, 2025
3342f4c
Merge pull request #144 from wpengine/chore-update-readme-text
colinmurphy Apr 22, 2025
c07baf2
Apply suggestions from code review
ahuseyn Apr 23, 2025
e54bb4d
fix: pnpm to npm
ahuseyn Apr 23, 2025
3310fc5
fix: fetchWpGlobalStyles cjs to esm
ahuseyn Apr 23, 2025
e2bc7ee
docs: minor fixes
ahuseyn Apr 23, 2025
86f0f3e
Merge pull request #115 from wpengine/example-wp-theme-rendered-blocks
ahuseyn Apr 30, 2025
1f459b5
docs: add wp-theme-rendered-blocks to examples readme
ahuseyn Apr 30, 2025
9a3c567
Merge pull request #149 from wpengine/docs-add-new-example-to-readme
colinmurphy May 1, 2025
bd78c15
Merge branch 'main' into chore-update-wp-env-setup-for-nuxt-gforms-pr
colinmurphy May 2, 2025
2c69407
Moved files with Nuxt going into "example-app" sub folder and wp-env …
colinmurphy May 2, 2025
a9bd00c
Fixed package.json and you can now run the headless app with "pnpm ex…
colinmurphy May 2, 2025
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ debug.log
.DS_Store
.idea
.vscode

## Examples
examples/**/package-lock.json
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
# hwptoolkit
# HWP Toolkit

Headless WordPress Toolkit

> A modern toolkit for building headless WordPress applications. Provides CLI tools, plugins, and best practices for decoupling WordPress into a powerful headless CMS.

## Project Organization

- `packages`: Dependency packages to be published on NPM
- `plugins`: PHP based WordPress Plugins
- `docs`: Documentation for the Toolkit?
- `examples`: Example code for HWP
- [`packages`](./packages): Dependency packages to be published on NPM
- [`plugins`](./plugins): PHP based WordPress Plugins
- [`docs`](./docs): Documentation for the Toolkit
- [`examples`](./examples): Example code for HWP


## Community

To chat with other headless WordPress users and the headless community as a whole, you can join the [WP Engine Developers Discord](https://discord.gg/J2khkF9XYK).

> **Note**: We also have a fortnightly Headless WordPress Community Meeting [here](https://discord.gg/fdWjcTt8?event=1351712352155992075).

Additionally, if you have questions or ideas, please share them on [GitHub Discussions](https://github.com/wpengine/hwptoolkit/discussions).

## Contributing

There are many ways to [contribute](/CONTRIBUTING.md) to this project.

- [Discuss open issues](https://github.com/wpengine/hwptoolkit/issues) to help define the future of the project.
- [Submit bugs](https://github.com/wpengine/hwptoolkit/issues) and help us verify fixes as they are checked in.
- Review and discuss the [source code changes](https://github.com/wpengine/hwptoolkit/pulls).
- [Contribute bug fixes](/CONTRIBUTING.md)
23 changes: 23 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Security Policy

WP Engine takes the security of our software and services seriously, including all
of the open-source code repositories managed through our
[WP Engine organization](https://github.com/wpengine).

## Reporting Security Issues
If you believe you have found a security vulnerability in any WP Engine-owned repository, please report it to us via email at [[email protected]](mailto:[email protected]?subject=HWPToolkit%20Security%20Vulnerability)

**Please do not report security vulnerabilities through public GitHub issues,
discussions, or pull requests.**

Please include as much of the information listed below as you can to help us better understand and resolve the issue:

- The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting).
- Full paths of the source file(s) related to the manifestation of the issue.
- The location of the affected source code (tag/branch/commit or direct URL).
- Any special configuration required to reproduce the issue.
- Step-by-step instructions to reproduce the issue.
- Proof-of-concept or exploit code (if possible).
- Impact of the issue, including how an attacker might exploit the issue.

This information will help us triage your report more quickly. Thank you for helping us keep WP Engine and our users safe!
25 changes: 25 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# HWP Toolkit Documentation


## Explanation Documentation

| Title | Description |
|------------------------------------|------------------------------|
| [GET vs POST](explanation/get-vs-post.md) | Explanation on choosing between GET and POST methods for WPGraphQL requests. |
| [GraphQL Endpoints](explanation/graphql-endpoints.md) | Documentation on differences between using /graphql or ?graphql for WPGraphQL endpoint. |
| [Headless Authentication](explanation/headless-authentication.md) | Overview of user authentication and access control in a decoupled WordPress architecture. |
| [Rendering Options](explanation/rendering-options.md) | A document that explores the various approaches to rendering content from a headless WordPress installation. |
| [Routing](explanation/routing.md) | A comprehensive explanation on routing in a headless WordPress application. |
| [Sitemaps](explanation/sitemaps.md) | A comprehensive explanation on sitemaps in a headless WordPress application. |


## How To Documentation

| Title | Description |
|------------------------------------|------------------------------|
| [Automatic Persisted Queries in Next.js Pages Router](how-to/nextjs-pages-router/enable-apq/index.md) | Learn how to reduce latency and network strain in GraphQL queries using Automatic Persisted Queries (APQ) by hashing and reusing query hashes. |


## Contributing

If you feel like something is missing or you want to add documentation, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.
139 changes: 139 additions & 0 deletions docs/explanation/rendering-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Headless WordPress Rendering Options
## Introduction

This document explores the various approaches to rendering content from a headless WordPress installation. As a front-end developer working with headless WordPress, you'll need to make important decisions about how to handle and display WordPress content in your frontend application. This guide aims to help you understand the available options, their trade-offs, and best practices.

### 1. Rendering Raw HTML Content from WordPress Classic Editor
When working with content created in the WordPress Classic Editor, you typically receive raw HTML content that needs to be rendered in your front-end application. Here's an overview of how to handle this content, focusing on React as an example framework.

#### Overview
* **Raw HTML Content**: Content from the WordPress Classic Editor is often in raw HTML format, which includes tags, classes, and inline styles.

* **Front-end Rendering**: To display this content in a React application, you need to render the raw HTML safely and efficiently.

#### Implementation
To render raw HTML in React, you can use the `dangerouslySetInnerHTML` property. Here's a basic example for a single post:

```javascript
const query = gql`query GetPost {
post(id: "hello-world", idType: SLUG) {
content
}
}`;

function PostContent({ content }) {
return <div dangerouslySetInnerHTML={{ __html: content }} />;
}
```
**Note**: Using `dangerouslySetInnerHTML` poses security risks if the content isn't sanitized.

#### Considerations:
* Simplicity: Easy to implement initially with dangerouslySetInnerHTML (React) or v-html (Vue).
* Styling Challenges: Global CSS styles needed to match WordPress styling which is usually not available
* Limited Control: Limited ability to manipulate or enhance specific content elements.

Considering those limitations, it's clear that rendering raw HTML Content is not suitable for most use cases. Hopefully there are better alternatives.

### 2. Rendering Block Editor (Gutenberg) Content
#### Overview
WordPress Block Editor (Gutenberg) stores content as HTML with special comments and structured JSON properties in the comments representing blocks, offering more flexibility for headless implementations. However exposing them in a Headless enviroment is tricky. That's why with the help of the [wp-graphql-content-blocks](https://github.com/wpengine/wp-graphql-content-blocks) plugin, you can query (Gutenberg) Blocks as data using graphql.

This gives you more controls and ability to manipulate or enhance specific content elements or blocks compared to the previous approach. Here is how to do it:

1. Querying the block data

```javascript
const query = gql`query GetPostBlocks {
posts {
nodes {
editorBlocks {
__typename
name
... on CoreParagraph {
attributes {
content
}
}
}
}
}
}`;
```
The response would include the block's `__typename`, `name`, and the `content` attribute:

```json
{
"__typename": "CoreParagraph",
"name": "core/paragraph",
"attributes": {
"content": "Hello World"
}
}
```
This query fetches the content of a `CoreParagraph` block, allowing you to access and manipulate its text content in your application.

To render this content in a React application, you can use the `dangerouslySetInnerHTML` property, but ensure you sanitize the content first to prevent XSS attacks:

```javascript
import DOMPurify from 'dompurify';

function PostContent({ attributes }) {
const { content } = attributes;
const sanitizedContent = DOMPurify.sanitize(content);
return <div dangerouslySetInnerHTML={{ __html: sanitizedContent }} />;
}
```
Similar to the Classic Editor approach, you can render the final HTML output of Gutenberg blocks.

#### Considerations:
* Querying: The ability to query block data using GraphQL provides a structured approach to accessing and manipulating content.
* Complexity: Handling nested blocks and reconstructing their hierarchy can be complex.
* Styling: While able to query classNames or block attributes, developers still have to provide the actual styles for the components to display correctly.

### 3. Rendering Blocks with WordPress Styles

Rendering Gutenberg blocks with WordPress styles in a headless environment involves fetching and applying the styles defined in WordPress to your frontend application. This approach ensures that the content looks consistent with how it appears in the WordPress editor.

#### Challenges
* CSS Sources: Gutenberg block styles come from multiple sources, including core blocks, themes, and user-defined styles. This complexity makes it challenging to replicate the exact styling in a headless setup.

* Inline Styles and CSS Variables: Gutenberg blocks often include inline styles and CSS variables (e.g., `var(--wp--preset--color--cyan-bluish-gray))`. These styles are not automatically applied when rendering blocks in a headless environment.

* Theme Styles: Themes provide additional styles that are crucial for maintaining consistency. However, fetching these styles dynamically can be difficult, especially if they are generated inline or through WordPress's Global Styles feature.

#### Solutions
* Import Global Stylesheet: Use tools like faust-cli to generate and import a global stylesheet from your WordPress site. This stylesheet includes CSS variables and other theme-specific styles.

```bash
"scripts": {
"generate": "faust generatePossibleTypes && faust generateGlobalStylesheet",
}
```
Then import the generated stylesheet in your application:

```javascript
import "../globalStylesheet.css";
```

* Include Block Library Styles: Import CSS styles from `@wordpress/block-library` to apply basic block styling:

```javascript
import "@wordpress/block-library/build-style/common.css";
import "@wordpress/block-library/build-style/style.css";
import "@wordpress/block-library/build-style/theme.css";
```

**Note**: Changes to the `@wordpress/block-library` package may introduce new styles or css classnames potentially changing the look and feel of the application.

* Define Custom CSS Variables: If using CSS variables, define them manually in your application's CSS to match WordPress's presets:

```css
:root {
--wp--preset--color--black: #000000;
--wp--preset--color--cyan-bluish-gray: #abb8c3;
}
```
Considerations
* Styling Parity: Achieving perfect styling parity can be challenging due to the dynamic nature of WordPress styles.

* Maintenance: Styles may change with theme updates, customizations or major WordPress updates, requiring periodic updates in your headless application.
Binary file added docs/explanation/sitemaps-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading