implement settings-page
This commit is contained in:
@@ -32,6 +32,8 @@ add_action('init', function () {
|
||||
exit();
|
||||
});
|
||||
|
||||
require_once 'settings-page.php';
|
||||
|
||||
function verify_laravel_token_and_get_user_id($token): bool|int
|
||||
{
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
add_action('admin_menu', function () {
|
||||
add_options_page(
|
||||
config('da.translations.settings-page-title'),
|
||||
config('da.translations.settings-page-menu'),
|
||||
'manage_options',
|
||||
config('da.settings-page'),
|
||||
'dabestaniha_authenticate_settings_page'
|
||||
);
|
||||
});
|
||||
|
||||
add_action('admin_init', function () {
|
||||
|
||||
register_setting(config('da.settings-group'), config('da.options.jwt-secret'));
|
||||
register_setting(config('da.settings-group'), config('da.options.user-identifier'));
|
||||
register_setting(config('da.settings-group'), config('da.options.login-route'));
|
||||
|
||||
add_settings_section(
|
||||
config('da.section-id'),
|
||||
config('da.translations.section-id'),
|
||||
null,
|
||||
config('da.settings-page')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('da.options.user-identifier'),
|
||||
config('da.translations.user-identifier'),
|
||||
function () {
|
||||
$name = config('da.options.user-identifier');
|
||||
$value = get_option($name, 'mobile');
|
||||
|
||||
$html = "<select name='$name'>";
|
||||
|
||||
foreach (config('da.user-identifiers') as $identifier) {
|
||||
$selected = $value === $identifier ? "selected='selected'" : null;
|
||||
$translate = config("da.translations.$identifier");
|
||||
$html .= "<option value='$identifier' $selected>$translate</option>";
|
||||
}
|
||||
|
||||
$html .= "</select>";
|
||||
echo $html;
|
||||
},
|
||||
config('da.settings-page'),
|
||||
config('da.section-id')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('da.options.jwt-secret'),
|
||||
config('da.translations.jwt-secret'),
|
||||
function () {
|
||||
$name = config('da.options.jwt-secret');
|
||||
$value = esc_attr(get_option($name, ''));
|
||||
echo "<input type='text' name='$name' value='$value' class='regular-text ltr' />";
|
||||
},
|
||||
config('da.settings-page'),
|
||||
config('da.section-id')
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
config('da.options.login-route'),
|
||||
config('da.translations.login-route'),
|
||||
function () {
|
||||
$name = config('da.options.login-route');
|
||||
$value = esc_attr(get_option($name, config('da.login_route_default')));
|
||||
echo "<input type='text' name=$name value='$value' class='regular-text ltr' />";
|
||||
},
|
||||
config('da.settings-page'),
|
||||
config('da.section-id')
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
function dabestaniha_authenticate_settings_page(): void
|
||||
{
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?= config('da.translations.settings-page-title') ?></h1>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
settings_fields(config('da.settings-group'));
|
||||
do_settings_sections(config('da.settings-page'));
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'settings-page' => 'dabestaniha-authenticate-settings',
|
||||
'settings-group' => 'dabestaniha_authenticate_settings',
|
||||
'section-id' => 'dabestaniha_authenticate_main',
|
||||
|
||||
|
||||
'options' => [
|
||||
'jwt-secret' => 'da_jwt_secret',
|
||||
'user-identifier' => 'da_user_identifier',
|
||||
'login-route' => 'da_login_route',
|
||||
],
|
||||
|
||||
'user-identifiers' => [
|
||||
'mobile',
|
||||
'email',
|
||||
'username',
|
||||
],
|
||||
|
||||
'login_route_default' => 'dabestaniha/login',
|
||||
|
||||
'translations' => [
|
||||
'mobile' => 'تلفن همراه',
|
||||
'email' => 'ایمیل',
|
||||
'username' => 'نام کاربری',
|
||||
|
||||
'section-id' => 'تنظیمات عمومی',
|
||||
'settings-page-title' => 'تنظیمات احراز هویت دبستانی ها',
|
||||
'settings-page-menu' => 'احراز هویت دبستانی ها',
|
||||
|
||||
'jwt-secret' => 'کلید JWT',
|
||||
'user-identifier' => 'فیلد شناسایی کاربر',
|
||||
'login-route' => 'آدرس لاگین از لاراول',
|
||||
],
|
||||
];
|
||||
@@ -16,3 +16,20 @@ if (!function_exists('dd')) {
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
define("DA_CASHED_CONFIG", [
|
||||
'da' => require plugin_dir_path(__FILE__) . 'configs/da.php',
|
||||
]);
|
||||
|
||||
|
||||
if (!function_exists('config')) {
|
||||
function config(string $key, ?string $default = null): null|string|array
|
||||
{
|
||||
$value = DA_CASHED_CONFIG;
|
||||
foreach (explode('.', $key) as $key) {
|
||||
$value = $value[$key] ?? $default;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user