// phpcs:ignore Generic.Commenting.DocComment.MissingShort
/** @noinspection PhpIllegalPsrClassPathInspection */
namespace WPForms\Logger;
* @param int $limit Query limit of records.
* @param int $offset Offset of records.
* @param string $search Search.
* @param string $type Type of records.
public function get( $limit, $offset = 0, $search = '', $type = '' ) {
//phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
return (array) $wpdb->get_results(
$this->build_query( $limit, $offset, $search, $type )
//phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
* @param int $limit Query limit of records.
* @param int $offset Offset of records.
* @param string $search Search.
* @param string $type Type of records.
private function build_query( $limit, $offset = 0, $search = '', $type = '' ) {
$sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM ' . Repository::get_table_name();
if ( ! empty( $search ) ) {
$where[] = $wpdb->prepare(
'`title` REGEXP %s OR `message` REGEXP %s',
if ( ! empty( $type ) ) {
$where[] = $wpdb->prepare(
$sql .= ' WHERE ' . implode( ' AND ', $where );
$sql .= ' ORDER BY `create_at` DESC, `id` DESC';
$sql .= $wpdb->prepare( ' LIMIT %d, %d', absint( $offset ), absint( $limit ) );