From eb2e67d17dd624bb9f1e517d0ba66be93eb6fe4c Mon Sep 17 00:00:00 2001 From: Nestor Soriano Date: Mon, 10 May 2021 11:32:39 +0200 Subject: [PATCH] Make the debug tools page entries for attribute filtering hidden by default. To show the entries the following needs to be run: wc_get_container() ->get(\Automattic\WooCommerce\Internal\ProductAttributesLookup\LookupDataStore::class) ->show_feature(); --- .../DataRegenerator.php | 4 +++ .../LookupDataStore.php | 35 +++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Internal/ProductAttributesLookup/DataRegenerator.php b/src/Internal/ProductAttributesLookup/DataRegenerator.php index ebc1758a0ff..e7a60bffd35 100644 --- a/src/Internal/ProductAttributesLookup/DataRegenerator.php +++ b/src/Internal/ProductAttributesLookup/DataRegenerator.php @@ -271,6 +271,10 @@ CREATE TABLE ' . $this->lookup_table_name . '( * @return array The tools array with the entry added. */ private function add_initiate_regeneration_entry_to_tools_array( array $tools_array ) { + if ( ! $this->data_store->is_feature_visible() ) { + return $tools_array; + } + $lookup_table_exists = $this->lookup_table_exists(); $generation_is_in_progress = $this->regeneration_is_in_progress(); diff --git a/src/Internal/ProductAttributesLookup/LookupDataStore.php b/src/Internal/ProductAttributesLookup/LookupDataStore.php index 9fceb95f41a..77cc2845238 100644 --- a/src/Internal/ProductAttributesLookup/LookupDataStore.php +++ b/src/Internal/ProductAttributesLookup/LookupDataStore.php @@ -22,12 +22,43 @@ class LookupDataStore { private $lookup_table_name; /** - * LookupDataStore constructor. + * Is the feature visible? + * + * @var bool + */ + private $is_feature_visible; + + /** + * LookupDataStore constructor. Makes the feature hidden by default. */ public function __construct() { global $wpdb; - $this->lookup_table_name = $wpdb->prefix . 'wc_product_attributes_lookup'; + $this->lookup_table_name = $wpdb->prefix . 'wc_product_attributes_lookup'; + $this->is_feature_visible = false; + } + + /** + * Checks if the feature is visible (so that dedicated entries will be added to the debug tools page). + * + * @return bool True if the feature is visible. + */ + public function is_feature_visible() { + return $this->is_feature_visible; + } + + /** + * Makes the feature visible, so that dedicated entries will be added to the debug tools page. + */ + public function show_feature() { + $this->is_feature_visible = true; + } + + /** + * Hides the feature, so that no entries will be added to the debug tools page. + */ + public function hide_feature() { + $this->is_feature_visible = false; } /**