Opened 3 years ago
Last modified 9 months ago
#57725 new enhancement
Use of rand() function instead of wp_rand()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Filesystem API | Keywords: | has-patch has-test-info 2nd-opinion changes-requested |
| Focuses: | performance, coding-standards | Cc: |
Description
Filesystem API function wp_edit_theme_plugin_file using PHP rand() function rather than WP's wp_rand(). Can we enhance this as rand() is discouraged?
File path: wp-admin/includes/file.php
Line: 524 and 526
Attachments (1)
Change History (9)
#1
@
3 years ago
- Keywords has-patch added; needs-patch removed
changes in file "wp-admin/includes/file.php" I just replace rand() by wp_rand()
If wp_rand() is encouraged to use.
#3
@
3 years ago
- Focuses performance added
- Keywords has-testing-info needs-testing added
Hi @haritpanchal, thanks for opening this ticket and to @sakibmd for the patch!
Testing Instructions
These steps define how to test the feature or enhancement, and indicates the expected behavior or results.
Steps to Test
- Apply the patch.
- Navigate to
Appearance > Themesand ensure that a classic theme is activated. - Navigate to
Appearance > Theme File Editor. - ✅ Open the
functions.phpfile and addecho 'Howdy, admin!';. Click Update File. - ✅ Remove the
;and click Update File. - Navigate to
Plugins > Plugin File Editor. - ✅ Open the main plugin file for an active plugin and add
echo 'Howdy, admin!';. Click Update File. - ✅ Remove the
;and click Update File.
Expected Results
Lists each expected result or behavior, i.e. what should happen when running the test(s):
- ✅ The theme file should be updated successfully.
- ✅ The theme file should fail to update.
- ✅ The plugin file should be updated successfully.
- ✅ The plugin file should fail to update.
Notes
- Adding
has-testing-infoandneeds-testing. - Adding
performancefocus and pinging @flixos90 for thoughts regarding performance.
#4
@
3 years ago
- Keywords reporter-feedback added
Hi, @costdev. After applying the patch, I tested all the scenarios and found all were working perfectly. Both times files were failing to update whenever the ; was missing.
#7
@
21 months ago
Hello @costdev, I've tested the patch & it's working as expected results.
Bug Report
Description
This report validates whether the indicated patch works as expected.
Patch tested: https://core.trac.wordpress.org/attachment/ticket/57725/57725.diff
Environment
- WordPress: 6.6-alpha-57778-src
- PHP: 7.4.33
- Server: nginx/1.23.2
- Database: mysqli (Server: 8.0.36 / Client: mysqlnd 7.4.33)
- Browser: Chrome 124.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Four 1.0
- MU Plugins: None activated
- Plugins:
- Test Reports 1.1.0
Steps to Reproduce
- Apply the patch.
- Navigate to Appearance > Themes and ensure that a classic theme is activated.
- Navigate to Appearance > Theme File Editor.
- Open the functions.php file and add echo 'Howdy, admin!';. Click Update File.
- Remove the, and click Update File.
- Navigate to Plugins > Plugin File Editor.
- Open the main plugin file for an active plugin and add echo 'Howdy, admin!';. Click Update File.
- Remove the; and click Update File.
Expected Results
- ✅ The theme file should be updated successfully.
- ✅ The theme file should fail to update.
- ✅ The plugin file should be updated successfully.
- ✅ The plugin file should fail to update.
Actual Results
- ✅ The theme file was updated successfully.
- ✅ The theme file fails to update.
- ✅ The plugin file was updated successfully.
- ✅ The plugin file fails to update.
If we can want to use wp_rand() instead of rand() then it could be solution.