'GET', 'callback' => [ $this, 'get_status' ], 'permission_callback' => [ $this, 'check_permission' ], ] ); register_rest_route( self::NAMESPACE, '/setup-status/dismiss', [ 'methods' => 'POST', 'callback' => [ $this, 'dismiss' ], 'permission_callback' => [ $this, 'check_permission' ], ] ); } /** * GET /mintall/v1/setup-status */ public function get_status() { $has_protected = (bool) get_posts( [ 'post_type' => 'product', 'post_status' => 'any', 'meta_key' => '_mintall_asset_id', 'meta_compare' => 'EXISTS', 'fields' => 'ids', 'posts_per_page' => 1, ] ); $has_synced_products = false; $has_visible = false; $domain_status = null; $domain_registered = null; $api_key = $this->get_api_key(); if ( ! is_wp_error( $api_key ) ) { $product_ids = wc_get_products( [ 'status' => 'publish', 'limit' => 100, 'return' => 'ids', ] ); if ( ! empty( $product_ids ) ) { $external_ids = array_map( 'strval', $product_ids ); $result = Mintall_Products::lookup( $api_key, $external_ids ); if ( ! is_wp_error( $result ) && is_array( $result ) ) { $has_synced_products = ! empty( $result ); foreach ( $result as $row ) { if ( ! empty( $row['visible_at'] ) ) { $has_visible = true; break; } } } } // Domain verification status. NOT_STARTED is a normal initial state; treat as null. $domain_response = Mintall_Domain::verify( $api_key ); if ( ! is_wp_error( $domain_response ) ) { $domain_status = $domain_response['status'] ?? null; $domain_registered = $domain_response['domain'] ?? null; } } $current_site = $this->current_site_info(); $verify_domain = 'verified' === $domain_status || ! $current_site['host_is_verifiable']; $dismissed = get_option( 'mintall_keep_setup_dismissed', false ); return new \WP_REST_Response( [ 'steps' => [ 'protect_product' => $has_protected, 'sync_products' => $has_synced_products, 'enable_visibility' => $has_visible, 'verify_domain' => $verify_domain, ], 'dismissed' => (bool) $dismissed, 'auto_protect' => (bool) get_option( 'mintall_keep_auto_protect', false ), 'visibility_on_protect' => (bool) get_option( 'mintall_keep_visibility_on_protect', false ), 'domain_verification_status' => $domain_status, 'domain_verification_domain' => $domain_registered, 'current_site_host' => $current_site['current_site_host'], 'host_is_verifiable' => $current_site['host_is_verifiable'], 'page_view_capture' => Mintall_Pageview::is_enabled(), 'page_view_capture_decided' => Mintall_Pageview::is_decided(), ] ); } private function current_site_info() { $host = wp_parse_url( home_url(), PHP_URL_HOST ); $host = is_string( $host ) ? strtolower( $host ) : ''; return [ 'current_site_host' => $host ?: null, 'host_is_verifiable' => $host ? $this->is_verifiable_host( $host ) : false, ]; } private function is_verifiable_host( $host ) { if ( in_array( $host, [ 'localhost', '127.0.0.1', '::1' ], true ) ) { return false; } if ( preg_match( '/\.(local|test|localhost|internal|lan)$/i', $host ) ) { return false; } if ( filter_var( $host, FILTER_VALIDATE_IP ) ) { return false; } if ( strpos( $host, '.' ) === false ) { return false; } return true; } /** * POST /mintall/v1/setup-status/dismiss */ public function dismiss() { update_option( 'mintall_keep_setup_dismissed', true ); return new \WP_REST_Response( [ 'success' => true ] ); } }