$options_key) { $args = []; if ($configured === 'debug-mode') { $args['sanitize_callback'] = function ($value): int { return (int) filter_var($value, FILTER_VALIDATE_BOOLEAN); }; $args['default'] = 0; } elseif ($configured === 'new-user-role') { $args['sanitize_callback'] = fn ($value): string => $this->sanitize_new_user_role($value); $args['default'] = 'wordpress_default'; } register_setting(config('mahak.settings-group'), $options_key, $args); } add_settings_section( config('mahak.section-id'), config('mahak.translations.section-id'), null, config('mahak.settings-page') ); add_settings_field( config('mahak.options.user-identifier'), config('mahak.translations.user-identifier'), fn () => $this->user_identifier(), config('mahak.settings-page'), config('mahak.section-id') ); add_settings_field( config('mahak.options.jwt-secret'), config('mahak.translations.jwt-secret'), fn () => $this->jwt_secret(), config('mahak.settings-page'), config('mahak.section-id') ); add_settings_field( config('mahak.options.login-route'), config('mahak.translations.login-route'), fn () => $this->login_route(), config('mahak.settings-page'), config('mahak.section-id') ); add_settings_field( config('mahak.options.after-login-route'), config('mahak.translations.after-login-route'), fn () => $this->after_login_route(), config('mahak.settings-page'), config('mahak.section-id') ); add_settings_field( config('mahak.options.new-user-role'), config('mahak.translations.new-user-role'), fn () => $this->new_user_role(), config('mahak.settings-page'), config('mahak.section-id') ); add_settings_field( config('mahak.options.debug-mode'), config('mahak.translations.debug-mode'), fn () => $this->debug_mode(), config('mahak.settings-page'), config('mahak.section-id') ); $loginRouteOptionName = config('mahak.options.login-route'); add_filter("pre_update_option_{$loginRouteOptionName}", function ($value) { return trim($value, '/'); }); $afterLoginRouteOptionName = config('mahak.options.after-login-route'); add_filter("pre_update_option_{$afterLoginRouteOptionName}", function ($value) { return trim($value, '/'); }); } public function user_identifier(): void { $name = config('mahak.options.user-identifier'); $value = get_option($name, 'mobile'); $html = ""; echo $html; } public function jwt_secret(): void { $name = config('mahak.options.jwt-secret'); $value = esc_attr(get_option($name, '')); echo ""; } public function login_route(): void { $name = config('mahak.options.login-route'); $value = esc_attr(get_option($name, config('mahak.login_route_default'))); echo '
'.esc_html(config('mahak.translations.new-user-role-description')).'
'; } public function sanitize_new_user_role($value): string { $role = sanitize_key((string) $value); if ($role === 'wordpress_default') { return $role; } if (get_role($role) !== null) { return $role; } add_settings_error( config('mahak.options.new-user-role'), 'mahak_invalid_new_user_role', 'نقش انتخابشده معتبر نیست. نقش پیشفرض وردپرس استفاده شد.' ); return 'wordpress_default'; } }