tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support('title-tag');
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support('post-thumbnails');
// This theme uses wp_nav_menu() in one location.
register_nav_menus(
array(
'menu-1' => esc_html__('Primary', 'skysafe'),
)
);
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
)
);
// Set up the WordPress core custom background feature.
add_theme_support(
'custom-background',
apply_filters(
'skysafe_custom_background_args',
array(
'default-color' => 'ffffff',
'default-image' => '',
)
)
);
// Add theme support for selective refresh for widgets.
add_theme_support('customize-selective-refresh-widgets');
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support(
'custom-logo',
array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
)
);
}
add_action('after_setup_theme', 'skysafe_setup');
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function skysafe_content_width()
{
$GLOBALS['content_width'] = apply_filters('skysafe_content_width', 640);
}
add_action('after_setup_theme', 'skysafe_content_width', 0);
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function skysafe_widgets_init()
{
register_sidebar(
array(
'name' => esc_html__('Sidebar', 'skysafe'),
'id' => 'sidebar-1',
'description' => esc_html__('Add widgets here.', 'skysafe'),
'before_widget' => '',
'before_title' => '
',
)
);
}
add_action('widgets_init', 'skysafe_widgets_init');
/**
* Enqueue scripts and styles.
*/
function skysafe_scripts()
{
wp_enqueue_style('skysafe-style', get_stylesheet_uri(), array(), _S_VERSION);
wp_style_add_data('skysafe-style', 'rtl', 'replace');
wp_enqueue_script('skysafe-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true);
if (is_singular() && comments_open() && get_option('thread_comments'))
{
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'skysafe_scripts');
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
if (defined('JETPACK__VERSION'))
{
require get_template_directory() . '/inc/jetpack.php';
}
function skysafe_enqueue_assets()
{
wp_enqueue_style('skysafe-style', get_stylesheet_uri());
wp_enqueue_style(
'skysafe-custom',
get_template_directory_uri() . '/css/custom.css',
array('skysafe-style'),
filemtime(get_template_directory() . '/css/custom.css')
);
}
add_action('wp_enqueue_scripts', 'skysafe_enqueue_assets');
function cf7_date_validation_script()
{
?>
id() !== $allowed_form_id ) {
return;
}
// pobierz obiekt submission (zawiera dane POST, pliki itd.)
$submission = WPCF7_Submission::get_instance();
if ( ! $submission ) {
die('[CF7] Brak submission');
return;
}
$data = $submission -> get_posted_data();
$your_name = isset( $data['your-name'] ) ? sanitize_text_field( $data['your-name'] ) : '';
$your_plate = isset( $data['your-plate'] ) ? sanitize_text_field( $data['your-plate'] ) : '';
$arrival = isset( $data['arrival'] ) ? sanitize_text_field( $data['arrival'] ) : '';
$departure = isset( $data['departure'] ) ? sanitize_text_field( $data['departure'] ) : '';
$your_email = isset( $data['your-email'] ) ? sanitize_email( $data['your-email'] ) : '';
$your_phone = isset( $data['your-phone'] ) ? preg_replace( '/\D+/', '', $data['your-phone'] ) : '';
// Zbuduj treść SMS – krótko i konkretnie
$sms_text = implode("\n", [
"Nowe zapytanie:",
"Imię i nazwisko: {$your_name}",
"Numer rejestracyjny: {$your_plate}",
"Przyjazd: {$arrival}",
"Wyjazd: {$departure}",
"Email: {$your_email}",
"Telefon: " . ($your_phone !== '—' ? '+'.ltrim($your_phone, '0') : '—'),
]);
// Opcjonalna transliteracja jak w Twoim przykładzie (uniknie problemów z 7-bit GSM)
$sms_text = smsapi_no_pl( $sms_text );
smsapi_send( SMSAPI_NOTIFY_TO, $sms_text, null ); // wysyłka
// smsapi_send( '+48530755774', $sms_text, 'SkySafe' ); // wysyłka
// smsapi_send( '+48533605006', $sms_text, null ); // wysyłka
}
function smsapi_send(string $to, string $message, ?string $from = null): array
{
if (!defined('SMSAPI_TOKEN') || !SMSAPI_TOKEN)
{
throw new RuntimeException('Brak SMSAPI_TOKEN w wp-config.php');
}
// Uporządkuj numer: dodaj +48 jeśli podano PL bez prefiksu
$to = preg_replace('/\D+/', '', $to);
if (strpos($to, '48') !== 0 && strpos($to, '+48') !== 0 && strlen($to) === 9)
{
$to = '48' . $to;
}
if ($to[0] !== '+')
{
$to = '+' . $to;
}
$body = [
'to' => $to,
'message' => $message,
'format' => 'json', // jak w Twoim przykładzie
// 'encoding' => 'utf-8', // opcjonalnie; przy transliteracji zwykle zbędne
];
if (!empty($from))
{
$body['from'] = $from; // wymaga aktywnego nadawcy w SMSAPI
}
$endpoints = [
'https://api.smsapi.pl/sms.do',
'https://api2.smsapi.pl/sms.do', // fallback jak w Twoim kodzie
];
$last_error = null;
foreach ($endpoints as $url)
{
$resp = wp_remote_post($url, [
'timeout' => 15,
'headers' => [
'Authorization' => 'Bearer ' . SMSAPI_TOKEN,
],
'body' => $body, // application/x-www-form-urlencoded
]);
if (is_wp_error($resp))
{
$last_error = $resp->get_error_message();
continue;
}
$code = wp_remote_retrieve_response_code($resp);
$raw = wp_remote_retrieve_body($resp);
if ($code >= 200 && $code < 300)
{
// Odpowiedź w formacie JSON (bo format=json) – spróbuj zdekodować
$json = json_decode($raw, true);
if (json_last_error() === JSON_ERROR_NONE)
{
// możesz tu zweryfikować status wg dokumentacji SMSAPI (np. "count", "list", "error")
if (!empty($json['error']))
{
// Gdy API zwróci błąd semantyczny (np. zły nadawca)
throw new RuntimeException('[SMSAPI] ' . (is_array($json['error']) ? wp_json_encode($json['error']) : $json['error']));
}
return [
'endpoint' => $url,
'http' => $code,
'data' => $json,
];
}
else
{
// Gdyby przyszła odpowiedź nie-JSON mimo format=json
return [
'endpoint' => $url,
'http' => $code,
'raw' => $raw,
];
}
}
else
{
// Nietypowy kod HTTP – próbuj kolejnego endpointu
$last_error = 'HTTP ' . $code . ' body: ' . $raw;
}
}
throw new RuntimeException('SMSAPI: nieudana wysyłka. Ostatni błąd: ' . ($last_error ?: 'brak danych'));
}
function smsapi_no_pl(string $s): string
{
// prosta transliteracja PL → ASCII (jak w Twoim kodzie, ale krócej)
$map = [
'ą' => 'a',
'ć' => 'c',
'ę' => 'e',
'ł' => 'l',
'ń' => 'n',
'ó' => 'o',
'ś' => 's',
'ż' => 'z',
'ź' => 'z',
'Ą' => 'A',
'Ć' => 'C',
'Ę' => 'E',
'Ł' => 'L',
'Ń' => 'N',
'Ó' => 'O',
'Ś' => 'S',
'Ż' => 'Z',
'Ź' => 'Z',
];
$s = strtr($s, $map);
// awaryjnie:
$t = @iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $s);
return $t !== false ? $t : $s;
}
add_action( 'wp_enqueue_scripts', function() {
wp_add_inline_script( 'contact-form-7', "
document.addEventListener('wpcf7invalid', function(event) {
let output = event.target.querySelector('.wpcf7-response-output');
if (output) {
output.classList.remove('success');
output.classList.add('error');
}
}, false);
document.addEventListener('wpcf7spam', function(event) {
let output = event.target.querySelector('.wpcf7-response-output');
if (output) {
output.classList.remove('success');
output.classList.add('error');
}
}, false);
document.addEventListener('wpcf7mailfailed', function(event) {
let output = event.target.querySelector('.wpcf7-response-output');
if (output) {
output.classList.remove('success');
output.classList.add('error');
}
}, false);
document.addEventListener('wpcf7mailsent', function(event) {
let output = event.target.querySelector('.wpcf7-response-output');
if (output) {
output.classList.remove('error');
output.classList.add('success');
}
}, false);
");
});