PHP 8.2.31
Preview: LaunchYourStore.php Size: 5.15 KB
/home/nshryvcy/radiantskinclinics.org/wp-content/plugins/woocommerce/src/Admin/API/LaunchYourStore.php

<?php
/**
 * REST API Launch Your Store Controller
 *
 * Handles requests to /launch-your-store/*
 */

namespace Automattic\WooCommerce\Admin\API;

use Automattic\WooCommerce\Admin\WCAdminHelper;

defined( 'ABSPATH' ) || exit;

/**
 * Launch Your Store controller.
 *
 * @internal
 */
class LaunchYourStore {

	/**
	 * Endpoint namespace.
	 *
	 * @var string
	 */
	protected $namespace = 'wc-admin';

	/**
	 * Route base.
	 *
	 * @var string
	 */
	protected $rest_base = 'launch-your-store';

	/**
	 * Register routes.
	 */
	public function register_routes() {
		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base . '/initialize-coming-soon',
			array(
				array(
					'methods'             => 'POST',
					'callback'            => array( $this, 'initialize_coming_soon' ),
					'permission_callback' => array( $this, 'must_be_shop_manager_or_admin' ),
				),
			)
		);

		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base . '/update-survey-status',
			array(
				array(
					'methods'             => 'POST',
					'callback'            => array( $this, 'update_survey_status' ),
					'permission_callback' => array( $this, 'must_be_shop_manager_or_admin' ),
					'args'                => array(
						'status' => array(
							'type' => 'string',
							'enum' => array( 'yes', 'no' ),
						),
					),
				),
			)
		);

		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base . '/survey-completed',
			array(
				array(
					'methods'             => 'GET',
					'callback'            => array( $this, 'has_survey_completed' ),
					'permission_callback' => array( $this, 'must_be_shop_manager_or_admin' ),
				),
			)
		);

		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base . '/woopayments/test-orders/count',
			array(
				array(
					'methods'             => 'GET',
					'callback'            => array( $this, 'get_woopay_test_orders_count' ),
					'permission_callback' => array( $this, 'must_be_shop_manager_or_admin' ),
				),
			)
		);

		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base . '/woopayments/test-orders',
			array(
				array(
					'methods'             => 'DELETE',
					'callback'            => array( $this, 'delete_woopay_test_orders' ),
					'permission_callback' => array( $this, 'must_be_shop_manager_or_admin' ),
				),
			)
		);
	}

	/**
	 * User must be either shop_manager or administrator.
	 *
	 * @return bool
	 */
	public function must_be_shop_manager_or_admin() {
		// phpcs:ignore
		if ( ! current_user_can( 'manage_woocommerce' ) && ! current_user_can( 'administrator' ) ) {
			return false;
		}
		return true;
	}

	/**
	 * Initializes options for coming soon. Overwrites existing coming soon status but keeps the private link and share key.
	 *
	 * @return bool|void
	 */
	public function initialize_coming_soon() {
		$current_user_id = get_current_user_id();
		// Abort if we don't have a user id for some reason.
		if ( ! $current_user_id ) {
			return;
		}

		$coming_soon      = 'yes';
		$store_pages_only = WCAdminHelper::is_site_fresh() ? 'no' : 'yes';
		$private_link     = 'no';
		$share_key        = wp_generate_password( 32, false );

		update_option( 'woocommerce_coming_soon', $coming_soon );
		update_option( 'woocommerce_store_pages_only', $store_pages_only );
		add_option( 'woocommerce_private_link', $private_link );
		add_option( 'woocommerce_share_key', $share_key );

		wc_admin_record_tracks_event(
			'launch_your_store_initialize_coming_soon',
			array(
				'coming_soon'      => $coming_soon,
				'store_pages_only' => $store_pages_only,
				'private_link'     => $private_link,
			)
		);

		return true;
	}

	/**
	 * Count the test orders created during Woo Payments test mode.
	 *
	 * @return \WP_REST_Response
	 */
	public function get_woopay_test_orders_count() {
		$return = function ( $count ) {
			return new \WP_REST_Response( array( 'count' => $count ) );
		};

		$orders = wc_get_orders(
			array(
				// phpcs:ignore
				'meta_key'   => '_wcpay_mode',
				// phpcs:ignore
				'meta_value' => 'test',
				'return'     => 'ids',
			)
		);

		return $return( count( $orders ) );
	}

	/**
	 * Delete WooPayments test orders.
	 *
	 * @return \WP_REST_Response
	 */
	public function delete_woopay_test_orders() {
		$return = function ( $status = 204 ) {
			return new \WP_REST_Response( null, $status );
		};

		$orders = wc_get_orders(
			array(
				// phpcs:ignore
				'meta_key'   => '_wcpay_mode',
				// phpcs:ignore
				'meta_value' => 'test',
			)
		);

		foreach ( $orders as $order ) {
			$order->delete();
		}

		return $return();
	}

	/**
	 * Update woocommerce_admin_launch_your_store_survey_completed to yes or no
	 *
	 * @param \WP_REST_Request $request WP_REST_Request object.
	 *
	 * @return \WP_REST_Response
	 */
	public function update_survey_status( \WP_REST_Request $request ) {
		update_option( 'woocommerce_admin_launch_your_store_survey_completed', $request->get_param( 'status' ) );
		return new \WP_REST_Response();
	}

	/**
	 * Return woocommerce_admin_launch_your_store_survey_completed option.
	 *
	 * @return \WP_REST_Response
	 */
	public function has_survey_completed() {
		return new \WP_REST_Response( get_option( 'woocommerce_admin_launch_your_store_survey_completed', 'no' ) );
	}
}

