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,179 @@
<?php // phpcs:ignoreFile
/**
* Manage backend-facing logic for GamiPress integration
*/
class Advanced_Ads_Pro_Module_GamiPress_Admin {
/**
* Array of GamiPress visitor conditions.
*
* @var array
*/
private $conditions;
/**
* constructor.
*/
public function __construct() {
add_filter( 'advanced-ads-visitor-conditions', [ $this, 'visitor_conditions' ] );
$this->conditions = [
'gamipress_points' => [
'label' => __( 'GamiPress Points', 'advanced-ads-pro' ),
'description' => __( 'Display ads based on GamiPress user points.', 'advanced-ads-pro' ),
'metabox' => [ $this, 'points_metabox' ],
'check' => [ 'Advanced_Ads_Pro_Module_GamiPress', 'check_points_visitor_condition' ],
],
'gamipress_rank' => [
'label' => __( 'GamiPress Rank', 'advanced-ads-pro' ),
'description' => __( 'Display ads based on GamiPress user ranks.', 'advanced-ads-pro' ),
'metabox' => [ $this, 'achievement_rank_metabox' ],
'check' => [ 'Advanced_Ads_Pro_Module_GamiPress', 'check_rank_visitor_condition' ],
],
'gamipress_achievement' => [
'label' => __( 'GamiPress Achievement', 'advanced-ads-pro' ),
'description' => __( 'Display ads based on GamiPress user achievements.', 'advanced-ads-pro' ),
'metabox' => [ $this, 'achievement_rank_metabox' ],
'check' => [ 'Advanced_Ads_Pro_Module_GamiPress', 'check_achievement_visitor_condition' ],
],
];
}
/**
* Add visitor condition for GamiPress fields
*
* @param array $conditions array of registered visitor conditions.
*
* @return array
*/
public function visitor_conditions( $conditions ) {
return array_merge( $conditions, $this->conditions );
}
/**
* Render visitor conditions for achievements and ranks.
*
* @param array $options condition options.
* @param int $index index of the option.
* @param string $form_name name of the form.
*/
public function achievement_rank_metabox( $options, $index, $form_name ) {
$type = $options['type'];
$condition = $this->conditions[ $type ];
$name = Advanced_Ads_Pro_Module_Advanced_Visitor_Conditions::get_form_name_with_index( $form_name, $index );
$operator = isset( $options['operator'] ) ? $options['operator'] : 'is';
$selected_value = isset( $options['value'] ) ? $options['value'] : 0;
$values = $this->get_possible_values( $this->get_possible_types( $options['type'] ) );
if ( $type === 'gamipress_achievement' ) {
include __DIR__ . '/views/visitor-condition-achievement.php';
} else {
$values = $this->order_ranks_by_priority( $values );
include __DIR__ . '/views/visitor-condition-rank.php';
}
}
/**
* Render visitor conditions for points.
*
* @param array $options condition options.
* @param int $index index of the option.
* @param string $form_name name of the form.
*/
public function points_metabox( $options, $index, $form_name ) {
$type = $options['type'];
$condition = $this->conditions[ $type ];
$name = Advanced_Ads_Pro_Module_Advanced_Visitor_Conditions::get_form_name_with_index( $form_name, $index );
$operator = isset( $options['operator'] ) ? $options['operator'] : 'is';
$point_ids = $this->get_posts( 'points-type' );
$points = array_combine( $point_ids, array_map( static function( $post_id ) {
return get_post_meta( $post_id, '_gamipress_plural_name', true );
}, $point_ids ) );
$selected_points_type = isset( $options['points'] ) ? $options['points'] : 0;
$value = isset( $options['value'] ) ? $options['value'] : 0;
include __DIR__ . '/views/visitor-condition-points.php';
}
/**
* Get an array of achievements/rank for each achievement/rank type.
*
* @param int[] $types Post ids for type post types.
*
* @return array
*/
private function get_possible_values( $types ) {
return array_filter( array_combine(
// get the type name as optgroup title
array_map( static function( $post_id ) {
return get_the_title( $post_id );
}, $types ),
// get the actual values as $post_id => name
array_map( function( $post_id ) {
$children = $this->get_posts( get_post_field( 'post_name', $post_id ) );
return array_combine( $children, array_map( static function( $post_id ) {
return get_the_title( $post_id );
}, $children ) );
}, $types )
) );
}
/**
* Get array of post ids for $post_type.
*
* @param string $post_type The post type to search for.
*
* @return int[]
*/
private function get_posts( $post_type ) {
return ( new WP_Query( [
'post_type' => $post_type,
'posts_per_page' => -1,
'post_status' => 'publish',
'fields' => 'ids',
] ) )->posts;
}
/**
* Get an array of post ids for achievement/rank types.
*
* @param string $type Post type name.
*
* @return int[]
*/
private function get_possible_types( $type ) {
if ( $type === 'gamipress_achievement' ) {
return $this->get_posts( 'achievement-type' );
}
if ( $type === 'gamipress_rank' ) {
return $this->get_posts( 'rank-type' );
}
return [];
}
/**
* As ranks have priorities, we want to sort them based on it.
*
* @param array $ranks Array of ranks in form [int $post_id => string $post_title].
*
* @return array
*/
private function order_ranks_by_priority( array $ranks ) {
foreach ( $ranks as &$sub_ranks ) {
uksort( $sub_ranks, static function( $a, $b ) {
$a_priority = gamipress_get_rank_priority( $a );
$b_priority = gamipress_get_rank_priority( $b );
if ( $a_priority === $b_priority ) {
return 0;
}
return ( $a_priority < $b_priority ) ? -1 : 1;
} );
}
return $ranks;
}
}

