hesabixWpTheme/inc/theme-settings.php

461 lines
20 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* تنظیمات قالب Hesabix2 در پیشخوان وردپرس
*
* مسیر: ظاهر → تنظیمات قالب
*
* @package Hesabix2
*/
if (!defined('ABSPATH')) {
exit;
}
/**
* ثبت منو و تنظیمات.
*/
function hesabix2_theme_settings_bootstrap() {
add_action('admin_menu', 'hesabix2_theme_settings_menu');
add_action('admin_init', 'hesabix2_theme_settings_register');
}
add_action('after_setup_theme', 'hesabix2_theme_settings_bootstrap', 40);
/**
* منوی ظاهر → تنظیمات قالب
*/
function hesabix2_theme_settings_menu() {
add_theme_page(
__('تنظیمات قالب حسابیکس', 'hesabix2'),
__('تنظیمات قالب', 'hesabix2'),
'manage_options',
'hesabix2-theme-settings',
'hesabix2_theme_settings_render_page'
);
}
/**
* گزینه‌های قابل ذخیره.
*
* @return array<string, array{type: string, sanitize_callback: callable, default: string}>
*/
function hesabix2_theme_settings_option_defs() {
return array(
'hesabix2_android_apk_url' => array(
'type' => 'string',
'sanitize_callback' => 'hesabix2_theme_settings_sanitize_url',
'default' => 'https://cdn.hesabix.ir/android/hesabix-latest.apk',
),
'hesabix2_android_app_version' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '1.0.0',
),
'hesabix2_android_min_os' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => 'Android 8.0+',
),
'hesabix2_android_apk_size' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '≈ ۳۵ مگابایت',
),
'hesabix2_windows_msi_url' => array(
'type' => 'string',
'sanitize_callback' => 'hesabix2_theme_settings_sanitize_url',
'default' => 'https://source.hesabix.ir/hesabix/arc/releases/download/70.11.900/hesabix-windows.70.11.900.msi',
),
'hesabix2_windows_releases_url' => array(
'type' => 'string',
'sanitize_callback' => 'hesabix2_theme_settings_sanitize_url',
'default' => 'https://source.hesabix.ir/hesabix/arc/releases',
),
'hesabix2_windows_app_version' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '70.11.900',
),
'hesabix2_windows_min_os' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => 'Windows 10 / 11 (64-bit)',
),
'hesabix2_windows_msi_size' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '≈ ۳۳ مگابایت',
),
'hesabix2_helo_migrator_url' => array(
'type' => 'string',
'sanitize_callback' => 'hesabix2_theme_settings_sanitize_url',
'default' => '',
),
'hesabix2_helo_migrator_version' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '1.0.0',
),
'hesabix2_helo_migrator_min_os' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => 'Windows 10 / 11 (64-bit)',
),
'hesabix2_helo_migrator_size' => array(
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'default' => '≈ ۱۵ مگابایت',
),
);
}
/**
* @param mixed $value
* @return string
*/
function hesabix2_theme_settings_sanitize_url($value) {
$value = is_string($value) ? trim($value) : '';
if ($value === '') {
return '';
}
return esc_url_raw($value);
}
/**
* ثبت settings API.
*/
function hesabix2_theme_settings_register() {
foreach (hesabix2_theme_settings_option_defs() as $option => $def) {
register_setting(
'hesabix2_theme_settings',
$option,
array(
'type' => $def['type'],
'sanitize_callback' => $def['sanitize_callback'],
'default' => $def['default'],
'show_in_rest' => false,
)
);
}
}
/**
* مقدار ذخیره‌شده یا پیش‌فرض.
*
* @param string $option
* @return string
*/
function hesabix2_theme_settings_get($option) {
$defs = hesabix2_theme_settings_option_defs();
$default = isset($defs[$option]['default']) ? (string) $defs[$option]['default'] : '';
$value = get_option($option, $default);
return is_string($value) ? $value : $default;
}
/**
* رندر صفحهٔ تنظیمات.
*/
function hesabix2_theme_settings_render_page() {
if (!current_user_can('manage_options')) {
return;
}
$page_url = function_exists('hesabix2_android_page_url')
? hesabix2_android_page_url()
: home_url('/android/');
$apk_url = hesabix2_theme_settings_get('hesabix2_android_apk_url');
$version = hesabix2_theme_settings_get('hesabix2_android_app_version');
$min_os = hesabix2_theme_settings_get('hesabix2_android_min_os');
$apk_size = hesabix2_theme_settings_get('hesabix2_android_apk_size');
$win_page_url = function_exists('hesabix2_windows_page_url')
? hesabix2_windows_page_url()
: home_url('/windows/');
$msi_url = hesabix2_theme_settings_get('hesabix2_windows_msi_url');
$releases_url = hesabix2_theme_settings_get('hesabix2_windows_releases_url');
$win_version = hesabix2_theme_settings_get('hesabix2_windows_app_version');
$win_min_os = hesabix2_theme_settings_get('hesabix2_windows_min_os');
$msi_size = hesabix2_theme_settings_get('hesabix2_windows_msi_size');
$helo_page_url = function_exists('hesabix2_helo_page_url')
? hesabix2_helo_page_url()
: home_url('/helo/');
$helo_url = hesabix2_theme_settings_get('hesabix2_helo_migrator_url');
$helo_version = hesabix2_theme_settings_get('hesabix2_helo_migrator_version');
$helo_min_os = hesabix2_theme_settings_get('hesabix2_helo_migrator_min_os');
$helo_size = hesabix2_theme_settings_get('hesabix2_helo_migrator_size');
?>
<div class="wrap">
<h1><?php esc_html_e('تنظیمات قالب حسابیکس', 'hesabix2'); ?></h1>
<p class="description" style="max-width:42rem;">
<?php esc_html_e('تنظیمات نمایشی قالب Hesabix2. تغییرات بلافاصله روی سایت اعمال می‌شوند.', 'hesabix2'); ?>
</p>
<?php settings_errors('hesabix2_theme_settings'); ?>
<form method="post" action="options.php">
<?php settings_fields('hesabix2_theme_settings'); ?>
<h2 class="title" style="margin-top:1.75rem;"><?php esc_html_e('اپلیکیشن اندروید', 'hesabix2'); ?></h2>
<p>
<?php
printf(
/* translators: %s: public android page URL */
esc_html__('صفحهٔ عمومی انتشار: %s', 'hesabix2'),
'<a href="' . esc_url($page_url) . '" target="_blank" rel="noopener noreferrer">' . esc_html($page_url) . '</a>'
);
?>
</p>
<table class="form-table" role="presentation">
<tr>
<th scope="row">
<label for="hesabix2_android_apk_url"><?php esc_html_e('لینک دانلود APK', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_android_apk_url"
id="hesabix2_android_apk_url"
type="url"
class="large-text"
dir="ltr"
value="<?php echo esc_attr($apk_url); ?>"
placeholder="https://cdn.hesabix.ir/android/hesabix-latest.apk"
/>
<p class="description">
<?php esc_html_e('آدرس مستقیم فایل APK (خارج از مارکت). همین لینک روی دکمهٔ دانلود صفحهٔ اندروید قرار می‌گیرد.', 'hesabix2'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_android_app_version"><?php esc_html_e('نسخهٔ اپ', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_android_app_version"
id="hesabix2_android_app_version"
type="text"
class="regular-text"
dir="ltr"
value="<?php echo esc_attr($version); ?>"
placeholder="1.0.0"
/>
<p class="description"><?php esc_html_e('مثلاً 1.0.0 — روی صفحه به‌صورت v1.0.0 نمایش داده می‌شود.', 'hesabix2'); ?></p>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_android_min_os"><?php esc_html_e('حداقل سیستم‌عامل', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_android_min_os"
id="hesabix2_android_min_os"
type="text"
class="regular-text"
dir="ltr"
value="<?php echo esc_attr($min_os); ?>"
placeholder="Android 8.0+"
/>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_android_apk_size"><?php esc_html_e('حجم تقریبی', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_android_apk_size"
id="hesabix2_android_apk_size"
type="text"
class="regular-text"
value="<?php echo esc_attr($apk_size); ?>"
placeholder="≈ ۳۵ مگابایت"
/>
<p class="description"><?php esc_html_e('متن نمایشی برای کاربر؛ لازم نیست دقیق باشد.', 'hesabix2'); ?></p>
</td>
</tr>
</table>
<h2 class="title" style="margin-top:2.5rem;"><?php esc_html_e('اپلیکیشن ویندوز', 'hesabix2'); ?></h2>
<p>
<?php
printf(
/* translators: %s: public windows page URL */
esc_html__('صفحهٔ عمومی انتشار: %s', 'hesabix2'),
'<a href="' . esc_url($win_page_url) . '" target="_blank" rel="noopener noreferrer">' . esc_html($win_page_url) . '</a>'
);
?>
</p>
<table class="form-table" role="presentation">
<tr>
<th scope="row">
<label for="hesabix2_windows_msi_url"><?php esc_html_e('لینک دانلود MSI', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_windows_msi_url"
id="hesabix2_windows_msi_url"
type="url"
class="large-text"
dir="ltr"
value="<?php echo esc_attr($msi_url); ?>"
placeholder="https://source.hesabix.ir/hesabix/arc/releases/download/70.11.900/hesabix-windows.70.11.900.msi"
/>
<p class="description">
<?php esc_html_e('آدرس مستقیم فایل نصب ویندوز. از صفحهٔ ریلیزهای آرک می‌توانید لینک آخرین نسخه را کپی کنید.', 'hesabix2'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_windows_releases_url"><?php esc_html_e('صفحهٔ ریلیزها', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_windows_releases_url"
id="hesabix2_windows_releases_url"
type="url"
class="large-text"
dir="ltr"
value="<?php echo esc_attr($releases_url); ?>"
placeholder="https://source.hesabix.ir/hesabix/arc/releases"
/>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_windows_app_version"><?php esc_html_e('نسخهٔ اپ', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_windows_app_version"
id="hesabix2_windows_app_version"
type="text"
class="regular-text"
dir="ltr"
value="<?php echo esc_attr($win_version); ?>"
placeholder="70.11.900"
/>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_windows_min_os"><?php esc_html_e('حداقل سیستم‌عامل', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_windows_min_os"
id="hesabix2_windows_min_os"
type="text"
class="regular-text"
dir="ltr"
value="<?php echo esc_attr($win_min_os); ?>"
placeholder="Windows 10 / 11 (64-bit)"
/>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_windows_msi_size"><?php esc_html_e('حجم تقریبی', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_windows_msi_size"
id="hesabix2_windows_msi_size"
type="text"
class="regular-text"
value="<?php echo esc_attr($msi_size); ?>"
placeholder="≈ ۳۳ مگابایت"
/>
</td>
</tr>
</table>
<h2 class="title" style="margin-top:2.5rem;"><?php esc_html_e('مهاجرت از هلو', 'hesabix2'); ?></h2>
<p>
<?php
printf(
/* translators: %s: public helo migration page URL */
esc_html__('صفحهٔ عمومی مهاجرت: %s', 'hesabix2'),
'<a href="' . esc_url($helo_page_url) . '" target="_blank" rel="noopener noreferrer">' . esc_html($helo_page_url) . '</a>'
);
?>
</p>
<table class="form-table" role="presentation">
<tr>
<th scope="row">
<label for="hesabix2_helo_migrator_url"><?php esc_html_e('لینک دانلود انتقال‌دهنده', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_helo_migrator_url"
id="hesabix2_helo_migrator_url"
type="url"
class="large-text"
dir="ltr"
value="<?php echo esc_attr($helo_url); ?>"
placeholder="https://cdn.hesabix.ir/tools/helo-migrator.exe"
/>
<p class="description">
<?php esc_html_e('آدرس مستقیم فایل برنامهٔ انتقال داده از هلو به آرک. همین لینک روی دکمهٔ دانلود صفحهٔ مهاجرت قرار می‌گیرد. اگر خالی باشد، دکمه به‌صورت غیرفعال نمایش داده می‌شود.', 'hesabix2'); ?>
</p>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_helo_migrator_version"><?php esc_html_e('نسخهٔ انتقال‌دهنده', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_helo_migrator_version"
id="hesabix2_helo_migrator_version"
type="text"
class="regular-text"
dir="ltr"
value="<?php echo esc_attr($helo_version); ?>"
placeholder="1.0.0"
/>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_helo_migrator_min_os"><?php esc_html_e('حداقل سیستم‌عامل', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_helo_migrator_min_os"
id="hesabix2_helo_migrator_min_os"
type="text"
class="regular-text"
dir="ltr"
value="<?php echo esc_attr($helo_min_os); ?>"
placeholder="Windows 10 / 11 (64-bit)"
/>
</td>
</tr>
<tr>
<th scope="row">
<label for="hesabix2_helo_migrator_size"><?php esc_html_e('حجم تقریبی', 'hesabix2'); ?></label>
</th>
<td>
<input
name="hesabix2_helo_migrator_size"
id="hesabix2_helo_migrator_size"
type="text"
class="regular-text"
value="<?php echo esc_attr($helo_size); ?>"
placeholder="≈ ۱۵ مگابایت"
/>
</td>
</tr>
</table>
<?php submit_button(__('ذخیرهٔ تنظیمات', 'hesabix2')); ?>
</form>
</div>
<?php
}