fix(filesystem): replace raw filesystem operations with WP_Filesystem APIs#3197
Open
faisalahammad wants to merge 2 commits into
Open
fix(filesystem): replace raw filesystem operations with WP_Filesystem APIs#3197faisalahammad wants to merge 2 commits into
faisalahammad wants to merge 2 commits into
Conversation
Replace fopen/fread/fwrite/fclose/unlink/rename/is_writable calls flagged by Plugin Check with WP_Filesystem methods and wp_delete_file/wp_tempnam helpers across 5 files. - class.llms.data.php: get_file_version() reads via WP_Filesystem::get_contents(). - class.llms.install.php: create_files() writes via WP_Filesystem::put_contents(). - class-llms-admin-export-download.php: unlink() -> wp_delete_file(). - class.llms.admin.page.status.php: is_file/is_writable/unlink replaced with WP_Filesystem equivalents. - class.llms.meta.box.voucher.export.php: array_to_csv() builds CSV string without streams; send_email() writes via WP_Filesystem::put_contents() and removes with wp_delete_file().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace raw PHP filesystem operations flagged by Plugin Check with WP_Filesystem APIs and wp_delete_file()/wp_tempnam() helpers across 5 files. All 18 file_system_operations_* errors resolved.
Changes
includes/class.llms.data.php — get_file_version()
Before:
After:
Why: Plugin Check flags fopen/fread/fclose as raw filesystem calls. WP_Filesystem get_contents() reads in one call and we slice the first 8KB via substr.
includes/class.llms.install.php — create_files()
Before:
After:
Why: Drop phpcs:ignore comments and use WP_Filesystem put_contents(). Removes 3 phpcs:ignore annotations on the previous lines.
includes/admin/class-llms-admin-export-download.php
Before:
unlink( $path );After:
wp_delete_file( $path );Why: wp_delete_file() is the WordPress wrapper for unlink() and is the recommended API per WordPress coding standards.
includes/admin/class.llms.admin.page.status.php — remove_log_file()
Before:
After:
Why: Plugin Check flags is_writable and unlink. Use the WP_Filesystem equivalents plus wp_delete_file.
includes/admin/post-types/meta-boxes/class.llms.meta.box.voucher.export.php
array_to_csv()
Before: Used
fopen('php://temp')+fputcsv+fread+fcloseto build an in-memory CSV string.After: Builds CSV directly via a new
csv_row()helper that produces RFC 4180 compliant output without touching a stream.Why: fopen/fread/fclose were flagged. CSV format identical to fputcsv for flat fields (always-enclosed, doubled enclosure for embedded quotes). Signature and return type unchanged, existing callers unaffected.
send_email()
Before:
tempnam+fopen+fwrite+rename+fclose+unlink.After:
wp_tempnam()+WP_Filesystem::put_contents()+wp_delete_file().Why: Use the WordPress temp file helper and WP_Filesystem write instead of low-level stream and filesystem ops.
Skipped
includes/class-llms-media-protector.php:606readfile(): already hasphpcs:ignore. Intentional. Streams large protected media files to the browser.WP_Filesystem::get_contents()would load the entire file into memory which is worse for large media.Testing
php -lon all 5 modified files: no syntax errorsvendor/bin/phpcs --sniffs=WordPress.WP.AlternativeFunctionson modified files: zero errorscomposer check-csfull project run: zero errorsBuild
Two commits on
fix/filesystem-api-replacement:468d6f9fbfix: replace raw filesystem operations with WP_Filesystem APIsbc2c4c9a9chore: add changelog entry for filesystem API fix