95 lines
2.9 KiB
PHP
95 lines
2.9 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
function mystat_settings_page() {
|
|
?>
|
|
<div class="wrap">
|
|
<h1>Ustawienia Wtyczki Statystyk</h1>
|
|
<form method="post" action="options.php">
|
|
<?php
|
|
settings_fields( 'mystat_privacy_settings' );
|
|
do_settings_sections( 'mystat-privacy-section' );
|
|
submit_button();
|
|
?>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
function mystat_register_settings() {
|
|
register_setting(
|
|
'mystat_privacy_settings',
|
|
'mystat_privacy_options',
|
|
'mystat_sanitize_privacy_options'
|
|
);
|
|
|
|
add_settings_section(
|
|
'mystat_privacy_zone_section',
|
|
'Strefa Prywatności GPX',
|
|
'mystat_privacy_section_callback',
|
|
'mystat-privacy-section'
|
|
);
|
|
|
|
add_settings_field(
|
|
'mystat_privacy_latitude',
|
|
'Szerokość geograficzna (Latitude)',
|
|
'mystat_render_lat_field',
|
|
'mystat-privacy-section',
|
|
'mystat_privacy_zone_section'
|
|
);
|
|
|
|
add_settings_field(
|
|
'mystat_privacy_longitude',
|
|
'Długość geograficzna (Longitude)',
|
|
'mystat_render_lon_field',
|
|
'mystat-privacy-section',
|
|
'mystat_privacy_zone_section'
|
|
);
|
|
|
|
add_settings_field(
|
|
'mystat_privacy_radius',
|
|
'Promień strefy (w metrach)',
|
|
'mystat_render_radius_field',
|
|
'mystat-privacy-section',
|
|
'mystat_privacy_zone_section'
|
|
);
|
|
}
|
|
|
|
function mystat_privacy_section_callback() {
|
|
echo '<p>Zdefiniuj strefę prywatności, aby ukryć początek i koniec swoich tras GPX. Punkty wewnątrz tego okręgu nie będą wyświetlane na mapie.</p>';
|
|
echo '<p>Aby znaleźć swoje współrzędne, kliknij prawym przyciskiem myszy na mapie Google w wybranym miejscu - współrzędne pojawią się jako pierwsza pozycja w menu.</p>';
|
|
}
|
|
|
|
function mystat_render_lat_field() {
|
|
$options = get_option( 'mystat_privacy_options' );
|
|
$latitude = isset( $options['latitude'] ) ? esc_attr( $options['latitude'] ) : '';
|
|
echo "<input type='text' name='mystat_privacy_options[latitude]' value='{$latitude}' placeholder='np. 52.2297' class='regular-text' />";
|
|
}
|
|
|
|
function mystat_render_lon_field() {
|
|
$options = get_option( 'mystat_privacy_options' );
|
|
$longitude = isset( $options['longitude'] ) ? esc_attr( $options['longitude'] ) : '';
|
|
echo "<input type='text' name='mystat_privacy_options[longitude]' value='{$longitude}' placeholder='np. 21.0122' class='regular-text' />";
|
|
}
|
|
|
|
function mystat_render_radius_field() {
|
|
$options = get_option( 'mystat_privacy_options' );
|
|
$radius = isset( $options['radius'] ) ? esc_attr( $options['radius'] ) : '500';
|
|
echo "<input type='number' name='mystat_privacy_options[radius]' value='{$radius}' class='small-text' /> metrów";
|
|
}
|
|
|
|
function mystat_sanitize_privacy_options( $input ) {
|
|
$sanitized_input = array();
|
|
if ( isset( $input['latitude'] ) ) {
|
|
$sanitized_input['latitude'] = floatval( str_replace( ',', '.', $input['latitude'] ) );
|
|
}
|
|
if ( isset( $input['longitude'] ) ) {
|
|
$sanitized_input['longitude'] = floatval( str_replace( ',', '.', $input['longitude'] ) );
|
|
}
|
|
if ( isset( $input['radius'] ) ) {
|
|
$sanitized_input['radius'] = abs( intval( $input['radius'] ) );
|
|
}
|
|
return $sanitized_input;
|
|
}
|