diff --git a/projects/packages/jetpack-mu-wpcom/changelog/help-center-load-disconnected-in-frontend b/projects/packages/jetpack-mu-wpcom/changelog/help-center-load-disconnected-in-frontend new file mode 100644 index 0000000000000..c625ec153e850 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/help-center-load-disconnected-in-frontend @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Help Center: show disconnected version on frontend diff --git a/projects/packages/jetpack-mu-wpcom/src/features/help-center/class-help-center.php b/projects/packages/jetpack-mu-wpcom/src/features/help-center/class-help-center.php index cb6e325b02cb3..42dcc9792dddd 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/help-center/class-help-center.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/help-center/class-help-center.php @@ -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. * @@ -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(); @@ -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;