Skip to content

Commit 181ff20

Browse files
authored
dev: use WP_Filesystem for Signature Field uploads (#434)
1 parent 8d8d94d commit 181ff20

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- feat: Add support for WPGraphQL Content Blocks.
1616
- dev: Remove `vendor` directory from the GitHub repository.
1717
- dev: Use `FormFieldsDataLoader` to resolve fields instead of instantiating a new `Model`.
18+
- dev: use WP_Filesystem to handle Signature field uploads.
1819
- chore!: Remove deprecated fields from the schema: `FormsConnectionOrderbyInput.field`, `GfFieldWithDisableQuantitySetting.isQuantityDisabled`. `GfSubmittedEntry.entryId`. `GfForm.button`, `gfForm.entryId`, `gfForm.lastPageButton`.
1920
- chore!: Remove deprecated hooks: `graphql_gf_form_modeled_data_experimental`, `graphql_gf_form_field_setting_properties`, `graphql_gf_form_field_value_properties`.
2021
- chore!: Remove deprecated helper method: `GFUtils::handle_file_upload()`.

src/Extensions/GFSignature/Data/FieldValueInput/SignatureValuesInput.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,16 @@ protected function save_signature( string $signature ): string {
8888
$folder = \GFSignature::get_signatures_folder();
8989
$filename = uniqid( '', true ) . '.png';
9090
$path = $folder . $filename;
91-
// @todo: switch to WP Filesystem.
92-
$number_of_bytes = file_put_contents( $path, $signature_decoded ); //phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
91+
92+
// Use WP_Filesystem to save the signature image.
93+
global $wp_filesystem;
94+
if ( ! $wp_filesystem instanceof \WP_Filesystem_Base ) {
95+
require_once ABSPATH . 'wp-admin/includes/file.php';
96+
WP_Filesystem();
97+
}
98+
99+
/** @var \WP_Filesystem_Base $wp_filesystem */
100+
$number_of_bytes = $wp_filesystem->put_contents( $path, $signature_decoded, FS_CHMOD_FILE );
93101

94102
if ( false === $number_of_bytes ) {
95103
throw new UserError( esc_html__( 'An error occurred while saving the signature image.', 'wp-graphql-gravity-forms' ) );

0 commit comments

Comments
 (0)