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,140 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Metrics;
use function add_filter;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
class Deactivate {
const TRACKING_URL = 'https://service-api.thrivethemes.com/plugin-deactivate';
public static function init() {
static::hooks();
}
public static function hooks() {
add_filter( 'tve_metrics_localize_data', [ __CLASS__, 'localize_data' ] );
}
/**
* Log the deactivation reason
*
* @param array $data
*
* @return void
*/
public static function log_data( $data ) {
$default_data = [
'site_id' => Utils::hash_256( get_site_url() ),
'timestamp' => time(),
'ttw_id' => class_exists( '\TD_TTW_Connection', false ) && \TD_TTW_Connection::get_instance()->is_connected() ? \TD_TTW_Connection::get_instance()->ttw_id : 0,
];
$data = array_merge( $default_data, $data );
$tracking_url = defined( 'TD_SERVICE_API_URL' ) ? rtrim(TD_SERVICE_API_URL, '/') . '/plugin-deactivate' : static::TRACKING_URL;
Utils::send_request( $tracking_url, $data );
}
/**
* Extra data to be passed to the frontend
*
* @param array $data
*
* @return array
*/
public static function localize_data( $data ) {
if ( Utils::is_plugins_screen() ) {
$data['deactivate_plugins'] = static::get_products();
$data['deactivate_reasons'] = static::get_reasons();
$data['i18n'] = array_merge( $data['i18n'], static::get_i18n() );
}
return $data;
}
/**
* Extra i18n strings for the deactivation popup
*
* @return array
*/
public static function get_i18n() {
return [
'deactivate_title' => __( 'Please share why you are deactivating', 'thrive-dash' ),
'submit_deactivate' => __( 'Submit & Deactivate', 'thrive-dash' ),
'skip_deactivate' => __( 'Skip & Deactivate', 'thrive-dash' ),
'deactivate_reason' => __( 'Reason for deactivation', 'thrive-dash' ),
];
}
/**
* Should enqueue the scripts for the deactivation popup only on the plugins page
*
* @return bool
*/
public static function should_enqueue() {
return Utils::is_plugins_screen();
}
/**
* Array of reasons for deactivation
*
* @return array[]
*/
public static function get_reasons() {
return [
[
'key' => 'plugin_not_working',
'label' => __( "I couldn't get the plugin to work", 'thrive-dash' ),
],
[
'key' => 'temporary_deactivation',
'label' => __( "It's a temporary deactivation", 'thrive-dash' ),
],
[
'key' => 'requesting_refund',
'label' => __( "I'm requesting a refund", 'thrive-dash' ),
],
[
'key' => 'cancel_subscription',
'label' => __( "I'm canceling my subscription", 'thrive-dash' ),
],
[
'key' => 'found_a_better_plugin',
'label' => __( 'I found a better plugin', 'thrive-dash' ),
],
[
'key' => 'no_longer_need',
'label' => __( 'I no longer need the plugin', 'thrive-dash' ),
],
[
'key' => 'other',
'label' => __( 'Other', 'thrive-dash' ),
],
];
}
/**
* List of plugins that should be tracked on deactivation
*
* @return mixed|null
*/
public static function get_products() {
$products = Utils::get_products();
foreach ( $products as $key => $data ) {
if ( $data['type'] === 'theme' ) {
unset( $products[ $key ] );
}
}
return apply_filters( 'tve_metrics_deactivate_products', $products );
}
}

View File

