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,174 @@
<?php // phpcs:ignore WordPress.Files.FileName
/**
* Admin class for the Ads for Adblockers module.
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*/
use AdvancedAds\Options;
use AdvancedAds\Constants;
use AdvancedAds\Abstracts\Placement;
use AdvancedAds\Utilities\WordPress;
use AdvancedAds\Importers\XML_Importer;
/**
* Admin class
*/
class Advanced_Ads_Pro_Module_Ads_For_Adblockers_Admin {
/**
* Constructor
*/
public function __construct() {
add_action( 'advanced-ads-settings-init', [ $this, 'settings_init' ] );
if ( ! Options::instance()->get( 'adblocker.ads-for-adblockers.enabled' ) ) {
return;
}
add_filter( 'advanced-ads-import-placement', [ $this, 'import_placement' ], 10, 2 );
add_action( 'advanced-ads-placement-options-after-advanced', [ $this, 'add_placement_setting' ], 10, 2 );
}
/**
* Initializes the settings
*
* @return void
*/
public function settings_init(): void {
add_settings_field(
'module-ads-for-adblockers',
__( 'Ads for ad blockers', 'advanced-ads-pro' ),
[ $this, 'render_settings' ],
ADVADS_SETTINGS_ADBLOCKER,
'advanced_ads_adblocker_setting_section'
);
}
/**
* Render 'Ads For Adblocker' settings
*
* @return void
*/
public function render_settings(): void {
$module_enabled = Options::instance()->get( 'adblocker.ads-for-adblockers.enabled' );
$cb_dashicon_class = ! empty( Advanced_Ads_Pro::get_instance()->get_options()['cache-busting']['enabled'] ) ? 'dashicons-yes advads-color-green' : 'dashicons-no color-red';
$ab_dashicon_class = Options::instance()->get( 'adblocker.use-adblocker' ) ? 'dashicons-yes advads-color-green' : 'dashicons-no color-red';
include_once __DIR__ . '/views/settings.php';
}
/**
* Render alternative item option.
*
* @param string $placement_slug Placement id.
* @param Placement $placement Placement instance.
*/
public function add_placement_setting( $placement_slug, $placement ) {
$type_option = $placement->get_type_object()->get_options();
if ( isset( $type_option['placement-item-alternative'] ) && ! $type_option['placement-item-alternative'] ) {
return;
}
$options = Advanced_Ads_Pro::get_instance()->get_options();
$items = $this->items_for_select();
$messages = $this->get_messages( $placement );
$placement_data = $placement->get_data();
$cb_off = empty( $options['cache-busting']['enabled'] ) || ( isset( $placement_data['cache-busting'] ) && Advanced_Ads_Pro_Module_Cache_Busting::OPTION_OFF === $placement_data['cache-busting'] );
ob_start();
include __DIR__ . '/views/placement-item.php';
$item_option_content = ob_get_clean();
$ad_blocker_description = sprintf(
'%1s. %2s (<a href="%3s" target="_blank">%4s</a>)',
__( 'Displayed to visitors with an ad blocker', 'advanced-ads-pro' ),
__( 'Cache Busting and Ad blocker disguise need to be enabled', 'advanced-ads-pro' ),
esc_url( get_admin_url( '/', 'admin.php?page=advanced-ads-settings#top#pro' ) ),
__( 'Settings', 'advanced-ads-pro' )
);
WordPress::render_option(
'placement-item-alternative',
__( 'Ad blocker item', 'advanced-ads-pro' ),
$item_option_content,
$ad_blocker_description
);
}
/**
* Get items for item select field.
*
* @return array $select Items for select field.
*/
private function items_for_select() {
static $select = null;
// Check if result was cached.
if ( null !== $select ) {
return $select;
}
$select = [];
// Load all ads.
$ads = wp_advads_ad_query(
[
'order' => 'ASC',
'orderby' => 'title',
]
)->posts;
foreach ( $ads as $_ad ) {
$ad = wp_advads_get_ad( $_ad->ID );
if ( $ad->is_type( [ 'plain', 'content', 'image' ] ) ) {
$select['ads'][ Constants::ENTITY_AD . '_' . $_ad->ID ] = $_ad->post_title;
}
}
return $select;
}
/**
* Get messages related to selected alternative item.
*
* @param Placement $placement Placement instance.
*
* @return array $messages Array of strings.
*/
private function get_messages( $placement ) {
$messages = [];
if ( $placement ) {
$ad = Advanced_Ads_Pro_Module_Ads_For_Adblockers::get_item_for_adblocker( $placement );
if ( $ad ) {
$content = $ad->output();
if ( preg_match( '/<script[^>]+src=[\'"]/is', $content ) ) {
$messages[] .= __( 'The chosen ad contains a reference to an external .js file', 'advanced-ads-pro' );
}
}
}
return $messages;
}
/**
* Set an ad for adblocker during the import of a placement.
*
* @param array $placement Placement data.
* @param XML_Importer $import Import instance.
*
* @return array $placement
*/
public function import_placement( $placement, XML_Importer $import ) {
if ( ! empty( $placement['options']['item_adblocker'] ) ) {
$_item = explode( '_', $placement['options']['item_adblocker'] );
if ( ! empty( $_item[1] ) ) {
$found = $import->search_item( $_item[1], $_item[0] );
$placement['options']['item_adblocker'] = $found ? $_item[0] . '_' . $found : '';
}
}
return $placement;
}
}

