0 ) { return; } // Allow to exclude critical phrases. if ( $hits === 0 ) { $excludedPhrases = apply_filters( 'dgwt/wcas/analytics/excluded_critical_phrases', [] ); if ( is_array( $excludedPhrases ) && in_array( $phrase, $excludedPhrases, true ) ) { return; } } // Break early when a user has specific roles. $roles = apply_filters( 'dgwt/wcas/analytics/exclude_roles', [] ); if ( !empty( $roles ) ) { foreach ( $roles as $role ) { if ( current_user_can( $role ) ) { return; } } } if ( Helpers::isProductSearchPage() ) { $autocomplete = false; } $phrase = strtolower( substr( $phrase, 0, 255 ) ); $lang = ( !empty( $lang ) && Multilingual::isLangCode( $lang ) ? $lang : '' ); $shouldRecord = apply_filters( 'dgwt/wcas/analytics/should_record', true, [ 'phrase' => $phrase, 'hits' => $hits, 'lang' => $lang, 'autocomplete' => $autocomplete, ] ); if ( !$shouldRecord ) { return; } $this->push( $phrase, $hits, $autocomplete, $lang ); } /** * Push a record to the index. * * @param string $phrase * @param int $hits * @param bool $autocomplete * @param string $lang * * @return void */ public function push( $phrase, $hits, $autocomplete, $lang ) { global $wpdb; $data = [ 'phrase' => $phrase, 'hits' => $hits, 'created_at' => date( 'Y-m-d H:i:s', current_time( 'timestamp', true ) ), 'autocomplete' => $autocomplete, ]; $format = [ '%s', '%d', '%s', '%d' ]; if ( !empty( $lang ) ) { $data['lang'] = $lang; $format[] = '%s'; } $wpdb->insert( $wpdb->dgwt_wcas_stats, $data, $format ); } }