Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: use WP_Filesystem for Signature Field uploads #434

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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
Loading