Files
roi-theme/wp-content/plugins/advanced-ads/includes/frontend/class-stats.php
root a22573bf0b Commit inicial - WordPress Análisis de Precios Unitarios
- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 21:04:30 -06:00

75 lines
1.3 KiB
PHP
Executable File

<?php
/**
* Frontend Stats.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.50.0
*/
namespace AdvancedAds\Frontend;
defined( 'ABSPATH' ) || exit;
/**
* Frontend Stats.
*/
class Stats {
/**
* Array with ads currently delivered in the frontend
*
* @var array Ads already loaded in the frontend
*/
public $entities = [];
/**
* Main instance
*
* Ensure only one instance is loaded or can be loaded.
*
* @return Stats
*/
public static function get() {
static $instance;
if ( null === $instance ) {
$instance = new Stats();
}
return $instance;
}
/**
* Add an entity to the stats.
*
* @param string $type Entity type.
* @param string $id Entity id.
* @param string $title Entity title.
* @param string $parent_id Parent entity id.
*
* @return void
*/
public function add_entity( $type, $id, $title, $parent_id = false ): void {
if ( ! isset( $this->entities[ $id ] ) ) {
$this->entities[ $id ] = [
'type' => $type,
'id' => $id,
'title' => $title,
'count' => 0,
'childs' => [],
];
}
if ( ! $parent_id ) {
++$this->entities[ $id ]['count'];
} else {
$this->entities[ $parent_id ]['childs'][ $id ] = [
'type' => $type,
'id' => $id,
'title' => $title,
];
}
}
}