Skip to content

Commit 1370086

Browse files
Help Center: Create wp-admin help center menu panel (#45699)
* Create HC menu panel * changelog
1 parent a142913 commit 1370086

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Help Center: Add menu panel for experiment in wp-admin and editor
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* Help Center Menu Panel
4+
*
5+
* @package automattic/jetpack-mu-wpcom
6+
*/
7+
8+
namespace A8C\FSE;
9+
10+
/**
11+
* Class Help_Center_Menu_Panel
12+
*
13+
* Handles the help center menu panel functionality in the admin bar.
14+
*
15+
* @since $$next-version$$
16+
*/
17+
class Help_Center_Menu_Panel {
18+
19+
/**
20+
* Check if the help center menu panel should be displayed.
21+
*
22+
* @return bool True if the menu panel should be displayed.
23+
*/
24+
public static function should_display_menu_panel() {
25+
// Only add the help center menu panel if the flags parameter is present
26+
// phpcs:disable WordPress.Security.NonceVerification.Recommended
27+
return isset( $_GET['flags'] ) && strpos( sanitize_text_field( wp_unslash( $_GET['flags'] ) ), 'help-center-menu-panel' ) !== false;
28+
// phpcs:enable WordPress.Security.NonceVerification.Recommended
29+
}
30+
31+
/**
32+
* Add the help center menu panel to the admin bar.
33+
*
34+
* @param \WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance.
35+
*/
36+
public static function add_menu_panel( $wp_admin_bar ) {
37+
if ( ! self::should_display_menu_panel() ) {
38+
return;
39+
}
40+
41+
// Add chat support group
42+
$wp_admin_bar->add_group(
43+
array(
44+
'parent' => 'help-center',
45+
'id' => 'help-center-menu-panel-chat',
46+
'meta' => array(
47+
'class' => 'ab-sub-secondary',
48+
),
49+
)
50+
);
51+
52+
// Add chat support menu item
53+
$wp_admin_bar->add_node(
54+
array(
55+
'parent' => 'help-center-menu-panel-chat',
56+
'id' => 'help-center-chat-support',
57+
'title' => __( 'Chat support', 'jetpack-mu-wpcom' ),
58+
)
59+
);
60+
61+
// Add chat history menu item
62+
$wp_admin_bar->add_node(
63+
array(
64+
'parent' => 'help-center-menu-panel-chat',
65+
'id' => 'help-center-chat-history',
66+
'title' => __( 'Chat history', 'jetpack-mu-wpcom' ),
67+
)
68+
);
69+
70+
// Add links group
71+
$wp_admin_bar->add_group(
72+
array(
73+
'parent' => 'help-center',
74+
'id' => 'help-center-menu-panel-links',
75+
'meta' => array(
76+
'class' => 'ab-sub-secondary',
77+
),
78+
)
79+
);
80+
81+
// Add support guides menu item
82+
$wp_admin_bar->add_node(
83+
array(
84+
'parent' => 'help-center-menu-panel-links',
85+
'id' => 'help-center-support-guides',
86+
'title' => __( 'Support guides', 'jetpack-mu-wpcom' ),
87+
)
88+
);
89+
90+
// Add courses menu item
91+
$wp_admin_bar->add_node(
92+
array(
93+
'parent' => 'help-center-menu-panel-links',
94+
'id' => 'help-center-courses',
95+
'title' => __( 'Courses', 'jetpack-mu-wpcom' ),
96+
'href' => 'https://wordpress.com/support/courses/',
97+
'meta' => array(
98+
'target' => '_blank',
99+
),
100+
)
101+
);
102+
103+
// Add product updates menu item
104+
$wp_admin_bar->add_node(
105+
array(
106+
'parent' => 'help-center-menu-panel-links',
107+
'id' => 'help-center-product-updates',
108+
'title' => __( 'Product updates', 'jetpack-mu-wpcom' ),
109+
'href' => 'https://wordpress.com/blog/category/product-features/',
110+
'meta' => array(
111+
'target' => '_blank',
112+
),
113+
)
114+
);
115+
}
116+
117+
/**
118+
* Initialize the help center menu panel.
119+
*
120+
* @param string $variant The variant of the help center being loaded.
121+
*/
122+
public static function init( $variant ) {
123+
if ( $variant === 'wp-admin' || $variant === 'wp-admin-disconnected' ) {
124+
add_action(
125+
'admin_bar_menu',
126+
array( __CLASS__, 'add_menu_panel' ),
127+
12
128+
);
129+
}
130+
}
131+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ function ( $wp_admin_bar ) {
204204
// Add the help center icon to the admin bar after the reader icon.
205205
12
206206
);
207+
208+
// Initialize the help center menu panel
209+
require_once __DIR__ . '/class-help-center-menu-panel.php';
210+
Help_Center_Menu_Panel::init( $variant );
207211
}
208212

209213
if ( $variant !== 'wp-admin-disconnected' && $variant !== 'gutenberg-disconnected' ) {

0 commit comments

Comments
 (0)