Skip to content

Commit

Permalink
Help Center: use disconnected version on frontend (#38941)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelini authored Aug 20, 2024
1 parent 199f506 commit a5a30f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Help Center: show disconnected version on frontend
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,35 @@ public function is_jetpack_disconnected() {
return false;
}

/**
* Returns true if...
* 1. The current user can edit posts.
* 2. The current user is a member of the blog.
* 3. The current request is not in the admin.
* 4. The current request is not in the block editor.
*
* @return bool True if the this is being loaded on the frontend.
*/
public function is_loading_on_frontend() {
$can_edit_posts = current_user_can( 'edit_posts' ) && is_user_member_of_blog();

return ! is_admin() && ! $this->is_block_editor() && $can_edit_posts;
}

/**
* Returns the URL for the Help Center redirect.
* Used for the Help Center when disconnected.
*/
public function get_help_center_url() {
$help_url = 'https://wordpress.com/help';
$help_url = 'https://wordpress.com/help?help-center=home';

if ( ! $this->is_jetpack_disconnected() ) {
return false;
if ( $this->is_jetpack_disconnected() || $this->is_loading_on_frontend() ) {
return $help_url;
}

return $help_url;
return false;
}

/**
* Get the asset via file-system on wpcom and via network on Atomic sites.
*
Expand Down Expand Up @@ -375,6 +391,10 @@ private static function download_asset( $filepath, $parse_json = true ) {
* Add icon to WP-ADMIN admin bar.
*/
public function enqueue_wp_admin_scripts() {
if ( $this->is_wc_admin_home_page() ) {
return;
}

require_once ABSPATH . 'wp-admin/includes/screen.php';

$can_edit_posts = current_user_can( 'edit_posts' ) && is_user_member_of_blog();
Expand All @@ -384,17 +404,17 @@ public function enqueue_wp_admin_scripts() {
// 1. On wp-admin
// 2. On the front end of the site if the current user can edit posts
// 3. On the front end of the site and the theme is not P2
// 4. If it is the frontend we show the disconnected version of the help center.
if ( ! is_admin() && ( ! $can_edit_posts || $is_p2 ) ) {
return;
} elseif ( $this->is_loading_on_frontend() ) {
$variant = 'wp-admin-disconnected';
} elseif ( $this->is_block_editor() ) {
$variant = 'gutenberg' . ( $this->is_jetpack_disconnected() ? '-disconnected' : '' );
} else {
$variant = 'wp-admin' . ( $this->is_jetpack_disconnected() ? '-disconnected' : '' );
}

if ( $this->is_wc_admin_home_page() ) {
return;
}

$variant = $this->is_block_editor() ? 'gutenberg' : 'wp-admin';
$variant .= $this->is_jetpack_disconnected() ? '-disconnected' : '';

$asset_file = self::download_asset( 'widgets.wp.com/help-center/help-center-' . $variant . '.asset.json' );
if ( ! $asset_file ) {
return;
Expand Down

0 comments on commit a5a30f6

Please sign in to comment.