View File

@@ -0,0 +1,7 @@
<?php
if ( ! class_exists( 'GamiPress' ) ) {
return;
}
new Advanced_Ads_Pro_Module_GamiPress_Admin();

View File

@@ -0,0 +1,72 @@
<?php
/**
* Callbacks for GamiPress visitor conditions.
*/
class Advanced_Ads_Pro_Module_GamiPress {
/**
* Check if current user meets points visitor condition.
*
* @param array $condition Array of visitor condition options.
*
* @return bool
*/
public static function check_points_visitor_condition( $condition ) {
$points = gamipress_get_user_points(
get_current_user_id(),
// dynamically get the post_name from the WP_Post::ID, post_name can change, while ID is immutable.
get_post_field( 'post_name', (int) $condition['points'] )
);
$compare = (int) $condition['value'];
switch ( $condition['operator'] ) {
case 'is_higher':
return $points >= $compare;
case 'is_lower':
return $points <= $compare;
case 'is_equal':
default:
return $points === $compare;
}
}
/**
* Check if current user meets rank visitor condition.
*
* @param array $condition Array of visitor condition options.
*
* @return bool
*/
public static function check_rank_visitor_condition( $condition ) {
$condition_rank = gamipress_get_rank_priority( (int) $condition['value'] );
$user_rank = gamipress_get_rank_priority( gamipress_get_user_rank(
get_current_user_id(),
gamipress_get_post_type( (int) $condition['value'] )
) );
switch ( $condition['operator'] ) {
case 'is_higher':
return $user_rank >= $condition_rank;
case 'is_lower':
return $user_rank <= $condition_rank;
case 'is_equal':
default:
return $user_rank === $condition_rank;
}
}
/**
* Check if current user meets achievement visitor condition.
*
* @param array $condition Array of visitor condition options.
*
* @return bool
*/
public static function check_achievement_visitor_condition( $condition ) {
$achieved = gamipress_has_user_earned_achievement( (int) $condition['value'], get_current_user_id() );
if ( $condition['operator'] === 'is_not' ) {
return ! $achieved;
}
return $achieved;
}
}

View File

@@ -0,0 +1,8 @@
<?php
if ( ! class_exists( 'GamiPress' ) ) {
return;
}
// the callbacks for the visitor conditions are registered in admin.
new Advanced_Ads_Pro_Module_GamiPress_Admin();

View File

@@ -0,0 +1,37 @@
<?php
/**
* View for GamiPress ranks and achievements visitor condition.
*
* @var string $type The visitor condition type.
* @var string $name Unique input name.
* @var string $operator The comparison operator.
* @var array $condition Details for the condition.
* @var array $values GamiPress achievements or ranks.
* @var array $selected_value The currently selected value.
*/
?>
<input type="hidden" name="<?php echo esc_attr( $name ); ?>[type]" value="<?php echo esc_attr( $type ); ?>"/>
<div class="advads-conditions-single">
<select name="<?php echo esc_attr( $name ); ?>[operator]">
<option value="is" <?php selected( 'is', $operator ); ?>><?php esc_attr_e( 'is', 'advanced-ads-pro' ); ?></option>
<option value="is_not" <?php selected( 'is_not', $operator ); ?>><?php esc_attr_e( 'is not', 'advanced-ads-pro' ); ?></option>
</select>
<div class="advads-conditions-select-wrap">
<select name="<?php echo esc_attr( $name ); ?>[value]">
<option value="" disabled <?php selected( 0, $selected_value ); ?>><?php esc_attr_e( 'Choose Achievement Type', 'advanced-ads-pro' ); ?></option>
<?php foreach ( $values as $label => $optgroup ) : ?>
<optgroup label="<?php echo esc_attr( $label ); ?> ">
<?php foreach ( $optgroup as $value => $option ) : ?>
<option value="<?php echo (int) $value; ?>" <?php selected( $value, $selected_value ); ?>><?php echo esc_attr( $option ); ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
</div>
<p class="description">
<?php echo esc_html( $condition['description'] ); ?>
<a href="https://wpadvancedads.com/manual/gamipress-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-gamipress" class="advads-manual-links" target="_blank">
<?php esc_html_e( 'Manual', 'advanced-ads-pro' ); ?>
</a>
</p>
</div>

