Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#30064 closed enhancement (fixed)

WP_User_Query should support orderby => include

Reported by: danielbachhuber's profile danielbachhuber Owned by: boonebgorges's profile boonebgorges
Milestone: 4.1 Priority: normal
Severity: normal Version:
Component: Users Keywords: good-first-bug needs-unit-tests needs-patch
Focuses: Cc:

Description

A la orderby => post__in

Attachments (3)

30064_gowp1.diff (775 bytes) - added by karpstrucking 9 years ago.
Adds support for 'orderby' => 'include'
30064_gowp1-2.diff (981 bytes) - added by jipmoors 9 years ago.
esc_sql applied to include parameter (and fixed tabbing)
30064_gowp1-3.diff (1.7 KB) - added by jipmoors 9 years ago.
type checking, added sanitation, preparing input before checking for empty content

Download all attachments as: .zip

Change History (9)

@karpstrucking
9 years ago

Adds support for 'orderby' => 'include'

#1 @karpstrucking
9 years ago

  • Keywords has-patch added; needs-patch removed

30064_gowp1.diff is pretty straight-forward rip-off of the approach used in WP_Query

#2 @boonebgorges
9 years ago

  • Keywords needs-unit-tests added

Thanks! Patch looks good at a glance, but we need to have some unit tests for the new orderby param.

@jipmoors
9 years ago

esc_sql applied to include parameter (and fixed tabbing)

#3 @jipmoors
9 years ago

Please let me know if my patch is formatted correctly, this is the first one I've created.

#4 @boonebgorges
9 years ago

  • Keywords needs-patch added; has-patch removed

jipmoors - Thanks for the updated patch. You're right that these values need sanitization. Because they're IDs, our preferred technique for sanization would be $include = implode( ',', array_map( 'intval', $qv['include'] ) );. There should probably also be some sanity checks here to make sure that the value passed was an array (plus support for comma-separated strings, if this is a parameter that can be accessed via URL - I don't know off the top of my head, so this would need to be checked).

Re formatting: https://core.trac.wordpress.org/attachment/ticket/30064/30064_gowp1-2.diff Looks like your editor may be formatted for spaces rather than tabs.

@jipmoors
9 years ago

type checking, added sanitation, preparing input before checking for empty content

#5 @boonebgorges
9 years ago

  • Milestone changed from Future Release to 4.1

Thanks, jipmoors! The logic here is good, but can be condensed a bit - we have wp_parse_id_list() to do all that array_filter(), array_unique(), etc. And since we need a parsed value for $include later on in the function, we can set it once at the top, and then use the parsed value below.

#6 @boonebgorges
9 years ago

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

In 30016:

Accept 'orderby=include' in WP_User_Query.

This lets the results of a user query be sorted manually by the value of the
'include' param.

Props jipmoors.
Fixes #30064.

Note: See TracTickets for help on using tickets.