← Back
Editing: Helper.php
<?php /** * The Helper class. * * @package GoDaddy */ namespace GoDaddy\WordPress\Plugins\Launch; defined( 'ABSPATH' ) || exit; /** * The Helper class. */ class Helper { /** * Returns the current server environment name from SERVER_ENV. * * @return string */ public static function wpnux_env() { return (string) getenv( 'SERVER_ENV', true ); } /** * Retrieve the correct URL of the NUX API depending on the environment * * @return string */ public static function wpnux_api_base() { $api_urls = array( 'local' => 'https://wpnux.test/v3/api', 'dev' => 'https://wpnux.dev-godaddy.com/v3/api', 'test' => 'https://wpnux.test-godaddy.com/v3/api', 'prod' => 'https://wpnux.godaddy.com/v3/api', ); $env = self::wpnux_env(); $api_url = ! empty( $api_urls[ $env ] ) ? $api_urls[ $env ] : $api_urls['dev']; return untrailingslashit( (string) apply_filters( 'godaddy_launch_wpnux_api_url', $api_url ) ); } /** * Determine if the RUM (Real User Metrics) is enabled * * @return bool */ public static function is_rum_enabled() { return (bool) apply_filters( 'wpaas_rum_enabled', defined( 'GD_RUM_ENABLED' ) ? GD_RUM_ENABLED : true ); } /** * Return the site domain. * * @return string */ public static function domain() { return wp_parse_url( home_url(), PHP_URL_HOST ); } /** * Convert option boolean value to timestamp when saved. * * @param string $value passed from filter. * * @return mixed */ public static function update_option_convert_true_to_timestamp( $value ) { return ( 'true' === $value || true === $value ) ? time() : $value; } /** * Get skipped or boolean as string. * * @param string $value passed from filter. * * @return bool */ public static function get_skipped_or_boolean_as_string( $value ) { return ( 'skipped' === $value ) ? $value : (string) self::get_option_convert_timestamp_to_true( $value ); } /** * Convert option timestamp value to boolean. * * @param string $value passed from filter. * * @return bool */ public static function get_option_convert_timestamp_to_true( $value ) { return ! empty( $value ); } /** * Whether the site belongs to a reseller brand (PLID other than GoDaddy's 1). * * Checks both the v1 GD_RESELLER constant and the v2 configData payload. * * @return bool */ public static function is_reseller() { $is_reseller_v1 = defined( 'GD_RESELLER' ) && 1 !== (int) constant( 'GD_RESELLER' ); $config_data = defined( 'configData' ) ? json_decode( constant( 'configData' ), true ) : array(); $is_reseller_v2 = is_array( $config_data ) && array_key_exists( 'GD_RESELLER', $config_data ) && '1' !== (string) $config_data['GD_RESELLER']; return $is_reseller_v1 || $is_reseller_v2; } /** * Return the hosting dashboard (MYH) host for the current brand. * * GoDaddy-direct sites (GD_RESELLER = 1 or undefined) use host.godaddy.com. * Reseller brands (123 Reg, Host Europe, etc.) use host.secureserver.net. * * @return string */ public static function myh_host() { $host = self::is_reseller() ? 'host.secureserver.net' : 'host.godaddy.com'; return (string) apply_filters( 'godaddy_launch_myh_host', $host ); } /** * Return the customer ID made available by the hosting platform. * * Managed WordPress sites expose this value in the JSON configData * constant, while other platform contexts use GD_CUSTOMER_ID directly. * * @return string A UUID customer ID, or an empty string when unavailable. */ public static function customer_id() { $config_data = defined( 'configData' ) ? json_decode( constant( 'configData' ), true ) : array(); $constant = defined( 'GD_CUSTOMER_ID' ) ? constant( 'GD_CUSTOMER_ID' ) : null; return self::resolve_customer_id( $config_data, $constant ); } /** * Resolve a valid customer ID from the two hosting-platform sources. * * @param mixed $config_data Decoded configData constant. * @param mixed $constant Standalone GD_CUSTOMER_ID constant. * @return string A UUID customer ID, or an empty string when unavailable. */ public static function resolve_customer_id( $config_data, $constant ) { $candidates = array(); if ( is_array( $config_data ) && isset( $config_data['GD_CUSTOMER_ID'] ) ) { $candidates[] = $config_data['GD_CUSTOMER_ID']; } if ( null !== $constant ) { $candidates[] = $constant; } foreach ( $candidates as $candidate ) { if ( is_scalar( $candidate ) && wp_is_uuid( (string) $candidate ) ) { return (string) $candidate; } } return ''; } /** * Get the default request body payload for the NUX API. * * @return array */ public static function get_default_nux_api_request_body() { $parent_theme = get_option( 'template' ); $parent_theme = is_string( $parent_theme ) ? strtolower( $parent_theme ) : null; return array( 'coblocks_version' => defined( 'COBLOCKS_VERSION' ) ? COBLOCKS_VERSION : null, 'current_theme' => $parent_theme, 'customer_id' => defined( 'GD_CUSTOMER_ID' ) ? GD_CUSTOMER_ID : null, 'gdl_version' => gdl()->version(), 'go_theme_version' => defined( 'GO_VERSION' ) ? GO_VERSION : null, 'hostname' => gethostname(), 'is_coblocks_active' => is_plugin_active( 'coblocks/class-coblocks.php' ), 'is_go_theme_active' => 'go' === $parent_theme, 'language' => substr( get_user_locale(), 0, 5 ), 'pl_id' => defined( 'GD_RESELLER' ) ? (int) GD_RESELLER : null, 'site_created_at' => defined( 'GD_SITE_CREATED' ) ? GD_SITE_CREATED : null, 'site_domain' => parse_url( home_url(), PHP_URL_HOST ), 'system_plugin_version' => is_callable( array( '\WPaaS\Plugin', 'version' ) ) ? \WPaaS\Plugin::version() : null, 'website_id' => defined( 'GD_ACCOUNT_UID' ) ? GD_ACCOUNT_UID : null, 'wp_user_id' => get_current_user_id(), 'wp_version' => get_bloginfo( 'version' ), ); } }
Save File
Cancel