View File

@@ -0,0 +1,44 @@
<?php
/**
* View for GamiPress points visitor condition.
*
* @var string $type The visitor condition type.
* @var string $name Unique input name.
* @var string $operator The comparison operator.
* @var array $condition Details for the condition.
* @var array $points GamiPress points types.
* @var array $selected_points_type The currently selected points type.
*/
?>
<input type="hidden" name="<?php echo esc_attr( $name ); ?>[type]" value="<?php echo esc_attr( $type ); ?>"/>
<div class="advads-conditions-single">
<div class="advads-conditions-select-wrap">
<select name="<?php echo esc_attr( $name ); ?>[points]">
<option value="" disabled <?php selected( 0, $selected_points_type ); ?>><?php esc_attr_e( 'Choose Points Type', 'advanced-ads-pro' ); ?></option>
<?php foreach ( $points as $points_id => $label ) : ?>
<option value="<?php echo (int) $points_id; ?>" <?php selected( $points_id, $selected_points_type ); ?>><?php echo esc_attr( $label ); ?></option>
<?php endforeach; ?>
</select>
</div>
<select name="<?php echo esc_attr( $name ); ?>[operator]">
<option value="is_equal" <?php selected( 'is_equal', $operator ); ?>>
<?php esc_html_e( 'is equal', 'advanced-ads' ); ?>
</option>
<option value="is_higher" <?php selected( 'is_higher', $operator ); ?>>
<?php esc_html_e( 'is higher or equal', 'advanced-ads' ); ?>
</option>
<option value="is_lower" <?php selected( 'is_lower', $operator ); ?>>
<?php esc_html_e( 'is lower or equal', 'advanced-ads' ); ?>
</option>
</select>
<input type="number" name="<?php echo esc_attr( $name ); ?>[value]" value="<?php echo (int) $value; ?>" min="0">
<p class="description">
<?php echo esc_html( $condition['description'] ); ?>
<a href="https://wpadvancedads.com/manual/gamipress-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-gamipress" class="advads-manual-link" target="_blank">
<?php esc_html_e( 'Manual', 'advanced-ads-pro' ); ?>
</a>
</p>
</div>

View File

@@ -0,0 +1,44 @@
<?php
/**
* View for GamiPress ranks and achievements visitor condition.
*
* @var string $type The visitor condition type.
* @var string $name Unique input name.
* @var string $operator The comparison operator.
* @var array $condition Details for the condition.
* @var array $values GamiPress achievements or ranks.
* @var array $selected_value The currently selected value.
*/
?>
<input type="hidden" name="<?php echo esc_attr( $name ); ?>[type]" value="<?php echo esc_attr( $type ); ?>"/>
<div class="advads-conditions-single">
<select name="<?php echo esc_attr( $name ); ?>[operator]">
<option value="is_equal" <?php selected( 'is_equal', $operator ); ?>>
<?php esc_html_e( 'is equal', 'advanced-ads' ); ?>
</option>
<option value="is_higher" <?php selected( 'is_higher', $operator ); ?>>
<?php esc_html_e( 'is higher or equal', 'advanced-ads' ); ?>
</option>
<option value="is_lower" <?php selected( 'is_lower', $operator ); ?>>
<?php esc_html_e( 'is lower or equal', 'advanced-ads' ); ?>
</option>
</select>
<div class="advads-conditions-select-wrap">
<select name="<?php echo esc_attr( $name ); ?>[value]">
<option value="" disabled <?php selected( 0, $selected_value ); ?>><?php esc_attr_e( 'Choose rank', 'advanced-ads-pro' ); ?></option>
<?php foreach ( $values as $label => $optgroup ) : ?>
<optgroup label="<?php echo esc_attr( $label ); ?> ">
<?php foreach ( $optgroup as $value => $option ) : ?>
<option value="<?php echo (int) $value; ?>" <?php selected( $value, $selected_value ); ?>><?php echo esc_attr( $option ); ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
</div>
<p class="description">
<?php echo esc_html( $condition['description'] ); ?>
<a href="https://wpadvancedads.com/manual/gamipress-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-gamipress" class="advads-manual-link" target="_blank">
<?php esc_html_e( 'Manual', 'advanced-ads-pro' ); ?>
</a>
</p>
</div>