Skip to content

Commit

Permalink
dev: use WP_Filesystem for Signature Field uploads (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
justlevine authored Jun 15, 2024
1 parent 8d8d94d commit 181ff20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- feat: Add support for WPGraphQL Content Blocks.
- dev: Remove `vendor` directory from the GitHub repository.
- dev: Use `FormFieldsDataLoader` to resolve fields instead of instantiating a new `Model`.
- dev: use WP_Filesystem to handle Signature field uploads.
- chore!: Remove deprecated fields from the schema: `FormsConnectionOrderbyInput.field`, `GfFieldWithDisableQuantitySetting.isQuantityDisabled`. `GfSubmittedEntry.entryId`. `GfForm.button`, `gfForm.entryId`, `gfForm.lastPageButton`.
- chore!: Remove deprecated hooks: `graphql_gf_form_modeled_data_experimental`, `graphql_gf_form_field_setting_properties`, `graphql_gf_form_field_value_properties`.
- chore!: Remove deprecated helper method: `GFUtils::handle_file_upload()`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@ protected function save_signature( string $signature ): string {
$folder = \GFSignature::get_signatures_folder();
$filename = uniqid( '', true ) . '.png';
$path = $folder . $filename;
// @todo: switch to WP Filesystem.
$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

// Use WP_Filesystem to save the signature image.
global $wp_filesystem;
if ( ! $wp_filesystem instanceof \WP_Filesystem_Base ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
}

/** @var \WP_Filesystem_Base $wp_filesystem */
$number_of_bytes = $wp_filesystem->put_contents( $path, $signature_decoded, FS_CHMOD_FILE );

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

0 comments on commit 181ff20

Please sign in to comment.