All Projects → postlight → Headless Wp Starter

postlight / Headless Wp Starter

Licence: gpl-2.0
🔪 WordPress + React Starter Kit: Spin up a WordPress-powered React app in one step

Programming Languages

javascript
184084 projects - #8 most used programming language
PHP
23972 projects - #3 most used programming language
SCSS
7915 projects
shell
77523 projects
HTML
75241 projects
Dockerfile
14818 projects
CSS
56736 projects

Projects that are alternatives of or similar to Headless Wp Starter

Pop
Monorepo of the PoP project, including: a server-side component model in PHP, a GraphQL server, a GraphQL API plugin for WordPress, and a website builder
Stars: ✭ 160 (-96.14%)
Mutual labels:  rest-api, graphql-api, wordpress, headless-cms
Nextjs Headless Wordpress
🔥 Nextjs Headless WordPress
Stars: ✭ 110 (-97.35%)
Mutual labels:  wordpress, headless-cms, nextjs
Headless Framework
[Preview/Alpha] WordPress Headless Framework
Stars: ✭ 182 (-95.61%)
Mutual labels:  wordpress, headless-cms, nextjs
Wordpress Starter
📦 A starter template for WordPress websites
Stars: ✭ 26 (-99.37%)
Mutual labels:  wordpress, wordpress-development, starter-kit
Woo Next
🚀 React WooCommerce theme, built with Next JS, Webpack, Babel, Node, Express, using GraphQL and Apollo Client
Stars: ✭ 342 (-91.75%)
Mutual labels:  rest-api, wordpress, nextjs
React With Wordpress
🔥 Example of react application to access WordPress REST API
Stars: ✭ 137 (-96.69%)
Mutual labels:  rest-api, wordpress, wordpress-development
Co Cart
🛒 CoCart is a flexible, open-source solution to enabling the shopping cart via the REST API for WooCommerce.
Stars: ✭ 198 (-95.22%)
Mutual labels:  rest-api, wordpress, wordpress-development
Awesome Wp Developer Tools
A collection of plugins, starter themes and tools to make WordPress development easier.
Stars: ✭ 388 (-90.64%)
Mutual labels:  rest-api, wordpress, wordpress-development
Acf Pro Installer
A composer install helper for Advanced Custom Fields PRO
Stars: ✭ 265 (-93.61%)
Mutual labels:  wordpress, wordpress-development
Wp Graphql
🚀 GraphQL API for WordPress
Stars: ✭ 3,097 (-25.27%)
Mutual labels:  graphql-api, wordpress
Air Light
WordPress starter theme - designed to be minimal, lightweight and easy for all kinds of WordPress projects. Public Roadmap: https://favro.com/organization/3b45e73eaf083f68fefef368/c1dd2d4a99d6723904d2e763
Stars: ✭ 285 (-93.12%)
Mutual labels:  wordpress, wordpress-development
Lumberjack
Lumberjack is a powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code.
Stars: ✭ 261 (-93.7%)
Mutual labels:  wordpress, wordpress-development
Nextjs Redux Starter
Next.js + Redux + styled-components + Express = 😇
Stars: ✭ 257 (-93.8%)
Mutual labels:  nextjs, starter-kit
Admin Page Framework
Facilitates WordPress plugin and theme development.
Stars: ✭ 273 (-93.41%)
Mutual labels:  wordpress, wordpress-development
Fabrica Dev Kit
A toolkit for faster, smoother WordPress 5 development
Stars: ✭ 256 (-93.82%)
Mutual labels:  wordpress, wordpress-development
Graphql Wp
GraphQL endpoint for WordPress
Stars: ✭ 303 (-92.69%)
Mutual labels:  wordpress, headless-cms
Super Progressive Web Apps
SuperPWA helps to convert your WordPress website into Progressive Web Apps instantly. PWA (Progressive Web Apps) demo at : https://superpwa.com and Plugin :
Stars: ✭ 304 (-92.66%)
Mutual labels:  wordpress, wordpress-development
dogstudio-next-starter
Opinionated Next.js starter by Dogstudio
Stars: ✭ 66 (-98.41%)
Mutual labels:  nextjs, starter-kit
Covid19 Brazil Api
API com dados atualizados sobre o status do COVID-19 🦠
Stars: ✭ 300 (-92.76%)
Mutual labels:  rest-api, nextjs
Wp Webpack Script
💥🔥📦👩‍💻 An easy to use, pre configured, hackable webpack setup & development server for WordPress themes and plugins.
Stars: ✭ 314 (-92.42%)
Mutual labels:  wordpress, wordpress-development

WordPress + React Starter Kit

Build status

Postlight's Headless WordPress + React Starter Kit is an automated toolset that will spin up three things:

  1. A WordPress backend that serves its data via the WP REST API and GraphQL.
  2. A sample React frontend powered by the WP GraphQL API, which supports posts, pages, categories, menus, search, and user sign-in.
  3. Another sample server-side rendered React frontend using Next.js powered by the WP REST API.

You can read all about it in this handy introduction.

What's inside:

  • An automated installer which bootstraps a core WordPress installation that provides an established, stable REST API.
  • A plugin which exposes a newer, in-progress GraphQL API for WordPress.
  • The WordPress plugins you need to set up custom post types and custom fields (Advanced Custom Fields and Custom Post Type UI).
  • Plugins which expose those custom fields and WordPress menus in the WP REST API (ACF to WP API and WP-REST-API V2 Menus).
  • JWT authentication plugins: JWT WP REST and JWT WP GraphQL.
  • All the starter WordPress theme code and settings headless requires, including pretty permalinks, CORS Allow-Origin headers, and useful logging functions for easy debugging.
  • A mechanism for easily importing data from an existing WordPress installation anywhere on the web using WP Migrate DB Pro and its accompanying plugins (license required).
  • A sample, starter frontend React app powered by GraphQL.
  • Another sample, starter frontend React app, server-side rendered via Next.js, powered by the WP REST API.
  • Docker containers and scripts to manage them, for easily running the frontend React apps and backend locally or deploying it to any hosting provider with Docker support.

