WC_Admin_Log_Table_List::get_sourcesprotectedWC 1.0

Get the list of unique sources in the log table.

The query in this method can be slow when there are a high number of log entries. The list of sources also most likely doesn't change that often. So this indefinitely caches the list into the WP options table. The cache will get cleared by the log handler if a new source is being added. See WC_Log_Handler_DB::handle().

Method of the class: WC_Admin_Log_Table_List{}

No Hooks.

Returns

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_sources();

WC_Admin_Log_Table_List::get_sources() code WC 10.7.0

protected function get_sources() {
	global $wpdb;

	$sources = get_option( self::SOURCE_CACHE_OPTION_KEY, null );
	if ( is_array( $sources ) ) {
		return $sources;
	}

	$sql = "
		SELECT DISTINCT source
		FROM {$wpdb->prefix}woocommerce_log
		WHERE source != ''
		ORDER BY source ASC
	";

	// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Not necessary.
	$sources = $wpdb->get_col( $sql );

	update_option( self::SOURCE_CACHE_OPTION_KEY, $sources );

	return $sources;
}