> */ const HOSTS = array( self::PRODUCTION => array( 'viewer' => 'https://viewer.thridify.com', 'models' => 'https://models.thridify.com', 'shopper' => 'https://admin.thridify.com', 'api' => 'https://api.thridify.com', ), self::SANDBOX => array( 'viewer' => 'https://devviewer.thridify.com', 'models' => 'https://devmodels.thridify.com', 'shopper' => 'https://devadmin.thridify.com', 'api' => 'https://api-dev.thridify.com', ), ); /** * The environment the storefront serves. * * @return string */ public static function current() { $env = Settings::get( 'environment' ); return self::SANDBOX === $env ? self::SANDBOX : self::PRODUCTION; } /** * Hosts for an environment (filterable for staging setups). * * @param string|null $env Environment; current when null. * @return array */ public static function hosts( $env = null ) { $env = self::SANDBOX === $env ? self::SANDBOX : ( null === $env ? self::current() : self::PRODUCTION ); $hosts = self::HOSTS[ $env ]; /** * Filters the Thridify hosts used by the plugin. * * @param array $hosts viewer, models, shopper and api base URLs. * @param string $env production|sandbox. */ $hosts = (array) apply_filters( 'thridify_hosts', $hosts, $env ); foreach ( $hosts as $key => $url ) { $hosts[ $key ] = untrailingslashit( esc_url_raw( (string) $url ) ); } return $hosts; } /** * One host. * * @param string $key viewer|models|shopper|api. * @param string|null $env Environment; current when null. * @return string */ public static function host( $key, $env = null ) { $hosts = self::hosts( $env ); return isset( $hosts[ $key ] ) ? $hosts[ $key ] : ''; } /** * Whether the site may pick the sandbox environment. * * @return bool */ public static function sandbox_allowed() { if ( defined( 'THRIDIFY_ALLOW_SANDBOX' ) && THRIDIFY_ALLOW_SANDBOX ) { return true; } if ( self::SANDBOX === self::current() ) { return true; } $health = \Thridify\Connect\Connection::health( self::PRODUCTION ); return ! empty( $health['sandboxAccess'] ); } }