Let's get started.

Install

Prerequisite: Before you begin, you need Docker installed. On Linux, you might need to install docker-compose separately.

Docker Compose builds and starts four containers by default: db-headless, wp-headless, frontend & frontend-graphql:

docker-compose up -d

Wait a few minutes for Docker to build the services for the first time. After the initial build, startup should only take a few seconds.

You can follow the Docker output to see build progress and logs:

docker-compose logs -f

Alternatively, you can use some useful Docker tools like Kitematic and/or VSCode Docker plugin to follow logs, start / stop / remove containers and images.

Optional: you can run the frontend locally while WordPress still runs on Docker:

docker-compose up -d wp-headless
cd frontend && yarn && yarn start

Once the containers are running, you can visit the React frontends and backend WordPress admin in your browser.

Frontend

This starter kit provides two frontend containers:

  • frontend container powered by the WP REST API is server-side rendered using Next.js, and exposed on port 3000: http://localhost:3000
  • frontend-graphql container powered by GraphQL, exposed on port 3001: http://localhost:3001

Here's what the frontend looks like:

Frontend Screencast

You can follow the yarn start output by running docker-compose logs command followed by the container name. For example:

docker-compose logs -f frontend

If you need to restart that process, restart the container:

docker-compose restart frontend

PS: Browsing the Next.js frontend in development mode is relatively slow due to the fact that pages are being built on demand. In a production environment, there would be a significant improvement in page load.

Backend

The wp-headless container exposes Apache on host port 8080:

This container includes some development tools:

docker exec wp-headless composer --help
docker exec wp-headless phpcbf --help
docker exec wp-headless phpcs --help
docker exec wp-headless phpunit --help
docker exec wp-headless wp --info

Apache/PHP logs are available via docker-compose logs -f wp-headless.

Database

The db-headless container exposes MySQL on host port 3307:

mysql -uwp_headless -pwp_headless -h127.0.0.1 -P3307 wp_headless

You can also run a mysql shell on the container:

docker exec db-headless mysql -hdb-headless -uwp_headless -pwp_headless wp_headless

Reinstall/Import

To reinstall WordPress from scratch, run:

docker exec wp-headless wp db reset --yes && docker exec wp-headless install_wordpress

To import data from a mysqldump with mysql, run:

docker exec db-headless mysql -hdb-headless -uwp_headless -pwp_headless wp_headless < example.sql
docker exec wp-headless wp search-replace https://example.com http://localhost:8080

Import Data from Another WordPress Installation

You can use a plugin called WP Migrate DB Pro to connect to another WordPress installation and import data from it. (A Pro license will be required.)

To do so, first set MIGRATEDB_LICENSE & MIGRATEDB_FROM in .env and recreate containers to enact the changes.

docker-compose up -d

Then run the import script:

docker exec wp-headless migratedb_import

If you need more advanced functionality check out the available WP-CLI commands:

docker exec wp-headless wp help migratedb

Extend the REST and GraphQL APIs

At this point you can start setting up custom fields in the WordPress admin, and if necessary, creating custom REST API endpoints in the Postlight Headless WordPress Starter theme.

The primary theme code is located in wordpress/wp-content/themes/postlight-headless-wp.

You can also modify and extend the GraphQL API, An example of creating a Custom Type and registering a Resolver is located in: wordpress/wp-content/themes/postlight-headless-wp/inc/graphql.

REST & GraphQL JWT Authentication

To give WordPress users the ability to sign in via the frontend app, use something like the WordPress Salt generator to generate a secret for JWT, then define it in wp-config.php

For the REST API:

define('JWT_AUTH_SECRET_KEY', 'your-secret-here');

For the GraphQL API:

define( 'GRAPHQL_JWT_AUTH_SECRET_KEY', 'your-secret-here');

Make sure to read the JWT REST and JWT GraphQL documentation for more info.

Linting

Remember to lint your code as you go.

To lint WordPress theme modifications, you can use PHP_CodeSniffer like this:

docker exec -w /var/www/html/wp-content/themes/postlight-headless-wp wp-headless phpcs -v .

You may also attempt to autofix PHPCS errors:

docker exec -w /var/www/html/wp-content/themes/postlight-headless-wp wp-headless phpcbf -v .

To lint and format the JavaScript apps, both Prettier and ESLint configuration files are included.

Hosting

Most WordPress hosts don't also host Node applications, so when it's time to go live, you will need to find a hosting service for the frontend.

That's why we've packaged the frontend app in a Docker container, which can be deployed to a hosting provider with Docker support like Amazon Web Services or Google Cloud Platform. For a fast, easier alternative, check out Now.

Troubleshooting Common Errors

Breaking Change Alert - Docker

If you had the project already setup and then updated to a commit newer than 99b4d7b, you will need to go through the installation process again because the project was migrated to Docker. You will need to also migrate MySQL data to the new MySQL db container.

Docker Caching

In some cases, you need to delete the wp-headless image (not only the container) and rebuild it.

CORS errors

If you have deployed your WordPress install and are having CORS issues be sure to update /wordpress/wp-content/themes/postlight-headless-wp/inc/frontend-origin.php with your frontend origin URL.

See anything else you'd like to add here? Please send a pull request!


🔬 A Labs project from your friends at Postlight. Happy coding!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].