Skip to content

Commit e4347aa

Browse files
authored
Make the Help Center runnable as a standalone plugin (#45354)
1 parent 46b8fea commit e4347aa

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Changed the Help Center to be runnable as a standalone plugin

projects/packages/jetpack-mu-wpcom/src/features/help-center/class-help-center.php

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace A8C\FSE;
99

1010
use Automattic\Jetpack\Connection\Manager as Connection_Manager;
11-
use Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;
1211

1312
/**
1413
* Class Help_Center
@@ -28,6 +27,13 @@ class Help_Center {
2827
*/
2928
private $is_support_site = false;
3029

30+
/**
31+
* The purchases of the current site.
32+
*
33+
* @var array
34+
*/
35+
private $purchases = array();
36+
3137
/**
3238
* Help_Center constructor.
3339
*/
@@ -38,8 +44,8 @@ public function __construct() {
3844
return;
3945
}
4046

41-
if ( ! function_exists( 'wpcom_get_site_purchases' ) ) {
42-
return;
47+
if ( function_exists( 'wpcom_get_site_purchases' ) ) {
48+
$this->purchases = wp_list_filter( wpcom_get_site_purchases(), array( 'product_type' => 'bundle' ) );
4349
}
4450

4551
add_action( 'rest_api_init', array( $this, 'register_rest_api' ) );
@@ -50,6 +56,28 @@ public function __construct() {
5056
$this->is_support_site = defined( 'WPCOM_SUPPORT_BLOG_IDS' ) && in_array( get_current_blog_id(), (array) WPCOM_SUPPORT_BLOG_IDS, true );
5157
}
5258

59+
/**
60+
* Returns ISO 639 conforming locale string of the current user.
61+
*
62+
* @return string ISO 639 locale string e.g. "en"
63+
*/
64+
private static function determine_iso_639_locale() {
65+
$language = get_user_locale();
66+
$language = strtolower( $language );
67+
68+
if ( in_array( $language, array( 'pt_br', 'pt-br', 'zh_tw', 'zh-tw', 'zh_cn', 'zh-cn' ), true ) ) {
69+
$language = str_replace( '_', '-', $language );
70+
} else {
71+
$language = preg_replace( '/([-_].*)$/i', '', $language );
72+
}
73+
74+
if ( empty( $language ) ) {
75+
return 'en';
76+
}
77+
78+
return $language;
79+
}
80+
5381
/**
5482
* We prefer to use the Help Center instead of the Help tab.
5583
*/
@@ -131,7 +159,7 @@ function ( $wp_admin_bar ) {
131159
}
132160

133161
if ( $variant !== 'wp-admin-disconnected' && $variant !== 'gutenberg-disconnected' ) {
134-
$locale = Common\determine_iso_639_locale();
162+
$locale = self::determine_iso_639_locale();
135163

136164
if ( 'en' !== $locale ) {
137165
// Load translations directly from widgets.wp.com.
@@ -202,7 +230,7 @@ function ( $wp_admin_bar ) {
202230
'email' => $user_email,
203231
),
204232
'site' => $this->get_current_site(),
205-
'locale' => Common\determine_iso_639_locale(),
233+
'locale' => self::determine_iso_639_locale(),
206234
)
207235
),
208236
'before'
@@ -246,7 +274,7 @@ public function get_current_site() {
246274
}
247275

248276
$logo_id = get_option( 'site_logo' );
249-
$bundles = wp_list_filter( wpcom_get_site_purchases(), array( 'product_type' => 'bundle' ) );
277+
$bundles = $this->purchases;
250278
$plan = array_pop( $bundles );
251279

252280
$return_data = array(
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Help center
4+
* This file is used to load the Help Center as a standalone plugin. It's not used by Jetpack.
5+
*
6+
* @package automattic/jetpack-mu-wpcom
7+
*/
8+
9+
/**
10+
* Load the Help Center class.
11+
*/
12+
require_once __DIR__ . '/class-help-center.php';

0 commit comments

Comments
 (0)