recorded ) { return; } $this->recorded = true; $result = $wpdb->insert( $wpdb->prefix . 'ph_search_log', array( 'searched_at' => current_time( 'mysql', true ), ), array( '%s', ) ); if ( false === $result ) { $this->recorded = false; } } public function clear_old_searches() { global $wpdb; $table_name = $wpdb->prefix . 'ph_search_log'; $cutoff = gmdate( 'Y-m-d H:i:s', strtotime( '-90 days' ) ); do { $deleted = $wpdb->query( $wpdb->prepare( "DELETE FROM {$table_name} WHERE searched_at < %s ORDER BY searched_at ASC LIMIT 500", $cutoff ) ); } while ( 500 === $deleted ); } } new PH_Search_Analytics();