@@ -0,0 +1,129 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Metrics;
use function apply_filters;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
class Main {
const SCRIPT_HANDLE = 'td-metrics';
const APP_ID = 'td-metrics-wrapper';
const NONCE = 'td-metrics-nonce';
public static function init() {
static::includes();
static::hooks();
}
public static function get_class_name_from_filename( $filename ) {
$name = str_replace( 'class-', '', basename( $filename, '.php' ) );
return str_replace( '-', '_', ucwords( $name, '-' ) );
}
/**
* Function that requires all the files needed for the metrics
*
* @return void
*/
public static function includes() {
foreach ( glob( __DIR__ . '/*.php' ) as $file ) {
if ( strpos( $file, 'class-main.php' ) !== false ) {
continue;
}
require_once $file;
$class = 'TVE\Dashboard\Metrics\\' . static::get_class_name_from_filename( $file );
if ( method_exists( $class, 'init' ) ) {
$class::init();
}
}
}
public static function hooks() {
add_action( 'admin_footer', [ __CLASS__, 'print_wrapper' ] );
add_action( 'rest_api_init', [ __CLASS__, 'rest_api_init' ] );
add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue_scripts' ] );
}
/**
* Print the wrapper for the Vue app
*
* @return void
*/
public static function print_wrapper() {
if ( static::should_enqueue() ) {
echo '<div id="' . static::APP_ID . '"></div>';
}
}
/**
* Enqueue the scripts for the metrics app
*
* @return void
*/
public static function enqueue_scripts() {
if ( static::should_enqueue() ) {
tve_dash_enqueue_vue();
tve_dash_enqueue_script( static::SCRIPT_HANDLE, TVE_DASH_URL . '/assets/dist/js/metrics.js', [], TVE_DASH_VERSION, true );
if ( is_file( TVE_DASH_PATH . '/assets/dist/css/metrics.css' ) ) {
tve_dash_enqueue_style( static::SCRIPT_HANDLE, TVE_DASH_URL . '/assets/dist/css/metrics.css' );
}
wp_localize_script( static::SCRIPT_HANDLE, 'TD_Metrics', static::localize_data() );
}
}
/**
* Whether we should enqueue the scripts for the metrics app
*
* @return mixed|null
*/
public static function should_enqueue() {
return apply_filters( 'tve_dash_metrics_should_enqueue', Deactivate::should_enqueue() || Tracking::should_enqueue() );
}
/**
* Data to be passed to the frontend
*
* @return mixed|null
*/
public static function localize_data() {
$data = [
'app_id' => static::APP_ID,
'tracking_consent_notice' => Tracking::TRACKING_NOTICE_ID,
'routes' => get_rest_url( get_current_blog_id(), Rest_Controller::REST_NAMESPACE ),
'wp_rest_nonce' => wp_create_nonce( 'wp_rest' ),
'td_metrics_nonce' => wp_create_nonce( static::NONCE ),
'is_plugin_screen' => Utils::is_plugins_screen(),
'plugins' => Utils::get_products(),
'i18n' => [],
'tracking_setting_id' => Tracking::SETTING_ID,
'tracking_enabled' => Tracking::get_tracking_allowed(),
];
return apply_filters( 'tve_metrics_localize_data', $data );
}
/**
* Initialize the REST API routes
*
* @return void
*/
public static function rest_api_init() {
$rest = new Rest_Controller();
$rest->register_routes();
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Metrics;
use WP_REST_Controller;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
class Rest_Controller extends WP_REST_Controller {
const REST_NAMESPACE = 'td-metrics/v1';
public function register_routes() {
register_rest_route( static::REST_NAMESPACE, '/track_deactivate', [
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( __CLASS__, 'track_deactivate' ),
'permission_callback' => array( __CLASS__, 'admin_permissions_check' ),
'args' => array(
'reason' => Utils::get_rest_string_arg_data(),
'reason_id' => Utils::get_rest_string_arg_data(),
'plugin_name' => Utils::get_rest_string_arg_data(),
'plugin_version' => [
'type' => 'string',
],
'extra_message' => [
'type' => 'string',
],
'nonce' => Utils::get_rest_string_arg_data(),
),
],
] );
register_rest_route( static::REST_NAMESPACE, '/settings/tracking_consent', [
[
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( __CLASS__, 'tracking_consent' ),
'permission_callback' => array( __CLASS__, 'admin_permissions_check' ),
'args' => array(
'tracking_enabled' => [
'type' => 'boolean',
'required' => true,
],
),
],
] );
}
/**
* Endpoint for tracking plugin deactivation
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response
*/
public static function track_deactivate( WP_REST_Request $request ) {
$nonce = $request->get_param( 'nonce' );
if ( ! wp_verify_nonce( $nonce, Main::NONCE ) ) {
return new WP_REST_Response( [ 'message' => 'Invalid nonce' ], 404 );
}
Deactivate::log_data( [
'reason' => $request->get_param( 'reason' ),
'reason_id' => $request->get_param( 'reason_id' ),
'extra_message' => $request->get_param( 'extra_message' ),
'plugin_name' => $request->get_param( 'plugin_name' ),
'plugin_version' => $request->get_param( 'plugin_version' ),
] );
return new WP_REST_Response( [ 'success' => true ], 200 );
}
/**
* Check if current user has TD permissions
*
* @return bool
*/
public static function admin_permissions_check() {
return current_user_can( TVE_DASH_CAPABILITY );
}
public static function tracking_consent( \WP_REST_Request $request ) {
$consent = (int) $request->get_param( 'tracking_enabled' );
Tracking::set_tracking_allowed( $consent );
return new WP_REST_Response( true, 200 );
}
}

View File

@@ -0,0 +1,196 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Metrics;
use WP_Theme;
use function is_plugin_active;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
class Tracking {
const SETTING_ID = 'tve_metrics_consent';
const CONSENT_RESET = 'tve-metrics-consent-reset';
const TRACKING_OPTION = 'tve-tracking-allowed';
const TRACKING_NOTICE_ID = 'tve-tracking-notice';
const ALLOWED_VIEWS = [ 'admin_page_tve_dash_general_settings_section' ];
/**
* List of our plugins that should be checked for tracking
* Do it like this because on some hooks plugins files might not be loaded yet
*/
const PLUGINS = [
'thrive-apprentice/thrive-apprentice.php',
'thrive-visual-editor/thrive-visual-editor.php',
'thrive-comments/thrive-comments.php',
'thrive-leads/thrive-leads.php',
'thrive-ultimatum/thrive-ultimatum.php',
'thrive-quiz-builder/thrive-quiz-builder.php',
'thrive-ovation/thrive-ovation.php',
'thrive-optimize/thrive-optimize.php',
'ab-page-testing/ab-page-testing.php',
];
const THEME = 'thrive-theme';
public static function init() {
static::hooks();
}
public static function hooks() {
add_action( 'admin_notices', [ __CLASS__, 'admin_notices' ], 1 );
add_action( 'activated_plugin', [ __CLASS__, 'after_plugin_activate' ], 10, 2 );
add_action( 'switch_theme', [ __CLASS__, 'after_theme_activate' ], 10, 3 );
add_filter( 'tve_dash_general_settings_filter', [ __CLASS__, 'add_settings' ] );
}
/**
* Add a settings in the dashboard settings page
*
* @param $settings
*
* @return mixed
*/
public static function add_settings( $settings ) {
$settings[] = [
'name' => static::SETTING_ID,
'id' => static::SETTING_ID,
'value' => static::get_tracking_allowed(),
'type' => 'checkbox',
'description' => __( 'Help us improve Thrive Themes products by sharing anonymized data with us.', 'thrive-dash' ),
'multiple' => false,
'link' => '//help.thrivethemes.com/en/articles/6796332-thrive-themes-data-collection',
];
return $settings;
}
/**
* Display the admin notice if needed
*
* @return void
*
*/
public static function admin_notices() {
if ( static::should_display_ribbon() ) {
echo sprintf( '<div id="%s" class="notice notice-success tve-metrics-consent-notice" style="display: none"></div>', static::TRACKING_NOTICE_ID );
}
}
/**
* Check if the tracking is allowed
*
* @return bool
*/
public static function get_tracking_allowed() {
return (bool) get_option( static::TRACKING_OPTION, 0 );
}
/**
* Whether we should display the ribbon
* We also need at least one license
*
* @return bool
*/
public static function should_display_ribbon() {
$products = array_filter( Utils::get_products(), static function ( $product ) {
return $product['is_activated'];
} );
return get_option( static::TRACKING_OPTION, '' ) === '' && count( $products ) > 0;
}
/**
* Allow enqueuing of the tracking script only on General settings page or if the user hasn't made a choice yet
*
* @return bool
*/
public static function should_enqueue() {
$screen = \tve_get_current_screen_key();
return ( $screen && in_array( $screen, static::ALLOWED_VIEWS ) ) || static::should_display_ribbon();
}
/**
* After plugin activation, clear the tracking consent option if needed
*
* @param $plugin
* @param $network_activation
*
* @return void
*/
public static function after_plugin_activate( $plugin, $network_activation ) {
if ( in_array( $plugin, static::PLUGINS, true ) && ! static::get_tracking_allowed() ) {
static::clear_tracking_consent();
}
}
/**
* After theme activation, clear the tracking consent if needed
*
* @param $theme_name
* @param WP_Theme $theme_object
* @param $old_theme_name
*
* @return void
*/
public static function after_theme_activate( $theme_name, WP_Theme $theme_object, $old_theme_name ) {
if ( ! empty( $theme_object ) && ! static::get_tracking_allowed() && $theme_object->get_stylesheet() === static::THEME ) {
static::clear_tracking_consent();
}
}
/**
* Get number of activated products
*/
public static function activated_products() {
if ( ! function_exists( '\is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$active_products = array_filter( static::PLUGINS, static function ( $product ) {
return is_plugin_active( $product );
} );
$active_count = count( $active_products );
if ( \tve_dash_is_ttb_active() ) {
$active_count ++;
}
return $active_count;
}
/**
* Delete the tracking consent option if there is more than one product active
*/
public static function clear_tracking_consent() {
if ( static::activated_products() === 1 && ! get_option( static::CONSENT_RESET, false ) ) {
delete_option( static::TRACKING_OPTION );
update_option( static::CONSENT_RESET, true, 'no' );
}
}
/**
* Save user tracking preference
*
* @param $value
*
* @return void
*/
public static function set_tracking_allowed( $value ) {
update_option( static::TRACKING_OPTION, $value, 'no' );
/**
* Action triggered when the user changes the tracking preference
*/
do_action( 'tve_tracking_consent_changed', $value );
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
namespace TVE\Dashboard\Metrics;
use TVE_Dash_Product_Abstract;
use function tve_dash_api_remote_post;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
class Utils {
const THRIVE_KEY = '@#$()%*%$^&*(#@$%@#$%93827456MASDFJIK3245';
/**
* @param string $url
* @param array $data
*
* @return void
*/
public static function send_request( $url, array $data = [] ) {
$url = add_query_arg( [
'p' => static::calc_thrive_hash( $data ),
], $url );
tve_dash_api_remote_post( $url,
[
'body' => json_encode( $data ),
'headers' => [
'Content-Type' => 'application/json',
],
]
);
}
/**
* Whether we are on plugin screen
*
* @return bool
*/
public static function is_plugins_screen() {
$screen = get_current_screen();
return $screen && in_array( $screen->id, [ 'plugins', 'plugins-network' ] );
}
/**
* Calc the hash that should be sent on APIs requests
*
* @param array $data
*
* @return string
*/
public static function calc_thrive_hash( array $data ) {
return md5( static::THRIVE_KEY . serialize( $data ) . static::THRIVE_KEY );
}
/**
* Hash a string
*
* @param string $string
*
* @return string
*/
public static function hash_256( $string ) {
if ( $string === null || static::is_hashed( $string ) ) {
return $string;
}
return hash( 'sha256', $string );
}
/**
* Check if a string is hashed
*
* @param string $string
*
* @return bool
*/
public static function is_hashed( $string ) {
return strlen( $string ) === 64 && ctype_xdigit( $string );
}
/**
* Default options for string required params
*
* @return array
*/
public static function get_rest_string_arg_data() {
return [
'type' => 'string',
'required' => true,
'validate_callback' => static function ( $param ) {
return ! empty( $param );
},
];
}
/**
* get a list of products with their localizations
*
* @return array
*/
public static function get_products() {
$installed = tve_dash_get_products( false );
$localized = [];
foreach ( $installed as $key => $product ) {
/**
* @var $product TVE_Dash_Product_Abstract
*/
$localized[ $key ] = $product->localize_data();
}
return $localized;
}
}