Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
get_charset_collate(); dbDelta("CREATE TABLE {$wpdb->prefix}bsh_pages ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT UNSIGNED NOT NULL, username VARCHAR(90) NOT NULL, page_name VARCHAR(180) DEFAULT 'My Page', display_name VARCHAR(180) DEFAULT '', title VARCHAR(220) DEFAULT '', bio TEXT NULL, avatar_url TEXT NULL, page_type VARCHAR(80) DEFAULT 'creator', theme VARCHAR(60) DEFAULT 'dark_purple', contact_enabled TINYINT(1) DEFAULT 1, status VARCHAR(30) DEFAULT 'published', branding TINYINT(1) DEFAULT 1, is_default TINYINT(1) DEFAULT 1, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY username (username), KEY user_id (user_id) ) $charset;"); dbDelta("CREATE TABLE {$wpdb->prefix}bsh_links ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, page_id BIGINT UNSIGNED NOT NULL, label VARCHAR(220) NOT NULL, url TEXT NOT NULL, icon VARCHAR(80) DEFAULT 'link', sort_order INT DEFAULT 10, is_active TINYINT(1) DEFAULT 1, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY page_id (page_id) ) $charset;"); dbDelta("CREATE TABLE {$wpdb->prefix}bsh_clicks ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, page_id BIGINT UNSIGNED NOT NULL, link_id BIGINT UNSIGNED DEFAULT 0, ip_hash VARCHAR(140) DEFAULT '', user_agent TEXT NULL, referrer TEXT NULL, clicked_at DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY page_id (page_id), KEY link_id (link_id) ) $charset;"); dbDelta("CREATE TABLE {$wpdb->prefix}bsh_leads ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, page_id BIGINT UNSIGNED NOT NULL, name VARCHAR(180) DEFAULT '', email VARCHAR(220) DEFAULT '', message TEXT NULL, is_read TINYINT(1) DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY page_id (page_id) ) $charset;"); $pages = [ 'home' => ['Home', '[bsh_home]'], 'login' => ['Login', '[bsh_login]'], 'register' => ['Register', '[bsh_register]'], 'setup' => ['Setup', '[bsh_setup]'], 'dashboard' => ['Dashboard', '[bsh_dashboard]'], 'my-pages' => ['My Pages', '[bsh_pages]'], 'editor' => ['Editor', '[bsh_editor]'], 'links' => ['Links', '[bsh_links]'], 'analytics' => ['Analytics', '[bsh_analytics]'], 'leads' => ['Leads', '[bsh_leads]'], 'themes' => ['Themes', '[bsh_themes]'], 'free-plan' => ['Free Plan', '[bsh_free_plan]'], 'settings' => ['Settings', '[bsh_settings]'], 'features' => ['Features', '[bsh_features]'], 'control-centre' => ['Control Centre', '[bsh_admin]'], ]; foreach ($pages as $slug => $data) { $existing = get_page_by_path($slug); if (!$existing) { wp_insert_post([ 'post_title' => $data[0], 'post_name' => $slug, 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => $data[1], ]); } else { wp_update_post([ 'ID' => $existing->ID, 'post_status' => 'publish', 'post_content' => $data[1], ]); } } $home = get_page_by_path('home'); if ($home) { update_option('show_on_front', 'page'); update_option('page_on_front', $home->ID); } if (!get_option('bsh_routes_flushed_v4')) { flush_rewrite_rules(false); update_option('bsh_routes_flushed_v4', 1); } } /* ========================================================= HELPERS ========================================================= */ function bsh_url($slug = '') { return home_url('/' . trim($slug, '/') . '/'); } function bsh_tbl($name) { global $wpdb; return $wpdb->prefix . 'bsh_' . $name; } function bsh_clean_username($username) { $username = strtolower(sanitize_title($username)); return trim(preg_replace('/[^a-z0-9\-]/', '', $username), '-'); } function bsh_redirect($url) { wp_safe_redirect($url); exit; } function bsh_auth_required() { if (!is_user_logged_in()) bsh_redirect(bsh_url('login')); } function bsh_app_pages() { return [ 'home','login','register','setup','dashboard','my-pages','editor','links', 'analytics','leads','themes','free-plan','settings','features','control-centre' ]; } function bsh_is_app_page() { return is_page(bsh_app_pages()) || get_query_var('bsh_profile'); } function bsh_unique_username($base, $ignore_id = 0) { global $wpdb; $base = bsh_clean_username($base); if (!$base) $base = 'page'; $username = $base; $i = 2; while (true) { $exists = $wpdb->get_var($wpdb->prepare( "SELECT id FROM " . bsh_tbl('pages') . " WHERE username=%s AND id!=%d", $username, $ignore_id )); if (!$exists) return $username; $username = $base . '-' . $i; $i++; } } function bsh_current_page() { if (!is_user_logged_in()) return null; global $wpdb; $page = $wpdb->get_row($wpdb->prepare( "SELECT * FROM " . bsh_tbl('pages') . " WHERE user_id=%d AND is_default=1 ORDER BY id ASC LIMIT 1", get_current_user_id() )); if (!$page) { $user = wp_get_current_user(); $username = bsh_unique_username($user->user_login ?: 'user'); $wpdb->insert(bsh_tbl('pages'), [ 'user_id' => get_current_user_id(), 'username' => $username, 'page_name' => 'Main Page', 'display_name' => $user->display_name ?: $username, 'title' => 'Creator | Business | Services', 'bio' => 'Welcome to my official BioSparkHub page.', 'page_type' => 'creator', 'theme' => 'dark_purple', 'status' => 'published', 'is_default' => 1, ]); $page_id = $wpdb->insert_id; bsh_seed_links($page_id, 'creator'); $page = $wpdb->get_row($wpdb->prepare( "SELECT * FROM " . bsh_tbl('pages') . " WHERE id=%d", $page_id )); } return $page; } function bsh_icons() { return [ 'link' => '🔗', 'website' => '🌐', 'instagram' => '📸', 'tiktok' => '🎶', 'youtube' => '▶️', 'x' => '𝕏', 'facebook' => 'f', 'linkedin' => 'in', 'snapchat' => '👻', 'whatsapp' => '💬', 'telegram' => '✈️', 'email' => '✉️', 'phone' => '📞', 'booking' => '📅', 'shop' => '🛒', 'music' => '🎵', 'spotify' => '🎧', 'apple_music' => '', 'soundcloud' => '☁️', 'twitch' => '🟣', 'discord' => '🎮', 'training' => '🏋️', 'food' => '🍎', 'gallery' => '🖼️', 'star' => '⭐', ]; } function bsh_icon($icon) { $icons = bsh_icons(); return $icons[$icon] ?? '🔗'; } function bsh_starter_links($type) { $sets = [ 'business' => [ ['View Our Services', 'https://example.com', 'website'], ['Book A Consultation', 'https://example.com', 'booking'], ['WhatsApp Us', 'https://wa.me/440000000000', 'whatsapp'], ['Follow On X', 'https://x.com', 'x'], ], 'music' => [ ['Listen On Spotify', 'https://spotify.com', 'spotify'], ['Watch On YouTube', 'https://youtube.com', 'youtube'], ['Follow On TikTok', 'https://tiktok.com', 'tiktok'], ['Book Me', 'https://example.com', 'booking'], ], 'fitness' => [ ['Book A Training Session', 'https://example.com', 'booking'], ['View Programmes', 'https://example.com', 'training'], ['Client Transformations', 'https://example.com', 'gallery'], ['WhatsApp Me', 'https://wa.me/440000000000', 'whatsapp'], ], 'beauty' => [ ['Book An Appointment', 'https://example.com', 'booking'], ['View Services', 'https://example.com', 'shop'], ['Instagram Gallery', 'https://instagram.com', 'instagram'], ['WhatsApp Me', 'https://wa.me/440000000000', 'whatsapp'], ], 'shop' => [ ['Shop Now', 'https://example.com', 'shop'], ['Best Sellers', 'https://example.com', 'star'], ['Customer Reviews', 'https://example.com', 'star'], ['Contact Us', 'mailto:hello@example.com', 'email'], ], 'creator' => [ ['My Website', 'https://example.com', 'website'], ['Follow On Instagram', 'https://instagram.com', 'instagram'], ['Follow On X', 'https://x.com', 'x'], ['Contact Me', 'mailto:hello@example.com', 'email'], ], ]; return $sets[$type] ?? $sets['creator']; } function bsh_seed_links($page_id, $type = 'creator') { global $wpdb; $count = (int) $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) FROM " . bsh_tbl('links') . " WHERE page_id=%d", $page_id )); if ($count > 0) return; foreach (bsh_starter_links($type) as $i => $link) { $wpdb->insert(bsh_tbl('links'), [ 'page_id' => $page_id, 'label' => $link[0], 'url' => $link[1], 'icon' => $link[2], 'sort_order' => $i + 1, 'is_active' => 1, ]); } } function bsh_upload_image($field) { if (empty($_FILES[$field]['name'])) return ''; require_once ABSPATH . 'wp-admin/includes/file.php'; $file = $_FILES[$field]; $allowed = ['image/jpeg', 'image/png', 'image/webp']; if (!in_array($file['type'], $allowed, true)) return ''; if ($file['size'] > 3 * 1024 * 1024) return ''; $upload = wp_handle_upload($file, ['test_form' => false]); return !empty($upload['url']) ? esc_url_raw($upload['url']) : ''; } /* ========================================================= LOCK WORDPRESS FOR NORMAL USERS ========================================================= */ add_filter('show_admin_bar', function ($show) { return current_user_can('manage_options') ? $show : false; }); add_action('admin_init', function () { if (current_user_can('manage_options')) return; if (wp_doing_ajax()) return; bsh_redirect(bsh_url('dashboard')); }); /* ========================================================= CSS ========================================================= */ add_filter('body_class', function ($classes) { if (bsh_is_app_page()) $classes[] = 'bsh-page'; return $classes; }, 999); add_action('wp_head', function () { if (!bsh_is_app_page()) return; ?>
You have been inactive. You will be signed out in 60 seconds.
Create a beautiful free page for your brand, business, content, bookings, products and services in minutes.
Choose what you do and BioSparkHub will create starter links for you.
BioSparkHub is free first. Share your page and grow your audience.
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!