Fix: Consolidar funciones sanitizadoras para resolver error fatal de redeclaración
Resuelve issue #21 y sub-issue #22 PROBLEMA: - La función apus_sanitize_checkbox() estaba definida en 4 archivos diferentes - Causaba error fatal: "Cannot redeclare apus_sanitize_checkbox()" - Impedía activación del tema en staging SOLUCIÓN: 1. Crear inc/sanitize-functions.php con funciones centralizadas 2. Incluir sanitize-functions.php al inicio de functions.php 3. Eliminar definiciones duplicadas en: - inc/customizer-fonts.php (líneas 83-93) - inc/adsense-delay.php (líneas 161-163) - inc/admin/options-api.php (líneas 240-242) - inc/critical-css.php (líneas 361-363) ARCHIVOS MODIFICADOS: - inc/sanitize-functions.php (nuevo) - functions.php (incluir sanitize-functions.php) - inc/customizer-fonts.php (eliminar duplicados) - inc/adsense-delay.php (eliminar duplicados) - inc/admin/options-api.php (eliminar duplicados) - inc/critical-css.php (eliminar duplicados) FUNCIONES CONSOLIDADAS: - apus_sanitize_checkbox($input): Sanitiza valores boolean - apus_sanitize_select($input, $setting): Sanitiza valores select VERIFICACIÓN: ✅ Sintaxis PHP correcta en todos los archivos ✅ No hay redeclaraciones de funciones ✅ Funciones protegidas con function_exists() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -146,6 +146,11 @@ add_filter('date_format', 'apus_custom_date_format');
|
|||||||
/**
|
/**
|
||||||
* Include modular files
|
* Include modular files
|
||||||
*/
|
*/
|
||||||
|
// Sanitize Functions (load first to avoid redeclaration errors)
|
||||||
|
if (file_exists(get_template_directory() . '/inc/sanitize-functions.php')) {
|
||||||
|
require_once get_template_directory() . '/inc/sanitize-functions.php';
|
||||||
|
}
|
||||||
|
|
||||||
// Theme Options Helpers (load first as other files may depend on it)
|
// Theme Options Helpers (load first as other files may depend on it)
|
||||||
if (file_exists(get_template_directory() . '/inc/theme-options-helpers.php')) {
|
if (file_exists(get_template_directory() . '/inc/theme-options-helpers.php')) {
|
||||||
require_once get_template_directory() . '/inc/theme-options-helpers.php';
|
require_once get_template_directory() . '/inc/theme-options-helpers.php';
|
||||||
|
|||||||
@@ -231,16 +231,6 @@ function apus_sanitize_js($js) {
|
|||||||
return trim($js);
|
return trim($js);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sanitize checkbox input
|
|
||||||
*
|
|
||||||
* @param mixed $input The input value
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function apus_sanitize_checkbox($input) {
|
|
||||||
return (bool) $input;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitize integer input
|
* Sanitize integer input
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -152,12 +152,3 @@ function apus_adsense_delay_customizer($wp_customize) {
|
|||||||
}
|
}
|
||||||
add_action('customize_register', 'apus_adsense_delay_customizer');
|
add_action('customize_register', 'apus_adsense_delay_customizer');
|
||||||
|
|
||||||
/**
|
|
||||||
* Sanitize checkbox input
|
|
||||||
*
|
|
||||||
* @param bool $checked Whether the checkbox is checked
|
|
||||||
* @return bool Sanitized value
|
|
||||||
*/
|
|
||||||
function apus_sanitize_checkbox($checked) {
|
|
||||||
return (isset($checked) && $checked === true || $checked === '1') ? true : false;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -351,17 +351,6 @@ function apus_critical_css_customizer( $wp_customize ) {
|
|||||||
}
|
}
|
||||||
add_action( 'customize_register', 'apus_critical_css_customizer' );
|
add_action( 'customize_register', 'apus_critical_css_customizer' );
|
||||||
|
|
||||||
/**
|
|
||||||
* Sanitize checkbox value
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @param bool $checked Whether the checkbox is checked.
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
function apus_sanitize_checkbox( $checked ) {
|
|
||||||
return ( isset( $checked ) && true === $checked ) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear critical CSS cache when theme is updated
|
* Clear critical CSS cache when theme is updated
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -77,21 +77,6 @@ function apus_customize_register_fonts($wp_customize) {
|
|||||||
|
|
||||||
add_action('customize_register', 'apus_customize_register_fonts');
|
add_action('customize_register', 'apus_customize_register_fonts');
|
||||||
|
|
||||||
/**
|
|
||||||
* Sanitize checkbox
|
|
||||||
*/
|
|
||||||
function apus_sanitize_checkbox($input) {
|
|
||||||
return (isset($input) && true === $input) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sanitize select
|
|
||||||
*/
|
|
||||||
function apus_sanitize_select($input, $setting) {
|
|
||||||
$choices = $setting->manager->get_control($setting->id)->choices;
|
|
||||||
return (array_key_exists($input, $choices) ? $input : $setting->default);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if custom fonts are enabled
|
* Check if custom fonts are enabled
|
||||||
*/
|
*/
|
||||||
|
|||||||
52
wp-content/themes/apus-theme/inc/sanitize-functions.php
Normal file
52
wp-content/themes/apus-theme/inc/sanitize-functions.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Funciones de sanitización para el tema APUS
|
||||||
|
*
|
||||||
|
* Este archivo centraliza todas las funciones de sanitización utilizadas
|
||||||
|
* en el Customizer, panel de opciones y demás componentes del tema.
|
||||||
|
*
|
||||||
|
* @package APUS_Theme
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly
|
||||||
|
if (!defined('ABSPATH')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('apus_sanitize_checkbox')) {
|
||||||
|
/**
|
||||||
|
* Sanitiza valores de checkbox
|
||||||
|
*
|
||||||
|
* Convierte cualquier valor a boolean para asegurar que solo
|
||||||
|
* se guarden valores true/false en la base de datos.
|
||||||
|
*
|
||||||
|
* @param mixed $input Valor a sanitizar
|
||||||
|
* @return bool Valor sanitizado como boolean
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
function apus_sanitize_checkbox($input) {
|
||||||
|
return (bool) $input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('apus_sanitize_select')) {
|
||||||
|
/**
|
||||||
|
* Sanitiza valores de select
|
||||||
|
*
|
||||||
|
* Verifica que el valor seleccionado existe en las opciones disponibles.
|
||||||
|
* Si no existe, retorna el valor por defecto del setting.
|
||||||
|
*
|
||||||
|
* @param mixed $input Valor a sanitizar
|
||||||
|
* @param object $setting Setting object del Customizer
|
||||||
|
* @return string Valor sanitizado
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
function apus_sanitize_select($input, $setting) {
|
||||||
|
// Asegurar que el setting tiene las opciones disponibles
|
||||||
|
$choices = $setting->manager->get_control($setting->id)->choices;
|
||||||
|
|
||||||
|
// Retornar el input si es una opción válida, de lo contrario retornar el default
|
||||||
|
return (array_key_exists($input, $choices) ? $input : $setting->default);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user