WordPress.org

Make WordPress Core

Opened 18 months ago

Closed 6 months ago

Last modified 4 months ago

#46302 closed enhancement (fixed)

Function clarity; Rename wp_get_user_request_data to wp_get_user_request as it returns the WP_User_Request

Reported by: garrett-eclipse Owned by: SergeyBiryukov
Milestone: 5.4 Priority: normal
Severity: normal Version: 4.9.6
Component: Privacy Keywords: has-patch needs-testing has-dev-note
Focuses: administration Cc:

Description

This is a follow-up to #44708.

In 5.1 changeset 44606 renamed variables from $request_data to $request. After a quick scrub it seems some were overlooked or are new.

Instances;
3 occurrences in the wp_create_user_request function - https://github.com/WordPress/WordPress/blob/50ddffbac37fdae9298d1f11fe1dd7b8535fc839/wp-includes/user.php#L3309-L3347
2 occurrences in the WP_User_Request class - https://github.com/WordPress/WordPress/blob/50ddffbac37fdae9298d1f11fe1dd7b8535fc839/wp-includes/user.php#L3712-L3738

I'm unsure if the instances in the class should be changed or not as the other changes were because the variable was held the entire class while this instance is a property of that class.

And a last thought was should the wp_get_user_request_data not be wp_get_user_request and it's docblock state 'Return the user request.' simply because it's a function to get the request itself and not just the request_data.
The function I mentioned - https://github.com/WordPress/WordPress/blob/50ddffbac37fdae9298d1f11fe1dd7b8535fc839/wp-includes/user.php#L3617-L3634

Thanks

Attachments (1)

48431.diff (9.5 KB) - added by garrett-eclipse 7 months ago.
Initial patch to correct the wp_get_user_request_data function as it returns the request and not the request_data which is a property of the WP_User_Request

Download all attachments as: .zip

Change History (9)

@garrett-eclipse
7 months ago

Initial patch to correct the wp_get_user_request_data function as it returns the request and not the request_data which is a property of the WP_User_Request

#1 @garrett-eclipse
7 months ago

  • Component changed from Administration to Privacy
  • Focuses administration added; privacy removed
  • Keywords has-patch needs-testing needs-dev-note added
  • Milestone changed from Awaiting Review to 5.4
  • Version set to 4.9.6

Coming back to review the instances of $request_data I'd initially flagged were valid as they represented the array form of request data. The wp_get_user_request_data function on the other hand specifically returns the WP_User_Request object which in itself has a $request_data property. To avoid confusion with this I've uploaded an initial patch to update the function to wp_get_user_request in order to clarify it's purpose. To maintain back-compat I've deprecated the function.

Please review and test, so far beyond throwing the deprecation warning with use of the old function there's no change to the request functionality.

Flagging for testing and dev-note.

#2 @garrett-eclipse
7 months ago

  • Summary changed from Coding consistency, found more $request_data that should be $request to Function clarity; Rename wp_get_user_request_data to wp_get_user_request as it returns the WP_User_Request

#3 @garrett-eclipse
7 months ago

Note... ignore the mismatch of patch number to ticket number. It's the right patch I just saved it as the wrong number.

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


6 months ago

#5 @SergeyBiryukov
6 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 47245:

Privacy: Rename wp_get_user_request_data() to wp_get_user_request() for clarity; deprecate the old function.

The function returns an instance of the WP_User_Request object itself, not its $request_data property.

Follow-up to [44606].

Props garrett-eclipse.
Fixes #46302.

#6 @garrett-eclipse
6 months ago

  • Keywords has-dev-note added; needs-dev-note removed

#7 @johnjamesjacoby
4 months ago

I believe this was erroneously deprecated into:

/wp-admin/includes/deprecated.php

instead of:

/wp-includes/deprecated.php.

Both the original function and the new one are available outside of WordPress admin, but the deprecated function is now only available within WordPress admin, which is a back-compat break.

See: https://buddypress.trac.wordpress.org/ticket/8265

@SergeyBiryukov Reopen, or create a new issue for 5.4.1?

#8 @garrett-eclipse
4 months ago

Thanks @johnjamesjacoby I appreciate you catching that and apologize for breaking buddypress.

As this was committed in 5.4 this back-compat issue should be handled in a new ticket which I've created and patched in #49802

Note: See TracTickets for help on using tickets.