View File

@@ -0,0 +1,3 @@
<?php
new Advanced_Ads_Pro_Module_Ads_For_Adblockers_Admin();

View File

@@ -0,0 +1,202 @@
<?php // phpcs:ignore WordPress.Files.FileName
use AdvancedAds\Options;
use AdvancedAds\Constants;
use AdvancedAds\Abstracts\Ad;
use AdvancedAds\Abstracts\Group;
use AdvancedAds\Abstracts\Placement;
/**
* Get an ad that is delivered to users for ad blocker request.
*/
class Advanced_Ads_Pro_Module_Ads_For_Adblockers {
/**
* Holds unique identifiers of each chain. It allows to show only one copy of the alternative ad.
*
* @var array
*/
private $shown_chains = [];
/**
* Constructor
*/
public function __construct() {
// Early bail!!
if ( ! Options::instance()->get( 'adblocker.ads-for-adblockers.enabled' ) ) {
return;
}
add_filter( 'advanced-ads-pro-ad-needs-backend-request', [ $this, 'ad_needs_backend_request' ], 10, 3 );
if ( wp_doing_ajax() ) {
add_filter( 'advanced-ads-can-display-ad', [ $this, 'can_display' ], 10, 2 );
add_filter( 'advanced-ads-ad-select-args', [ $this, 'save_chain_id' ], 10, 1 );
add_filter( 'advanced-ads-ad-select-override-by-ad', [ $this, 'override_ad_select_by_ad' ], 10, 3 );
add_filter( 'advanced-ads-ad-select-override-by-group', [ $this, 'override_ad_select_by_group' ], 10, 4 );
}
}
/**
* Enable cache-busting if there is an ad for adblocker.
*
* @param string $check The original return value.
* @param Ad $ad The ad object.
* @param string $fallback The fallback value.
*
* @return string The value indicating if a backend request is needed ('passive') or the fallback value.
*/
public function ad_needs_backend_request( $check, Ad $ad, $fallback ) {
$ad_for_adblocker = self::get_item_for_adblocker( $ad );
if ( ! $ad_for_adblocker ) {
return $check;
}
if ( $check === $fallback ) {
return $fallback;
}
// AJAX or no cache-busting if PHP is enabled for ad for adblocker.
if ( $ad_for_adblocker->is_type( 'plain' ) && $ad_for_adblocker->is_php_allowed() ) {
return $fallback;
}
return 'passive';
}
/**
* Save chain id.
*
* @param array $args Ad arguments.
*
* @return array $args
*/
public function save_chain_id( $args ) {
if ( ! isset( $args['chain_id'] ) ) {
$args['chain_id'] = wp_rand();
}
return $args;
}
/**
* Check if the ad can be displayed.
*
* @param bool $can_display Can the ad be displayed.
* @param Ad $ad Ad instance.
*
* @return bool
*/
public function can_display( $can_display, Ad $ad ) {
if ( ! $can_display ) {
return $can_display;
}
if ( in_array( $ad->get_prop( 'chain_id' ), $this->shown_chains, true ) ) {
return false;
}
return true;
}
/**
* Overrides the selected ad with a new ad based on certain conditions.
*
* @param string $overriden_ad The original selected ad.
* @param AD $ad Ad instance.
* @param array $args Additional arguments.
*
* @return string The overridden ad output.
*/
public function override_ad_select_by_ad( $overriden_ad, AD $ad, $args ) {
return $this->override_ad_select( $overriden_ad, $ad, $args );
}
/**
* Overrides the selected ad with a new ad based on certain conditions.
*
* @param string $overriden_group The original selected ad.
* @param Group $group Group instance.
* @param array|null $ordered_ad_ids ordered ids of the ads that belong to the group.
* @param array $args Additional arguments.
*
* @return string The overridden ad output.
*/
public function override_ad_select_by_group( $overriden_group, Group $group, $ordered_ad_ids, $args ) {
return $this->override_ad_select( $overriden_group, $group, $args );
}
/**
* Common logic for overriding the selected ad or group.
*
* @param string $overriden_item The original selected ad or group.
* @param Ad|Group $entity Ad or Group instance.
* @param array $args Additional arguments.
*
* @return string The overridden ad or group output.
*/
private function override_ad_select( $overriden_item, $entity, $args ) {
if ( ! $entity->can_display() || empty( $args['adblocker_active'] ) || empty( $args['item_adblocker'] ) ) {
return $overriden_item;
}
$_item = explode( '_', $args['item_adblocker'] );
if ( ! empty( $_item[1] ) ) {
if ( in_array( $_item[0], [ Constants::ENTITY_AD, 'id' ], true ) ) {
$ab_ad = wp_advads_get_ad( $_item[1] );
$ab_ad->set_parent( $entity->get_root_placement() );
$overriden_item = $ab_ad->output();
$this->shown_chains[] = $args['chain_id'];
} elseif ( Constants::ENTITY_GROUP === $_item[0] ) {
$group = wp_advads_get_group( (int) $_item[1] );
$group->set_parent( $entity->get_root_placement() );
$overriden_item = $group->output();
}
}
return $overriden_item;
}
/**
* Get an ad that is delivered to users with an ad blocker enabled.
*
* @param Ad|Placement $entity Ad or placement instance.
*
* @return Ad|Group|bool bool false; Ad or Group if an item for ad blocker is found.
*/
public static function get_item_for_adblocker( $entity ) {
// Early bail!!
if ( ! Options::instance()->get( 'adblocker.ads-for-adblockers.enabled' ) ) {
return false;
}
$placement = is_a_placement( $entity ) ? $entity : $entity->get_root_placement();
if ( empty( $placement ) || empty( $placement->get_prop( 'item_adblocker' ) ) ) {
return false;
}
$_item = explode( '_', $placement->get_prop( 'item_adblocker' ) );
if ( ! empty( $_item[1] ) ) {
$item_id = absint( $_item[1] );
if ( in_array( $_item[0], [ Constants::ENTITY_AD, 'id' ], true ) ) {
$ad = wp_advads_get_ad( $item_id );
if ( $ad ) {
$ad->set_parent( $placement );
return $ad;
}
} elseif ( Constants::ENTITY_GROUP === $_item[0] ) {
$group = wp_advads_get_group( $item_id );
if ( $group ) {
foreach ( $group->get_ads() as $ad ) {
$ad->set_parent( $placement );
}
return $group;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,2 @@
<?php
new Advanced_Ads_Pro_Module_Ads_For_Adblockers();

View File

@@ -0,0 +1,47 @@
<?php
/**
* Placement adblocker item dropdown
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
*/
use AdvancedAds\Constants;
$groups = wp_advads_get_all_groups();
?>
<div class="advanced-ads-inputs-dependent-on-cb" <?php echo $cb_off ? 'style="display:none;"' : null; ?>>
<select id="advads-placements-item-adblocker-<?php echo esc_attr( $placement_slug ); ?>" name="advads[placements][options][item_adblocker]">
<option value=""><?php esc_html_e( '--not selected--', 'advanced-ads-pro' ); ?></option>
<?php if ( ! empty( $groups ) ) : ?>
<optgroup label="<?php esc_html_e( 'Groups', 'advanced-ads-pro' ); ?>">
<?php foreach ( $groups as $group ) : ?>
<option value="<?php echo esc_attr( Constants::ENTITY_GROUP . '_' . $group->get_id() ); ?>"<?php selected( Constants::ENTITY_GROUP . '_' . $group->get_id(), $placement_data['item_adblocker'] ?? '' ); ?>>
<?php echo esc_html( $group->get_name() ); ?>
<?php endforeach; ?>
</optgroup>
<?php endif; ?>
<?php if ( isset( $items['ads'] ) ) : ?>
<optgroup label="<?php esc_html_e( 'Ads', 'advanced-ads-pro' ); ?>">
<?php foreach ( $items['ads'] as $_item_id => $_item_title ) : ?>
<option value="<?php echo esc_attr( $_item_id ); ?>"<?php selected( $_item_id, $placement_data['item_adblocker'] ?? '' ); ?>>
<?php echo esc_html( $_item_title ); ?>
</option>
<?php endforeach; ?>
</optgroup>
<?php endif; ?>
</select>
<?php if ( $messages ) : ?>
<?php foreach ( $messages as $_message ) : ?>
<p class="advads-notice-inline advads-error">
<?php echo esc_html( $_message ); ?>
</p>
<?php endforeach; ?>
<?php endif; ?>
</div>
<p class="advads-notice-inline advads-idea" <?php echo ! $cb_off ? 'style="display:none;"' : null; ?>>
<?php esc_html_e( 'Works only with cache-busting enabled', 'advanced-ads-pro' ); ?>
</p>

View File

@@ -0,0 +1,33 @@
<?php
/**
* Render 'Ads For Adblocker' settings
*
* @package AdvancedAds\Pro
* @author Advanced Ads <info@wpadvancedads.com>
* @since 2.26.0
*
* @var array $options Advanced Ads Pro options.
* @var bool $module_enabled if the ads-for-adblockers module is enabled.
* @var string $cb_dashicon_class CSS class for Cache Busting on or off.
* @var string $ab_dashicon_class CSS class for Ad block disguise on or off.
*/
?>
<input name="<?php echo esc_attr( ADVADS_SETTINGS_ADBLOCKER ); ?>[ads-for-adblockers][enabled]" id="advanced-ads-pro-ads-for-adblockers-enabled" type="checkbox" value="1" class="advads-has-sub-settings" <?php checked( $module_enabled ); ?> />
<label for="advanced-ads-pro-ads-for-adblockers-enabled" class="description">
<?php esc_html_e( 'Activate module.', 'advanced-ads-pro' ); ?>
</label>
<a href="https://wpadvancedads.com/manual/ad-blockers/?utm_source=advanced-ads&utm_medium=link&utm_campaign=pro-ab-manual" target="_blank" class="advads-manual-link"><?php esc_html_e( 'Manual', 'advanced-ads-pro' ); ?></a>
<div class="advads-sub-settings">
<p class="description">
<?php
echo wp_kses_post(
__( 'This module requires:', 'advanced-ads-pro' )
. '<br> <span class="dashicons ' . esc_attr( $cb_dashicon_class ) . '"></span>'
. __( 'Cache Busting', 'advanced-ads-pro' )
. '<br> <span class="dashicons ' . esc_attr( $ab_dashicon_class ) . '"></span>'
. __( 'Ad block disguise', 'advanced-ads-pro' )
);
?>
</p>
</div>