Skip to content

Commit

Permalink
Merge pull request #73 from Automattic/update/plugin-plumbing-only
Browse files Browse the repository at this point in the history
Plumbing updates
  • Loading branch information
ingeniumed authored Oct 25, 2023
2 parents d19ea68 + f4fe186 commit 2bf00e6
Show file tree
Hide file tree
Showing 23 changed files with 510 additions and 187 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
* @Automattic/vip-bistro
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ingeniumed, smithjw1, alecgeatches, chriszarate

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
- Include what kind of a post has caused this problem

**Expected behavior**
A clear and concise description of what you expected to happen.

**Actual behavior**
A clear and concise description of what actually happened.

**Version of the plugin**
Version of the plugin

**Additional context**
Add any other context about the problem here. Please be careful to not share any confidential information here.
17 changes: 17 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Description

A few sentences describing the overall goals of the Pull Request.

Should include any special considerations, decisions, and links to relevant GitHub issues.

## Steps to Test

Outline the steps to test and verify the PR here.

Example:

1. Check out PR.
1. Run `npm run build`.
1. Test the thing.`
1. Verify cookies are delicious.

45 changes: 18 additions & 27 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,30 @@ on:
pull_request:
branches:
- trunk

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php-versions:
- 7.4
- 8.0

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer
php-version: ${{ matrix.php-versions }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: PHPCS
run: composer run-script phpcs
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer
php-version: ${{ matrix.php-versions }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install Composer dependencies
uses: ramsey/composer-install@v2

- name: PHPCS
run: composer run-script phpcs
66 changes: 24 additions & 42 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,29 @@ jobs:
strategy:
matrix:
php-versions:
- 7.4

env:
DB_DATABASE: test_db
DB_USER: root
DB_PASSWORD: root
- 8.0

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install wordpress environment
run: npm -g install @wordpress/env

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer
php-version: ${{ matrix.php-versions }}

- name: Setup MySQL
run: |
sudo /etc/init.d/mysql start
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Setup the wordpress environment
run: wp-env start

- name: PHPUnit
run: composer test

- name: PHPUnit multisite
run: composer run-script test-multisite
- name: Checkout
uses: actions/checkout@v2

- name: Install wordpress environment
run: npm -g install @wordpress/env

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer
php-version: ${{ matrix.php-versions }}

- name: Install Composer dependencies
uses: ramsey/composer-install@v2

- name: Setup the wordpress environment
run: wp-env start

- name: PHPUnit
run: composer test --no-interaction

- name: PHPUnit multisite
run: composer run-script test-multisite --no-interaction
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.3.0

- Adjusted the minimum support version for WP, PHP as well as the WP version that it's tested upto.
- Added a link to this repo, in the plugin's uri so it's easy to navigate to.
- Added installation instructions in the README.

## 0.2.0

- **Content blocks:** _[BREAKING]_ By default, `innerHTML` no longer removes the wrapping tag. That behavior is still available by passing a field directive `innerHTML(removeWrappingTag: true)`. The field `outerHTML` is now deprecated, since `innerHTML` provides that behavior. [#38](/~https://github.com/Automattic/vip-decoupled-bundle/pull/38)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

Please open a pull request against the default branch (`trunk`).
Please open a pull request against the default branch (`trunk`). The reviewers for the PR will be automatically assigned.

## Running unit tests

Expand Down
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# WordPress VIP decoupled plugin bundle
# WordPress VIP Decoupled Plugin Bundle

This plugin bundle provides a number of plugins to help you quickly setup a decoupled WordPress application. It is designed to support VIP’s [Next.js boilerplate][nextjs-boilerplate] but can be used to support any decoupled frontend. It solves a number of common problems facing decoupled sites, including:

Expand All @@ -9,6 +9,34 @@ This plugin bundle provides a number of plugins to help you quickly setup a deco

> ⚠️ This project is under active development. If you are a VIP customer, please let us know if you'd like to use this plugin and we can provide additional guidance. Issues and PRs are welcome. 💖
## Table of contents
- [Table of contents](#table-of-contents)
- [Installation](#installation)
- [Plugin activation](#plugin-activation)
- [Getting started](#getting-started)
- [Configuration](#configuration)
- [Setting the home URL](#setting-the-home-url)
- [Jetpack Configuration](#jetpack-configuration)
- [Plugin settings](#plugin-settings)
- [Sub-plugins](#sub-plugins)
- [WPGraphQL](#wpgraphql)
- [WPGraphQL Content blocks](#wpgraphql-content-blocks)
- [WPGraphQL Preview](#wpgraphql-preview)
- [Contributing](#contributing)

## Installation

The latest version of the plugin can be downloaded from the [repository's Releases page][repo-releases]. Unzip the downloaded plugin and add it to the `plugins/` directory of your site's GitHub repository.

### Plugin activation

For VIP sites, we recommend [activating plugins with code][wpvip-plugin-activate].

For Non-VIP sites, activate the plugin in the WordPress Admin dashboard using the following steps:

1. Navigate to the WordPress Admin dashboard as a logged-in user.
2. Select **Plugins** from the lefthand navigation menu.
3. Locate the "VIP Decoupled Plugin Bundle" plugin in the list and select the "Activate" link located below it.

## Getting started

Expand All @@ -22,7 +50,6 @@ This command will start a local WordPress environment, activate the plugin, and

The default credentials for the Admin Dashboard (provided by `wp-env`) are U: `admin` / P: `password`.


## Configuration

### Setting the home URL
Expand Down Expand Up @@ -57,7 +84,6 @@ This plugin provides a settings page in the Admin Dashboard, found at Settings >

That's all the configuration that's needed to support your decoupled frontend. If you are using VIP's Next.js boilerplate, [head over to the README][nextjs-boilerplate] to get your frontend up and running.


## Sub-plugins

This plugin bundle provides a number of "sub-plugins" that are commonly useful in decoupled environments. You are free to disable any of them and bring your own alternatives.
Expand Down Expand Up @@ -105,6 +131,11 @@ This plugin overrides WordPress's native preview functionality and securely send

**This plugin currently only works with our Next.js boilerplate** and should be disabled if you are not using it. If you are interested in using this plugin for other frontend frameworks, please see the [preview `README`][preview-readme].

## Contributing

Refer [here](CONTRIBUTING.md) for how to contribute to this plugin's development.

<!-- Links -->
[graphql]: https://graphql.org
[mulisite-file]: MULTISITE.md
[preview-readme]: preview/README.md
Expand All @@ -113,3 +144,5 @@ This plugin overrides WordPress's native preview functionality and securely send
[wp-env]: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/
[wp-env-file]: wp-env.json
[vip-jetpack-sync-cron]: /~https://github.com/Automattic/vip-jetpack-sync-cron
[repo-releases]: /~https://github.com/Automattic/vip-decoupled-bundle/releases
[wpvip-plugin-activate]: https://docs.wpvip.com/how-tos/activate-plugins-through-code/
61 changes: 61 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Release steps

## 1. Create a release branch

1. Before merging a feature, create a release branch for the next target version, e.g.

```bash
git checkout trunk
git checkout -b planned-release/0.2.1
```

2. In GitHub, select the base branch as the `planned-release/...` branch.
3. Merge feature branches into the `planned-release/...` branch.

## 2. Update build files

```bash
composer install --no-dev
```

Note: If new production dependencies have been added, modify the root `.gitignore` file to include new `vendor/` subfolders.

Now commit these build changes in.

## 3. Bump plugin version

1. When the version is ready for release, inside the `planned-release/...` branch, bump the version number in `vip-decoupled.php`.
2. Create a PR for the planned release branch (e.g. "Planned release 0.2.1") and merge to `trunk`.

## 4. Tag branch for release

1. In `trunk`, add a tag for the release:

```bash
git checkout trunk
git pull
git tag -a <version> -m "Release <version>"

