✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ premium290.web-hosting.com ​🇻​♯➤ 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2025

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 63.250.38.37 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.138
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /home/tdhomesa/public_html/wp-content/plugins/woocommerce/src/Internal/Admin//CategoryLookup.php
<?php
/**
 * Keeps the product category lookup table in sync with live data.
 */

namespace Automattic\WooCommerce\Internal\Admin;

defined( 'ABSPATH' ) || exit;

/**
 * \Automattic\WooCommerce\Internal\Admin\CategoryLookup class.
 */
class CategoryLookup {

	/**
	 * Stores changes to categories we need to sync.
	 *
	 * @var array
	 */
	protected $edited_product_cats = array();

	/**
	 * The single instance of the class.
	 *
	 * @var object
	 */
	protected static $instance = null;

	/**
	 * Constructor
	 *
	 * @return void
	 */
	protected function __construct() {}

	/**
	 * Get class instance.
	 *
	 * @return object Instance.
	 */
	final public static function instance() {
		if ( null === static::$instance ) {
			static::$instance = new static();
		}
		return static::$instance;
	}

	/**
	 * Init hooks.
	 */
	public function init() {
		add_action( 'generate_category_lookup_table', array( $this, 'regenerate' ) );
		add_action( 'edit_product_cat', array( $this, 'before_edit' ), 99 );
		add_action( 'edited_product_cat', array( $this, 'on_edit' ), 99 );
		add_action( 'created_product_cat', array( $this, 'on_create' ), 99 );
		add_action( 'init', array( $this, 'define_category_lookup_tables_in_wpdb' ) );
	}

