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>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,266 @@
<?php
/**
* This class is responsible for handling the display conditions of ads.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.50.0
*/
namespace AdvancedAds\Frontend;
use Advanced_Ads_Utils;
use AdvancedAds\Options;
use AdvancedAds\Utilities\WordPress;
use AdvancedAds\Utilities\Conditional;
defined( 'ABSPATH' ) || exit;
/**
* Page display condition class.
*/
class Ad_Display_Condition {
/**
* Identifier that supplement the disabled reason.
*
* @var int|string
*/
public $disabled_id = '';
/**
* Reason why are disabled.
*
* @var string
*/
public $disabled_reason = '';
/**
* Get the disabled id.
*
* @return int|string
*/
public function get_disabled_id() {
return $this->disabled_id;
}
/**
* Get the reason why ads are disabled.
*
* @return string
*/
public function get_disabled_reason(): string {
return $this->disabled_reason ?? '';
}
/**
* Runs checks and set disabled constants accordingly.
*
* @return void
*/
public function run_checks(): void {
global $wp_the_query;
// Early bail!!
if ( Conditional::is_ad_disabled() ) {
return;
}
$is_rest = Conditional::is_rest_request();
$options = Options::instance()->get( 'advanced-ads' );
$checks = [
// Check if ads are disabled completely.
'all' => [
'check' => ! $is_rest && ! is_feed() && ! empty( $options['disabled-ads']['all'] ),
'args' => [ 'all' ],
],
// Check if ads are disabled in REST API.
'rest' => [
'check' => $is_rest && ! empty( $options['disabled-ads']['rest-api'] ),
'args' => [ 'rest-api' ],
],
// Check if ads are disabled from 404 pages.
'error404' => [
'check' => $wp_the_query->is_404() && ! empty( $options['disabled-ads']['404'] ),
'args' => [ '404' ],
],
// Check if ads are disabled from non-singular frontend pages (often = archives).
'archive' => [
'check' => ! is_feed() && ! $is_rest && ! $wp_the_query->is_singular() && ! empty( $options['disabled-ads']['archives'] ),
'args' => [ 'archive' ],
],
// Check if ads are disabled in Feed.
'feed' => [
'check' => $wp_the_query->is_feed() && ( $options['disabled-ads']['feed'] ?? false ),
'args' => [ 'feed' ],
],
'current_page' => [ $this, 'check_current_page' ],
'posts_page' => [ $this, 'check_posts_page' ],
'shop' => [ $this, 'check_shop' ],
'user_roles' => [ $this, 'check_user_roles' ],
'bots' => [ $this, 'check_bots' ],
'ip_addresses' => [ $this, 'check_ip_addresses' ],
];
/**
* Allows experienced user to customize the rules that disable ads on a page
*
* @param array $checks list of the rules that will be checked.
* @param array $options plugin options.
*/
$checks = apply_filters( 'advanced-ads-ad-display-check', $checks, $options );
if ( ! is_array( $checks ) ) {
$checks = [];
}
foreach ( $checks as $check ) {
if ( isset( $check['check'] ) && $check['check'] ) {
$this->disable_ads( ...$check['args'] );
return;
}
if ( is_callable( $check ) ) {
$truthiness = call_user_func( $check );
if ( $truthiness ) {
return;
}
}
}
}
/**
* Check if ads are disabled on the current page.
*
* @return bool
*/
private function check_current_page(): bool {
global $post, $wp_the_query;
if ( $wp_the_query->is_singular() && isset( $post->ID ) ) {
$settings = get_post_meta( $post->ID, '_advads_ad_settings', true );
if ( ! empty( $settings['disable_ads'] ) ) {
$this->disable_ads( 'page', $post->ID );
return true;
}
}
return false;
}
/**
* Check if ads are disabled on "Posts page" set on the WordPress Reading settings page.
*
* @return bool
*/
private function check_posts_page(): bool {
global $wp_the_query;
if ( $wp_the_query->is_posts_page ) {
$settings = get_post_meta( $wp_the_query->queried_object_id, '_advads_ad_settings', true );
if ( ! empty( $settings['disable_ads'] ) ) {
$this->disable_ads( 'page', $wp_the_query->queried_object_id );
return true;
}
}
return false;
}
/**
* Check if ads are disabled on WooCommerce shop page (and currently on shop page).
*
* @return bool
*/
private function check_shop(): bool {
if ( function_exists( 'is_shop' ) && is_shop() ) {
$shop_id = wc_get_page_id( 'shop' );
$settings = get_post_meta( $shop_id, '_advads_ad_settings', true );
if ( ! empty( $settings['disable_ads'] ) ) {
$this->disable_ads( 'page', $shop_id );
return true;
}
}
return false;
}
/**
* Check if ads are disabled for current user role.
*
* @return bool
*/
private function check_user_roles(): bool {
$options = Options::instance()->get( 'advanced-ads' );
$current_user = wp_get_current_user();
$hide_for_roles = isset( $options['hide-for-user-role'] )
? Advanced_Ads_Utils::maybe_translate_cap_to_role( $options['hide-for-user-role'] )
: [];
if (
$hide_for_roles && is_user_logged_in() && is_array( $current_user->roles ) &&
array_intersect( $hide_for_roles, $current_user->roles )
) {
$this->disable_ads( 'user-role' );
return true;
}
return false;
}
/**
* Check if ads are disabled for bots.
*
* @return bool
*/
private function check_bots(): bool {
$options = Options::instance()->get( 'advanced-ads' );
if (
isset( $options['block-bots'] ) && $options['block-bots'] &&
! WordPress::is_cache_bot() && Conditional::is_ua_bot()
) {
$this->disable_ads();
return true;
}
return false;
}
/**
* Check if ads are disabled for IP addresses.
*
* @return bool
*/
private function check_ip_addresses(): bool {
$options = Options::instance()->get( 'advanced-ads' );
if ( isset( $options['hide-for-ip-address']['enabled'] ) ) {
$ip_addresses = isset( $options['hide-for-ip-address']['ips'] )
? explode( "\n", $options['hide-for-ip-address']['ips'] )
: [];
$ip_addresses = array_map( 'trim', $ip_addresses );
$user_ip = get_user_ip_address();
if ( $user_ip && ! empty( $ip_addresses ) && in_array( $user_ip, $ip_addresses, true ) ) {
$this->disable_ads( 'ip-address' );
return true;
}
}
return false;
}
/**
* Disable ads.
*
* @param string $reason Reason why are disabled.
* @param int|string $id Identifier that supplement the disabled reason.
*/
private function disable_ads( $reason = null, $id = null ) {
$this->disabled_id = $id;
$this->disabled_reason = $reason;
define( 'ADVADS_ADS_DISABLED', true );
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* Frontend Ad Renderer.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.50.0
*/
namespace AdvancedAds\Frontend;
use AdvancedAds\Widget;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Frontend Ad Renderer.
*/
class Ad_Renderer implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_action( 'advanced-ads-frontend', [ $this, 'init' ] );
add_action( 'widgets_init', [ $this, 'register_widget' ] );
}
/**
* Inject ads into various sections of our site
*
* @return void
*/
public function init(): void {
// TODO: move priority to 0 for head.
add_action( 'wp_head', [ $this, 'inject_header' ], 20 );
// TODO: move priority to 9999 for footer.
add_action( 'wp_footer', [ $this, 'inject_footer' ], 20 );
}
/**
* Injected ad into header
*
* @return void
*/
public function inject_header(): void {
$placements = wp_advads_get_placements_by_types( 'header' );
foreach ( $placements as $placement ) {
the_ad_placement( $placement->get_id() );
}
}
/**
* Injected ads into footer
*
* @return void
*/
public function inject_footer(): void {
$placements = wp_advads_get_placements_by_types( 'footer' );
foreach ( $placements as $placement ) {
the_ad_placement( $placement->get_id() );
}
}
/**
* Register the Advanced Ads widget
*
* @return void
*/
public function register_widget(): void {
register_widget( Widget::class );
}
}

