Opened 22 months ago
Last modified 7 months ago
#57725 new enhancement
Use of rand() function instead of wp_rand()
Reported by: | haritpanchal | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Filesystem API | Keywords: | has-patch has-testing-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 (8)
#1
@
22 months 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
@
22 months ago
- Focuses performance added
- Keywords has-testing-info needs-testing added
Hi @sakibmd, thanks for opening this ticket and 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 > Themes
and ensure that a classic theme is activated. - Navigate to
Appearance > Theme File Editor
. - ✅ Open the
functions.php
file 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-info
andneeds-testing
. - Adding
performance
focus and pinging @flixos90 for thoughts regarding performance.
#4
@
21 months 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
@
7 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.