From 90f75b01bc962f0b4641f2d9195ca614f15a9985 Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 2 Aug 2024 22:18:31 +0000 Subject: [PATCH] fix: return default value for `FieldWithFileSize.maxFileSize` --- CHANGELOG.md | 2 +- src/Type/WPInterface/FieldSetting/FieldWithFileSize.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42d190bd..979ded46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,9 @@ ## [Unreleased] - fix: Check if classes are loaded by a different autoloader before attempting to autoload them. H/t @cvanh +- fix: Return `wp_max_upload_size()` instead of `null` if `FieldWithFileSize.maxFileSize` is `null`. H/t @Gytjarek - ci: Replace calls to `docker-compose` with `docker compose`. - ## v0.13.0 **:warning: This release contains multiple breaking changes.** diff --git a/src/Type/WPInterface/FieldSetting/FieldWithFileSize.php b/src/Type/WPInterface/FieldSetting/FieldWithFileSize.php index 48bd91db..bd83464e 100644 --- a/src/Type/WPInterface/FieldSetting/FieldWithFileSize.php +++ b/src/Type/WPInterface/FieldSetting/FieldWithFileSize.php @@ -36,6 +36,10 @@ public static function get_fields(): array { 'maxFileSize' => [ 'type' => 'Int', 'description' => __( 'The maximum size (in MB) an uploaded file may be .', 'wp-graphql-gravity-forms' ), + 'resolve' => static function ( $source ) { + // Fall back to the WP max upload size if the field setting is not set, to mimic GF frontend behavior. + return ! empty( $source->maxFileSize ) ? (int) $source->maxFileSize : ( wp_max_upload_size() / 1048576 ); + }, ], ]; }