Skip to content

Commit

Permalink
Removed all GQL functions
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbaker committed Nov 1, 2024
1 parent 4dcbc92 commit bab9cee
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 781 deletions.
26 changes: 3 additions & 23 deletions blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,10 @@ https://www.advancedcustomfields.com/resources/blocks/
1. Be sure to set a good icon.

1. Create ACF field group, set location as Form > Block. Be sure to select "Show in GraphQL". You don't need to se the GraphQL types manually. The default works.
1. Refresh Gutenberg Block cache in menu graphql > gutenberg
1. Verify that new component is available in gutenberg editor or graphiql (note you may need to clear site cache)
1. Verify that new component is available in the editor (note you may need to clear site cache)
1. Create backend PHP template and styles
1. in /blocks/ dir add new dir for block (eg "/block/slideshow")
1. add template to `/block/slideshow/block.php`
1. add styles to `/block/slideshow/block.css`
1. Add GQL to /gql/fragments/GutenbergBlocks.gql query. Be sure to alias your fields with `fields` like so:
```
# Custom Blocks
fragment SlideshowBlock on Block {
... on AcfSlideshowBlock {
# AcfCreditBlock is always like `Acf${BlockName}Block`
attributes {
wpClasses: className
}
fields: blockSlideshow {
# blockSlideshow is the ACF field group name
slides {
...MediaImage
}
}
}
}
```
1. Import Component to the WpGutenberg.vue file for lazy loading
1. Build frontend Vue template in `/components/gutenberg`
1. See Missing Pieces for demos
1. Import Component to the WpContent.vue file for lazy loading
1. Build frontend Vue template in `/components/wp-block`
5 changes: 1 addition & 4 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ body:not(.is-developer) #toplevel_page_edit-post_type-acf-field-group {
body.post-php.is-developer-locked:not(.is-developer) #edit-slug-buttons {
display: none;
}
body:not(.is-developer) #wp-admin-bar-graphiql-ide,
body:not(.is-developer) #adminmenu #toplevel_page_graphql,
body:not(.is-developer) #adminmenu #toplevel_page_wp-graphiql-wp-graphiql,
body:not(.is-developer) #adminmenu #toplevel_page_wp-graphql-gutenberg-admin
body:not(.is-developer) #toplevel_page_wp-openapi,
body:not(.is-developer) #adminmenu #toplevel_page_proxy-settings {
display: none;
}
Expand Down
Binary file modified favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Load all modules.
*/
require_once get_template_directory() . '/functions/wp-functions.php';
require_once get_template_directory() . '/functions/gql-functions.php';
require_once get_template_directory() . '/functions/theme-config.php';
require_once get_template_directory() . '/functions/gutenberg-functions.php';
require_once get_template_directory() . '/functions/acf-functions.php';
Expand All @@ -21,4 +20,4 @@
require_once get_template_directory() . '/functions/developer-role.php';
require_once get_template_directory() . '/functions/widgets.php';
require_once get_template_directory() . '/functions/svg.php';
require_once get_template_directory() . '/functions/proxy.php';
require_once get_template_directory() . '/functions/proxy.php';
100 changes: 1 addition & 99 deletions functions/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,102 +46,4 @@ function fuxt_custom_blocks() {
);

}
//add_action( 'acf/init', 'fuxt_custom_blocks' );

/**
* Extend GraphQL to add a mutation to send emails via the wp_mail() function.
* SEE https://developer.wordpress.org/reference/functions/wp_mail/ for more info on how each input works.
* SEE https://docs.wpgraphql.com/extending/mutations/
*/
function gql_register_email_mutation() {
// Define the input parameters
$input_fields = array(
'to' => array(
'type' => array( 'list_of' => 'String' ),
'description' =>
'Array of email addresses to send email to. Must comply to RFC 2822 format.',
),
'subject' => array(
'type' => 'String',
'description' => 'Email subject.',
),
'message' => array(
'type' => 'String',
'description' => 'Message contents.',
),
'headers' => array(
'type' => array( 'list_of' => 'String' ),
'description' =>
'Array of any additional headers. This is how you set BCC, CC and HTML type. See wp_mail() function for more details.',
),
'trap' => array(
'type' => 'String',
'description' =>
'Crude anti-spam measure. This must equal the clientMutationId, otherwise the email will not be sent.',
),
);

// Define the ouput parameters
$output_fields = array(
'to' => array(
'type' => array( 'list_of' => 'String' ),
'description' =>
'Array of email addresses to send email to. Must comply to RFC 2822 format.',
),
'subject' => array(
'type' => 'String',
'description' => 'Email subject.',
),
'message' => array(
'type' => 'String',
'description' => 'Message contents.',
),
'headers' => array(
'type' => array( 'list_of' => 'String' ),
'description' =>
'Array of any additional headers. This is how you set BCC, CC and HTML type. See wp_mail() function for more details.',
),
'sent' => array(
'type' => 'Boolean',
'description' => 'Returns true if the email was sent successfully.',
'resolve' => function ( $payload, $args, $context, $info ) {
return isset( $payload['sent'] ) ? $payload['sent'] : false;
},
),
);

// This function processes the submitted data
$mutate_and_get_payload = function ( $input, $context, $info ) {
// Spam honeypot. Make sure that the clientMutationId matches the trap input.
if ( $input['clientMutationId'] !== $input['trap'] ) {
throw new \GraphQL\Error\UserError( 'You got caught in a spam trap' );
}

// Vailidate email before trying to send
foreach ( $input['to'] as $email ) {
if ( ! is_email( $email ) ) {
throw new \GraphQL\Error\UserError( 'Invalid email address: ' . $email );
}
}

// Send email!
$input['sent'] = wp_mail(
$input['to'],
$input['subject'],
$input['message'],
$input['headers'],
$input['attachments']
);

return $input;
};

// Add mutation to WP-GQL now
$args = array(
'inputFields' => $input_fields,
'outputFields' => $output_fields,
'mutateAndGetPayload' => $mutate_and_get_payload,
);
register_graphql_mutation( 'sendEmail', $args );
}
//add_action( 'graphql_register_types', 'gql_register_email_mutation' );
//add_action( 'acf/init', 'fuxt_custom_blocks' );
Loading

0 comments on commit bab9cee

Please sign in to comment.