| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
|
| 5 |
|
| 6 |
function wpstream_track_onboarding_step_php( $action, $step, $element_type = 'system', $element_name = '' ) { |
| 7 |
if ( ! defined( 'WPSTREAM_CLICK' ) || empty( WPSTREAM_CLICK ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
$endpoint = trailingslashit( WPSTREAM_CLICK ) . 'onboarding/index.php'; |
| 12 |
$transaction_id = ''; |
| 13 |
if ( isset( $_COOKIE['transactionId'] ) ) { |
| 14 |
$transaction_id = sanitize_text_field( wp_unslash( $_COOKIE['transactionId'] ) ); |
| 15 |
} |
| 16 |
|
| 17 |
$payload = array( |
| 18 |
'website' => home_url(), |
| 19 |
'action' => $action, |
| 20 |
'wps_user' => get_option('wpstream_api_username_from_token'), |
| 21 |
'parameters' => array( |
| 22 |
'step' => $step, |
| 23 |
'element_type' => $element_type, |
| 24 |
'element_name' => $element_name, |
| 25 |
), |
| 26 |
'plugin_version' => defined( 'WPSTREAM_PLUGIN_VERSION' ) ? WPSTREAM_PLUGIN_VERSION : '', |
| 27 |
'session_id' => '', |
| 28 |
'transaction_id' => $transaction_id, |
| 29 |
); |
| 30 |
|
| 31 |
$response = wp_remote_post( |
| 32 |
$endpoint, |
| 33 |
array( |
| 34 |
'timeout' => 5, |
| 35 |
'headers' => array( |
| 36 |
'Content-Type' => 'application/json', |
| 37 |
), |
| 38 |
'body' => wp_json_encode( $payload ), |
| 39 |
) |
| 40 |
); |
| 41 |
|
| 42 |
return ! is_wp_error( $response ); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
function wpstream_track_ocdi_import_attempt( $selected_import ) { |
| 47 |
$import_name = 'unknown_import'; |
| 48 |
|
| 49 |
if ( is_array( $selected_import ) && ! empty( $selected_import['import_file_name'] ) ) { |
| 50 |
$import_name = sanitize_text_field( $selected_import['import_file_name'] ); |
| 51 |
} |
| 52 |
|
| 53 |
wpstream_track_onboarding_step_php( 'import_attempted', 'ocdi_before_content_import', 'system', $import_name ); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
function wpstream_ocdi_plugin_intro_text( $default_text ) { |
| 58 |
$default_text = '<div class="ocdi__intro-text intro-text_wpstream_theme notice notice-warning "> For speed purposes, demo images are not included in the import.</div>'; |
| 59 |
|
| 60 |
return $default_text; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
function wpstream_ocdi_import_files() { |
| 65 |
|
| 66 |
if(!function_exists( 'wpstream_load_theme_files' )){ |
| 67 |
return; |
| 68 |
} |
| 69 |
$demo_array= array( |
| 70 |
'main-demo' => array( |
| 71 |
'import_file_name' => 'Main Demo', |
| 72 |
'import_file_url' => 'https://wpstream.net/downloads/demos/main/demo-content.xml', |
| 73 |
'import_widget_file_url' => 'https://wpstream.net/downloads/demos/main/widgets.wie', |
| 74 |
'import_customizer_file_url' => 'https://wpstream.net/downloads/demos/main/customizer.dat', |
| 75 |
'import_preview_image_url' => 'https://wpstream.net/downloads/demos/main/preview.png' , |
| 76 |
'import_notice' => esc_html__( 'Clear theme cache after demo import is complete!', 'hello-wpstream' ), |
| 77 |
'preview_url' => 'https://theme.wpstream.net/', |
| 78 |
|
| 79 |
), |
| 80 |
'esports-demo' => array( |
| 81 |
'import_file_name' => 'ESports Demo', |
| 82 |
'import_file_url' => 'https://wpstream.net/downloads/demos/esports/esports-demo.xml', |
| 83 |
'import_widget_file_url' => 'https://wpstream.net/downloads/demos/esports/widgets.wie', |
| 84 |
'import_customizer_file_url' => 'https://wpstream.net/downloads/demos/esports/customizer.dat', |
| 85 |
'import_preview_image_url' => 'https://wpstream.net/downloads/demos/esports/preview.png' , |
| 86 |
'import_notice' => esc_html__( 'Clear theme cache after demo import is complete!', 'hello-wpstream' ), |
| 87 |
'preview_url' => 'https://esports.wpstream.net/', |
| 88 |
), |
| 89 |
'church-demo' => array( |
| 90 |
'import_file_name' => 'Church Demo', |
| 91 |
'import_file_url' => 'https://wpstream.net/downloads/demos/church/church-demo.xml', |
| 92 |
'import_widget_file_url' => 'https://wpstream.net/downloads/demos/church/widgets.wie', |
| 93 |
'import_customizer_file_url' => 'https://wpstream.net/downloads/demos/church/customizer.dat', |
| 94 |
'import_preview_image_url' => 'https://wpstream.net/downloads/demos/church/preview.png' , |
| 95 |
'import_notice' => esc_html__( 'Clear theme cache after demo import is complete!', 'hello-wpstream' ), |
| 96 |
'preview_url' => 'https://church.wpstream.net/', |
| 97 |
|
| 98 |
), |
| 99 |
'live-shopping-demo' => array( |
| 100 |
'import_file_name' => 'Live Shopping Demo', |
| 101 |
'import_file_url' => 'https://wpstream.net/downloads/demos/live-shoping/live_shoping_content.xml', |
| 102 |
'import_widget_file_url' => 'https://wpstream.net/downloads/demos/live-shoping/live_shoping_widgets.wie', |
| 103 |
'import_customizer_file_url' => 'https://wpstream.net/downloads/demos/live-shoping/live_shoping_customizer.dat', |
| 104 |
'import_preview_image_url' => 'https://wpstream.net/downloads/demos/live-shoping/preview.png' , |
| 105 |
'import_notice' => esc_html__( 'Clear theme cache after demo import is complete!', 'hello-wpstream' ), |
| 106 |
'preview_url' => 'https://liveshopping.wpstream.net/', |
| 107 |
), |
| 108 |
'believe-demo' => array( |
| 109 |
'import_file_name' => 'Believe Demo', |
| 110 |
'import_file_url' => 'https://wpstream.net/downloads/demos/believe/believe-demo.xml', |
| 111 |
'import_widget_file_url' => 'https://wpstream.net/downloads/demos/believe/widgets.wie', |
| 112 |
'import_customizer_file_url' => 'https://wpstream.net/downloads/demos/believe/customizer.dat', |
| 113 |
'import_preview_image_url' => 'https://wpstream.net/downloads/demos/believe/preview.png' , |
| 114 |
'import_notice' => esc_html__( 'Clear theme cache after demo import is complete!', 'hello-wpstream' ), |
| 115 |
'preview_url' => 'https://believe.wpstream.net/', |
| 116 |
) |
| 117 |
); |
| 118 |
|
| 119 |
return $demo_array; |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
function wpstream_ocdi_after_import_setup() { |
| 128 |
// Assign menus to their locations. |
| 129 |
|
| 130 |
$main_menu = get_term_by( 'name', 'Main Menu', 'nav_menu' ); |
| 131 |
$main_menu2 = get_term_by( 'name', 'First Menu', 'nav_menu' ); |
| 132 |
$main_menu3 = get_term_by( 'name', 'Third menu', 'nav_menu' ); |
| 133 |
|
| 134 |
set_theme_mod( 'nav_menu_locations', array( |
| 135 |
'main-menu' => $main_menu->term_id, |
| 136 |
'main-menu2' => $main_menu2->term_id, |
| 137 |
'main-menu3' => $main_menu3->term_id |
| 138 |
) |
| 139 |
); |
| 140 |
|
| 141 |
|
| 142 |
// Assign front page and posts page (blog page). |
| 143 |
$front_page_id = get_page_by_title( 'Homepage' ); |
| 144 |
$blog_page_id = get_page_by_title( 'Blog' ); |
| 145 |
|
| 146 |
update_option( 'show_on_front', 'page' ); |
| 147 |
update_option( 'page_on_front', $front_page_id->ID ); |
| 148 |
update_option( 'page_for_posts', $blog_page_id->ID ); |
| 149 |
|
| 150 |
// disable coming soon mode of WooCommerce |
| 151 |
// so users can see the paid channels/VODs after demo import |
| 152 |
update_option('woocommerce_coming_soon', 'no'); |
| 153 |
|
| 154 |
// Track successful demo import for onboarding analytics. |
| 155 |
wpstream_track_onboarding_step_php( 'import_succeeded', 'ocdi_after_import_setup', 'system', 'demo_import' ); |
| 156 |
} |
| 157 |
|
| 158 |
?> |