Directory Contents

Dirs: 3 × Files: 46

Name Size Perms Modified Actions
AI DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Reports DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
Templates DIR
- drwxr-xr-x 2026-05-29 02:43:21
Edit Download
9.09 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
2.15 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
3.40 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
2.11 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
939 B lrw-r--r-- 2022-04-20 06:50:54
Edit Download
1.12 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
4.15 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
1.82 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
1.70 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
10.57 KB lrw-r--r-- 2026-01-19 14:46:18
Edit Download
5.15 KB lrw-r--r-- 2024-12-18 22:19:16
Edit Download
18.22 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
4.90 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
9.64 KB lrw-r--r-- 2024-03-26 16:56:02
Edit Download
6.02 KB lrw-r--r-- 2023-01-25 03:19:12
Edit Download
5.74 KB lrw-r--r-- 2023-01-25 03:19:12
Edit Download
3.41 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
5.94 KB lrw-r--r-- 2024-01-30 23:24:56
Edit Download
2.10 KB lrw-r--r-- 2022-09-20 22:53:36
Edit Download
2.39 KB lrw-r--r-- 2023-03-21 20:45:06
Edit Download
25.32 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
2.38 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
2.58 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
10.77 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
1.94 KB lrw-r--r-- 2024-01-30 23:24:56
Edit Download
1.80 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
18.38 KB lrw-r--r-- 2025-05-12 21:07:28
Edit Download
32.02 KB lrw-r--r-- 2025-10-06 17:56:06
Edit Download
5.49 KB lrw-r--r-- 2025-10-06 17:56:06
Edit Download
10.00 KB lrw-r--r-- 2025-05-26 19:11:58
Edit Download
10.13 KB lrw-r--r-- 2024-07-30 19:31:16
Edit Download
5.91 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
21.27 KB lrw-r--r-- 2026-05-05 14:26:50
Edit Download
4.46 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
4.36 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
458 B lrw-r--r-- 2022-04-20 06:50:54
Edit Download
3.06 KB lrw-r--r-- 2023-02-22 07:17:34
Edit Download
1.30 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
9.73 KB lrw-r--r-- 2024-10-21 23:53:16
Edit Download
17.62 KB lrw-r--r-- 2026-02-23 17:58:34
Edit Download
6.03 KB lrw-r--r-- 2025-01-21 18:53:44
Edit Download
878 B lrw-r--r-- 2023-03-21 20:45:06
Edit Download
4.20 KB lrw-r--r-- 2025-03-03 22:28:12
Edit Download
6.33 KB lrw-r--r-- 2026-05-11 17:17:08
Edit Download
4.90 KB lrw-r--r-- 2022-04-20 06:50:54
Edit Download
6.12 KB lrw-r--r-- 2024-02-27 18:59:46
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).