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