Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
98.43% |
188 / 191 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Brands | |
98.43% |
188 / 191 |
|
75.00% |
3 / 4 |
12 | |
0.00% |
0 / 1 |
| get_brand_data | |
100.00% |
171 / 171 |
|
100.00% |
1 / 1 |
1 | |||
| get_data_for_brand | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| get_resource_link_for_brand | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| set_current_brand | |
66.67% |
6 / 9 |
|
0.00% |
0 / 1 |
5.93 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\HelpCenter\Data; |
| 4 | |
| 5 | /** |
| 6 | * Contains Brand information. |
| 7 | */ |
| 8 | final class Brands { |
| 9 | |
| 10 | /** |
| 11 | * Brand-specific data for JS components and resource links. |
| 12 | * Keys match NFD_HELPCENTER_PLUGIN_BRAND (bluehost, hostgator-us, hostgator-ar, etc.). |
| 13 | * HostGator regions mirror region.js: main, help_phone_number, help_chat, help_kb. |
| 14 | * |
| 15 | * @return array |
| 16 | */ |
| 17 | public static function get_brand_data() { |
| 18 | $help_chat_latam = 'https://soporte.hostgator.mx/hc/es-419/articles/28439167280915-C%C3%B3mo-entrar-en-contacto-con-Soporte'; |
| 19 | $help_kb_latam = 'https://soporte.hostgator.mx/hc/es-419'; |
| 20 | |
| 21 | return array( |
| 22 | 'bluehost' => array( |
| 23 | 'brand' => 'bluehost', |
| 24 | 'name' => __( 'Bluehost', 'wp-module-help-center' ), |
| 25 | 'url' => apply_filters( 'nfd_build_url', 'https://bluehost.com' ), |
| 26 | 'helpURL' => apply_filters( 'nfd_build_url', 'https://www.bluehost.com/help' ), |
| 27 | 'contactUrl' => apply_filters( 'nfd_build_url', 'https://www.bluehost.com/contact' ), |
| 28 | 'phone' => '8884014678', |
| 29 | 'phoneDisplay' => '888-401-4678', |
| 30 | 'accountName' => __( 'Bluehost', 'wp-module-help-center' ), |
| 31 | 'hasPhone' => true, |
| 32 | 'showProDesignBanner' => true, |
| 33 | 'kbClickDomains' => array( 'bhmultisite.com' ), |
| 34 | 'proDesignUrl' => apply_filters( 'nfd_build_url', 'https://www.bluehost.com/pro-design-live' ), |
| 35 | 'proDesignHeading' => __( 'Your dream site is just a click away.', 'wp-module-help-center' ), |
| 36 | 'proDesignSubheading' => __( "Let's build a site you love, together.", 'wp-module-help-center' ), |
| 37 | 'proDesignBody' => __( 'With Pro Design Live, our expert team bring your vision to life. We help you to create the site you\'ve always dreamed of — tailored to your goals, ready to perform.', 'wp-module-help-center' ), |
| 38 | 'proDesignCta' => __( 'Start Now', 'wp-module-help-center' ), |
| 39 | ), |
| 40 | 'hostgator-us' => array( |
| 41 | 'brand' => 'hostgator', |
| 42 | 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 43 | 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.com' ), |
| 44 | 'helpURL' => apply_filters( 'nfd_build_url', 'https://www.hostgator.com/help' ), |
| 45 | 'contactUrl' => apply_filters( 'nfd_build_url', 'https://helpchat.hostgator.com' ), |
| 46 | 'phone' => '8669642867', |
| 47 | 'phoneDisplay' => '866-964-2867', |
| 48 | 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 49 | 'hasPhone' => true, |
| 50 | 'showProDesignBanner' => false, |
| 51 | 'kbClickDomains' => array(), |
| 52 | ), |
| 53 | |
| 54 | /* |
| 55 | * HostGator regions below are NOT YET IN USE — only US sites have the help center capability. |
| 56 | * Uncomment when ready to enable help center for these regions. |
| 57 | */ |
| 58 | // phpcs:disable Squiz.PHP.CommentedOutCode.Found -- Future regions, keep for easy re-enable. |
| 59 | // 'hostgator-ar' => array( |
| 60 | // 'brand' => 'hostgator-ar', |
| 61 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 62 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.ar' ), |
| 63 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 64 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 65 | // 'phone' => '', |
| 66 | // 'phoneDisplay' => '', |
| 67 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 68 | // 'hasPhone' => false, |
| 69 | // 'showProDesignBanner' => false, |
| 70 | // 'kbClickDomains' => array(), |
| 71 | // ), |
| 72 | // 'hostgator-bo' => array( |
| 73 | // 'brand' => 'hostgator-bo', |
| 74 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 75 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.bo' ), |
| 76 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 77 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 78 | // 'phone' => '', |
| 79 | // 'phoneDisplay' => '', |
| 80 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 81 | // 'hasPhone' => false, |
| 82 | // 'showProDesignBanner' => false, |
| 83 | // 'kbClickDomains' => array(), |
| 84 | // ), |
| 85 | // 'hostgator-br' => array( |
| 86 | // 'brand' => 'hostgator-br', |
| 87 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 88 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.com.br' ), |
| 89 | // 'helpURL' => apply_filters( 'nfd_build_url', 'https://suporte.hostgator.com.br/hc/pt-br' ), |
| 90 | // 'contactUrl' => apply_filters( 'nfd_build_url', 'https://suporte.hostgator.com.br/hc/pt-br' ), |
| 91 | // 'phone' => '', |
| 92 | // 'phoneDisplay' => '', |
| 93 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 94 | // 'hasPhone' => false, |
| 95 | // 'showProDesignBanner' => false, |
| 96 | // 'kbClickDomains' => array(), |
| 97 | // ), |
| 98 | // 'hostgator-cl' => array( |
| 99 | // 'brand' => 'hostgator-cl', |
| 100 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 101 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.cl' ), |
| 102 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 103 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 104 | // 'phone' => '', |
| 105 | // 'phoneDisplay' => '', |
| 106 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 107 | // 'hasPhone' => false, |
| 108 | // 'showProDesignBanner' => false, |
| 109 | // 'kbClickDomains' => array(), |
| 110 | // ), |
| 111 | // 'hostgator-co' => array( |
| 112 | // 'brand' => 'hostgator-co', |
| 113 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 114 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.co' ), |
| 115 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 116 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 117 | // 'phone' => '', |
| 118 | // 'phoneDisplay' => '', |
| 119 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 120 | // 'hasPhone' => false, |
| 121 | // 'showProDesignBanner' => false, |
| 122 | // 'kbClickDomains' => array(), |
| 123 | // ), |
| 124 | // 'hostgator-do' => array( |
| 125 | // 'brand' => 'hostgator-do', |
| 126 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 127 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.do' ), |
| 128 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 129 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 130 | // 'phone' => '', |
| 131 | // 'phoneDisplay' => '', |
| 132 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 133 | // 'hasPhone' => false, |
| 134 | // 'showProDesignBanner' => false, |
| 135 | // 'kbClickDomains' => array(), |
| 136 | // ), |
| 137 | // 'hostgator-ec' => array( |
| 138 | // 'brand' => 'hostgator-ec', |
| 139 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 140 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.net.ec' ), |
| 141 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 142 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 143 | // 'phone' => '', |
| 144 | // 'phoneDisplay' => '', |
| 145 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 146 | // 'hasPhone' => false, |
| 147 | // 'showProDesignBanner' => false, |
| 148 | // 'kbClickDomains' => array(), |
| 149 | // ), |
| 150 | // 'hostgator-mx' => array( |
| 151 | // 'brand' => 'hostgator-mx', |
| 152 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 153 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.mx' ), |
| 154 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 155 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 156 | // 'phone' => '', |
| 157 | // 'phoneDisplay' => '', |
| 158 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 159 | // 'hasPhone' => false, |
| 160 | // 'showProDesignBanner' => false, |
| 161 | // 'kbClickDomains' => array(), |
| 162 | // ), |
| 163 | // 'hostgator-pe' => array( |
| 164 | // 'brand' => 'hostgator-pe', |
| 165 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 166 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.pe' ), |
| 167 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 168 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 169 | // 'phone' => '', |
| 170 | // 'phoneDisplay' => '', |
| 171 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 172 | // 'hasPhone' => false, |
| 173 | // 'showProDesignBanner' => false, |
| 174 | // 'kbClickDomains' => array(), |
| 175 | // ), |
| 176 | // 'hostgator-uy' => array( |
| 177 | // 'brand' => 'hostgator-uy', |
| 178 | // 'name' => __( 'HostGator', 'wp-module-help-center' ), |
| 179 | // 'url' => apply_filters( 'nfd_build_url', 'https://www.hostgator.uy' ), |
| 180 | // 'helpURL' => apply_filters( 'nfd_build_url', $help_kb_latam ), |
| 181 | // 'contactUrl' => apply_filters( 'nfd_build_url', $help_chat_latam ), |
| 182 | // 'phone' => '', |
| 183 | // 'phoneDisplay' => '', |
| 184 | // 'accountName' => __( 'HostGator', 'wp-module-help-center' ), |
| 185 | // 'hasPhone' => false, |
| 186 | // 'showProDesignBanner' => false, |
| 187 | // 'kbClickDomains' => array(), |
| 188 | // ), |
| 189 | // phpcs:enable Squiz.PHP.CommentedOutCode.Found |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Get the brand data for the given brand key. |
| 195 | * |
| 196 | * @param string $brand_key NFD_HELPCENTER_PLUGIN_BRAND (e.g. bluehost, hostgator-us). |
| 197 | * @return array |
| 198 | */ |
| 199 | public static function get_data_for_brand( $brand_key ) { |
| 200 | $data = self::get_brand_data(); |
| 201 | |
| 202 | // 1. Exact match: return the requested brand's data if it exists. |
| 203 | if ( isset( $data[ $brand_key ] ) ) { |
| 204 | return $data[ $brand_key ]; |
| 205 | } |
| 206 | |
| 207 | // 2. HostGator fallback: for hostgator-* keys not defined (e.g. hostgator-xy, or future regions |
| 208 | // that are commented out), use hostgator-us as the default. Only US has help center capability. |
| 209 | if ( 0 === strpos( $brand_key, 'hostgator' ) ) { |
| 210 | return $data['hostgator-us'] ?? $data['bluehost']; |
| 211 | } |
| 212 | |
| 213 | // 3. Unknown brand: fall back to bluehost. |
| 214 | return $data['bluehost']; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Returns the resource link (help URL) for the given brand. |
| 219 | * |
| 220 | * @param string $brand_key NFD_HELPCENTER_PLUGIN_BRAND. |
| 221 | * @return string |
| 222 | */ |
| 223 | public static function get_resource_link_for_brand( $brand_key ) { |
| 224 | $all_data = self::get_brand_data(); |
| 225 | if ( ! isset( $all_data[ $brand_key ] ) && 0 !== strpos( $brand_key, 'hostgator' ) ) { |
| 226 | return ''; |
| 227 | } |
| 228 | $data = self::get_data_for_brand( $brand_key ); |
| 229 | return $data['helpURL'] ?? ''; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Sets the hosting brand and defines NFD_HELPCENTER_PLUGIN_BRAND. |
| 234 | * |
| 235 | * Called from the module bootstrap (before the help center loads). Uses the container's |
| 236 | * plugin()->brand and plugin()->region to determine the brand key. |
| 237 | * |
| 238 | * For HostGator: appends region → hostgator-us, hostgator-br, etc. This is used by: |
| 239 | * - HelpCenter.php (brandConfig, resourceLink) |
| 240 | * - MultiSearchController (filter_by post_category) — the TypeSense index must have articles |
| 241 | * with post_category matching this value (e.g. "hostgator-us" or "hostgator" depending on index). |
| 242 | * |
| 243 | * @param object $container The brand plugin container (from Newfold Module Loader). |
| 244 | */ |
| 245 | public static function set_current_brand( $container ) { |
| 246 | if ( ! defined( 'NFD_HELPCENTER_PLUGIN_BRAND' ) ) { |
| 247 | // Get brand from container (set in plugin) |
| 248 | $brand = $container->plugin()->brand; |
| 249 | if ( empty( $brand ) ) { |
| 250 | $brand = 'WordPress'; |
| 251 | } |
| 252 | |
| 253 | // Only HostGator uses region; Bluehost does not. |
| 254 | // Region may be empty in the container but is populated as "us" in the runtime by default. |
| 255 | // But only US has help center capability for now see canAccessHelpCenter in Site Model in Hiive. |
| 256 | if ( false !== strpos( $brand, 'hostgator' ) ) { |
| 257 | $region = strtolower( $container->plugin()->region ?? '' ); |
| 258 | $brand = ! empty( $region ) ? 'hostgator-' . $region : 'hostgator'; |
| 259 | } |
| 260 | |
| 261 | $brand = sanitize_title_with_dashes( str_replace( '_', '-', $brand ) ); |
| 262 | |
| 263 | define( 'NFD_HELPCENTER_PLUGIN_BRAND', $brand ); |
| 264 | } |
| 265 | } |
| 266 | } |