This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'parse_request', 'disable_front_end', 99 ); | |
function disable_front_end() { | |
global $wp; | |
/** | |
* If the request is not part of a CRON, REST Request, GraphQL Request or Admin request, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'graphql_PostObjectsConnectionOrderbyEnum_values', function( $values ) { | |
$values['LIKE_COUNT'] = [ | |
'value' => 'like_count', | |
'description' => __( 'The number of likes on the post', 'wp-graphql' ), | |
]; | |
return $values; | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createPersistedQueryLink} from '@apollo/client/link/persisted-queries'; | |
import {HttpLink} from "@apollo/client"; | |
import {sha256} from 'crypto-hash'; | |
const linkChain = createPersistedQueryLink({ sha256 }).concat( | |
new HttpLink({ uri: process.env.WPGRAPHQL_URL }), | |
); | |
class PersistedQueriesPlugin { | |
apply({ addFilter }) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _graphql_acf_sanitize_post_object_resolver( $value ) { | |
if ( ! $value instanceof \WPGraphQL\Model\Post ) { | |
return $value; | |
} | |
if ( 'publish' !== $value->status ) { | |
return $value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] ) ); |
NewerOlder