	/**
	 * Regenerate all lookup table data.
	 */
	public function regenerate() {
		global $wpdb;

		$wpdb->query( "TRUNCATE TABLE $wpdb->wc_category_lookup" );

		$terms = get_terms(
			'product_cat',
			array(
				'hide_empty' => false,
				'fields'     => 'id=>parent',
			)
		);

		$hierarchy = array();
		$inserts   = array();

		$this->unflatten_terms( $hierarchy, $terms, 0 );
		$this->get_term_insert_values( $inserts, $hierarchy );

		if ( ! $inserts ) {
			return;
		}

		$insert_string = implode(
			'),(',
			array_map(
				function( $item ) {
					return implode( ',', $item );
				},
				$inserts
			)
		);

		$wpdb->query( "INSERT IGNORE INTO $wpdb->wc_category_lookup (category_tree_id,category_id) VALUES ({$insert_string})" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	}

	/**
	 * Store edits so we know when the parent ID changes.
	 *
	 * @param int $category_id Term ID being edited.
	 */
	public function before_edit( $category_id ) {
		$category                                  = get_term( $category_id, 'product_cat' );
		$this->edited_product_cats[ $category_id ] = $category->parent;
	}

	/**
	 * When a product category gets edited, see if we need to sync the table.
	 *
	 * @param int $category_id Term ID being edited.
	 */
	public function on_edit( $category_id ) {
		global $wpdb;

		if ( ! isset( $this->edited_product_cats[ $category_id ] ) ) {
			return;
		}

		$category_object = get_term( $category_id, 'product_cat' );
		$prev_parent     = $this->edited_product_cats[ $category_id ];
		$new_parent      = $category_object->parent;

		// No edits - no need to modify relationships.
		if ( $prev_parent === $new_parent ) {
			return;
		}

		$this->delete( $category_id, $prev_parent );
		$this->update( $category_id );
	}

	/**
	 * When a product category gets created, add a new lookup row.
	 *
	 * @param int $category_id Term ID being created.
	 */
	public function on_create( $category_id ) {
		// If WooCommerce is being installed on a multisite, lookup tables haven't been created yet.
		if ( 'yes' === get_transient( 'wc_installing' ) ) {
			return;
		}

		$this->update( $category_id );
	}

	/**
	 * Delete lookup table data from a tree.
	 *
	 * @param int $category_id Category ID to delete.
	 * @param int $category_tree_id Tree to delete from.
	 * @return void
	 */
	protected function delete( $category_id, $category_tree_id ) {
		global $wpdb;

		if ( ! $category_tree_id ) {
			return;
		}

		$ancestors   = get_ancestors( $category_tree_id, 'product_cat', 'taxonomy' );
		$ancestors[] = $category_tree_id;
		$children    = get_term_children( $category_id, 'product_cat' );
		$children[]  = $category_id;
		$id_list     = implode( ',', array_map( 'intval', array_unique( array_filter( $children ) ) ) );

		foreach ( $ancestors as $ancestor ) {
			$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->wc_category_lookup WHERE category_tree_id = %d AND category_id IN ({$id_list})", $ancestor ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
		}
	}

	/**
	 * Updates lookup table data for a category by ID.
	 *
	 * @param int $category_id Category ID to update.
	 */
	protected function update( $category_id ) {
		global $wpdb;

		$ancestors    = get_ancestors( $category_id, 'product_cat', 'taxonomy' );
		$children     = get_term_children( $category_id, 'product_cat' );
		$inserts      = array();
		$inserts[]    = $this->get_insert_sql( $category_id, $category_id );
		$children_ids = array_map( 'intval', array_unique( array_filter( $children ) ) );

		foreach ( $ancestors as $ancestor ) {
			$inserts[] = $this->get_insert_sql( $category_id, $ancestor );

			foreach ( $children_ids as $child_category_id ) {
				$inserts[] = $this->get_insert_sql( $child_category_id, $ancestor );
			}
		}

		$insert_string = implode( ',', $inserts );

		$wpdb->query( "INSERT IGNORE INTO $wpdb->wc_category_lookup (category_id, category_tree_id) VALUES {$insert_string}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	}

	/**
	 * Get category lookup table values to insert.
	 *
	 * @param int $category_id Category ID to insert.
	 * @param int $category_tree_id Tree to insert into.
	 * @return string
	 */
	protected function get_insert_sql( $category_id, $category_tree_id ) {
		global $wpdb;
		return $wpdb->prepare( '(%d,%d)', $category_id, $category_tree_id );
	}

	/**
	 * Used to construct insert query recursively.
	 *
	 * @param  array $inserts Array of data to insert.
	 * @param  array $terms   Terms to insert.
	 * @param  array $parents Parent IDs the terms belong to.
	 */
	protected function get_term_insert_values( &$inserts, $terms, $parents = array() ) {
		foreach ( $terms as $term ) {
			$insert_parents = array_merge( array( $term['term_id'] ), $parents );

			foreach ( $insert_parents as $parent ) {
				$inserts[] = array(
					$parent,
					$term['term_id'],
				);
			}

			$this->get_term_insert_values( $inserts, $term['descendants'], $insert_parents );
		}
	}

	/**
	 * Convert flat terms array into nested array.
	 *
	 * @param array   $hierarchy Array to put terms into.
	 * @param array   $terms Array of terms (id=>parent).
	 * @param integer $parent Parent ID.
	 */
	protected function unflatten_terms( &$hierarchy, &$terms, $parent = 0 ) {
		foreach ( $terms as $term_id => $parent_id ) {
			if ( (int) $parent_id === $parent ) {
				$hierarchy[ $term_id ] = array(
					'term_id'     => $term_id,
					'descendants' => array(),
				);
				unset( $terms[ $term_id ] );
			}
		}
		foreach ( $hierarchy as $term_id => $terms_array ) {
			$this->unflatten_terms( $hierarchy[ $term_id ]['descendants'], $terms, $term_id );
		}
	}

	/**
	 * Get category descendants.
	 *
	 * @param int $category_id The category ID to lookup.
	 * @return array
	 */
	protected function get_descendants( $category_id ) {
		global $wpdb;

		return wp_parse_id_list(
			$wpdb->get_col(
				$wpdb->prepare(
					"SELECT category_id FROM $wpdb->wc_category_lookup WHERE category_tree_id = %d",
					$category_id
				)
			)
		);
	}

	/**
	 * Return all ancestor category ids for a category.
	 *
	 * @param int $category_id The category ID to lookup.
	 * @return array
	 */
	protected function get_ancestors( $category_id ) {
		global $wpdb;

		return wp_parse_id_list(
			$wpdb->get_col(
				$wpdb->prepare(
					"SELECT category_tree_id FROM $wpdb->wc_category_lookup WHERE category_id = %d",
					$category_id
				)
			)
		);
	}

	/**
	 * Add category lookup table to $wpdb object.
	 */
	public static function define_category_lookup_tables_in_wpdb() {
		global $wpdb;

		// List of tables without prefixes.
		$tables = array(
			'wc_category_lookup' => 'wc_category_lookup',
		);

		foreach ( $tables as $name => $table ) {
			$wpdb->$name    = $wpdb->prefix . $table;
			$wpdb->tables[] = $table;
		}
	}
}


Current_dir [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Agentic
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
BlockTemplates
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
EmailImprovements
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
EmailPreview
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Emails
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
ImportExport
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Logging
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Marketing
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Notes
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Onboarding
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Orders
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
ProductForm
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
ProductReviews
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
RemoteFreeExtensions
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Schedulers
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Settings
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
Suggestions
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
WCPayPromotion
--
28 May 2026 10.38 AM
tdhomesa / tdhomesa
0755
ActivityPanels.php
1.578 KB
24 Aug 2022 2.07 AM
tdhomesa / tdhomesa
0644
Analytics.php
11.784 KB
19 Jan 2026 2.46 PM
tdhomesa / tdhomesa
0644
CategoryLookup.php
7.988 KB
20 Apr 2022 6.50 AM
tdhomesa / tdhomesa
0644
Coupons.php
2.859 KB
14 Nov 2024 1.17 AM
tdhomesa / tdhomesa
0644
CouponsMovedTrait.php
2.412 KB
19 Jan 2026 2.46 PM
tdhomesa / tdhomesa
0644
CustomerEffortScoreTracks.php
17.652 KB
24 Nov 2025 11.10 PM
tdhomesa / tdhomesa
0644
Events.php
8.538 KB
5 May 2026 2.26 PM
tdhomesa / tdhomesa
0644
FeaturePlugin.php
6.766 KB
23 Feb 2026 5.58 PM
tdhomesa / tdhomesa
0644
Homescreen.php
8.697 KB
11 May 2026 5.17 PM
tdhomesa / tdhomesa
0644
Loader.php
19.183 KB
12 May 2025 9.07 PM
tdhomesa / tdhomesa
0644
Marketing.php
6.289 KB
14 Nov 2024 1.17 AM
tdhomesa / tdhomesa
0644
Marketplace.php
3.478 KB
19 Jan 2026 2.46 PM
tdhomesa / tdhomesa
0644
MobileAppBanner.php
0.934 KB
20 Apr 2022 6.50 AM
tdhomesa / tdhomesa
0644
RemoteInboxNotifications.php
0.91 KB
21 Mar 2023 8.45 PM
tdhomesa / tdhomesa
0644
Settings.php
14.613 KB
5 May 2026 2.26 PM
tdhomesa / tdhomesa
0644
ShippingLabelBanner.php
4.667 KB
23 Sep 2024 8.44 PM
tdhomesa / tdhomesa
0644
ShippingLabelBannerDisplayRules.php
3.631 KB
4 Sep 2024 8.34 PM
tdhomesa / tdhomesa
0644
SiteHealth.php
2.314 KB
22 Feb 2023 7.17 AM
tdhomesa / tdhomesa
0644
Survey.php
0.75 KB
20 Apr 2022 6.50 AM
tdhomesa / tdhomesa
0644
SystemStatusReport.php
5.85 KB
12 May 2025 9.07 PM
tdhomesa / tdhomesa
0644
Translations.php
11.662 KB
14 Nov 2024 1.17 AM
tdhomesa / tdhomesa
0644
WCAdminAssets.php
17.744 KB
5 May 2026 2.26 PM
tdhomesa / tdhomesa
0644
WCAdminSharedSettings.php
2.078 KB
22 Apr 2025 3.40 PM
tdhomesa / tdhomesa
0644
WCAdminUser.php
5.264 KB
6 Oct 2025 5.56 PM
tdhomesa / tdhomesa
0644
WcPayWelcomePage.php
6.329 KB
23 Jun 2025 7.46 PM
tdhomesa / tdhomesa
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF