backup: estado antes de limpieza de defaults

This commit is contained in:
FrankZamora
2025-11-13 21:45:11 -06:00
parent d73e0dc9cd
commit 0038ad502c
38 changed files with 9495 additions and 512 deletions

View File

@@ -0,0 +1,237 @@
<?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'
);
// Social Share Settings Section
add_settings_section(
'apus_social_share_section',
__('Social Share Buttons', 'apus-theme'),
'apus_social_share_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(__('&copy; %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,
// Social Share Buttons
'apus_enable_share_buttons' => '1',
'apus_share_text' => __('Compartir:', 'apus-theme'),
// 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>';
}
function apus_social_share_section_callback() {
echo '<p>' . __('Configure social share buttons 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;
// Social Share Buttons
$sanitized['apus_enable_share_buttons'] = isset($input['apus_enable_share_buttons']) ? sanitize_text_field($input['apus_enable_share_buttons']) : '1';
$sanitized['apus_share_text'] = isset($input['apus_share_text']) ? sanitize_text_field($input['apus_share_text']) : __('Compartir:', 'apus-theme');
// 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;
}
/**
* NOTE: All sanitization functions have been moved to inc/sanitize-functions.php
* to avoid function redeclaration errors. This includes:
* - apus_sanitize_css()
* - apus_sanitize_js()
* - apus_sanitize_integer()
* - apus_sanitize_text()
* - apus_sanitize_url()
* - apus_sanitize_html()
* - apus_sanitize_checkbox()
* - apus_sanitize_select()
*/