['label' => 'Facebook', 'placeholder' => 'https://facebook.com/your-profile'], 'instagram' => ['label' => 'Instagram', 'placeholder' => 'https://instagram.com/your-profile'], 'linkedin' => ['label' => 'LinkedIn', 'placeholder' => 'https://linkedin.com/company/your-company'], 'youtube' => ['label' => 'YouTube', 'placeholder' => 'https://youtube.com/@your-channel'], 'tiktok' => ['label' => 'TikTok', 'placeholder' => 'https://tiktok.com/@your-profile'], 'x' => ['label' => 'X / Twitter', 'placeholder' => 'https://x.com/your-profile'], 'pinterest' => ['label' => 'Pinterest', 'placeholder' => 'https://pinterest.com/your-profile'], 'whatsapp' => ['label' => 'WhatsApp', 'placeholder' => 'https://wa.me/15551234567'], ]; } public static function init() { // Optional fallback when the page does not render the AI footer shortcode. add_action('wp_enqueue_scripts', [__CLASS__, 'enqueue_assets']); add_action('wp_footer', [__CLASS__, 'render_wp_footer_fallback'], 98); } public static function enqueue_assets() { if (self::visible_links()) { wp_enqueue_style('aiwest-social-media', AIWEST_URL . 'assets/social-media.css', [], AIWEST_VERSION); } } public static function get_links() { $saved = get_option('aiwest_social_links', []); if (!is_array($saved)) $saved = []; $out = []; foreach (self::platforms() as $key => $data) { $url = esc_url_raw(trim((string)($saved[$key] ?? ''))); if ($url !== '') $out[$key] = $url; } return $out; } public static function get_enabled_platforms() { $saved = get_option('aiwest_social_enabled_platforms', null); $links = self::get_links(); // Backward compatibility: enable profiles with a saved URL when no checkbox state exists. if (!is_array($saved)) { return array_fill_keys(array_keys($links), 'yes'); } $out = []; foreach (self::platforms() as $key => $data) { if (!empty($saved[$key]) && $saved[$key] === 'yes') { $out[$key] = 'yes'; } } return $out; } public static function sanitize_links($input) { $out = []; foreach (self::platforms() as $key => $data) { $url = esc_url_raw(trim((string)($input[$key] ?? ''))); if ($url !== '') $out[$key] = $url; } return $out; } public static function sanitize_enabled_platforms($input) { $out = []; foreach (self::platforms() as $key => $data) { if (!empty($input[$key])) $out[$key] = 'yes'; } return $out; } public static function is_footer_enabled() { return get_option('aiwest_social_footer_enabled', 'yes') === 'yes'; } public static function visible_links() { if (!self::is_footer_enabled()) return []; $links = self::get_links(); $enabled = self::get_enabled_platforms(); $out = []; foreach ($links as $key => $url) { if (!empty($enabled[$key]) && $enabled[$key] === 'yes') { $out[$key] = $url; } } return $out; } public static function render_footer_icons() { $links = self::visible_links(); if (!$links) return ''; self::enqueue_assets(); self::$rendered_footer_icons = true; $label = trim((string)get_option('aiwest_social_footer_label', __('Find us on social media', 'ai-webmaster-studio'))); if ($label === '') $label = 'Social media'; $html = '
'; return $html; } public static function inject_into_footer_content($footer_content) { $html = self::render_footer_icons(); if ($html === '') return $footer_content; // Remove any social block accidentally appended by an older renderer to avoid duplicates. $footer_content = preg_replace('/]*>\s*Zapisz\s+się\s+do\s+newslettera[\s\S]*?<\/p>)/iu'; if (preg_match($newsletter_pattern, $footer_content)) { return preg_replace($newsletter_pattern, $html . '$1', $footer_content, 1); } // Secondary placement: before copyright/legal text if newsletter copy is not present. $copyright_pattern = '/(
]*>\s*(?:©|©|Copyright)[\s\S]*?<\/p>)/iu';
if (preg_match($copyright_pattern, $footer_content)) {
return preg_replace($copyright_pattern, $html . '$1', $footer_content, 1);
}
// Last resort: keep the block inside the .aiwest-footer-draft section, before its closing tag.
if (preg_match('/(