INSERT INTO ' . self::get_table_name() . ' ( `id`, `title`, `message`, `types`, `create_at`, `form_id`, `entry_id`, `user_id` ) VALUES '; foreach ( $this->records as $record ) { $sql .= $wpdb->prepare( '( NULL, %s, %s, %s, %s, %d, %d, %d ),', $record->get_title(), $record->get_message(), implode( ',', $record->get_types() ), $record->get_date( 'sql' ), $record->get_form_id(), $record->get_entry_id(), $record->get_user_id() ); } $sql = rtrim( $sql, ',' ); //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( $sql ); //phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared wp_cache_delete( self::CACHE_TOTAL_KEY ); } /** * Check if the database table exists. * * @since 1.6.4 * * @return bool */ public function table_exists() { return DB::table_exists( self::get_table_name() ); } /** * Get total count of logs. * * @since 1.6.3 * * @return int */ public function get_total() { global $wpdb; $total = wp_cache_get( self::CACHE_TOTAL_KEY ); if ( ! $total ) { //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared $total = $this->full_total ? $wpdb->get_var( 'SELECT FOUND_ROWS()' ) : $wpdb->get_var( 'SELECT COUNT( ID ) FROM ' . self::get_table_name() ); //phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared wp_cache_set( self::CACHE_TOTAL_KEY, $total, 'wpforms', DAY_IN_SECONDS ); } return absint( $total ); } /** * Clear all records in the Database. * * @since 1.6.3 */ public function clear_all() { global $wpdb; //phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching //phpcs:disable WordPress.DB.PreparedSQL.NotPrepared $wpdb->query( 'TRUNCATE TABLE ' . self::get_table_name() ); //phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching //phpcs:enable WordPress.DB.PreparedSQL.NotPrepared } }