__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
<?php

namespace Elementor\Modules\GlobalClasses\Usage;

use Elementor\Plugin;
use Elementor\Core\Base\Document as ElementorDocument;
use Elementor\Modules\GlobalClasses\Global_Classes_Repository;

/**
 * Tracks usage of global CSS classes within a specific Elementor document.
 */
class Document_Usage {


	/** @var ElementorDocument */
	private ElementorDocument $document;

	/** @var array<string, Css_Class_Usage> */
	private array $usages = [];

	/**
	 * Constructor.
	 *
	 * @param ElementorDocument $document The Elementor document object.
	 */
	public function __construct( ElementorDocument $document ) {
		$this->document = $document;
	}

	/**
	 * Analyze the document to find and record usage of global CSS classes.
	 */
	public function analyze(): void {
		$page_id       = $this->document->get_main_id();
		$page_title    = $this->document->get_post()->post_title;
		$class_ids     = $this->get_all_global_class_ids();
		$elements_data = $this->document->get_elements_raw_data() ?? [];

		$document_type = $this->document->get_type();
		if ( empty( $document_type ) ) {
			$document_type = get_post_type( $page_id ) ?? 'unknown';
		}

		if ( empty( $elements_data ) ) {
			return;
		}

		Plugin::$instance->db->iterate_data(
			$elements_data,
			function ( $element_data ) use ( $class_ids, $page_id, $page_title, $document_type ) {
				$class_values = $element_data['settings']['classes']['value'] ?? [];

				if ( empty( $class_values ) || ! is_array( $class_values ) ) {
					return;
				}

				foreach ( $class_values as $class_id ) {
					if ( ! in_array( $class_id, $class_ids, true ) ) {
						continue;
					}

					if ( ! isset( $this->usages[ $class_id ] ) ) {
						$this->usages[ $class_id ] = new Css_Class_Usage( $class_id );
					}

					$this->usages[ $class_id ]->track_usage(
						$page_id,
						$page_title,
						$element_data['id'] ?? 'unknown',
						$document_type
					);
				}
			}
		);
	}

	/**
	 * Get all recorded usages of global CSS classes in this document.
	 *
	 * @return array<string, Css_Class_Usage>
	 */
	public function get_usages(): array {
		return $this->usages;
	}

	/**֜
	 * Retrieve all registered global CSS class IDs.
	 *
	 * @return string[]
	 */
	protected function get_all_global_class_ids(): array {
		return Global_Classes_Repository::make()
			->all()
			->get_items()
			->filter( fn( $item ) => ! empty( $item['id'] ?? null ) )
			->keys()
			->all();
	}
}

Filemanager

Name Type Size Permission Actions
applied-global-classes-usage.php File 2.94 KB 0664
css-class-usage.php File 2.83 KB 0664
document-usage.php File 2.37 KB 0664
global-classes-usage.php File 1.12 KB 0664
Filemanager