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

Remove duplicate orderby for users query #2435

Merged
merged 2 commits into from
Nov 5, 2021
Merged

Remove duplicate orderby for users query #2435

merged 2 commits into from
Nov 5, 2021

Conversation

rebeccahum
Copy link
Contributor

@rebeccahum rebeccahum commented Nov 2, 2021

Description of the Change

We noticed that there was a typo for the users query resulting in a duplicate orderby clause:

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

This resulted in the below query:

SELECT SQL_CALC_FOUND_ROWS ID FROM wp_users ORDER BY ‘ID’ ‘ID’ LIMIT 0, 350

sanitize_sql_orderby() is for sanitizing the ORDER BY clause for variable use in the $wpdb statement. Variable usage is for avoiding quotes since $wpdb->prepare() uses quotes in placeholders and that doesn't play nicely with mariadb.

Props @brettshumaker Automattic#97, @pschoffer https://github.com/Automattic/ElasticPress/pull/112/files

Alternate Designs

N/A.

Benefits

No more duplicate orderby clause!

Possible Drawbacks

None that I can tell.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Changelog Entry

Fixed: Duplicate orderby statement in Users query.

@felipeelia felipeelia merged commit 16c56cb into 10up:develop Nov 5, 2021
@felipeelia felipeelia added this to the 3.6.5 milestone Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants