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>
273 lines
10 KiB
PHP
273 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* Theme Options Settings API
|
|
*
|
|
* @package Apus_Theme
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Register all theme settings
|
|
*/
|
|
function apus_register_settings() {
|
|
// Register main options group
|
|
register_setting(
|
|
'apus_theme_options_group',
|
|
'apus_theme_options',
|
|
array(
|
|
'sanitize_callback' => 'apus_sanitize_options',
|
|
'default' => apus_get_default_options(),
|
|
)
|
|
);
|
|
|
|
// General Settings Section
|
|
add_settings_section(
|
|
'apus_general_section',
|
|
__('General Settings', 'apus-theme'),
|
|
'apus_general_section_callback',
|
|
'apus-theme-options'
|
|
);
|
|
|
|
// Content Settings Section
|
|
add_settings_section(
|
|
'apus_content_section',
|
|
__('Content Settings', 'apus-theme'),
|
|
'apus_content_section_callback',
|
|
'apus-theme-options'
|
|
);
|
|
|
|
// Performance Settings Section
|
|
add_settings_section(
|
|
'apus_performance_section',
|
|
__('Performance Settings', 'apus-theme'),
|
|
'apus_performance_section_callback',
|
|
'apus-theme-options'
|
|
);
|
|
|
|
// Related Posts Settings Section
|
|
add_settings_section(
|
|
'apus_related_posts_section',
|
|
__('Related Posts Settings', 'apus-theme'),
|
|
'apus_related_posts_section_callback',
|
|
'apus-theme-options'
|
|
);
|
|
}
|
|
add_action('admin_init', 'apus_register_settings');
|
|
|
|
/**
|
|
* Get default options
|
|
*
|
|
* @return array
|
|
*/
|
|
function apus_get_default_options() {
|
|
return array(
|
|
// General
|
|
'site_logo' => 0,
|
|
'site_favicon' => 0,
|
|
'enable_breadcrumbs' => true,
|
|
'breadcrumb_separator' => '>',
|
|
'date_format' => 'd/m/Y',
|
|
'time_format' => 'H:i',
|
|
'copyright_text' => sprintf(__('© %s %s. All rights reserved.', 'apus-theme'), date('Y'), get_bloginfo('name')),
|
|
'social_facebook' => '',
|
|
'social_twitter' => '',
|
|
'social_instagram' => '',
|
|
'social_linkedin' => '',
|
|
'social_youtube' => '',
|
|
|
|
// Content
|
|
'excerpt_length' => 55,
|
|
'excerpt_more' => '...',
|
|
'default_post_layout' => 'right-sidebar',
|
|
'default_page_layout' => 'right-sidebar',
|
|
'archive_posts_per_page' => 10,
|
|
'show_featured_image_single' => true,
|
|
'show_author_box' => true,
|
|
'enable_comments_posts' => true,
|
|
'enable_comments_pages' => false,
|
|
'show_post_meta' => true,
|
|
'show_post_tags' => true,
|
|
'show_post_categories' => true,
|
|
|
|
// Performance
|
|
'enable_lazy_loading' => true,
|
|
'performance_remove_emoji' => true,
|
|
'performance_remove_embeds' => false,
|
|
'performance_remove_dashicons' => true,
|
|
'performance_defer_js' => false,
|
|
'performance_minify_html' => false,
|
|
'performance_disable_gutenberg' => false,
|
|
|
|
// Related Posts
|
|
'enable_related_posts' => true,
|
|
'related_posts_count' => 3,
|
|
'related_posts_taxonomy' => 'category',
|
|
'related_posts_title' => __('Related Posts', 'apus-theme'),
|
|
'related_posts_columns' => 3,
|
|
|
|
// Advanced
|
|
'custom_css' => '',
|
|
'custom_js_header' => '',
|
|
'custom_js_footer' => '',
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Section Callbacks
|
|
*/
|
|
function apus_general_section_callback() {
|
|
echo '<p>' . __('Configure general theme settings including logo, branding, and social media.', 'apus-theme') . '</p>';
|
|
}
|
|
|
|
function apus_content_section_callback() {
|
|
echo '<p>' . __('Configure content display settings for posts, pages, and archives.', 'apus-theme') . '</p>';
|
|
}
|
|
|
|
function apus_performance_section_callback() {
|
|
echo '<p>' . __('Optimize your site performance with these settings.', 'apus-theme') . '</p>';
|
|
}
|
|
|
|
function apus_related_posts_section_callback() {
|
|
echo '<p>' . __('Configure related posts display on single post pages.', 'apus-theme') . '</p>';
|
|
}
|
|
|
|
/**
|
|
* Sanitize all options
|
|
*
|
|
* @param array $input The input array
|
|
* @return array The sanitized array
|
|
*/
|
|
function apus_sanitize_options($input) {
|
|
$sanitized = array();
|
|
|
|
if (!is_array($input)) {
|
|
return $sanitized;
|
|
}
|
|
|
|
// General Settings
|
|
$sanitized['site_logo'] = isset($input['site_logo']) ? absint($input['site_logo']) : 0;
|
|
$sanitized['site_favicon'] = isset($input['site_favicon']) ? absint($input['site_favicon']) : 0;
|
|
$sanitized['enable_breadcrumbs'] = isset($input['enable_breadcrumbs']) ? (bool) $input['enable_breadcrumbs'] : false;
|
|
$sanitized['breadcrumb_separator'] = isset($input['breadcrumb_separator']) ? sanitize_text_field($input['breadcrumb_separator']) : '>';
|
|
$sanitized['date_format'] = isset($input['date_format']) ? sanitize_text_field($input['date_format']) : 'd/m/Y';
|
|
$sanitized['time_format'] = isset($input['time_format']) ? sanitize_text_field($input['time_format']) : 'H:i';
|
|
$sanitized['copyright_text'] = isset($input['copyright_text']) ? wp_kses_post($input['copyright_text']) : '';
|
|
|
|
// Social Media
|
|
$social_fields = array('facebook', 'twitter', 'instagram', 'linkedin', 'youtube');
|
|
foreach ($social_fields as $social) {
|
|
$key = 'social_' . $social;
|
|
$sanitized[$key] = isset($input[$key]) ? esc_url_raw($input[$key]) : '';
|
|
}
|
|
|
|
// Content Settings
|
|
$sanitized['excerpt_length'] = isset($input['excerpt_length']) ? absint($input['excerpt_length']) : 55;
|
|
$sanitized['excerpt_more'] = isset($input['excerpt_more']) ? sanitize_text_field($input['excerpt_more']) : '...';
|
|
$sanitized['default_post_layout'] = isset($input['default_post_layout']) ? sanitize_text_field($input['default_post_layout']) : 'right-sidebar';
|
|
$sanitized['default_page_layout'] = isset($input['default_page_layout']) ? sanitize_text_field($input['default_page_layout']) : 'right-sidebar';
|
|
$sanitized['archive_posts_per_page'] = isset($input['archive_posts_per_page']) ? absint($input['archive_posts_per_page']) : 10;
|
|
$sanitized['show_featured_image_single'] = isset($input['show_featured_image_single']) ? (bool) $input['show_featured_image_single'] : false;
|
|
$sanitized['show_author_box'] = isset($input['show_author_box']) ? (bool) $input['show_author_box'] : false;
|
|
$sanitized['enable_comments_posts'] = isset($input['enable_comments_posts']) ? (bool) $input['enable_comments_posts'] : false;
|
|
$sanitized['enable_comments_pages'] = isset($input['enable_comments_pages']) ? (bool) $input['enable_comments_pages'] : false;
|
|
$sanitized['show_post_meta'] = isset($input['show_post_meta']) ? (bool) $input['show_post_meta'] : false;
|
|
$sanitized['show_post_tags'] = isset($input['show_post_tags']) ? (bool) $input['show_post_tags'] : false;
|
|
$sanitized['show_post_categories'] = isset($input['show_post_categories']) ? (bool) $input['show_post_categories'] : false;
|
|
|
|
// Performance Settings
|
|
$sanitized['enable_lazy_loading'] = isset($input['enable_lazy_loading']) ? (bool) $input['enable_lazy_loading'] : false;
|
|
$sanitized['performance_remove_emoji'] = isset($input['performance_remove_emoji']) ? (bool) $input['performance_remove_emoji'] : false;
|
|
$sanitized['performance_remove_embeds'] = isset($input['performance_remove_embeds']) ? (bool) $input['performance_remove_embeds'] : false;
|
|
$sanitized['performance_remove_dashicons'] = isset($input['performance_remove_dashicons']) ? (bool) $input['performance_remove_dashicons'] : false;
|
|
$sanitized['performance_defer_js'] = isset($input['performance_defer_js']) ? (bool) $input['performance_defer_js'] : false;
|
|
$sanitized['performance_minify_html'] = isset($input['performance_minify_html']) ? (bool) $input['performance_minify_html'] : false;
|
|
$sanitized['performance_disable_gutenberg'] = isset($input['performance_disable_gutenberg']) ? (bool) $input['performance_disable_gutenberg'] : false;
|
|
|
|
// Related Posts
|
|
$sanitized['enable_related_posts'] = isset($input['enable_related_posts']) ? (bool) $input['enable_related_posts'] : false;
|
|
$sanitized['related_posts_count'] = isset($input['related_posts_count']) ? absint($input['related_posts_count']) : 3;
|
|
$sanitized['related_posts_taxonomy'] = isset($input['related_posts_taxonomy']) ? sanitize_text_field($input['related_posts_taxonomy']) : 'category';
|
|
$sanitized['related_posts_title'] = isset($input['related_posts_title']) ? sanitize_text_field($input['related_posts_title']) : __('Related Posts', 'apus-theme');
|
|
$sanitized['related_posts_columns'] = isset($input['related_posts_columns']) ? absint($input['related_posts_columns']) : 3;
|
|
|
|
// Advanced Settings
|
|
$sanitized['custom_css'] = isset($input['custom_css']) ? apus_sanitize_css($input['custom_css']) : '';
|
|
$sanitized['custom_js_header'] = isset($input['custom_js_header']) ? apus_sanitize_js($input['custom_js_header']) : '';
|
|
$sanitized['custom_js_footer'] = isset($input['custom_js_footer']) ? apus_sanitize_js($input['custom_js_footer']) : '';
|
|
|
|
return $sanitized;
|
|
}
|
|
|
|
/**
|
|
* Sanitize CSS
|
|
*
|
|
* @param string $css The CSS string
|
|
* @return string The sanitized CSS
|
|
*/
|
|
function apus_sanitize_css($css) {
|
|
// Remove <script> tags
|
|
$css = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $css);
|
|
// Remove potential PHP code
|
|
$css = preg_replace('#<\?php(.*?)\?>#is', '', $css);
|
|
return wp_strip_all_tags($css);
|
|
}
|
|
|
|
/**
|
|
* Sanitize JavaScript
|
|
*
|
|
* @param string $js The JavaScript string
|
|
* @return string The sanitized JavaScript
|
|
*/
|
|
function apus_sanitize_js($js) {
|
|
// Remove <script> tags if present
|
|
$js = preg_replace('#<script(.*?)>(.*?)</script>#is', '$2', $js);
|
|
// Remove potential PHP code
|
|
$js = preg_replace('#<\?php(.*?)\?>#is', '', $js);
|
|
return trim($js);
|
|
}
|
|
|
|
/**
|
|
* Sanitize integer input
|
|
*
|
|
* @param mixed $input The input value
|
|
* @return int
|
|
*/
|
|
function apus_sanitize_integer($input) {
|
|
return absint($input);
|
|
}
|
|
|
|
/**
|
|
* Sanitize text field
|
|
*
|
|
* @param string $input The input value
|
|
* @return string
|
|
*/
|
|
function apus_sanitize_text($input) {
|
|
return sanitize_text_field($input);
|
|
}
|
|
|
|
/**
|
|
* Sanitize URL
|
|
*
|
|
* @param string $input The input value
|
|
* @return string
|
|
*/
|
|
function apus_sanitize_url($input) {
|
|
return esc_url_raw($input);
|
|
}
|
|
|
|
/**
|
|
* Sanitize HTML content
|
|
*
|
|
* @param string $input The input value
|
|
* @return string
|
|
*/
|
|
function apus_sanitize_html($input) {
|
|
return wp_kses_post($input);
|
|
}
|