5846c515f3
- 4 temas WordPress: persona-cv (activo), lumina, apex-cv, cvolio - Plugin pflores-cv-fields con CMB2 (100% gratuito) — admin editable - Generador PDF dinámico con Chromium headless (?cv_pdf=1) - Datos del CV de Patricia Flores cargados en CMB2 - URL dinámica con soporte proxy SSL (NPM/X-Forwarded-Proto) - WP Mail SMTP instalado (pendiente config SMTP) - Documentación completa: PROMPT_IA.md, DEPLOY_WEB.md, PRODUCCION.md, VERSIONADO.md
36 lines
1.7 KiB
PHP
36 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
function persona_should_track(): bool {
|
|
if (is_admin() || wp_doing_ajax() || wp_doing_cron()) return false;
|
|
if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'GET') return false;
|
|
if (is_user_logged_in() && current_user_can('manage_options')) return false;
|
|
return is_front_page() || is_home() || is_singular();
|
|
}
|
|
function persona_track_visit(): void {
|
|
if (!persona_should_track()) return;
|
|
$uri = isset($_SERVER['REQUEST_URI']) ? sanitize_text_field(wp_unslash($_SERVER['REQUEST_URI'])) : '';
|
|
$key = 'persona_v_' . md5($uri . '|' . persona_client_ip() . '|' . gmdate('Y-m-d-H'));
|
|
if (get_transient($key)) return;
|
|
set_transient($key, '1', HOUR_IN_SECONDS);
|
|
update_option('persona_total_visits', (int) get_option('persona_total_visits', 0) + 1, false);
|
|
if (is_front_page()) {
|
|
$fp = (int) get_option('page_on_front');
|
|
if ($fp > 0) update_post_meta($fp, '_persona_views', (int) get_post_meta($fp, '_persona_views', true) + 1);
|
|
return;
|
|
}
|
|
$id = get_queried_object_id();
|
|
if ($id > 0) update_post_meta($id, '_persona_views', (int) get_post_meta($id, '_persona_views', true) + 1);
|
|
}
|
|
add_action('template_redirect', 'persona_track_visit');
|
|
function persona_client_ip(): string {
|
|
foreach (['HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR'] as $k) {
|
|
if (!empty($_SERVER[$k])) return trim(explode(',', (string) $_SERVER[$k])[0]);
|
|
}
|
|
return '0.0.0.0';
|
|
}
|
|
add_action('wp_dashboard_setup', function() {
|
|
wp_add_dashboard_widget('persona_visits', __('Persona CV: Visitas', 'persona'), function() {
|
|
printf('<p><strong>%s</strong> %d</p>', esc_html__('Total:', 'persona'), (int) get_option('persona_total_visits', 0));
|
|
});
|
|
});
|