Skip to content

Commit 50e5cc2

Browse files
authored
fix: Check for url before passing it to url_to_postid() (#423)
1 parent 22b31ac commit 50e5cc2

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- feat!: Narrow `FormField.choices` and `FormField.inputs` field types to their implementations.
88
- fix!: Keep `PageField` with previous page data when filtering `formFields` by `pageNumber`. H/t @SamuelHadsall .
99
- fix: Handle RadioField submission values when using a custom "other" choice. H/t @Gytjarek .
10+
- fix: Check for Submission Confirmation url before attempting to get the associated post ID.
1011
- dev: Use `FormFieldsDataLoader` to resolve fields instead of instantiating a new `Model`.
1112
- chore: Add iterable type hints.
1213
- chore!: Bump minimum WPGraphQL version to v1.26.0.

src/Type/WPObject/SubmissionConfirmation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public static function get_connections(): array {
5050
'toType' => 'Page',
5151
'oneToOne' => true,
5252
'resolve' => static function ( $source, array $args, AppContext $context, ResolveInfo $info ) {
53-
$page_id = url_to_postid( $source['url'] ); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.url_to_postid_url_to_postid
53+
$page_id = isset( $source['url'] ) ? url_to_postid( $source['url'] ) : null; //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.url_to_postid_url_to_postid
54+
55+
if ( empty( $page_id ) ) {
56+
return null;
57+
}
5458

5559
$resolver = new PostObjectConnectionResolver( $source, $args, $context, $info, 'page' );
5660

@@ -90,7 +94,7 @@ public static function get_fields(): array {
9094
'type' => 'Int',
9195
'description' => __( 'Contains the Id of the WordPress page that the browser will be redirected to. Only applicable when type is set to `PAGE`.', 'wp-graphql-gravity-forms' ),
9296
'resolve' => static function ( $source ) {
93-
$post_id = url_to_postid( $source['url'] ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.url_to_postid_url_to_postid
97+
$post_id = isset( $source['url'] ) ? url_to_postid( $source['url'] ) : null; // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.url_to_postid_url_to_postid
9498

9599
return ! empty( $post_id ) ? $post_id : null;
96100
},

0 commit comments

Comments
 (0)