Skip to content

Instantly share code, notes, and snippets.

View jasonbahl's full-sized avatar
:octocat:

Jason Bahl jasonbahl

:octocat:
View GitHub Profile
@jasonbahl
jasonbahl / security-fix.patch
Created December 11, 2025 19:55
Fix for authenticated cache leak vulnerability
diff --git a/src/Cache/Query.php b/src/Cache/Query.php
index ec5cfdc..3435ac0 100644
--- a/src/Cache/Query.php
+++ b/src/Cache/Query.php
@@ -22,6 +22,13 @@ class Query {
**/
public static $storage = null;
+ /**
+ * The current GraphQL request.
@jasonbahl
jasonbahl / security-fix.patch
Last active December 11, 2025 19:44
Fix for authenticated cache leak vulnerability
diff --git a/src/Cache/Query.php b/src/Cache/Query.php
index ec5cfdc..3435ac0 100644
--- a/src/Cache/Query.php
+++ b/src/Cache/Query.php
@@ -22,6 +22,13 @@ class Query {
**/
public static $storage = null;
+ /**
+ * The current GraphQL request.
import { GraphQLClient, gql } from 'graphql-request';
import { SEED_QUERY } from '@/components/WPTemplateRouter/SEED_QUERY';
import templates from '@/wp-templates/wp-templates.js';
/**
* Fetches the seed node data from WordPress using the SEED_QUERY.
*
* @param {object} context - The context object.
* @param {string} context.uri - The URI of the node to fetch.
* @param {boolean} [context.isPreview=false] - Whether this is a preview request.
<?php
/**
* Plugin Name: WPGraphQL Track GetText
* Description: Test plugin for tracking the number of times the wp-graphql textdomain is translated during a WPGraphQL request. The count is output in the "extensions" portion of the graphql response.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@jasonbahl
jasonbahl / wp-graphql-page-siblings-connection.php
Created July 13, 2023 14:47
Register a page siblings connection in WPGraphQL
add_action( 'graphql_register_types', function() {
register_graphql_connection( [
'fromType' => 'Page',
'toType' => 'Page',
'connectionTypeName' => 'PageSiblings',
'fromFieldName' => 'siblings',
'resolve' => function( $page, $args, $context, $info ) {
$parent = $page->parentDatabaseId ?? null;
@jasonbahl
jasonbahl / wp-graphql-smart-cache-custom-even-listener.php
Created June 1, 2023 16:33
Listen to custom events and call purge
add_action( 'graphql_cache_invalidation_init', static function( \WPGraphQL\SmartCache\Cache\Invalidation $invalidation ) {
add_action( 'updated_option', static function( $option, $value, $original_value ) use ( $invalidation ) {
// phpcs:ignore
if ( ! isset( $_POST['_acf_screen'] ) || 'options' !== $_POST['_acf_screen'] ) {
return;
}
// phpcs:ignore
add_filter( 'graphql_query_analyzer_graphql_keys', function( $graphql_keys, $return_keys, $skipped_keys, $return_keys_array, $skipped_keys_array ) {
$keys_array = explode( ' ', $return_keys );
if ( empty( $keys_array ) || ! in_array( 'operation:GetPostBySlug', $keys_array, true ) ) {
return $graphql_keys;
}
if ( ( $key = array_search('list:tag', $keys_array ) ) !== false ) {
unset( $keys_array[$key] );
add_action( 'graphql_return_response', function( $filtered_response, $response, $schema, $operation, $query, $variables, $request, $query_id ) {
$errors = [];
if ( ! is_array( $filtered_response ) && ! empty( $filtered_response->errors ) && is_array( $filtered_response->errors ) ) {
$errors = $filtered_response->errors;
} else if ( is_array( $filtered_response ) && ! empty( $filtered_response['errors'] ) && is_array( $filtered_response['errors'] ) ) {
$errors = $filtered_response['errors'];
}
function _graphql_acf_sanitize_flexible_content_resolver( $value, $acf_field, $context, $type_name ) {
if ( ! isset( $value['acf_fc_layout'] ) ) {
return null;
}
$type_registry = $context->type_registry;
$field_type_name = $type_name . '_' . ucfirst( \WPGraphQL\ACF\Config::camel_case( $acf_field['name'] ) );
@jasonbahl
jasonbahl / wp-graphql-acf-override-resolver.php
Last active May 11, 2023 15:33
Override a resolver for wp-graphql-acf v0.6.1 and older to prevent orphaned IDs from causing errors.
function _graphql_acf_sanitize_post_object_resolver( $value ) {
if ( ! $value instanceof \WPGraphQL\Model\Post ) {
return $value;
}
if ( 'publish' !== $value->status ) {
return $value;
}