View File

@@ -0,0 +1,347 @@
<?php
/**
* Frontend Debug Ads.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.50.0
*/
namespace AdvancedAds\Frontend;
use AdvancedAds\Abstracts\Ad;
use Advanced_Ads_Display_Conditions;
use Advanced_Ads_Visitor_Conditions;
use AdvancedAds\Utilities\Validation;
use AdvancedAds\Utilities\Conditional;
use AdvancedAds\Framework\Utilities\Str;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Frontend Debug Ads.
*/
class Debug_Ads implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_action( 'advanced-ads-ad-pre-output', [ $this, 'override_ad_output' ], 50, 2 );
}
/**
* Override ad output.
*
* @param string $output Override content.
* @param Ad $ad Ad object.
*
* @return string
*/
public function override_ad_output( $output, $ad ) {
$user_can_manage_ads = Conditional::user_can( 'advanced_ads_manage_options' );
if (
$ad->is_debug_mode() &&
( $user_can_manage_ads || ( ! $user_can_manage_ads && ! defined( 'ADVANCED_ADS_AD_DEBUG_FOR_ADMIN_ONLY' ) ) )
) {
return $this->prepare_output( $ad );
}
return $output;
}
/**
* Prepare debug mode output.
*
* @param Ad $ad Ad instance.
*
* @return string The ad debug output.
*/
private function prepare_output( Ad $ad ): string {
global $post, $wp_query;
$width = 300;
$height = 250;
if ( $ad->get_width() > 100 && $ad->get_height() > 100 ) {
$width = $ad->get_width();
$height = $ad->get_height();
}
$style = "width:{$width}px;height:{$height}px;background-color:#ddd;overflow:scroll;";
$style_full = 'width: 100%; height: 100vh; background-color: #ddd; overflow: scroll; position: fixed; top: 0; left: 0; min-width: 600px; z-index: 99999;';
$wrapper_id = Str::is_non_empty( $ad->get_wrapper_id() )
? $ad->get_wrapper_id()
: wp_advads()->get_frontend_prefix() . wp_rand();
$content = [];
if ( $ad->can_display( [ 'ignore_debugmode' => true ] ) ) {
$content[] = __( 'The ad is displayed on the page', 'advanced-ads' );
} else {
$content[] = __( 'The ad is not displayed on the page', 'advanced-ads' );
}
// Compare current wp_query with global wp_main_query.
if ( ! $wp_query->is_main_query() ) {
$content[] = sprintf( '<span style="color: red;">%s</span>', __( 'Current query is not identical to main query.', 'advanced-ads' ) );
$content[] = $this->build_query_diff_table();
}
if ( isset( $post->post_title ) && isset( $post->ID ) ) {
$content[] = sprintf( '%s: %s, %s: %s', __( 'current post', 'advanced-ads' ), $post->post_title, 'ID', $post->ID );
}
// Compare current post with global post.
if ( $wp_query->post !== $post ) {
$error = sprintf( '<span style="color: red;">%s</span>', __( 'Current post is not identical to main post.', 'advanced-ads' ) );
if ( isset( $wp_query->post->post_title ) && $wp_query->post->ID ) {
$error .= sprintf( '<br />%s: %s, %s: %s', __( 'main post', 'advanced-ads' ), $wp_query->post->post_title, 'ID', $wp_query->post->ID );
}
$content[] = $error;
}
$content[] = $this->build_call_chain( $ad );
$content[] = $this->build_display_conditions_table( $ad );
$content[] = $this->build_visitor_conditions_table( $ad );
$message = Validation::is_ad_https( $ad );
if ( $message ) {
$content[] = sprintf( '<span style="color: red;">%s</span>', $message );
}
$content = apply_filters( 'advanced-ads-ad-output-debug-content', $content, $ad );
$content = array_filter(
$content,
fn( $value ) => ! empty( $value )
);
ob_start();
include ADVADS_ABSPATH . '/public/views/ad-debug.php';
$output = ob_get_clean();
$output = apply_filters( 'advanced-ads-ad-output-debug', $output, $ad );
$output = apply_filters( 'advanced-ads-ad-output', $output, $ad );
return $output;
}
/**
* Build table with differences between current and main query
*
* @since 1.7.0.3
*/
private function build_query_diff_table() {
global $wp_query, $wp_the_query;
$diff_current = array_diff_assoc( $wp_query->query_vars, $wp_the_query->query_vars );
$diff_main = array_diff_assoc( $wp_the_query->query_vars, $wp_query->query_vars );
if ( ! is_array( $diff_current ) || ! is_array( $diff_main ) ) {
return '';
}
ob_start();
?>
<table>
<thead>
<tr>
<th></th>
<th><?php esc_html_e( 'current query', 'advanced-ads' ); ?></th>
<th><?php esc_html_e( 'main query', 'advanced-ads' ); ?></th>
</tr>
</thead>
<?php foreach ( $diff_current as $_key => $_value ) : ?>
<tr>
<td><?php echo esc_html( $_key ); ?></td>
<td><?php echo esc_html( $_value ); ?></td>
<td><?php echo esc_html( $diff_main[ $_key ] ?? '' ); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php
return ob_get_clean();
}
/**
* Build call chain (placement->group->ad)
*
* @param Ad $ad Ad instance.
*
* @return string
*/
private function build_call_chain( Ad $ad ) {
$output = '';
$output .= sprintf(
'%s: %s (%s)',
__( 'Ad', 'advanced-ads' ),
esc_html( $ad->get_title() ),
$ad->get_id()
);
if ( $ad->get_parent() ) {
$output .= sprintf(
'<br />%s: %s (%s)',
$ad->get_parent_entity_name(),
esc_html( $ad->get_parent()->get_title() ),
$ad->get_parent()->get_id()
);
}
return $output;
}
/**
* Build display conditions table.
*
* @param Ad $ad Ad instance.
*
* @return string
*/
private function build_display_conditions_table( Ad $ad ) {
$conditions = $ad->get_display_conditions();
if ( ! is_array( $conditions ) || empty( $conditions ) ) {
return;
}
$display_conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
$the_query = Advanced_Ads_Display_Conditions::get_instance()->ad_select_args_callback( [] );
ob_start();
esc_html_e( 'Display Conditions', 'advanced-ads' );
foreach ( $conditions as $_condition ) {
if (
! is_array( $_condition ) ||
! isset( $_condition['type'] ) ||
! isset( $display_conditions[ $_condition['type'] ]['check'][1] )
) {
continue;
}
printf(
'<div style="margin-bottom: 20px; white-space: pre-wrap; font-family: monospace; width: 100%%; background: %s;"><strong>%s</strong>',
Advanced_Ads_Display_Conditions::frontend_check( $_condition, $ad ) ? '#e9ffe9' : '#ffe9e9',
esc_html( $display_conditions[ $_condition['type'] ]['label'] )
);
$check = $display_conditions[ $_condition['type'] ]['check'][1];
if ( 'check_general' === $check ) {
printf( '<table border="1"><thead><tr><th></th><th>%s</th><th>%s</th></tr></thead>', esc_html__( 'Ad', 'advanced-ads' ), 'wp_the_query' );
} else {
printf( '<table border="1"><thead><tr><th>%s</th><th>%s</th></tr></thead>', esc_html__( 'Ad', 'advanced-ads' ), 'wp_the_query' );
}
switch ( $check ) {
case 'check_post_type':
printf(
'<tr><td>%s</td><td>%s</td></tr>',
isset( $_condition['value'] ) && is_array( $_condition['value'] ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
isset( $the_query['post']['post_type'] ) ? esc_html( $the_query['post']['post_type'] ) : ''
);
break;
case 'check_general':
if ( isset( $the_query['wp_the_query'] ) && is_array( $the_query['wp_the_query'] ) ) {
$ad_vars = ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? $_condition['value'] : [];
if ( in_array( 'is_front_page', $ad_vars, true ) ) {
$ad_vars[] = 'is_home';
}
foreach ( $the_query['wp_the_query'] as $_var => $_flag ) {
printf(
'<tr><td>%s</td><td>%s</td><td>%s</td></tr>',
esc_html( $_var ),
in_array( $_var, $ad_vars, true ) ? 1 : 0,
esc_html( $_flag )
);
}
}
break;
case 'check_author':
printf(
'<tr><td>%s</td><td>%s</td></tr>',
isset( $_condition['value'] ) && is_array( $_condition['value'] ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
isset( $the_query['post']['author'] ) ? esc_html( $the_query['post']['author'] ) : ''
);
break;
case 'check_post_ids':
case 'check_taxonomies':
printf(
'<tr><td>%s</td><td>post_id: %s<br />is_singular: %s</td></tr>',
isset( $_condition['value'] ) && is_array( $_condition['value'] ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
isset( $the_query['post']['id'] ) ? esc_html( $the_query['post']['id'] ) : '',
! empty( $the_query['wp_the_query']['is_singular'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
break;
case 'check_taxonomy_archive':
printf(
'<tr><td>%s</td><td>term_id: %s<br />is_archive: %s</td></tr>',
isset( $_condition['value'] ) && is_array( $_condition['value'] ) ? esc_html( implode( ',', $_condition['value'] ) ) : '',
isset( $the_query['wp_the_query']['term_id'] ) ? esc_html( $the_query['wp_the_query']['term_id'] ) : '',
! empty( $the_query['wp_the_query']['is_archive'] ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
break;
default:
printf(
'<tr><td>%s</td><td>%s</td></tr>',
esc_html( print_r( $_condition, true ) ), // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
print_r( $the_query, true ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_print_r
);
break;
}
echo '</table></div>';
}
return ob_get_clean();
}
/**
* Build visitor conditions table.
*
* @param Ad $ad Ad instance.
*
* @return string
*/
private function build_visitor_conditions_table( Ad $ad ) {
$conditions = $ad->get_visitor_conditions();
if ( ! is_array( $conditions ) || empty( $conditions ) ) {
return;
}
ob_start();
$visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
esc_html_e( 'Visitor Conditions', 'advanced-ads' );
foreach ( $conditions as $_condition ) {
if (
! is_array( $_condition ) ||
! isset( $_condition['type'] ) ||
! isset( $visitor_conditions[ $_condition['type'] ]['check'][1] )
) {
continue;
}
$content = '';
foreach ( $_condition as $_k => $_v ) {
$content .= esc_html( $_k ) . ': ' . esc_html( is_array( $_v ) ? implode( ', ', $_v ) : $_v ) . '<br>';
}
printf(
'<div style="margin-bottom: 20px; white-space: pre-wrap; font-family: monospace; width: 100%%; background: %s;">%s</div>',
Advanced_Ads_Visitor_Conditions::frontend_check( $_condition, $ad ) ? '#e9ffe9' : '#ffe9e9',
$content // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
return ob_get_clean();
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Frontend Manager.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.50.0
*/
namespace AdvancedAds\Frontend;
use AdvancedAds\Utilities\Conditional;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Frontend Manager.
*/
class Manager implements Integration_Interface {
/**
* Page display condition object.
*
* @var Ad_Display_Condition
*/
private $page_display;
/**
* Magic method to handle dynamic method calls.
*
* @param string $name The name of the method being called.
* @param array $arguments The arguments passed to the method.
*
* @return mixed The result of the method call, if the method exists. Otherwise, null is returned.
*/
public function __call( $name, $arguments ) {
if ( method_exists( $this->page_display, $name ) ) {
return call_user_func_array( [ $this->page_display, $name ], $arguments );
}
}
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
$this->page_display = new Ad_Display_Condition();
add_action( 'rest_api_init', [ $this, 'run_checks' ] );
add_action( 'template_redirect', [ $this, 'run_checks' ], 11 );
}
/**
* Run the check.
*
* @return void
*/
public function run_checks(): void {
$this->page_display->run_checks();
if ( ! Conditional::is_ad_disabled() ) {
do_action( 'advanced-ads-frontend' );
}
}
}

View File

@@ -0,0 +1,160 @@
<?php
/**
* Frontend Scripts.
*
* @package AdvancedAds
* @author Advanced Ads <info@wpadvancedads.com>
* @since 1.50.0
*/
namespace AdvancedAds\Frontend;
use Advanced_Ads;
use Advanced_Ads_Utils;
use Advanced_Ads_Privacy;
use AdvancedAds\Utilities\WordPress;
use AdvancedAds\Utilities\Conditional;
use AdvancedAds\Framework\Utilities\Params;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
/**
* Frontend Scripts.
*/
class Scripts implements Integration_Interface {
/**
* Hook into WordPress.
*
* @return void
*/
public function hooks(): void {
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
add_action( 'wp_head', [ $this, 'print_head_scripts' ], 7 );
add_action( 'wp_footer', [ $this, 'print_footer_scripts' ], 100 );
}
/**
* Register and enqueues public-facing JavaScript files.
*
* @return void
*/
public function enqueue_scripts(): void {
if ( Conditional::is_amp() ) {
return;
}
wp_register_script(
ADVADS_SLUG . '-advanced-js',
sprintf( '%spublic/assets/js/advanced%s.js', ADVADS_BASE_URL, defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ),
[ 'jquery' ],
ADVADS_VERSION,
false
);
$privacy = Advanced_Ads_Privacy::get_instance();
$privacy_options = $privacy->options();
$privacy_options['enabled'] = ! empty( $privacy_options['enabled'] );
$privacy_options['state'] = $privacy->get_state();
wp_localize_script(
ADVADS_SLUG . '-advanced-js',
'advads_options',
[
'blog_id' => get_current_blog_id(),
'privacy' => $privacy_options,
]
);
$frontend_picker = Params::cookie( 'advads_frontend_picker' );
$activated_js = apply_filters( 'advanced-ads-activate-advanced-js', isset( Advanced_Ads::get_instance()->options()['advanced-js'] ) );
if ( $activated_js || ! empty( $frontend_picker ) ) {
wp_enqueue_script( ADVADS_SLUG . '-advanced-js' );
}
wp_register_script(
ADVADS_SLUG . '-frontend-picker',
sprintf( '%spublic/assets/js/frontend-picker%s.js', ADVADS_BASE_URL, defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ),
[ 'jquery', ADVADS_SLUG . '-advanced-js' ],
ADVADS_VERSION,
false
);
if ( ! empty( $frontend_picker ) ) {
wp_enqueue_script( ADVADS_SLUG . '-frontend-picker' );
}
wp_advads()->registry->enqueue_script( 'find-adblocker' );
}
/**
* Print public-facing JavaScript in the HTML head.
*
* @return void
*/
public function print_head_scripts(): void {
printf(
'<!-- %1$s is managing ads with Advanced Ads %2$s https://wpadvancedads.com/ -->',
esc_html( WordPress::get_site_domain() ),
esc_html( ADVADS_VERSION )
);
if ( Conditional::is_amp() ) {
return;
}
$frontend_prefix = wp_advads()->get_frontend_prefix();
ob_start();
?>
<script id="<?php echo esc_attr( $frontend_prefix ); ?>ready">
<?php
readfile( // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- we're getting the contents of a local file
sprintf(
'%spublic/assets/js/ready%s.js',
ADVADS_ABSPATH,
defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'
)
);
?>
</script>
<?php
/**
* Print inline script in the page header form add-ons.
*
* @param string $frontend_prefix the prefix used for Advanced Ads related HTML ID-s and classes.
*/
do_action( 'advanced_ads_inline_header_scripts', $frontend_prefix );
echo Advanced_Ads_Utils::get_inline_asset( ob_get_clean() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Print inline scripts in wp_footer.
*
* @return void
*/
public function print_footer_scripts(): void {
if ( Conditional::is_amp() ) {
return;
}
$file_path = sprintf(
'%spublic/assets/js/ready-queue%s.js',
ADVADS_ABSPATH,
defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'
);
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo Advanced_Ads_Utils::get_inline_asset(
sprintf(
'<script>%s</script>',
file_get_contents( $file_path ) // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
)
);
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
}
}

View File

@@ -0,0 +1,74 @@
<?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,
];
}
}
}