LLMS_Student_Query::prepare_query()
Prepare the SQL for the query.
Contents
Return Return
(string)
Source Source
File: includes/class.llms.student.query.php
global $wpdb;
$search_vars = array();
if ( $this->get( 'search' ) ) {
$search = '%' . $wpdb->esc_like( $this->get( 'search' ) ) . '%';
$search_vars[] = $search;
$search_vars[] = $search;
$search_vars[] = $search;
}
$base_query = "SELECT {$this->sql_select()}
FROM {$wpdb->users} AS u
{$this->sql_joins()}
{$this->sql_search()}
{$this->sql_having()}";
if ( $this->get( 'count_only' ) ) {
$sql_query = "SELECT COUNT(*) AS total FROM ({$base_query}) as t;";
if ( empty( $search_vars ) ) {
return $sql_query;
}
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
return $wpdb->prepare( $sql_query, $search_vars );
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}
if ( ! $this->get( 'no_found_rows' ) ) {
$count_sql = "SELECT COUNT(*) FROM ({$base_query}) as t";
if ( ! empty( $search_vars ) ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 6.0.0 | Renamed from preprare_query(). |
| 4.10.2 | Demands to $this->sql_select() to determine whether or not SQL_CALC_FOUND_ROWS statement is needed. |
| 3.4.0 | |
| 3.13.0 | Introduced. |