Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-post indexing #112

Merged
merged 6 commits into from
Sep 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion includes/classes/Indexable/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,13 @@ public function query_db( $args ) {
/**
* WP_User_Query doesn't let us get users across all blogs easily. This is the best
* way to do that.
*
* The $wpdb->prepare will quote placeholders.
* We are sanitizing orderby in advance and putting it as a variable to avoid quotes.
*/
$objects = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->users} %s LIMIT %d, %d", $orderby, (int) $args['offset'], (int) $args['number'] ) );
// @codingStandardsIgnoreStart
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use input on this one. But with the sanitize_order_by above I think this is safe.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems pretty strict on what is allowed. The only alternative would be to provide an allowlist of valid $args['orderby'] columns and ensure it's one of them - but I don't feel like that is necessary here as it's no a top-level user API really.

$objects = $wpdb->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS ID FROM {$wpdb->users} {$orderby} LIMIT %d, %d", (int) $args['offset'], (int) $args['number'] ) );
// @codingStandardsIgnoreStop

return [
'objects' => $objects,
Expand Down