Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 30 additions & 6 deletions .github/scripts/get_plugin_slug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,40 @@ done
# Get unique plugin names
UNIQUE_PLUGINS=($(printf '%s\n' "${PLUGINS[@]}" | sort -u))

# Find the first plugin that actually exists
PLUGIN_SLUG=""
# Find all valid plugins that have changes
VALID_PLUGINS=()
for plugin in "${UNIQUE_PLUGINS[@]}"; do
if [ -d "plugins/$plugin" ] || [[ " ${CHANGED_FILES[@]} " =~ "plugins/$plugin/" ]]; then
PLUGIN_SLUG="$plugin"
echo "Found plugin in changes or directory: $PLUGIN_SLUG"
break
if [ -d "plugins/$plugin" ]; then
count=$(printf '%s\n' "${PLUGINS[@]}" | grep -c "^$plugin$")
VALID_PLUGINS+=("$plugin")
echo "Found plugin with $count changes: $plugin"
fi
done

# Output all valid plugins as JSON array for matrix strategy
if [ ${#VALID_PLUGINS[@]} -gt 0 ]; then
# Simple, reliable JSON array generation
PLUGINS_JSON="["
for i in "${!VALID_PLUGINS[@]}"; do
if [ $i -eq 0 ]; then
PLUGINS_JSON="$PLUGINS_JSON\"${VALID_PLUGINS[i]}\""
else
PLUGINS_JSON="$PLUGINS_JSON,\"${VALID_PLUGINS[i]}\""
fi
done
PLUGINS_JSON="$PLUGINS_JSON]"

echo "plugins=$PLUGINS_JSON" >> "$GITHUB_OUTPUT"
echo "has-plugins=true" >> "$GITHUB_OUTPUT"

# For backward compatibility, set slug to first plugin
PLUGIN_SLUG="${VALID_PLUGINS[0]}"
else
echo "plugins=[]" >> "$GITHUB_OUTPUT"
echo "has-plugins=false" >> "$GITHUB_OUTPUT"
PLUGIN_SLUG=""
fi

if [ -z "$PLUGIN_SLUG" ]; then
echo "No valid plugin directory found"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/update_composer_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ usage() {
echo " description - Optional: Package description (uses generic default if not provided)"
echo ""
echo "Examples:"
echo " $0 '0.0.2' 'https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.2/wp-graphql-webhooks.zip'"
echo " $0 '0.0.2' 'https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.2/wpgraphql-webhooks.zip'"
echo ""
echo " With custom package name and description:"
echo " $0 '0.0.5' 'https://example.com/plugin.zip' 'wpengine/my-plugin' 'My custom plugin description'"
Expand Down
53 changes: 40 additions & 13 deletions .github/workflows/plugin-artifact-for-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,68 @@ on:
- 'plugins/*/**.json'

jobs:
create-plugin-artifact:
name: Create Plugin Artifact
detect-plugins:
name: Detect Changed Plugins
runs-on: ubuntu-latest

outputs:
plugins: ${{ steps.plugin.outputs.plugins }}
has-plugins: ${{ steps.plugin.outputs.has-plugins }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get changed plugin directory
- name: Get changed plugin directories
id: plugin
run: |
bash .github/scripts/get_plugin_slug.sh \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }}

- name: Create plugin artifact
create-plugin-artifacts:
name: Create Plugin Artifacts
runs-on: ubuntu-latest
needs: detect-plugins
if: needs.detect-plugins.outputs.has-plugins == 'true'
strategy:
fail-fast: false
matrix:
plugin: ${{ fromJson(needs.detect-plugins.outputs.plugins) }}

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

- name: Create plugin artifact for ${{ matrix.plugin }}
uses: ./.github/actions/create-plugin-artifact
env:
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
with:
slug: ${{ env.PLUGIN_SLUG }}
slug: ${{ matrix.plugin }}
composer-options: '--no-progress --optimize-autoloader --no-dev'

- name: Comment with artifact link
comment-on-pr:
name: Comment with Artifact Links
runs-on: ubuntu-latest
needs: [detect-plugins, create-plugin-artifacts]
if: needs.detect-plugins.outputs.has-plugins == 'true'
steps:
- name: Comment with artifact links
uses: actions/github-script@v7
env:
PLUGIN_SLUG: ${{ steps.plugin.outputs.slug }}
PLUGINS: ${{ needs.detect-plugins.outputs.plugins }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = context.payload.pull_request;
const runId = context.runId;
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
const slug = process.env.PLUGIN_SLUG;
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;
const plugins = JSON.parse(process.env.PLUGINS);

let body = '## 📦 Plugin Artifacts Ready!\n\n';
body += `[Download from GitHub Actions run](${artifactUrl})\n\n`;
body += '**Available plugins:**\n';
plugins.forEach(plugin => {
body += `- ✅ ${plugin}.zip\n`;
});
body += '\n<em>See the "Artifacts" section at the bottom of the Actions run page</em>';

// Find existing comment from this bot
const comments = await github.rest.issues.listComments({
Expand All @@ -55,7 +82,7 @@ jobs:
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.user.login === 'github-actions[bot]' &&
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
comment.body.includes('## 📦 Plugin Artifacts Ready!')
);

if (botComment) {
Expand Down
4 changes: 2 additions & 2 deletions docs/how-to/install-toolkit-plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Copy and use this example as your `composer.json` for a typical WordPress projec
],
"require": {
"wpengine/hwp-previews": "*",
"wpengine/wp-graphql-webhooks": "*"
"wpengine/wpgraphql-webhooks": "*"
},
"config": {
"allow-plugins": {
Expand Down Expand Up @@ -57,7 +57,7 @@ Copy and use this example as your `composer.json` for a typical WordPress projec
To update to the latest version:

```bash
composer update wpengine/hwp-previews wpengine/wp-graphql-webhooks
composer update wpengine/hwp-previews wpengine/wpgraphql-webhooks
```

---
Expand Down
2 changes: 1 addition & 1 deletion plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WordPress plugins for the Headless WordPress Toolkit. Each plugin is paired with
| Plugin | Description |
|--------|-------------|
| [`hwp-previews`](./hwp-previews/README.md) | Headless Previews solution for WordPress: fully configurable preview URLs via the settings page which is framework agnostic. |
| [`wp-graphql-webhooks`](./wp-graphql-webhooks/README.md) | A WordPress plugin that extends [WPGraphQL](https://www.wpgraphql.com/) to support webhook subscriptions and dispatching for headless WordPress environments. This allows external applications to listen and respond to WordPress content changes through GraphQL-driven webhook events. |
| [`wpgraphql-webhooks`](./wpgraphql-webhooks/README.md) | A WordPress plugin that extends [WPGraphQL](https://www.wpgraphql.com/) to support webhook subscriptions and dispatching for headless WordPress environments. This allows external applications to listen and respond to WordPress content changes through GraphQL-driven webhook events. |


## Install
Expand Down
14 changes: 7 additions & 7 deletions plugins/composer-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@
}
}
},
"wpengine/wp-graphql-webhooks": {
"wpengine/wpgraphql-webhooks": {
"0.0.4": {
"name": "wpengine/wp-graphql-webhooks",
"name": "wpengine/wpgraphql-webhooks",
"version": "0.0.4",
"type": "wordpress-plugin",
"description": "Headless webhooks for WPGraphQL",
Expand All @@ -180,15 +180,15 @@
"email": "[email protected]"
},
"dist": {
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.4/wp-graphql-webhooks.zip",
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.4/wpgraphql-webhooks.zip",
"type": "zip"
},
"require": {
"composer/installers": "~1.0 || ~2.0"
}
},
"0.0.3": {
"name": "wpengine/wp-graphql-webhooks",
"name": "wpengine/wpgraphql-webhooks",
"version": "0.0.3",
"type": "wordpress-plugin",
"description": "Headless webhooks for WPGraphQL",
Expand All @@ -206,15 +206,15 @@
"email": "[email protected]"
},
"dist": {
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.3/wp-graphql-webhooks.zip",
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.3/wpgraphql-webhooks.zip",
"type": "zip"
},
"require": {
"composer/installers": "~1.0 || ~2.0"
}
},
"0.0.2": {
"name": "wpengine/wp-graphql-webhooks",
"name": "wpengine/wpgraphql-webhooks",
"version": "0.0.2",
"type": "wordpress-plugin",
"description": "Headless webhooks for WPGraphQL",
Expand All @@ -232,7 +232,7 @@
"email": "[email protected]"
},
"dist": {
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.2/wp-graphql-webhooks.zip",
"url": "https://github.com/wpengine/hwptoolkit/releases/download/%40wpengine%2Fwpgraphql-webhooks-wordpress-plugin-0.0.2/wpgraphql-webhooks.zip",
"type": "zip"
},
"require": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ setup_plugin() {
fi

# Add this repo as a plugin to the repo
if [ ! -d $WORDPRESS_ROOT_DIR/wp-content/plugins/wp-graphql-webhooks ]; then
if [ ! -d $WORDPRESS_ROOT_DIR/wp-content/plugins/wpgraphql-webhooks ]; then
echo -e "$(status_message "Symlinking the plugin to the WordPress plugins directory...")"

cd "$ORIGINAL_PATH"
Expand Down
2 changes: 1 addition & 1 deletion plugins/wpgraphql-webhooks/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"php:psalm:fix": "psalm --alter"
},
"archive": {
"name": "wp-graphql-webhooks",
"name": "wpgraphql-webhooks",
"exclude": [
"/.*",
"/assets",
Expand Down
30 changes: 15 additions & 15 deletions plugins/wpgraphql-webhooks/src/Admin/WebhooksListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function __construct( WebhookRepository $repository ) {
$this->repository = $repository;

parent::__construct( [
'singular' => __( 'Webhook', 'wp-graphql-webhooks' ),
'plural' => __( 'Webhooks', 'wp-graphql-webhooks' ),
'singular' => __( 'Webhook', 'graphql-webhooks' ),
'plural' => __( 'Webhooks', 'graphql-webhooks' ),
'ajax' => false,
] );
}
Expand All @@ -49,11 +49,11 @@ public function __construct( WebhookRepository $repository ) {
public function get_columns() {
return [
'cb' => '<input type="checkbox" />',
'name' => __( 'Name', 'wp-graphql-webhooks' ),
'event' => __( 'Event', 'wp-graphql-webhooks' ),
'method' => __( 'Method', 'wp-graphql-webhooks' ),
'url' => __( 'URL', 'wp-graphql-webhooks' ),
'headers' => __( 'Headers', 'wp-graphql-webhooks' ),
'name' => __( 'Name', 'graphql-webhooks' ),
'event' => __( 'Event', 'graphql-webhooks' ),
'method' => __( 'Method', 'graphql-webhooks' ),
'url' => __( 'URL', 'graphql-webhooks' ),
'headers' => __( 'Headers', 'graphql-webhooks' ),
];
}

Expand All @@ -77,7 +77,7 @@ public function get_sortable_columns() {
*/
public function get_bulk_actions() {
return [
'delete' => __( 'Delete', 'wp-graphql-webhooks' ),
'delete' => __( 'Delete', 'graphql-webhooks' ),
];
}

Expand All @@ -93,12 +93,12 @@ public function process_bulk_action() {

// Verify nonce
if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'bulk-' . $this->_args['plural'] ) ) {
wp_die( esc_html__( 'Security check failed.', 'wp-graphql-webhooks' ) );
wp_die( esc_html__( 'Security check failed.', 'graphql-webhooks' ) );
}

// Check permissions
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wp-graphql-webhooks' ) );
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'graphql-webhooks' ) );
}

// Get selected webhooks
Expand Down Expand Up @@ -194,7 +194,7 @@ public function column_default( $item, $column_name ) {
return '<span class="webhook-method">' . esc_html( $item->method ) . '</span>';
case 'headers':
$count = is_array( $item->headers ) ? count( $item->headers ) : 0;
return $count > 0 ? sprintf( __( '%d headers', 'wp-graphql-webhooks' ), $count ) : '—';
return $count > 0 ? sprintf( __( '%d headers', 'graphql-webhooks' ), $count ) : '—';
default:
return '';
}
Expand Down Expand Up @@ -236,9 +236,9 @@ public function column_name( $item ) {
);

$actions = [
'edit' => sprintf( '<a href="%s">%s</a>', esc_url( $edit_url ), __( 'Edit', 'wp-graphql-webhooks' ) ),
'test' => sprintf( '<a href="#" class="test-webhook" data-webhook-id="%d">%s</a>', $item->id, __( 'Test', 'wp-graphql-webhooks' ) ),
'delete' => sprintf( '<a href="%s" class="submitdelete">%s</a>', esc_url( $delete_url ), __( 'Delete', 'wp-graphql-webhooks' ) ),
'edit' => sprintf( '<a href="%s">%s</a>', esc_url( $edit_url ), __( 'Edit', 'graphql-webhooks' ) ),
'test' => sprintf( '<a href="#" class="test-webhook" data-webhook-id="%d">%s</a>', $item->id, __( 'Test', 'graphql-webhooks' ) ),
'delete' => sprintf( '<a href="%s" class="submitdelete">%s</a>', esc_url( $delete_url ), __( 'Delete', 'graphql-webhooks' ) ),
];

return sprintf(
Expand All @@ -253,7 +253,7 @@ public function column_name( $item ) {
* Display when no items
*/
public function no_items() {
esc_html_e( 'No webhooks found.', 'wp-graphql-webhooks' );
esc_html_e( 'No webhooks found.', 'graphql-webhooks' );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/wpgraphql-webhooks/wpgraphql-webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Author URI: https://github.com/wpengine
* Update URI: https://github.com/wpengine/hwptoolkit
* Version: 0.0.4
* Text Domain: wpgraphql-webhooks
* Text Domain: graphql-webhooks
* Domain Path: /languages
* Requires at least: 6.0
* Tested up to: 6.8
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.