# e.g. git tag -a 1.0.2 -m "Release 1.0.2"
```

2. Run `git push --tags`.

## 5. Create a release

1. In the `vip-decoupled-bundle` folder, run this command to create a plugin ZIP:

```bash
git archive --prefix "vip-decoupled-bundle/" <version> -o vip-decoupled-bundle-<version>.zip

# e.g. git archive --prefix "vip-decoupled-bundle/" 1.0.2 -o vip-decoupled-bundle-1.0.2.zip
#
# Creates a ZIP archive with the prefix folder "vip-decoupled-bundle/" containing files from tag 1.0.2
```

2. Visit the [vip-decoupled-bundle create release page](/~https://github.com/automattic/vip-decoupled-bundle/releases/new).
3. Select the newly created version tag in the dropdown.
4. For the title, enter the release version name (e.g. `1.0.2`)
5. Add a description of release changes.
6. Attach the plugin ZIP.
7. Click "Publish release."
5 changes: 4 additions & 1 deletion admin/admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
/**
* The compatibility/configuration checker module.
*
* @package vip-bundle-decoupled
*/

Expand All @@ -24,7 +26,8 @@ function is_decoupled() {
}

/**
*
* Check if the multisite is misconfigured.
*
* @return bool
*/
function is_misconfigured_multisite() {
Expand Down
10 changes: 6 additions & 4 deletions blocks/blocks.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
/**
* The content blocks module.
*
* @package vip-bundle-decoupled
*/

Expand Down Expand Up @@ -63,7 +65,7 @@ function transform_block_attributes( $block ) {
$block['attributes']['srcset'] = \wp_get_attachment_image_srcset( $block['attributes']['id'] );
$block['attributes']['alt'] = trim( wp_strip_all_tags( \get_post_meta( $block['attributes']['id'], '_wp_attachment_image_alt', true ) ) );

// If width and height attributes aren't exposed, add the default ones
// If width and height attributes aren't exposed, add the default ones.
if ( ! isset( $block['attributes']['height'] ) ) {
$block['attributes']['height'] = $attachment_metadata['height'];
}
Expand Down Expand Up @@ -93,10 +95,10 @@ function parse_inner_html( $html ) {
$orphaned_tag_pattern = '#^[^<]*</[A-z][A-z0-9]*>#s';

// Strip all the tags from the provided html, and compare it to the trimmed original html
// to see if its the same or not. If it is the same, then there's no html provided
// to see if its the same or not. If it is the same, then there's no html provided.
$tagless_value = wp_strip_all_tags( $html );

// trim is necessary as the wp_strip_all_tags is removing all the linebreaks so this accounts for that
// trim is necessary as the wp_strip_all_tags is removing all the linebreaks so this accounts for that.
if ( trim( $html ) === $tagless_value ) {
return [
'innerHTMLUnwrapped' => $tagless_value,
Expand All @@ -107,7 +109,7 @@ function parse_inner_html( $html ) {
if ( preg_match( $wrapping_tag_pattern, $html, $matches ) ) {
// Check for orphaned tag that would indicate that we should not have
// stripped the top-level wrapping tag. Example:
// <div>1</div><div>2</div>
// <div>1</div><div>2</div>.
if ( 1 === preg_match( $orphaned_tag_pattern, $matches[3] ) ) {
return [
'innerHTMLUnwrapped' => null,
Expand Down
Loading

0 comments on commit 2bf00e6

Please sign in to comment.