backup: estado antes de limpieza de defaults
This commit is contained in:
418
inc/theme-settings.php
Normal file
418
inc/theme-settings.php
Normal file
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
/**
|
||||
* Theme Settings Helper Functions
|
||||
*
|
||||
* Funciones helper para leer configuraciones del tema desde la tabla personalizada
|
||||
*
|
||||
* @package Apus_Theme
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme setting value from custom table
|
||||
*
|
||||
* @param string $setting_name The setting name
|
||||
* @param mixed $default Default value if setting doesn't exist
|
||||
* @return mixed The setting value
|
||||
*/
|
||||
function apus_get_setting($setting_name, $default = '') {
|
||||
// Cache estático para optimizar performance
|
||||
static $db_manager = null;
|
||||
static $settings_cache = null;
|
||||
|
||||
// Inicializar DB Manager una sola vez
|
||||
if ($db_manager === null) {
|
||||
$db_manager = new APUS_DB_Manager();
|
||||
}
|
||||
|
||||
// Cargar todas las configuraciones una sola vez por request
|
||||
if ($settings_cache === null) {
|
||||
$settings_cache = $db_manager->get_config('theme');
|
||||
|
||||
// Si no hay configuraciones en la tabla, intentar desde wp_options
|
||||
// (backward compatibility durante migración)
|
||||
if (empty($settings_cache)) {
|
||||
$settings_cache = get_option('apus_theme_options', array());
|
||||
}
|
||||
}
|
||||
|
||||
// Retornar valor específico
|
||||
if (isset($settings_cache[$setting_name])) {
|
||||
return $settings_cache[$setting_name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get theme option value (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use apus_get_setting() instead
|
||||
* @param string $option_name The option name
|
||||
* @param mixed $default Default value if option doesn't exist
|
||||
* @return mixed The option value
|
||||
*/
|
||||
function apus_get_option($option_name, $default = '') {
|
||||
return apus_get_setting($option_name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if setting is enabled (checkbox/switch)
|
||||
*
|
||||
* @param string $setting_name The setting name
|
||||
* @return bool True if enabled, false otherwise
|
||||
*/
|
||||
function apus_is_setting_enabled($setting_name) {
|
||||
return (bool) apus_get_setting($setting_name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if option is enabled (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use apus_is_setting_enabled() instead
|
||||
* @param string $option_name The option name
|
||||
* @return bool True if enabled, false otherwise
|
||||
*/
|
||||
function apus_is_option_enabled($option_name) {
|
||||
return apus_is_setting_enabled($option_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get breadcrumbs separator
|
||||
*
|
||||
* @return string The separator
|
||||
*/
|
||||
function apus_get_breadcrumb_separator() {
|
||||
return apus_get_setting('breadcrumb_separator', '>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if breadcrumbs should be shown
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_show_breadcrumbs() {
|
||||
return apus_is_setting_enabled('enable_breadcrumbs');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get excerpt length
|
||||
*
|
||||
* @return int The excerpt length
|
||||
*/
|
||||
function apus_get_excerpt_length() {
|
||||
return (int) apus_get_setting('excerpt_length', 55);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get excerpt more text
|
||||
*
|
||||
* @return string The excerpt more text
|
||||
*/
|
||||
function apus_get_excerpt_more() {
|
||||
return apus_get_setting('excerpt_more', '...');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if related posts should be shown
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_show_related_posts() {
|
||||
return apus_is_setting_enabled('enable_related_posts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of related posts to show
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function apus_get_related_posts_count() {
|
||||
return (int) apus_get_setting('related_posts_count', 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related posts taxonomy
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_related_posts_taxonomy() {
|
||||
return apus_get_setting('related_posts_taxonomy', 'category');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get related posts title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_related_posts_title() {
|
||||
return apus_get_setting('related_posts_title', __('Related Posts', 'apus-theme'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if specific performance optimization is enabled
|
||||
*
|
||||
* @param string $optimization The optimization name
|
||||
* @return bool
|
||||
*/
|
||||
function apus_is_performance_enabled($optimization) {
|
||||
return apus_is_setting_enabled('performance_' . $optimization);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get copyright text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_copyright_text() {
|
||||
$default = sprintf(
|
||||
__('© %s %s. All rights reserved.', 'apus-theme'),
|
||||
date('Y'),
|
||||
get_bloginfo('name')
|
||||
);
|
||||
return apus_get_setting('copyright_text', $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get social media links
|
||||
*
|
||||
* @return array Array of social media links
|
||||
*/
|
||||
function apus_get_social_links() {
|
||||
return array(
|
||||
'facebook' => apus_get_setting('social_facebook', ''),
|
||||
'twitter' => apus_get_setting('social_twitter', ''),
|
||||
'instagram' => apus_get_setting('social_instagram', ''),
|
||||
'linkedin' => apus_get_setting('social_linkedin', ''),
|
||||
'youtube' => apus_get_setting('social_youtube', ''),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comments are enabled for posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_comments_enabled_for_posts() {
|
||||
return apus_is_setting_enabled('enable_comments_posts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if comments are enabled for pages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_comments_enabled_for_pages() {
|
||||
return apus_is_setting_enabled('enable_comments_pages');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default post layout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_default_post_layout() {
|
||||
return apus_get_setting('default_post_layout', 'right-sidebar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default page layout
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_default_page_layout() {
|
||||
return apus_get_setting('default_page_layout', 'right-sidebar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get posts per page for archive
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function apus_get_archive_posts_per_page() {
|
||||
$custom = (int) apus_get_setting('archive_posts_per_page', 0);
|
||||
return $custom > 0 ? $custom : get_option('posts_per_page', 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if featured image should be shown on single posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_show_featured_image_single() {
|
||||
return apus_is_setting_enabled('show_featured_image_single');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if author box should be shown on single posts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_show_author_box() {
|
||||
return apus_is_setting_enabled('show_author_box');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_date_format() {
|
||||
return apus_get_setting('date_format', 'd/m/Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_time_format() {
|
||||
return apus_get_setting('time_format', 'H:i');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_logo_url() {
|
||||
$logo_id = apus_get_setting('site_logo', 0);
|
||||
if ($logo_id) {
|
||||
$logo = wp_get_attachment_image_url($logo_id, 'full');
|
||||
if ($logo) {
|
||||
return $logo;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get favicon URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_favicon_url() {
|
||||
$favicon_id = apus_get_setting('site_favicon', 0);
|
||||
if ($favicon_id) {
|
||||
$favicon = wp_get_attachment_image_url($favicon_id, 'full');
|
||||
if ($favicon) {
|
||||
return $favicon;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom CSS
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_custom_css() {
|
||||
return apus_get_setting('custom_css', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom JS (header)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_custom_js_header() {
|
||||
return apus_get_setting('custom_js_header', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom JS (footer)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_custom_js_footer() {
|
||||
return apus_get_setting('custom_js_footer', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if lazy loading is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_is_lazy_loading_enabled() {
|
||||
return apus_is_setting_enabled('enable_lazy_loading');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all theme settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function apus_get_all_settings() {
|
||||
$db_manager = new APUS_DB_Manager();
|
||||
$settings = $db_manager->get_config('theme');
|
||||
|
||||
// Backward compatibility: si no hay settings en tabla, leer de wp_options
|
||||
if (empty($settings)) {
|
||||
$settings = get_option('apus_theme_options', array());
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all theme options (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use apus_get_all_settings() instead
|
||||
* @return array
|
||||
*/
|
||||
function apus_get_all_options() {
|
||||
return apus_get_all_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset theme settings to defaults
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_reset_settings() {
|
||||
$db_manager = new APUS_DB_Manager();
|
||||
return $db_manager->delete_config('theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset theme options to defaults (ALIAS for backward compatibility)
|
||||
*
|
||||
* @deprecated 2.0.0 Use apus_reset_settings() instead
|
||||
* @return bool
|
||||
*/
|
||||
function apus_reset_options() {
|
||||
return apus_reset_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Table of Contents is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function apus_is_toc_enabled() {
|
||||
return apus_get_setting('enable_toc', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum headings required to display TOC
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function apus_get_toc_min_headings() {
|
||||
return (int) apus_get_setting('toc_min_headings', 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get TOC title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function apus_get_toc_title() {
|
||||
return apus_get_setting('toc_title', __('Table of Contents', 'apus-theme'));
|
||||
}
|
||||
Reference in New Issue
Block a user