HEX
Server: LiteSpeed
System: Linux prometheus.hongkongserver.net 4.18.0-553.134.1.el8_10.x86_64 #1 SMP Tue Jun 16 16:05:57 EDT 2026 x86_64
User: ayxmplky (1112)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/ayxmplky/public_html/wp-content/themes/tactic/inc/admin-contact-settings.php
<?php
/**
 * WP Admin: единая страница контактных данных
 * WP Admin -> TACTIC -> Контакты
 *
 * @package tactic
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function tactic_contact_settings_menu(): void {
	add_submenu_page(
		'tactic-translations',
		'TACTIC - Контакты',
		'Контакты',
		'manage_options',
		'tactic-contact-settings',
		'tactic_contact_settings_page'
	);
}
add_action( 'admin_menu', 'tactic_contact_settings_menu' );

function tactic_contact_settings_page(): void {
	if ( ! current_user_can( 'manage_options' ) ) {
		return;
	}

	$notice = '';

	$contact_fields = [
		'tactic_address_cn'               => [ 'label' => 'Адрес (ZH)',                                  'type' => 'textarea', 'sanitize' => 'sanitize_textarea_field' ],
		'tactic_address_en'               => [ 'label' => 'Address (EN)',                                'type' => 'textarea', 'sanitize' => 'sanitize_textarea_field' ],
		'tactic_postal_code'              => [ 'label' => 'Postal Code',                                 'type' => 'text',     'sanitize' => 'sanitize_text_field' ],
		'tactic_email_global'             => [ 'label' => 'Email (China block)',                         'type' => 'email',    'sanitize' => 'sanitize_email' ],
		'tactic_email_eu'                 => [ 'label' => 'Email (Europe)',                              'type' => 'email',    'sanitize' => 'sanitize_email' ],
		'tactic_contact_main_website_url' => [ 'label' => 'Main Website URL (кнопка в модальном окне)', 'type' => 'url',      'sanitize' => 'esc_url_raw' ],
	];

	$modal_translation_fields = [
		'contact_modal_title' => [ 'label' => 'Заголовок модального окна',        'type' => 'text' ],
		'contact_modal_text'  => [ 'label' => 'Текст модального окна',             'type' => 'textarea' ],
		'contact_modal_stay'  => [ 'label' => 'Кнопка "Stay on this page"',      'type' => 'text' ],
		'contact_modal_go'    => [ 'label' => 'Кнопка "Go to main website"',     'type' => 'text' ],
	];

	$defaults              = require TACTIC_DIR . '/inc/strings.php';
	$translation_overrides = (array) get_option( 'tactic_translations', [] );
	$strings               = array_replace_recursive( $defaults, $translation_overrides );

	if (
		isset( $_POST['tactic_contact_settings_nonce'] )
		&& wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['tactic_contact_settings_nonce'] ) ), 'tactic_save_contact_settings' )
	) {
		foreach ( $contact_fields as $id => $meta ) {
			$raw   = isset( $_POST[ $id ] ) ? wp_unslash( $_POST[ $id ] ) : '';
			$value = '';

			if ( is_string( $raw ) ) {
				$sanitize = $meta['sanitize'];
				if ( is_callable( $sanitize ) ) {
					$value = $sanitize( $raw );
				}
			}

			set_theme_mod( $id, $value );
		}

		$input_modal_strings = isset( $_POST['tactic_modal_strings'] ) && is_array( $_POST['tactic_modal_strings'] )
			? $_POST['tactic_modal_strings']
			: [];

		$updated_overrides = $translation_overrides;

		foreach ( $modal_translation_fields as $key => $meta ) {
			foreach ( [ 'zh', 'en' ] as $lang ) {
				$current = (string) ( $strings[ $key ][ $lang ] ?? '' );
				$raw     = $input_modal_strings[ $key ][ $lang ] ?? $current;

				if ( ! is_string( $raw ) ) {
					$raw = '';
				} else {
					$raw = wp_unslash( $raw );
				}

				$clean = $meta['type'] === 'textarea'
					? sanitize_textarea_field( $raw )
					: sanitize_text_field( $raw );

				if ( ! isset( $updated_overrides[ $key ] ) || ! is_array( $updated_overrides[ $key ] ) ) {
					$updated_overrides[ $key ] = [];
				}

				$updated_overrides[ $key ][ $lang ] = $clean;
			}
		}

		update_option( 'tactic_translations', $updated_overrides );
		tactic_s( '__reset__' );

		$translation_overrides = $updated_overrides;
		$strings               = array_replace_recursive( $defaults, $translation_overrides );

		$notice = '<div class="notice notice-success is-dismissible"><p>Контактные данные сохранены.</p></div>';
	}
	?>
	<div class="wrap">
		<h1>TACTIC - Контакты</h1>
		<p style="max-width:900px;color:#646970;">Здесь редактируются данные блока внизу страницы Contact, локали модального окна после отправки формы и ссылка кнопки main website.</p>
		<?php echo wp_kses_post( $notice ); ?>

		<form method="post">
			<?php wp_nonce_field( 'tactic_save_contact_settings', 'tactic_contact_settings_nonce' ); ?>
			<table class="form-table" role="presentation">
				<tbody>
					<?php foreach ( $contact_fields as $id => $meta ) : ?>
						<?php $value = (string) get_theme_mod( $id, '' ); ?>
						<tr>
							<th scope="row"><label for="<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $meta['label'] ); ?></label></th>
							<td>
								<?php if ( $meta['type'] === 'textarea' ) : ?>
									<textarea
										name="<?php echo esc_attr( $id ); ?>"
										id="<?php echo esc_attr( $id ); ?>"
										rows="3"
										class="large-text"
									><?php echo esc_textarea( $value ); ?></textarea>
								<?php else : ?>
									<input
										type="<?php echo esc_attr( $meta['type'] ); ?>"
										name="<?php echo esc_attr( $id ); ?>"
										id="<?php echo esc_attr( $id ); ?>"
										value="<?php echo esc_attr( $value ); ?>"
										class="regular-text"
									>
								<?php endif; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>

			<h2 style="margin-top:24px;">Локали модального окна после отправки формы</h2>
			<table class="widefat striped" style="max-width:1100px;">
				<thead>
					<tr>
						<th style="width:260px;">Поле</th>
						<th>Китайский (zh)</th>
						<th>Английский (en)</th>
					</tr>
				</thead>
				<tbody>
					<?php foreach ( $modal_translation_fields as $key => $meta ) : ?>
						<?php
						$zh_val = (string) ( $strings[ $key ]['zh'] ?? '' );
						$en_val = (string) ( $strings[ $key ]['en'] ?? '' );
						?>
						<tr>
							<td>
								<strong><?php echo esc_html( $meta['label'] ); ?></strong><br>
								<code><?php echo esc_html( $key ); ?></code>
							</td>
							<td>
								<?php if ( $meta['type'] === 'textarea' ) : ?>
									<textarea
										name="tactic_modal_strings[<?php echo esc_attr( $key ); ?>][zh]"
										rows="3"
										class="large-text"
									><?php echo esc_textarea( $zh_val ); ?></textarea>
								<?php else : ?>
									<input
										type="text"
										name="tactic_modal_strings[<?php echo esc_attr( $key ); ?>][zh]"
										value="<?php echo esc_attr( $zh_val ); ?>"
										class="large-text"
									>
								<?php endif; ?>
							</td>
							<td>
								<?php if ( $meta['type'] === 'textarea' ) : ?>
									<textarea
										name="tactic_modal_strings[<?php echo esc_attr( $key ); ?>][en]"
										rows="3"
										class="large-text"
									><?php echo esc_textarea( $en_val ); ?></textarea>
								<?php else : ?>
									<input
										type="text"
										name="tactic_modal_strings[<?php echo esc_attr( $key ); ?>][en]"
										value="<?php echo esc_attr( $en_val ); ?>"
										class="large-text"
									>
								<?php endif; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
			<p class="description" style="max-width:1100px; margin-top:8px;">
				Эти значения обновляют те же ключи, что и раздел TACTIC → Переводы, и используются в модальном окне после успешной отправки формы.
			</p>

			<?php submit_button( 'Сохранить контакты' ); ?>
		</form>
	</div>
	<?php
}