WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Internal\ProductAttributesLookup

DataRegenerator::add_initiate_regeneration_entry_to_tools_array() private WC 1.0

Add a 'Regenerate product attributes lookup table' entry to the Status - Tools page.

{} It's a method of the class: DataRegenerator{}

No Hooks.

Return

Array. The tools array with the entry added.

Usage

// private - for code of main (parent) class only
$result = $this->add_initiate_regeneration_entry_to_tools_array( $tools_array );
$tools_array(array) (required)
The tool definitions array that is passed ro the woocommerce_debug_tools filter.

Code of DataRegenerator::add_initiate_regeneration_entry_to_tools_array() WC 5.9.0

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->data_store->check_lookup_table_exists();
	$generation_is_in_progress = $this->data_store->regeneration_is_in_progress();

	// Regenerate table.

	if ( $lookup_table_exists ) {
		$generate_item_name   = __( 'Regenerate the product attributes lookup table', 'woocommerce' );
		$generate_item_desc   = __( 'This tool will regenerate the product attributes lookup table data from existing product(s) data. This process may take a while.', 'woocommerce' );
		$generate_item_return = __( 'Product attributes lookup table data is regenerating', 'woocommerce' );
		$generate_item_button = __( 'Regenerate', 'woocommerce' );
	} else {
		$generate_item_name   = __( 'Create and fill product attributes lookup table', 'woocommerce' );
		$generate_item_desc   = __( 'This tool will create the product attributes lookup table data and fill it with existing products data. This process may take a while.', 'woocommerce' );
		$generate_item_return = __( 'Product attributes lookup table is being filled', 'woocommerce' );
		$generate_item_button = __( 'Create', 'woocommerce' );
	}

	$entry = array(
		'name'             => $generate_item_name,
		'desc'             => $generate_item_desc,
		'requires_refresh' => true,
		'callback'         => function() use ( $generate_item_return ) {
			$this->initiate_regeneration_from_tools_page();
			return $generate_item_return;
		},
	);

	if ( $lookup_table_exists ) {
		$entry['selector'] = array(
			'description'   => __( 'Select a product to regenerate the data for, or leave empty for a full table regeneration:', 'woocommerce' ),
			'class'         => 'wc-product-search',
			'search_action' => 'woocommerce_json_search_products',
			'name'          => 'regenerate_product_attribute_lookup_data_product_id',
			'placeholder'   => esc_attr__( 'Search for a product…', 'woocommerce' ),
		);
	}

	if ( $generation_is_in_progress ) {
		$entry['button'] = sprintf(
			/* translators: %d: How many products have been processed so far. */
			__( 'Filling in progress (%d)', 'woocommerce' ),
			get_option( 'woocommerce_attribute_lookup_last_products_page_processed', 0 ) * self::PRODUCTS_PER_GENERATION_STEP
		);
		$entry['disabled'] = true;
	} else {
		$entry['button'] = $generate_item_button;
	}

	$tools_array['regenerate_product_attributes_lookup_table'] = $entry;

	if ( $lookup_table_exists ) {

		// Delete the table.

		$tools_array['delete_product_attributes_lookup_table'] = array(
			'name'             => __( 'Delete the product attributes lookup table', 'woocommerce' ),
			'desc'             => sprintf(
				'<strong class="red">%1$s</strong> %2$s',
				__( 'Note:', 'woocommerce' ),
				__( 'This will delete the product attributes lookup table. You can create it again with the "Create and fill product attributes lookup table" tool.', 'woocommerce' )
			),
			'button'           => __( 'Delete', 'woocommerce' ),
			'requires_refresh' => true,
			'callback'         => function () {
				$this->delete_all_attributes_lookup_data();
				return __( 'Product attributes lookup table has been deleted.', 'woocommerce' );
			},
		);
	}

	return $tools_array;
}