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,14 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-ab-page-testing
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class Thrive_AB_Page_Variation extends Thrive_AB_Variation {
}

View File

@@ -0,0 +1,237 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-ab-page-testing
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
/**
* Class Thrive_AB_Variation_Manager
*
* Applies logic based on info: page, variation(s)
*/
class Thrive_AB_Variation_Manager {
protected static $_instance;
/**
* Flag for overwriting the current query
*
* @var bool
*/
protected static $_querying_variations;
/**
* @var Thrive_AB_Test|null
*/
protected $_running_test;
protected function __construct() {
add_filter( 'the_posts', array( $this, 'the_posts' ), 10, 2 );
}
public static function instance() {
if ( empty( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Overwrite the queried post if the post is_singular(if it's page)
*
* @param $posts
* @param $wp_query WP_Query
*
* @return mixed
*/
public function the_posts( $posts, $wp_query ) {
$variation = null;
self::$_querying_variations = false;
if ( $this->should_determine_variation( $wp_query ) ) {
if ( function_exists( 'tve_do_not_cache_page' ) ) {
tve_do_not_cache_page();
}
$variation = $this->determine_variation();
// Reset the flag.
self::$_querying_variations = false;
/**
* enqueue the frontend script to allow
* - making conversions for html forms if the test type is 'optins' only
* - register lazy impressions on DOM Ready
*/
$js_suffix = defined( 'TVE_DEBUG' ) && TVE_DEBUG ? '.js' : '.min.js';
thrive_ab()->enqueue_script( 'tab-frontend', thrive_ab()->url( 'assets/js/dist/tab-frontend' . $js_suffix ), array(
'tve_frontend',
'tve-dash-frontend'
), true, true );
$localize_data = array(
'impression_data' => array(
'action' => Thrive_AB_Ajax::REGISTER_IMPRESSION_ACTION_NAME,
'test_id' => $this->_running_test->id,
'page_id' => $this->_running_test->page_id,
'variation_id' => (int) $variation->ID,
),
'test_type' => $this->_running_test->type,
);
if ( $this->_running_test->page_id != $variation->ID ) {
$variation_data['page_id'] = $this->_running_test->page_id;
$variation_data['variation_id'] = $variation->ID;
add_filter( 'tcb_lp_body_class', function ( $classes ) use ( $variation_data ) {
$classes .= ' page-id-' . $variation_data['variation_id'];
return $classes;
}, 10 );
}
wp_localize_script( 'tab-frontend', 'ThriveAB', $localize_data );
try {
/**
* let this here in case we need to implement option for user to register stats on server or lazy loading
* if there has to be on server side just uncomment next line
*/
//Thrive_AB_Event_Manager::do_impression( $this->_running_test->page_id, $this->_running_test->id, $variation->ID );
} catch ( Exception $e ) {
}
}
if ( self::$_querying_variations === false && isset( $variation ) ) {
$wp_query->post = $variation;
$posts = array( $variation );
}
return $posts;
}
/**
* Read the variations from DB and determine one to be displayed
* Call this function if there is a running test only so we are sure there is a test running on this context/instance
*
* @return WP_Post always
*/
protected function determine_variation() {
/**
* If a cookie is set with a certain variation, the same variation should be displayed
*/
$cookie_variation_id = Thrive_AB_Cookie_Manager::get_cookie( $this->_running_test->id, $this->_running_test->page_id, 1 );
$variation = $cookie_variation_id ? get_post( $cookie_variation_id ) : $this->_determine_traffic_variation();
if ( $variation === null ) {
$variation = get_post( $this->_running_test->page_id );
}
return $variation;
}
/**
* Checks if the current request should display variations content
*
* @param $wp_query WP_Query
*
* @return bool
*/
protected function should_determine_variation( $wp_query ) {
$should = function_exists( 'tve_dash_is_crawler' ) && ! tve_dash_is_crawler( true );
$should = $should && $wp_query->is_singular;
/**
* when user wants to edit a page with TAr which has variations
*/
$should = $should && defined( 'TVE_EDITOR_FLAG' ) && ! isset( $_GET[ TVE_EDITOR_FLAG ] );
/**
* if user wants to see the page variations dashboard
*/
$should = $should && ! thrive_ab()->is_dashboard();
/**
* if current user is not admin
*/
$should = $should && ! ( current_user_can( 'edit_posts' ) || Thrive_AB_Product::has_access() );
if ( $should ) {
$post = isset( $wp_query->posts[0] ) ? $wp_query->posts[0] : null;
Thrive_AB_Event_Manager::check_thank_you_page( $post );
$this->_init_test( $wp_query->queried_object_id ? $wp_query->queried_object_id : ( $post instanceof WP_Post ? $post->ID : null ) );
}
/**
* The control variation should be displayed if the AB Test is not running
*/
$should = $should && $this->_running_test instanceof Thrive_AB_Test;
return $should;
}
/**
* Based on traffic allocated on each variations return the corresponding one
* Please complete this doc based on todo
*
* @return WP_POST|null
*/
protected function _determine_traffic_variation() {
$variations = $this->query_variations();
$_rand = function_exists( 'mt_rand' ) ? mt_rand( 0, 101 ) : rand( 0, 101 );
$measurement = 0;
/**@var Thrive_AB_Variation $variation */
foreach ( $variations as $variation ) {
$traffic = $variation->get_meta()->get( 'traffic' );
if ( ( $_rand >= $measurement ) && ( $_rand < ( $measurement + $traffic ) ) ) {
return $variation->get_post();
}
$measurement += $traffic;
}
return null;
}
/**
* @param $filters array
*
* @return array|null
*/
protected function query_variations( $filters = array() ) {
$page = new Thrive_AB_Page( (int) $this->_running_test->page_id );
self::$_querying_variations = true;
return $page->get_variations( $filters, 'obj' );
}
protected function _init_test( $page_id ) {
if ( empty( $page_id ) ) {
return $this;
}
$test_manager = new Thrive_AB_Test_Manager();
$this->_running_test = $test_manager->get_running_test( $page_id );
return $this;
}
}
return Thrive_AB_Variation_Manager::instance();

View File

@@ -0,0 +1,334 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-ab-page-testing
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class Thrive_AB_Variation extends Thrive_AB_Post {
protected $_test_item;
protected $_page;
/**
* Already loaded lightbox which have LG Element
*
* @var array
*/
private static $tcb_lightbox_ids = array();
public function get_data() {
$data = array(
'ID' => $this->_post->ID,
'post_title' => $this->_post->post_title,
'post_parent' => $this->_post->post_parent,
'preview_link' => $this->get_preview_url(),
'edit_link' => $this->get_editor_url(),
'thumb_link' => $this->get_thumb_link(),
'is_control' => $this->get_meta()->get( 'is_control' ),
'traffic' => $this->get_meta()->get( 'traffic' ),
'has_form' => $this->_has_form(),
);
return $data;
}
public function get_traffic() {
return $this->get_meta()->get( 'traffic' );
}
public function get_test_item() {
if ( ! $this->_test_item ) {
$this->_test_item = new Thrive_AB_Test_Item();
$this->_test_item->init_by_filters( array(
'page_id' => thrive_ab()->maybe_variation( $this->_post ) ? $this->_post->post_parent : $this->_post->ID,
'variation_id' => $this->_post->ID,
) );
}
return $this->_test_item;
}
/**
* Delete variation post with all its meta
* and if it's control then set the next variation in list as control
*
* @return bool
* @throws Exception
*/
public function delete() {
if ( $this->is_control() ) {
throw new Exception( 'Control cannot be deleted' );
}
$deleted = wp_delete_post( $this->_post->ID, true );
if ( $deleted === false || is_wp_error( $deleted ) ) {
throw new Exception( __( 'Variation could not be deleted', 'thrive-ab-page-testing' ) );
}
return true;
}
/**
* Gets the preview thumb for current variation
* if the thumb is a print screen then applies a random version number to the url
* to prevent browser cache
*
* @return null|string
*/
public function get_thumb_link() {
$args = array(
'v' => rand( 1000, 10000 ),
);
$thumb = $this->_get_print_screen_url();
if ( ! empty( $thumb ) ) {
$thumb = add_query_arg( $args, $thumb );
}
$thumb = ! empty( $thumb ) ? $thumb : $this->_get_landing_page_thumb_url();
$thumb = ! empty( $thumb ) ? $thumb : thrive_ab()->url( 'assets/images/default-variation.jpg' );
return $thumb;
}
/**
* Check if the variation has any landing page template set and try to
* return template's thumb url
*
* @return null|string
*/
protected function _get_landing_page_thumb_url() {
$url = null;
$landing_page_name = $this->get_meta()->get( 'tve_landing_page' );
$upload = wp_upload_dir();
if ( $landing_page_name && defined( 'TVE_CLOUD_LP_FOLDER' ) ) {
$thumb_file_path = trailingslashit( $upload['basedir'] ) . TVE_CLOUD_LP_FOLDER . '/templates/thumbnails/' . $landing_page_name . '.png';
}
if ( isset( $thumb_file_path ) && is_file( $thumb_file_path ) ) {
$url = trailingslashit( $upload['baseurl'] ) . TVE_CLOUD_LP_FOLDER . '/templates/thumbnails/' . $landing_page_name . '.png';
}
return $url;
}
/**
* Gets the print screen file url if file exists
*
* @return null|string
*/
protected function _get_print_screen_url() {
$url = null;
$wp_upload_dir = wp_get_upload_dir();
$filename = $this->ID . '.png';
$file_path = $wp_upload_dir['basedir'] . '/thrive-ab-page-testing/variations/' . $filename;
if ( is_file( $file_path ) ) {
$url = $wp_upload_dir['baseurl'] . '/thrive-ab-page-testing/variations/' . $filename;
}
return $url;
}
public function get_editor_url() {
if ( $this->_page instanceof WP_Post && $this->_page->post_status === 'draft' ) {
/**
* construct the url manually because WP doesn't see this post_status as draft or pending
*
* @see _get_page_link()
*/
$params = array(
'tve' => 'true',
'action' => 'architect',
);
$link = add_query_arg( $params, get_edit_post_link( $this->_post->ID ) );
} else {
$link = tcb_get_editor_url( $this->_post->ID );
}
return $link;
}
public function get_preview_url() {
$link = tcb_get_preview_url( $this->_post->ID );
return $link;
}
public function is_control() {
return (bool) $this->_post->is_control;
}
public function get_parent_ID() {
return $this->_post->post_parent;
}
public function save( $model ) {
$saved = wp_update_post( $model );
return ! is_wp_error( $saved ) && $saved !== 0;
}
/**
* @return bool
*/
protected function _has_form() {
/**
* TOP-108: Remove Subscription goal restriction
*
* For now, we removed this restriction.
*/
return true;
$content = $this->_get_content();
/**
* check if variation content has any LG ELement in content
*/
$has_form = strpos( $content, 'thrv_lead_generation_container' ) !== false;
/**
* Check for Leads ThriveBox
*/
$has_form = $has_form || strpos( $content, '[thrive_2step id' ) !== false;
$has_form = $has_form || strpos( $content, 'thrive_leads_2_step' ) !== false;
/**
* check if variation has a Thrive Lightbox assigned and Thrive Lightbox has LG Element in content
*/
$has_form = $has_form || $this->_parse_events( $content );
return $has_form;
}
/**
* @return string
*/
protected function _get_content() {
return $this->get_meta()->get( 'tve_updated_post' );
}
/**
* @param string $content
*
* @return bool if action content html has LG element
*/
protected function _parse_events( $content ) {
list( $start, $end ) = array(
'__TCB_EVENT_',
'_TNEVE_BCT__',
);
$event_pattern = "#data-tcb-events=('|\"){$start}(.+?){$end}('|\")#";
$triggers = tve_get_event_triggers();
$actions = tve_get_event_actions();
$registered_actions = array();
if ( preg_match_all( $event_pattern, $content, $matches, PREG_OFFSET_CAPTURE ) !== false ) {
foreach ( $matches[2] as $i => $data ) {
$m = htmlspecialchars_decode( $data[0] ); // the actual matched regexp group
if ( ! ( $_params = json_decode( $m, true ) ) ) {
$_params = array();
}
if ( empty( $_params ) ) {
continue;
}
foreach ( $_params as $event_config ) {
if ( empty( $event_config['t'] ) || empty( $event_config['a'] ) || ! isset( $triggers[ $event_config['t'] ] ) || ! isset( $actions[ $event_config['a'] ] ) ) {
continue;
}
$action = clone $actions[ $event_config['a'] ];
$registered_actions [] = array(
'class' => $action,
'event_config' => $event_config,
);
}
}
}
if ( ! empty( $registered_actions ) ) {
foreach ( $registered_actions as $data ) {
if ( ! empty( $data['class'] ) && $data['class'] instanceof TCB_Event_Action_Abstract ) {
$lightbox_id = $data['event_config']['config']['l_id'];
if ( in_array( $lightbox_id, self::$tcb_lightbox_ids ) ) {
return true;
}
$content_html = $data['class']->applyContentFilter( $data['event_config'] );
$has_form = strpos( $content_html, 'thrv_lead_generation_container' ) !== false;
if ( $has_form ) {
self::$tcb_lightbox_ids[] = $lightbox_id;
return true;
}
}
}
}
return false;
}
public function copy_thumb_to( $new_variation_id ) {
$new_filename = $new_variation_id . '.png';
add_filter( 'upload_dir', array( 'Thrive_AB_Ajax', 'upload_dir' ) );
$upload = wp_upload_dir();
$editor = wp_get_image_editor( $upload['path'] . '/' . $this->ID . '.png' );
if ( ! is_wp_error( $editor ) ) {
$editor->save( $upload['path'] . '/' . $new_filename );
}
remove_filter( 'upload_dir', array( 'Thrive_AB_Ajax', 'upload_dir' ) );
}
/**
* Set the parent page for current variation for checking
*
* @param $page WP_Post
*
* @return $this
* @see get_editor_url()
*
*/
public function set_page( $page ) {
if ( $page instanceof WP_Post && thrive_ab()->is_cpt_allowed( $page->post_type ) ) {
$this->_page = $page;
}
return $this;
}
}