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 / update-wp-graphql-woocommerce-resolveNode.php
Created July 29, 2021 15:18
Allow WPGraphQL for WooCommerce resolveNode callbacks to work with WPGraphQL v1.15+
add_filter( 'graphql_pre_resolve_field', function( $nil, $source, $args, \WPGraphQL\AppContext $context, \GraphQL\Type\Definition\ResolveInfo $info, $type_name, $field_key, $field, $field_resolver ) {
if ( 'RootQueryToShippingMethodConnection' === $type_name ) {
if ( 'nodes' === $field_key ) {
if ( ! empty( $source['nodes'] ) && is_array( $source['nodes'] ) ) {
$nodes = [];
foreach ( $source['nodes'] as $node ) {
$nodes[] = \WPGraphQL\WooCommerce\Data\Factory\Factory::resolve_shipping_method( $node );
}
@jasonbahl
jasonbahl / functions.php
Created July 27, 2021 04:27
Create new posts with unique authors
add_action( 'init', function() {
return;
$users = graphql([
'query' => '
{
users(first:100) {
nodes {
databaseId
}
}
// src/pages/Blog.vue
<template>
<Layout>
<section>
<article v-for="(post, index) in $static.posts.edges" :key="index">
<h1>{{ post.node.title }}</h1>
<p>
By <span>{{ post.node.author.node.name }}</span> on
{{ getDate(post.node.date) }}
<script>
export default {
methods: {
getDate(date) {
const newDate = new Date(date);
const newDateString = `${newDate.toLocaleString("default", {
month: "long",
})}, ${newDate.getDate()} ${newDate.getFullYear()}`;
return newDateString;
},
// src/pages/Blog.vue
<static-query>
query {
posts {
edges {
node {
title
content
uri
// src/templates/Post.vue
<article>
<h1 class="title">{{ $page.post.title }}</h1>
<div class="content" v-html="$page.post.content"></div>
</article>
<template>
<div>
<h1 v-html="$page.post.title" />
<div v-html="$page.post.content" />
</div>
</template>
<page-query>
query ($id: ID!) {
post(id: $id) {
add_action( 'plugins_loaded', function() {
if ( ! class_exists( 'Redux' ) ) {
return;
}
add_action( 'redux/loaded', function( $redux ) {
if ( ! isset( $redux->sections ) || empty( $redux->sections ) ) {
return;
@jasonbahl
jasonbahl / register-redux-settings
Created January 8, 2021 09:18
Initial support for WPGraphQL for the Redux Framework
$opt_name = 'graphql_demo';
$theme = wp_get_theme(); // For use with some settings. Not necessary.
$args = array(
'display_name' => $theme->get( 'Name' ),
'display_version' => $theme->get( 'Version' ),
'menu_title' => esc_html__( 'Sample Options', 'redux-framework-demo' ),
'customizer' => true,
);