Rusk Starter Content Importer
What this will create
- Pages: Home, About, Contact (and Shop if WooCommerce exists)
- Sets Home as the static front page
- Primary menu (or the first available menu location)
- Optional: WooCommerce categories and sample products (if WooCommerce is installed)
- Optional: Imports images from
/assetsand assigns them
Notes
- If items already exist (same slug), the importer will not duplicate them.
- To change text later, edit Pages under Pages and Products under Products.
Fresh, crunchy rusks — perfect with coffee or tea. Order online for delivery or collection.
Popular Rusks
Try our best sellers: Buttermilk, Aniseed, Bran, and Chocolate Chip.
[products limit=”4″ columns=”4″ orderby=”popularity”]
HTML; } private function about_content() { return <<About Corliese HoekieWe bake small-batch rusks using traditional recipes and quality ingredients. Our rusks are dried to a perfect crunch, packed fresh, and shipped with care.
Made in South Africa. Perfect for gifting, events, guesthouses, or everyday coffee moments.
HTML; } private function contact_content() { return <<Contact / OrdersFor bulk orders, custom packs, or delivery questions, get in touch:
- WhatsApp: +27 XX XXX XXXX
- Email: orders@corliesehoekie.co.za
- Collection: By arrangement
You can also place orders directly through the Shop page.
HTML; } /* ——————————- * Helpers: create pages / menu * ——————————- */ private function create_page_if_missing($title, $slug, $content) { $existing = get_page_by_path($slug); if ($existing && isset($existing->ID)) { // Update content if empty only if (empty(trim($existing->post_content))) { wp_update_post([ ‘ID’ => $existing->ID, ‘post_content’ => $content ]); } return (int) $existing->ID; } $id = wp_insert_post([ ‘post_title’ => $title, ‘post_name’ => $slug, ‘post_content’ => $content, ‘post_status’ => ‘publish’, ‘post_type’ => ‘page’, ]); return is_wp_error($id) ? 0 : (int) $id; } private function create_menu_if_missing($menu_name) { $menu = wp_get_nav_menu_object($menu_name); if ($menu && isset($menu->term_id)) return (int) $menu->term_id; $menu_id = wp_create_nav_menu($menu_name); return is_wp_error($menu_id) ? 0 : (int) $menu_id; } private function add_menu_item_page($menu_id, $label, $page_id) { if (!$menu_id || !$page_id) return; $items = wp_get_nav_menu_items($menu_id); if ($items) { foreach ($items as $item) { if ((int)$item->object_id === (int)$page_id) { return; // already exists } } } wp_update_nav_menu_item($menu_id, 0, [ ‘menu-item-title’ => $label, ‘menu-item-object’ => ‘page’, ‘menu-item-object-id’ => (int) $page_id, ‘menu-item-type’ => ‘post_type’, ‘menu-item-status’ => ‘publish’ ]); } private function assign_menu_to_location($menu_id) { if (!$menu_id) return; $locations = get_theme_mod(‘nav_menu_locations’, []); $registered = get_registered_nav_menus(); // Prefer “primary”, else first location $target = null; if (isset($registered[‘primary’])) { $target = ‘primary’; } elseif (!empty($registered)) { $keys = array_keys($registered); $target = $keys[0]; } if ($target) { $locations[$target] = $menu_id; set_theme_mod(‘nav_menu_locations’, $locations); } } /* ——————————- * Image import from plugin assets * ——————————- */ private function import_assets_images() { $map = []; $files = [ ‘hero.jpg’ => ‘Hero Image’, ‘buttermilk-rusks.jpg’ => ‘Buttermilk Rusks’, ‘aniseed-rusks.jpg’ => ‘Aniseed Rusks’, ‘bran-rusks.jpg’ => ‘Bran Rusks’, ‘chocchip-rusks.jpg’ => ‘Chocolate Chip Rusks’, ]; require_once ABSPATH . ‘wp-admin/includes/file.php’; require_once ABSPATH . ‘wp-admin/includes/media.php’; require_once ABSPATH . ‘wp-admin/includes/image.php’; foreach ($files as $filename => $title) { $path = plugin_dir_path(__FILE__) . ‘assets/’ . $filename; if (!file_exists($path)) continue; // Skip if an attachment already exists with same file name in uploads $existing_id = $this->find_attachment_by_filename($filename); if ($existing_id) { $map[$filename] = $existing_id; continue; } $upload = wp_upload_bits($filename, null, file_get_contents($path)); if (!empty($upload[‘error’])) continue; $filetype = wp_check_filetype($upload[‘file’], null); $attachment_id = wp_insert_attachment([ ‘post_mime_type’ => $filetype[‘type’], ‘post_title’ => $title, ‘post_content’ => ”, ‘post_status’ => ‘inherit’ ], $upload[‘file’]); if (is_wp_error($attachment_id)) continue; $attach_data = wp_generate_attachment_metadata($attachment_id, $upload[‘file’]); wp_update_attachment_metadata($attachment_id, $attach_data); $map[$filename] = (int) $attachment_id; } return $map; // filename => attachment_id } private function find_attachment_by_filename($filename) { global $wpdb; $like = ‘%’ . $wpdb->esc_like(‘/’ . $filename) . ‘%’; $id = $wpdb->get_var($wpdb->prepare( “SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = ‘_wp_attached_file’ AND meta_value LIKE %s LIMIT 1”, $like )); return $id ? (int) $id : 0; } /* ——————————- * WooCommerce products * ——————————- */ private function create_sample_products($attachments_map) { if (!class_exists(‘WC_Product_Simple’)) return []; // Create categories $cats = [‘Buttermilk’, ‘Aniseed’, ‘Bran’, ‘Sweet’]; foreach ($cats as $cat) { if (!term_exists($cat, ‘product_cat’)) { wp_insert_term($cat, ‘product_cat’); } } $products = [ [ ‘sku’ => ‘RUSK-BUT-001’, ‘name’ => ‘Buttermilk Rusks (1kg)’, ‘price’ => 95, ‘category’ => ‘Buttermilk’, ‘image’ => ‘buttermilk-rusks.jpg’, ‘desc’ => ‘Crisp golden buttermilk rusks baked in small batches. Perfect with coffee or tea.’, ], [ ‘sku’ => ‘RUSK-ANI-001’, ‘name’ => ‘Aniseed Rusks (1kg)’, ‘price’ => 100, ‘category’ => ‘Aniseed’, ‘image’ => ‘aniseed-rusks.jpg’, ‘desc’ => ‘Traditional aniseed flavour with a satisfying crunch.’, ], [ ‘sku’ => ‘RUSK-BRA-001’, ‘name’ => ‘Bran Rusks (1kg)’, ‘price’ => 99, ‘category’ => ‘Bran’, ‘image’ => ‘bran-rusks.jpg’, ‘desc’ => ‘Wholesome high-fibre bran rusks with a hearty bite.’, ], [ ‘sku’ => ‘RUSK-CHO-001’, ‘name’ => ‘Chocolate Chip Rusks (1kg)’, ‘price’ => 120, ‘sale_price’ => 110, ‘category’ => ‘Sweet’, ‘image’ => ‘chocchip-rusks.jpg’, ‘desc’ => ‘A sweeter rusk with chocolate chips — a crowd favourite.’, ], ]; $created = []; foreach ($products as $p) { // Skip if SKU exists $existing_id = wc_get_product_id_by_sku($p[‘sku’]); if ($existing_id) { $created[] = (int) $existing_id; continue; } $product = new WC_Product_Simple(); $product->set_name($p[‘name’]); $product->set_sku($p[‘sku’]); $product->set_status(‘publish’); $product->set_catalog_visibility(‘visible’); $product->set_regular_price((string) $p[‘price’]); if (!empty($p[‘sale_price’])) { $product->set_sale_price((string) $p[‘sale_price’]); } $product->set_description($p[‘desc’]); $product->set_short_description($p[‘desc’]); $product->set_weight(‘1’); // 1kg default // Category $term = get_term_by(‘name’, $p[‘category’], ‘product_cat’); if ($term && !is_wp_error($term)) { $product->set_category_ids([(int) $term->term_id]); } // Image if (!empty($p[‘image’]) && !empty($attachments_map[$p[‘image’]])) { $product->set_image_id((int) $attachments_map[$p[‘image’]]); } $id = $product->save(); if ($id) $created[] = (int) $id; } return $created; } } new Rusk_Starter_Importer();