]*class=["\'][^"\']*aiwest-header-draft[^"\']*["\'][^>]*>[\s\S]*?)(<\/section>)/isu',
'$1$2',
$content_without_menu,
1
);
}
return $content_without_menu . '';
}
protected static function clean_header_front_labels($content) {
$content = preg_replace('/]*)>\s*Projekt\s+nagłówka\s*<\/p>/iu', '', $content);
$content = preg_replace('/]*)>\s*Projekt\s+nagłówka\s*<\/span>/iu', '', $content);
$content = preg_replace('/]*)>\s*Header\s+project\s*<\/p>/iu', '', $content);
$content = preg_replace('/]*)>\s*Header\s+project\s*<\/span>/iu', '', $content);
return $content;
}
protected static function apply_header_branding($content) {
$logo_url = esc_url(get_option('aiwest_header_logo_url', ''));
$logo_w = intval(get_option('aiwest_header_logo_width', 180));
$logo_h = trim(get_option('aiwest_header_logo_height', 'auto'));
$hide_title = get_option('aiwest_header_hide_text_title', '0') === '1';
$alt = esc_attr(get_option('aiwest_header_logo_alt', get_bloginfo('name')));
if (!$logo_url) return $content;
if ($logo_w <= 0) $logo_w = 180;
$height_css = ($logo_h === 'auto' || $logo_h === '') ? 'auto' : max(1, intval($logo_h)) . 'px';
$logo = '';
if ($hide_title) {
$site_name_pattern = preg_quote(get_bloginfo('name'), '/');
$content = preg_replace('/]*)>\s*' . $site_name_pattern . '\s*<\/h2>/iu', '', $content, 1);
$content = preg_replace('/]*)>\s*' . $site_name_pattern . '\s*<\/h1>/iu', '', $content, 1);
} else {
$site_name_pattern = preg_quote(get_bloginfo('name'), '/');
$content = preg_replace('/(]*>\s*' . $site_name_pattern . '\s*<\/h[12]>)/iu', '$1
', $content, 1);
}
if (stripos($content, 'aiwest-header-logo') === false) {
$content = preg_replace('/(]*class=["\'][^"\']*aiwest-header-draft[^"\']*["\'][^>]*>)/iu', '$1', $content, 1);
}
return $content;
}
protected static function aiwest_158_clean_header_labels($content) {
// Remove technical/admin-only labels from the public AI Header output.
$content = preg_replace('/]*>\s*Projekt\s+nagłówka\s*<\/p>/iu', '', $content);
$content = preg_replace('/]*>\s*Projekt\s+nagłówka\s*<\/span>/iu', '', $content);
$content = preg_replace('/]*>\s*Projekt\s+nagłówka\s*<\/div>/iu', '', $content);
$content = preg_replace('/
]*>\s*Header\s+project\s*<\/p>/iu', '', $content);
$content = preg_replace('/]*>\s*Header\s+project\s*<\/span>/iu', '', $content);
$content = preg_replace('/]*>\s*Header\s+project\s*<\/div>/iu', '', $content);
return $content;
}
protected static function aiwest_158_get_header_logo_url() {
$logo_url = esc_url(get_option('aiwest_header_logo_url', ''));
if ($logo_url) return $logo_url;
// Safe fallback: use the WordPress custom logo if no AI Header logo URL is saved.
$custom_logo_id = function_exists('get_theme_mod') ? intval(get_theme_mod('custom_logo')) : 0;
if ($custom_logo_id) {
$src = wp_get_attachment_image_src($custom_logo_id, 'full');
if (!empty($src[0])) return esc_url($src[0]);
}
return '';
}
protected static function aiwest_158_apply_header_logo($content) {
$logo_url = self::aiwest_158_get_header_logo_url();
if (!$logo_url) return $content;
// Avoid inserting a duplicate logo.
if (stripos($content, 'aiwest-header-logo') !== false) {
return $content;
}
$logo_w = intval(get_option('aiwest_header_logo_width', 180));
if ($logo_w <= 0) $logo_w = 180;
$logo_h = trim(get_option('aiwest_header_logo_height', 'auto'));
$height_css = ($logo_h === '' || strtolower($logo_h) === 'auto') ? 'auto' : max(1, intval($logo_h)) . 'px';
$alt = esc_attr(get_option('aiwest_header_logo_alt', get_bloginfo('name')));
$hide_title = get_option('aiwest_header_hide_text_title', '1') === '1';
$logo = '';
// Replace the common text brand heading.
if ($hide_title) {
$site_name_pattern = preg_quote(get_bloginfo('name'), '/');
$replaced = preg_replace('/
]*>\s*' . $site_name_pattern . '\s*<\/h\1>/iu', '', $content, 1);
if ($replaced !== null && $replaced !== $content) return $replaced;
} else {
$site_name_pattern = preg_quote(get_bloginfo('name'), '/');
$replaced = preg_replace('/(]*>\s*' . $site_name_pattern . '\s*<\/h\2>)/iu', '$1
', $content, 1);
if ($replaced !== null && $replaced !== $content) return $replaced;
}
// Fallback: insert logo at the beginning of the header draft section.
$replaced = preg_replace(
'/(]*class=["\'][^"\']*aiwest-header-draft[^"\']*["\'][^>]*>)/iu',
'$1',
$content,
1
);
return $replaced ?: $content;
}
protected static function aiwest_1535_should_use_logo() {
return get_option('aiwest_header_hide_text_title', '1') === '1';
}
protected static function aiwest_1535_get_header_logo_url() {
$logo_url = esc_url(get_option('aiwest_header_logo_url', ''));
if ($logo_url) return $logo_url;
// WordPress site logo fallback is allowed only when the administrator explicitly enables it.
if (get_option('aiwest_header_use_wp_logo_fallback', '0') !== '1') return '';
$custom_logo_id = function_exists('get_theme_mod') ? intval(get_theme_mod('custom_logo')) : 0;
if ($custom_logo_id) {
$src = wp_get_attachment_image_src($custom_logo_id, 'full');
if (!empty($src[0])) return esc_url($src[0]);
}
return '';
}
protected static function aiwest_1535_remove_existing_logo_fragments($content) {
// When the administrator chooses text branding, remove AIW-injected logo wrappers from public output.
$content = preg_replace('/]*class=["\'][^"\']*aiwest-header-logo-wrap[^"\']*["\'][^>]*>\s*
![]()
]*class=["\'][^"\']*aiwest-header-logo[^"\']*["\'][^>]*>\s*<\/div>/isu', '', $content);
$content = preg_replace('/
]*class=["\'][^"\']*aiwest-header-brand-row[^"\']*["\'][^>]*>\s*
]*class=["\'][^"\']*aiwest-header-logo-wrap[^"\']*["\'][^>]*>\s*
![]()
]*class=["\'][^"\']*aiwest-header-logo[^"\']*["\'][^>]*>\s*<\/div>\s*(
]*>.*?<\/h[12]>)\s*<\/div>/isu', '$1', $content);
return $content;
}
protected static function aiwest_1535_apply_header_branding($content) {
$use_logo = self::aiwest_1535_should_use_logo();
if (!$use_logo) {
return self::aiwest_1535_remove_existing_logo_fragments($content);
}
$logo_url = self::aiwest_1535_get_header_logo_url();
if (!$logo_url) return $content;
$content = self::aiwest_1535_remove_existing_logo_fragments($content);
$logo_w = intval(get_option('aiwest_header_logo_width', 180));
if ($logo_w <= 0) $logo_w = 180;
$logo_h = trim(get_option('aiwest_header_logo_height', 'auto'));
$height_css = ($logo_h === '' || strtolower($logo_h) === 'auto') ? 'auto' : max(1, intval($logo_h)) . 'px';
$alt = esc_attr(get_option('aiwest_header_logo_alt', get_bloginfo('name')));
$logo = '';
$site_name = preg_quote(get_bloginfo('name'), '/');
$patterns = [
'/]*>\s*' . $site_name . '\s*<\/h\1>/iu',
];
foreach ($patterns as $pattern) {
$replaced = preg_replace($pattern, '', $content, 1);
if ($replaced !== null && $replaced !== $content) return $replaced;
}
return preg_replace('/(]*class=["\'][^"\']*aiwest-header-draft[^"\']*["\'][^>]*>)/iu', '$1', $content, 1) ?: $content;
}
public static function footer($atts = []) {
self::enqueue_assets();
$post_id = intval(get_option('aiwest_active_footer_page_id', 0));
if (!$post_id || get_post_status($post_id) === false || get_post_status($post_id) === 'trash') {
if (current_user_can('manage_options')) {
return '' . esc_html(__('AI Webmaster Studio: no active footer project. Create one in AI Webmaster Studio → Site Builder → Footer.', 'ai-webmaster-studio')) . '
';
}
return '';
}
$post = get_post($post_id);
if (!$post) return '';
$footer_content = do_shortcode(wp_kses_post($post->post_content));
if (class_exists('AIWEST_Social_Media')) {
$footer_content = AIWEST_Social_Media::inject_into_footer_content($footer_content);
}
return self::sanitize_output('');
}
public static function enqueue_assets() {
wp_enqueue_style('aiwest-shortcodes', AIWEST_URL . 'assets/shortcodes.css', [], AIWEST_VERSION);
}
public static function maybe_enqueue_assets() {
if (!is_singular()) return;
$post = get_post();
if (!$post) return;
$content = (string) $post->post_content;
if (has_shortcode($content, 'aiwest_header') || has_shortcode($content, 'aiwest_footer')) {
self::enqueue_assets();
}
}
public static function allowed_html() {
$allowed = wp_kses_allowed_html('post');
$allowed['nav'] = [
'class' => true,
'id' => true,
'aria-label' => true,
'role' => true,
];
$allowed['svg'] = [
'class' => true,
'viewbox' => true,
'aria-hidden' => true,
'role' => true,
'xmlns' => true,
];
$allowed['path'] = [
'd' => true,
'fill' => true,
];
return $allowed;
}
public static function sanitize_output($html) {
return wp_kses((string) $html, self::allowed_html());
}
}
AIWEST_Shortcodes::init();