array( 'items' => array( 'Linen apron', 'Ceramic mug set', 'Gift box “Slow morning”', 'Olive wood board' ), 'forms' => array( 'Question about shipping', 'Is the gift box in stock?', 'Wholesale enquiry', 'Order question' ), 'deals' => array( 'Wholesale order: café chain', 'Corporate gifts: 40 boxes', 'Shop-in-shop pilot', 'Wedding favours: 120 mugs', 'Restock for boutique', 'Hotel amenities' ), 'values' => array( 1800, 3200, 2500, 1400, 900, 4100 ), 'pages' => array( '/product/linen-apron/', '/product/ceramic-mug-set/', '/product/gift-box/', '/shop/', '/cart/' ), ), 'rentals' => array( 'items' => array( 'Ocean View Villa', 'Garden Studio', 'Casa Azul', 'Treehouse loft' ), 'forms' => array( 'Availability in March?', 'Do you allow pets?', 'Group of 6, two weeks', 'Long stay discount?' ), 'deals' => array( 'Ocean View Villa: 7 nights', 'Casa Azul: family reunion', 'Garden Studio: 1 month', 'Treehouse: honeymoon', 'Corporate retreat: 3 houses', 'Christmas week' ), 'values' => array( 2100, 4800, 1600, 1250, 9600, 3400 ), 'pages' => array( '/rentals/ocean-view-villa/', '/rentals/garden-studio/', '/rentals/casa-azul/', '/availability/', '/book/' ), ), 'realestate' => array( 'items' => array( '3-bed house, El Cangrejo', 'Penthouse with sea view', 'Beach lot, Coronado', 'Office floor, Obarrio' ), 'forms' => array( 'Can I book a viewing?', 'Is the price negotiable?', 'Looking for a 2-bed to rent', 'Valuation of my apartment' ), 'deals' => array( 'Penthouse: buyer', '3-bed house: viewing done', 'Beach lot: offer', 'Office floor: lease', 'Valuation: Costa del Este', 'Rental: 2-bed, Marbella' ), 'values' => array( 12000, 8500, 6200, 9000, 1500, 1100 ), 'pages' => array( '/properties/penthouse-sea-view/', '/properties/3-bed-el-cangrejo/', '/properties/beach-lot-coronado/', '/sell/', '/contact/' ), ), 'services' => array( 'items' => array( 'First consultation', 'Teeth whitening', 'Monthly plan', 'Workshop for teams' ), 'forms' => array( 'Book a first consultation', 'What does whitening cost?', 'Monthly plan for my team', 'Can you come on a Saturday?' ), 'deals' => array( 'Team workshop: 12 people', 'Monthly plan: family', 'Whitening + check-up', 'Clinic partnership', 'Annual check-ups: company', 'Follow-up programme' ), 'values' => array( 1800, 960, 420, 5000, 3600, 750 ), 'pages' => array( '/services/first-consultation/', '/services/whitening/', '/pricing/', '/book-a-call/', '/about/' ), ), 'retreats' => array( 'items' => array( 'Spring yoga retreat', 'Silent weekend', 'Surf & breathe week', 'Writers’ residency' ), 'forms' => array( 'Is there still a spot in April?', 'Single room possible?', 'Coming with a friend', 'Payment in two parts?' ), 'deals' => array( 'Spring retreat: 2 spots', 'Silent weekend: single room', 'Surf week: group of 4', 'Residency: application', 'Company offsite: 10 people', 'Retreat gift voucher' ), 'values' => array( 2400, 680, 4200, 1900, 12000, 600 ), 'pages' => array( '/retreats/spring-yoga/', '/retreats/silent-weekend/', '/retreats/surf-week/', '/apply/', '/faq/' ), ), 'b2b' => array( 'items' => array( 'Annual licence', 'Pilot project', 'Onboarding package', 'Support plan' ), 'forms' => array( 'Request a demo', 'Pricing for 25 seats', 'Security questionnaire', 'Partnership' ), 'deals' => array( 'Annual licence: 25 seats', 'Pilot: logistics team', 'Onboarding package', 'Support plan upgrade', 'Enterprise trial', 'Reseller agreement' ), 'values' => array( 14000, 4500, 2500, 3600, 22000, 8000 ), 'pages' => array( '/product/', '/pricing/', '/demo/', '/security/', '/customers/' ), ), ); $kit = $kits[ $niche ] ?? array( 'items' => array( 'Website project', 'Strategy session', 'Monthly support', 'Brand refresh' ), 'forms' => array( 'Question about pricing', 'Book a call', 'Can you help with our website?', 'Partnership' ), 'deals' => array( 'Website project', 'Strategy session: 3 days', 'Monthly support plan', 'Brand refresh', 'Landing pages: spring campaign', 'Maintenance contract' ), 'values' => array( 6500, 2400, 900, 4800, 1800, 1200 ), 'pages' => array( '/services/', '/pricing/', '/work/', '/contact/', '/about/' ), ); /** * The sample business for a niche. * * @param array $kit items, forms, deals, values, pages. * @param string $niche Niche key. */ return (array) apply_filters( 'nodebook_sample_kit', $kit, $niche ); } /** * Add the sample business. Returns how many contacts were added (0 when sample data is already there). */ public static function add() { global $wpdb; if ( self::present() ) { return 0; } self::$running = true; $kit = self::kit( Nodebook_Niche::current() ); $made = array( 'contacts' => array(), 'companies' => array(), 'deals' => array(), 'tasks' => array(), 'segments' => array(), 'gatherings' => array(), 'at' => time(), ); $ago = static function ( $days, $hours = 0 ) { return gmdate( 'Y-m-d H:i:s', time() - (int) ( $days * DAY_IN_SECONDS ) - (int) ( $hours * HOUR_IN_SECONDS ) ); }; $me = get_current_user_id(); $cos = array(); foreach ( array( array( 'Casa Verde Hotels', 'casaverde.example.com' ), array( 'Boquete Coffee Co.', 'boquetecoffee.example.com' ), array( 'Pacific Realty', 'pacificrealty.example.com' ), array( 'Atlas Logistics', 'atlas.example.com' ), array( 'Lumen Studio', 'lumen.example.com' ) ) as $c ) { $id = (int) Nodebook_Companies::insert( array( 'name' => $c[0], 'domain' => $c[1], ) ); if ( $id ) { $cos[] = $id; $made['companies'][] = $id; } } $people = array( array( 'Maria', 'López', 'Panama City', 'PA', 'customer', array( 'google', 'organic' ) ), array( 'Tom', 'Lindqvist', 'Stockholm', 'SE', 'lead', array( 'instagram', 'social' ) ), array( 'Sara', 'Haddad', 'Amsterdam', 'NL', 'prospect', array( 'google', 'cpc' ) ), array( 'Jonas', 'Berg', 'Berlin', 'DE', 'customer', array( '', 'direct' ) ), array( 'Aisha', 'Khan', 'London', 'GB', 'lead', array( 'newsletter', 'email' ) ), array( 'Diego', 'Herrera', 'Medellín', 'CO', 'customer', array( 'facebook', 'social' ) ), array( 'Emma', 'de Vries', 'Utrecht', 'NL', 'subscriber', array( 'newsletter', 'email' ) ), array( 'Lucas', 'Moreau', 'Lyon', 'FR', 'lead', array( 'google', 'organic' ) ), array( 'Sofia', 'Rossi', 'Milan', 'IT', 'customer', array( 'instagram', 'social' ) ), array( 'Noah', 'Smith', 'Austin', 'US', 'prospect', array( 'google', 'cpc' ) ), array( 'Camila', 'Torres', 'Boquete', 'PA', 'lead', array( '', 'direct' ) ), array( 'Felix', 'Bauer', 'Vienna', 'AT', 'customer', array( 'partner', 'referral' ) ), array( 'Ines', 'Costa', 'Lisbon', 'PT', 'lead', array( 'google', 'organic' ) ), array( 'Omar', 'Said', 'Dubai', 'AE', 'prospect', array( 'linkedin', 'social' ) ), array( 'Julia', 'Novak', 'Prague', 'CZ', 'subscriber', array( 'newsletter', 'email' ) ), array( 'Mateo', 'Silva', 'Buenos Aires', 'AR', 'customer', array( 'google', 'organic' ) ), array( 'Lena', 'Fischer', 'Munich', 'DE', 'lead', array( 'facebook', 'social' ) ), array( 'Hugo', 'Garcia', 'Madrid', 'ES', 'inactive', array( '', 'direct' ) ), array( 'Valentina', 'Ruiz', 'Panama City', 'PA', 'lead', array( 'instagram', 'social' ) ), array( 'Daniel', 'Kim', 'Seoul', 'KR', 'customer', array( 'google', 'cpc' ) ), array( 'Chloe', 'Martin', 'Montreal', 'CA', 'lead', array( 'partner', 'referral' ) ), array( 'Pablo', 'Vega', 'Mexico City', 'MX', 'prospect', array( 'google', 'organic' ) ), array( 'Nina', 'Jansen', 'Rotterdam', 'NL', 'customer', array( 'newsletter', 'email' ) ), array( 'Leo', 'Brennan', 'Dublin', 'IE', 'lead', array( '', 'direct' ) ), ); $titles = array( 'Owner', 'Marketing lead', 'Operations manager', '', 'Founder', 'Office manager' ); $known = array_keys( Nodebook_Fields::statuses() ); foreach ( $people as $i => $p ) { $created = $ago( 2 + ( $i * 5 ) % 90, $i % 9 ); $seen = $ago( $i % 11, ( $i * 3 ) % 20 ); $status = in_array( $p[4], $known, true ) ? $p[4] : 'lead'; $buyer = 'customer' === $status; $id = (int) Nodebook_Contacts::insert( array( 'email' => strtolower( remove_accents( $p[0] . '.' . str_replace( ' ', '', $p[1] ) ) ) . '@example.com', 'first_name' => $p[0], 'last_name' => $p[1], 'phone' => '+507 6' . str_pad( (string) ( 100 + $i * 37 ), 3, '0', STR_PAD_LEFT ) . '-' . str_pad( (string) ( 1000 + $i * 211 ), 4, '0', STR_PAD_LEFT ), 'job_title' => $titles[ $i % count( $titles ) ], 'company_id' => 0 === $i % 3 ? 0 : $cos[ $i % count( $cos ) ], 'status' => $status, 'city' => $p[2], 'country' => $p[3], 'first_source' => $p[5][0], 'first_medium' => $p[5][1], 'source' => __( 'Sample data', 'nodebook' ), 'owner_id' => $me, 'visits_count' => 1 + ( $i * 7 ) % 12, 'orders_count' => $buyer ? 1 + $i % 4 : 0, 'total_spent' => $buyer ? 120 + ( $i * 173 ) % 2200 : 0, 'first_seen' => $created, 'last_seen' => $seen, ) ); if ( ! $id ) { continue; } $made['contacts'][] = $id; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the plugin's own table; backdating sample rows. $wpdb->update( Nodebook_Contacts::table(), array( 'created_at' => $created ), array( 'id' => $id ) ); $page = $kit['pages'][ $i % count( $kit['pages'] ) ]; Nodebook_Activities::add( $id, 'form', $kit['forms'][ $i % count( $kit['forms'] ) ], array( 'url' => home_url( $page ), 'created_at' => $created, 'data' => array( 'source' => __( 'Sample data', 'nodebook' ), 'fields' => array( 'Message' => sprintf( /* translators: %s: product or service */ __( 'Hi! I am interested in %s. Could you tell me more about the options and availability?', 'nodebook' ), $kit['items'][ $i % count( $kit['items'] ) ] ), ), ), ) ); for ( $v = 0; $v < 1 + $i % 4; $v++ ) { $path = $kit['pages'][ ( $i + $v ) % count( $kit['pages'] ) ]; Nodebook_Activities::add( $id, 'pageview', trim( $path, '/' ), array( 'url' => home_url( $path ), 'created_at' => $ago( $i % 11, $v + 1 ), // Pricing, booking and contact pages count as high intent. 'data' => array_filter( array( 'path' => $path, 'intent' => 0 === $v && 2 !== $i % 3, ) ), ) ); } // Visits, mostly at the same time of day, so "best time to reach" has something to show. $hour = array( 8, 12, 19, 20, 9, 21, 13 )[ $i % 7 ]; $tz = wp_timezone(); for ( $v = 0; $v < min( 8, 1 + ( $i * 7 ) % 12 ); $v++ ) { $day = ( new DateTimeImmutable( 'today', $tz ) )->modify( '-' . ( 1 + $v * 4 + $i % 3 ) . ' days' )->setTime( $hour + $v % 2, 10 + $v * 7 % 50 ); Nodebook_Activities::add( $id, 'visit', __( 'Visit', 'nodebook' ), array( 'url' => home_url( '/' ), 'created_at' => $day->setTimezone( new DateTimeZone( 'UTC' ) )->format( 'Y-m-d H:i:s' ), ) ); } // Customers: orders at a steady rhythm; one of them is overdue for the next. if ( $buyer ) { $every = 21 + ( $i % 3 ) * 14; $last = 'Nina' === $p[0] ? (int) round( $every * 1.6 ) : 3 + $i % 9; for ( $o = 3; $o >= 0; $o-- ) { Nodebook_Activities::add( $id, 'order', /* translators: %s: order number */ sprintf( __( 'Order #%s', 'nodebook' ), (string) ( 1000 + $i * 10 + $o ) ), array( 'created_at' => $ago( $last + $o * $every, 2 ), 'data' => array( 'value' => 40 + ( $i * 13 ) % 90, 'source' => __( 'Sample data', 'nodebook' ), ), ) ); } } if ( 0 === $i % 4 ) { Nodebook_Activities::add( $id, 'note', sprintf( /* translators: %s: product or service */ __( 'Called. Very interested in %s, wants a proposal by Friday.', 'nodebook' ), $kit['items'][ $i % count( $kit['items'] ) ] ), array( 'user_id' => $me, 'created_at' => $ago( 1 + $i % 6 ), ) ); } $set = array(); if ( $i < 4 ) { $set['last_intent_at'] = $ago( 0, $i + 1 ); } if ( $i >= 4 && $i < 7 ) { $set['remind_at'] = $ago( 0, 2 ); $set['last_inquiry_at'] = $ago( 2 ); } if ( $set ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- the plugin's own table. $wpdb->update( Nodebook_Contacts::table(), $set, array( 'id' => $id ) ); } } $ids = $made['contacts']; if ( Nodebook_Deals::on() && $ids ) { $stages = array_keys( Nodebook_Deals::stages() ); foreach ( $kit['deals'] as $n => $title ) { $cid = $ids[ ( $n * 3 + 1 ) % count( $ids ) ]; $deal = (int) Nodebook_Deals::add( array( 'title' => $title, 'contact_id' => $cid, 'value' => $kit['values'][ $n % count( $kit['values'] ) ], 'stage' => $stages[ $n % max( 1, count( $stages ) ) ], 'owner_id' => $me, 'expected_close' => gmdate( 'Y-m-d', time() + ( 5 + $n * 6 - 8 ) * DAY_IN_SECONDS ), ) ); if ( $deal ) { $made['deals'][] = $deal; if ( 4 === $n ) { Nodebook_Deals::close( $deal, 'won' ); } } } } $todo = array( array( __( 'Send the proposal', 'nodebook' ), 0 ), array( __( 'Call back about the dates', 'nodebook' ), -1 ), array( __( 'Check in after the first order', 'nodebook' ), 2 ), array( __( 'Ask for a review', 'nodebook' ), 0 ), ); foreach ( $todo as $n => $t ) { if ( empty( $ids[ $n * 2 ] ) ) { break; } $task = (int) Nodebook_Tasks::add( $ids[ $n * 2 ], $t[0], array( 'due_at' => gmdate( 'Y-m-d 15:00:00', time() + $t[1] * DAY_IN_SECONDS ) ) ); if ( $task ) { $made['tasks'][] = $task; } } $vip = (int) Nodebook_Segments::save( array( 'name' => __( 'VIP (sample)', 'nodebook' ), 'type' => 'static', ) ); if ( $vip ) { $made['segments'][] = $vip; $vips = array(); foreach ( $ids as $k => $cid ) { if ( 0 === $k % 3 && count( $vips ) < 5 ) { $vips[] = $cid; } } Nodebook_Segments::add_contacts( $vip, $vips ); } if ( class_exists( 'Nodebook_Gatherings' ) && Nodebook_Gatherings::on() && $ids ) { $g = (int) Nodebook_Gatherings::save( array( 'title' => $kit['items'][0], 'starts_on' => gmdate( 'Y-m-d', time() + 34 * DAY_IN_SECONDS ), 'ends_on' => gmdate( 'Y-m-d', time() + 39 * DAY_IN_SECONDS ), 'location' => 'Boquete, Panama', 'capacity' => 12, 'price' => 1800, 'deposit' => 500, 'status' => 'open', ) ); if ( $g ) { $made['gatherings'][] = $g; foreach ( array_slice( $ids, 0, 7 ) as $n => $cid ) { Nodebook_Gatherings::add( $g, $cid, array( 'status' => $n < 5 ? 'reserved' : 'interested', 'paid' => $n < 2 ? 1800 : ( $n < 4 ? 500 : 0 ), ) ); } } } update_option( self::OPTION, $made, false ); self::$running = false; /** * Sample data was added. * * @param array $made Ids of what was added. */ do_action( 'nodebook_sample_added', $made ); return count( $made['contacts'] ); } /** Remove every sample row, and nothing else. */ public static function remove() { $s = get_option( self::OPTION ); if ( ! is_array( $s ) ) { return 0; } foreach ( (array) ( $s['tasks'] ?? array() ) as $id ) { Nodebook_Tasks::delete( (int) $id ); } foreach ( (array) ( $s['deals'] ?? array() ) as $id ) { Nodebook_Deals::delete( (int) $id ); } if ( class_exists( 'Nodebook_Gatherings' ) && Nodebook_Gatherings::on() ) { foreach ( (array) ( $s['gatherings'] ?? array() ) as $id ) { Nodebook_Gatherings::delete( (int) $id ); } } foreach ( (array) ( $s['segments'] ?? array() ) as $id ) { Nodebook_Segments::delete( (int) $id ); } $n = count( (array) ( $s['contacts'] ?? array() ) ); if ( $n ) { Nodebook_Contacts::delete( array_map( 'intval', (array) $s['contacts'] ) ); } if ( ! empty( $s['companies'] ) ) { Nodebook_Companies::delete( array_map( 'intval', (array) $s['companies'] ) ); } delete_option( self::OPTION ); return $n; } /** admin-post: add or remove sample data. */ public static function handle() { Nodebook_Admin::require_cap(); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Only administrators can add or remove sample data.', 'nodebook' ), 403 ); } check_admin_referer( 'nodebook_sample' ); $do = isset( $_POST['do'] ) ? sanitize_key( wp_unslash( $_POST['do'] ) ) : ''; if ( 'remove' === $do ) { self::remove(); Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-today' ), 'sampleoff' ); } self::add(); Nodebook_Admin::redirect( Nodebook_Admin::url( 'nodebook-today' ), 'sampleon' ); } /** * The button that adds or removes sample data. * * @param string $class Extra button class. */ public static function button( $class = '' ) { if ( ! current_user_can( 'manage_options' ) ) { return; } $on = self::present(); echo '
'; } /** The strip on every Nodebook screen while sample data is in: what it is, and how to remove it. */ public static function banner() { if ( ! self::present() ) { return; } echo ''; } }