AdditionalPayments.php
1 year ago
Appearance.php
2 years ago
CustomizeStore.php
2 weeks ago
ExperimentalShippingRecommendation.php
2 weeks ago
ExtendStore.php
1 year ago
GetMobileApp.php
3 years ago
LaunchYourStore.php
2 weeks ago
Marketing.php
2 weeks ago
Payments.php
2 weeks ago
Products.php
2 weeks ago
ReviewShippingOptions.php
4 years ago
Shipping.php
2 weeks ago
StoreCreation.php
4 years ago
StoreDetails.php
2 weeks ago
Tax.php
2 weeks ago
TourInAppMarketplace.php
2 years ago
WooCommercePayments.php
2 weeks ago
LaunchYourStore.php
142 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks; |
| 4 | |
| 5 | use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task; |
| 6 | |
| 7 | /** |
| 8 | * Launch Your Store Task |
| 9 | */ |
| 10 | class LaunchYourStore extends Task { |
| 11 | /** |
| 12 | * Constructor |
| 13 | * |
| 14 | * @param TaskList $task_list Parent task list. |
| 15 | */ |
| 16 | public function __construct( $task_list ) { |
| 17 | parent::__construct( $task_list ); |
| 18 | |
| 19 | add_action( 'show_admin_bar', array( $this, 'possibly_hide_wp_admin_bar' ) ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * ID. |
| 24 | * |
| 25 | * @return string |
| 26 | */ |
| 27 | public function get_id() { |
| 28 | return 'launch-your-store'; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Contextual image URL. |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | public function get_image_url() { |
| 37 | return WC()->plugin_url() . '/assets/images/task_list/launch-your-store-illustration.svg'; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Alt text for the contextual image. |
| 42 | * |
| 43 | * @return string |
| 44 | */ |
| 45 | public function get_image_alt() { |
| 46 | return __( 'Launch your store illustration', 'woocommerce' ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Title. |
| 51 | * |
| 52 | * @return string |
| 53 | */ |
| 54 | public function get_title() { |
| 55 | return __( 'Launch your store', 'woocommerce' ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Content. |
| 60 | * |
| 61 | * @return string |
| 62 | */ |
| 63 | public function get_content() { |
| 64 | return __( |
| 65 | "It's time to celebrate – you're ready to launch your store! Woo! Hit the button to preview your store and make it public.", |
| 66 | 'woocommerce' |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Time. |
| 72 | * |
| 73 | * @return string |
| 74 | */ |
| 75 | public function get_time() { |
| 76 | return ''; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Action URL. |
| 81 | * |
| 82 | * @return string |
| 83 | */ |
| 84 | public function get_action_url() { |
| 85 | return admin_url( 'admin.php?page=wc-admin&path=%2Flaunch-your-store' ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Task completion. |
| 90 | * |
| 91 | * @return bool |
| 92 | */ |
| 93 | public function is_complete() { |
| 94 | return 'yes' !== get_option( 'woocommerce_coming_soon' ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Task visibility. |
| 99 | * |
| 100 | * @return bool |
| 101 | */ |
| 102 | public function can_view() { |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Hide the WP admin bar when the user is previewing the site. |
| 108 | * |
| 109 | * @param bool $show Whether to show the admin bar. |
| 110 | */ |
| 111 | public function possibly_hide_wp_admin_bar( $show ) { |
| 112 | if ( isset( $_GET['site-preview'] ) ) { // @phpcs:ignore |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | global $wp; |
| 117 | $http_referer = wp_get_referer() ?? ''; |
| 118 | $parsed_url = wp_parse_url( $http_referer, PHP_URL_QUERY ); |
| 119 | $query_string = is_string( $parsed_url ) ? $parsed_url : ''; |
| 120 | |
| 121 | // Check if the user is coming from the site preview link. |
| 122 | if ( strpos( $query_string, 'site-preview' ) !== false ) { |
| 123 | if ( ! isset( $_SERVER['REQUEST_URI'] ) ) { |
| 124 | return $show; |
| 125 | } |
| 126 | |
| 127 | // Redirect to the current URL with the site-preview query string. |
| 128 | $current_url = |
| 129 | add_query_arg( |
| 130 | array( |
| 131 | 'site-preview' => 1, |
| 132 | ), |
| 133 | esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) |
| 134 | ); |
| 135 | wp_safe_redirect( $current_url ); |
| 136 | exit; |
| 137 | } |
| 138 | |
| 139 | return $show; |
| 140 | } |
| 141 | } |
| 142 |