@@ -437,75 +437,4 @@ public static function get_gravity_forms_upload_dir( int $form_id ): array {
437437 'baseurl ' => untrailingslashit ( GFFormsModel::get_upload_url_root () ),
438438 ];
439439 }
440-
441- /**
442- * Handle custom file upload.
443- *
444- * This mimics WP Core upload functionality but allows for uploading file to a custom directory rather than the standard WP uploads dir.
445- * Slightly modified from source.
446- *
447- * @see https://developer.wordpress.org/reference/functions/_wp_handle_upload/
448- *
449- * @author WebDevStudios
450- * @source https://github.com/WebDevStudios/wds-headless-wordpress/blob/5a8e84a2dbb7a0bb537422223ab409ecd2568b00/themes/wds_headless/inc/wp-graphql.php#L452
451- * @param array<string,mixed> $file File data to upload.
452- * @param array<string,mixed> $target Target upload directory; WP uploads dir will be used if none provided.
453- *
454- * @return array{file:string,url:string,type:mixed}
455- *
456- * @deprecated 0.11.0
457- *
458- * @throws \GraphQL\Error\UserError .
459- */
460- public static function handle_file_upload ( $ file , $ target ) {
461- _doing_it_wrong ( __FUNCTION__ , esc_html__ ( 'GFUtils::handle_file_upload() is deprecated. Please use native WP/GF methods instead. ' , 'wp-graphql-gravity-forms ' ), '0.11.0 ' );
462-
463- $ target = $ target ?: wp_upload_dir ();
464-
465- $ wp_filetype = wp_check_filetype_and_ext ( $ file ['tmp_name ' ], $ file ['name ' ] );
466- $ ext = empty ( $ wp_filetype ['ext ' ] ) ? '' : $ wp_filetype ['ext ' ];
467- $ type = empty ( $ wp_filetype ['type ' ] ) ? '' : $ wp_filetype ['type ' ];
468- $ proper_filename = empty ( $ wp_filetype ['proper_filename ' ] ) ? '' : $ wp_filetype ['proper_filename ' ];
469-
470- // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect.
471- if ( ! empty ( $ proper_filename ) ) {
472- $ file ['name ' ] = $ proper_filename ;
473- }
474-
475- // Return error if file type not allowed.
476- if ( ( ! $ type || ! $ ext ) && ! current_user_can ( 'unfiltered_upload ' ) ) {
477- throw new UserError ( esc_html__ ( 'This file type is not permitted for security reasons. ' , 'wp-graphql-gravity-forms ' ) );
478- }
479-
480- $ type = empty ( $ type ) ? $ file ['type ' ] : $ type ;
481-
482- $ filename = wp_unique_filename ( $ target ['path ' ], $ file ['name ' ] );
483-
484- // Move the file to the GF uploads dir.
485- $ new_file = $ target ['path ' ] . sprintf ( '/%s ' , $ filename );
486-
487- // Use copy and unlink because rename breaks streams.
488- $ move_new_file = @copy ( $ file ['tmp_name ' ], $ new_file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged,Generic.PHP.NoSilencedErrors.Forbidden
489- unlink ( $ file ['tmp_name ' ] ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink
490-
491- if ( ! $ move_new_file ) {
492- throw new UserError ( esc_html__ ( 'Failed to copy the file to the server. ' , 'wp-graphql-gravity-forms ' ) );
493- }
494-
495- // Set correct file permissions.
496- $ stat = stat ( dirname ( $ new_file ) );
497- if ( is_array ( $ stat ) ) {
498- $ perms = $ stat ['mode ' ] & 0000666 ;
499- chmod ( $ new_file , $ perms ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.chmod_chmod
500- }
501-
502- // Compute the URL.
503- $ url = $ target ['url ' ] . sprintf ( '/%s ' , $ filename );
504-
505- return [
506- 'file ' => $ new_file ,
507- 'url ' => $ url ,
508- 'type ' => $ type ,
509- ];
510- }
511440}
0 commit comments