@@ -96,6 +96,15 @@ class Admin {
9696 */
9797 public $ tools_page ;
9898
99+ /**
100+ * Admin banner helper instance.
101+ *
102+ * @since 3.0.0
103+ *
104+ * @var Admin_Banner
105+ */
106+ public Admin_Banner $ admin_banner ;
107+
99108 /**
100109 * Main constructor class.
101110 *
@@ -113,84 +122,90 @@ public function __construct() {
113122 $ this ->product_migrator = new Product_Migrator ();
114123 $ this ->setup_wizard = new Setup_Wizard ();
115124 $ this ->tools_page = new Tools_Page ();
125+ $ this ->admin_banner = new Admin_Banner ( $ this ->get_admin_banner_config () );
116126 }
117127
118128 /**
119- * Render the Knowledge Base admin banner.
129+ * Retrieve the configuration array for the admin banner.
120130 *
121131 * @since 3.0.0
132+ *
133+ * @return array<string, mixed>
122134 */
123- public function render_admin_banner () {
124- $ screen = get_current_screen ();
125-
126- if ( ! $ screen || ! current_user_can ( 'edit_posts ' ) ) {
127- return ;
128- }
129-
130- // Skip post editor screens where Gutenberg already provides its own header UI.
131- if ( isset ( $ screen ->base ) && in_array ( $ screen ->base , array ( 'post ' , 'post-new ' ), true ) ) {
132- return ;
133- }
134-
135- if ( ! $ this ->is_knowledge_base_screen ( $ screen ) ) {
136- return ;
137- }
138-
139- $ kb_url = wzkb_get_kb_url ();
140- $ products_url = admin_url ( 'edit-tags.php?taxonomy=wzkb_product&post_type=wz_knowledgebase ' );
141- $ sections_url = admin_url ( 'edit-tags.php?taxonomy=wzkb_category&post_type=wz_knowledgebase ' );
142- $ tags_url = admin_url ( 'edit-tags.php?taxonomy=wzkb_tag&post_type=wz_knowledgebase ' );
143- $ tools_url = admin_url ( 'edit.php?post_type=wz_knowledgebase&page=wzkb_tools_page ' );
144- $ plugin_url = 'https://webberzone.com/plugins/ ' ;
145- $ current_section = '' ;
146- $ page_param = $ this ->get_request_page_param ();
147-
148- if ( ! empty ( $ screen ->taxonomy ) ) {
149- if ( 'wzkb_product ' === $ screen ->taxonomy ) {
150- $ current_section = 'products ' ;
151- } elseif ( 'wzkb_category ' === $ screen ->taxonomy ) {
152- $ current_section = 'sections ' ;
153- } elseif ( 'wzkb_tag ' === $ screen ->taxonomy ) {
154- $ current_section = 'tags ' ;
155- }
156- } elseif ( $ this ->is_tools_screen ( $ screen , $ page_param ) ) {
157- $ current_section = 'tools ' ;
158- }
159-
160- $ products_classes = 'wzkb-admin-banner__link wzkb-admin-banner__link--secondary ' . ( 'products ' === $ current_section ? ' wzkb-admin-banner__link--current ' : '' );
161- $ sections_classes = 'wzkb-admin-banner__link wzkb-admin-banner__link--secondary ' . ( 'sections ' === $ current_section ? ' wzkb-admin-banner__link--current ' : '' );
162- $ tags_classes = 'wzkb-admin-banner__link wzkb-admin-banner__link--secondary ' . ( 'tags ' === $ current_section ? ' wzkb-admin-banner__link--current ' : '' );
163- $ tools_classes = 'wzkb-admin-banner__link wzkb-admin-banner__link--secondary ' . ( 'tools ' === $ current_section ? ' wzkb-admin-banner__link--current ' : '' );
164-
165- ?>
166- <div class="wzkb-admin-banner" role="region" aria-label="<?php echo esc_attr__ ( 'Knowledge Base quick links ' , 'knowledgebase ' ); ?> ">
167- <div class="wzkb-admin-banner__intro">
168- <span class="wzkb-admin-banner__eyebrow"><?php esc_html_e ( 'WebberZone Knowledge Base ' , 'knowledgebase ' ); ?> </span>
169- <p class="wzkb-admin-banner__title"><?php esc_html_e ( 'Shape a helpful support hub your users will love. ' , 'knowledgebase ' ); ?> </p>
170- <p class="wzkb-admin-banner__text"><?php esc_html_e ( 'Jump to your most-used Knowledge Base tools, manage content faster, and explore more WebberZone plugins. ' , 'knowledgebase ' ); ?> </p>
171- </div>
172- <nav class="wzkb-admin-banner__links" aria-label="<?php echo esc_attr__ ( 'Knowledge Base admin shortcuts ' , 'knowledgebase ' ); ?> ">
173- <a class="wzkb-admin-banner__link wzkb-admin-banner__link--primary wzkb-admin-banner__link--kb-archive" href="<?php echo esc_url ( $ kb_url ); ?> " target="_blank" rel="noopener noreferrer">
174- <?php esc_html_e ( 'View Knowledge Base ' , 'knowledgebase ' ); ?>
175- </a>
176- <a class="<?php echo esc_attr ( $ products_classes . ' wzkb-admin-banner__link--products ' ); ?> " href="<?php echo esc_url ( $ products_url ); ?> ">
177- <?php esc_html_e ( 'Products ' , 'knowledgebase ' ); ?>
178- </a>
179- <a class="<?php echo esc_attr ( $ sections_classes . ' wzkb-admin-banner__link--sections ' ); ?> " href="<?php echo esc_url ( $ sections_url ); ?> ">
180- <?php esc_html_e ( 'Sections ' , 'knowledgebase ' ); ?>
181- </a>
182- <a class="<?php echo esc_attr ( $ tags_classes . ' wzkb-admin-banner__link--tags ' ); ?> " href="<?php echo esc_url ( $ tags_url ); ?> ">
183- <?php esc_html_e ( 'Tags ' , 'knowledgebase ' ); ?>
184- </a>
185- <a class="<?php echo esc_attr ( $ tools_classes . ' wzkb-admin-banner__link--tools ' ); ?> " href="<?php echo esc_url ( $ tools_url ); ?> ">
186- <?php esc_html_e ( 'Tools ' , 'knowledgebase ' ); ?>
187- </a>
188- <a class="wzkb-admin-banner__link wzkb-admin-banner__link--accent wzkb-admin-banner__link--plugins" href="<?php echo esc_url ( $ plugin_url ); ?> " target="_blank" rel="noopener noreferrer">
189- <?php esc_html_e ( 'More WebberZone Plugins ' , 'knowledgebase ' ); ?>
190- </a>
191- </nav>
192- </div>
193- <?php
135+ private function get_admin_banner_config (): array {
136+ $ kb_url = wzkb_get_kb_url ();
137+ $ products_url = admin_url ( 'edit-tags.php?taxonomy=wzkb_product&post_type=wz_knowledgebase ' );
138+ $ sections_url = admin_url ( 'edit-tags.php?taxonomy=wzkb_category&post_type=wz_knowledgebase ' );
139+ $ tags_url = admin_url ( 'edit-tags.php?taxonomy=wzkb_tag&post_type=wz_knowledgebase ' );
140+ $ tools_url = admin_url ( 'edit.php?post_type=wz_knowledgebase&page=wzkb_tools_page ' );
141+
142+ return array (
143+ 'capability ' => 'edit_posts ' ,
144+ 'prefix ' => 'wzkb ' ,
145+ 'screen_ids ' => array (
146+ 'edit-wz_knowledgebase ' ,
147+ 'wz_knowledgebase ' ,
148+ 'wz_knowledgebase_page_wzkb-settings ' ,
149+ 'knowledgebase_page_wzkb-settings ' ,
150+ 'wz_knowledgebase_page_wzkb_tools_page ' ,
151+ 'knowledgebase_page_wzkb_tools_page ' ,
152+ 'edit-wzkb_category ' ,
153+ 'term-wzkb_category ' ,
154+ 'edit-wzkb_product ' ,
155+ 'term-wzkb_product ' ,
156+ 'edit-wzkb_tag ' ,
157+ 'term-wzkb_tag ' ,
158+ ),
159+ 'page_slugs ' => array (
160+ 'wzkb-settings ' ,
161+ 'wzkb_tools_page ' ,
162+ ),
163+ 'strings ' => array (
164+ 'region_label ' => esc_html__ ( 'Knowledge Base quick links ' , 'knowledgebase ' ),
165+ 'nav_label ' => esc_html__ ( 'Knowledge Base admin shortcuts ' , 'knowledgebase ' ),
166+ 'eyebrow ' => esc_html__ ( 'WebberZone Knowledge Base ' , 'knowledgebase ' ),
167+ 'title ' => esc_html__ ( 'Shape a helpful support hub your users will love. ' , 'knowledgebase ' ),
168+ 'text ' => esc_html__ ( 'Jump to your most-used Knowledge Base tools, manage content faster, and explore more WebberZone plugins. ' , 'knowledgebase ' ),
169+ ),
170+ 'sections ' => array (
171+ 'archive ' => array (
172+ 'label ' => esc_html__ ( 'View Knowledge Base ' , 'knowledgebase ' ),
173+ 'url ' => $ kb_url ,
174+ 'type ' => 'primary ' ,
175+ 'target ' => '_blank ' ,
176+ 'rel ' => 'noopener noreferrer ' ,
177+ ),
178+ 'products ' => array (
179+ 'label ' => esc_html__ ( 'Products ' , 'knowledgebase ' ),
180+ 'url ' => $ products_url ,
181+ 'screen_ids ' => array ( 'edit-wzkb_product ' , 'term-wzkb_product ' ),
182+ 'page_slugs ' => array ( 'edit-tags.php?taxonomy=wzkb_product ' ),
183+ ),
184+ 'sections ' => array (
185+ 'label ' => esc_html__ ( 'Sections ' , 'knowledgebase ' ),
186+ 'url ' => $ sections_url ,
187+ 'screen_ids ' => array ( 'edit-wzkb_category ' , 'term-wzkb_category ' ),
188+ ),
189+ 'tags ' => array (
190+ 'label ' => esc_html__ ( 'Tags ' , 'knowledgebase ' ),
191+ 'url ' => $ tags_url ,
192+ 'screen_ids ' => array ( 'edit-wzkb_tag ' , 'term-wzkb_tag ' ),
193+ ),
194+ 'tools ' => array (
195+ 'label ' => esc_html__ ( 'Tools ' , 'knowledgebase ' ),
196+ 'url ' => $ tools_url ,
197+ 'screen_ids ' => array ( 'wz_knowledgebase_page_wzkb_tools_page ' , 'knowledgebase_page_wzkb_tools_page ' ),
198+ 'page_slugs ' => array ( 'wzkb_tools_page ' ),
199+ ),
200+ 'plugins ' => array (
201+ 'label ' => esc_html__ ( 'WebberZone Plugins ' , 'knowledgebase ' ),
202+ 'url ' => 'https://webberzone.com/plugins/ ' ,
203+ 'type ' => 'secondary ' ,
204+ 'target ' => '_blank ' ,
205+ 'rel ' => 'noopener noreferrer ' ,
206+ ),
207+ ),
208+ );
194209 }
195210
196211 /**
@@ -205,15 +220,17 @@ public function render_admin_banner() {
205220 private function is_knowledge_base_screen ( \WP_Screen $ screen ): bool {
206221 $ page_param = $ this ->get_request_page_param ();
207222
208- if ( isset ( $ screen -> post_type ) && 'wz_knowledgebase ' === $ screen ->post_type ) {
223+ if ( 'wz_knowledgebase ' === ( string ) $ screen ->post_type ) {
209224 return true ;
210225 }
211226
212- if ( isset ( $ screen ->taxonomy ) && in_array ( $ screen ->taxonomy , array ( 'wzkb_category ' , 'wzkb_product ' , 'wzkb_tag ' ), true ) ) {
227+ $ screen_taxonomy = (string ) $ screen ->taxonomy ;
228+ if ( '' !== $ screen_taxonomy && in_array ( $ screen_taxonomy , array ( 'wzkb_category ' , 'wzkb_product ' , 'wzkb_tag ' ), true ) ) {
213229 return true ;
214230 }
215231
216- if ( isset ( $ screen ->id ) && in_array ( $ screen ->id , array ( 'wz_knowledgebase_page_wzkb-settings ' , 'knowledgebase_page_wzkb-settings ' ), true ) ) {
232+ $ screen_id = (string ) $ screen ->id ;
233+ if ( '' !== $ screen_id && in_array ( $ screen_id , array ( 'wz_knowledgebase_page_wzkb-settings ' , 'knowledgebase_page_wzkb-settings ' ), true ) ) {
217234 return true ;
218235 }
219236
@@ -252,7 +269,7 @@ private function get_request_page_param(): string {
252269 /**
253270 * Retrieve a sanitized request variable intended for use as a key/slug.
254271 *
255- * @since 4 .0.0
272+ * @since 3 .0.0
256273 *
257274 * @param string $key Request key to fetch.
258275 *
@@ -283,33 +300,17 @@ private function get_request_key_param( string $key ): string {
283300 * @return bool
284301 */
285302 private function is_tools_screen ( \WP_Screen $ screen , string $ page_param ): bool {
286- $ candidates = array ();
287-
288- if ( isset ( $ screen ->id ) ) {
289- $ candidates [] = (string ) $ screen ->id ;
290- }
291-
292- if ( isset ( $ screen ->base ) ) {
293- $ candidates [] = (string ) $ screen ->base ;
294- }
295-
296- if ( isset ( $ screen ->parent_base ) ) {
297- $ candidates [] = (string ) $ screen ->parent_base ;
298- }
299-
300- if ( isset ( $ screen ->parent_file ) ) {
301- $ candidates [] = (string ) $ screen ->parent_file ;
302- }
303-
304- if ( '' !== $ page_param ) {
305- $ candidates [] = $ page_param ;
306- }
303+ $ candidates = array_filter (
304+ array (
305+ (string ) $ screen ->id ,
306+ (string ) $ screen ->base ,
307+ (string ) $ screen ->parent_base ,
308+ (string ) $ screen ->parent_file ,
309+ $ page_param ,
310+ )
311+ );
307312
308313 foreach ( $ candidates as $ candidate ) {
309- if ( '' === $ candidate ) {
310- continue ;
311- }
312-
313314 if ( false !== strpos ( $ candidate , 'wzkb_tools_page ' ) ) {
314315 return true ;
315316 }
@@ -328,7 +329,6 @@ public function hooks() {
328329 Hook_Registry::add_action ( 'admin_notices ' , array ( $ this , 'admin_notices ' ) );
329330 Hook_Registry::add_filter ( 'dashboard_glance_items ' , array ( $ this , 'dashboard_glance_items ' ), 10 , 1 );
330331 Hook_Registry::add_filter ( 'admin_head ' , array ( $ this , 'admin_head ' ) );
331- Hook_Registry::add_action ( 'in_admin_header ' , array ( $ this , 'render_admin_banner ' ) );
332332 }
333333
334334 /**
@@ -354,10 +354,11 @@ public function admin_enqueue_scripts() {
354354 'ajax_url ' => admin_url ( 'admin-ajax.php ' ),
355355 'security ' => wp_create_nonce ( 'wzkb-admin ' ),
356356 'strings ' => array (
357- 'confirm_message ' => esc_html__ ( 'Are you sure you want to clear the cache? ' , 'knowledgebase ' ),
358- 'success_message ' => esc_html__ ( 'Cache cleared successfully! ' , 'knowledgebase ' ),
359- 'fail_message ' => esc_html__ ( 'Failed to clear cache. Please try again. ' , 'knowledgebase ' ),
360- 'request_fail_message ' => esc_html__ ( 'Request failed: ' , 'knowledgebase ' ),
357+ 'confirm_message ' => esc_html__ ( 'Are you sure you want to clear the cache? ' , 'knowledgebase ' ),
358+ 'flush_confirm_message ' => esc_html__ ( 'Are you sure you want to flush the permalinks? ' , 'knowledgebase ' ),
359+ 'success_message ' => esc_html__ ( 'Cache cleared successfully! ' , 'knowledgebase ' ),
360+ 'fail_message ' => esc_html__ ( 'Failed to clear cache. Please try again. ' , 'knowledgebase ' ),
361+ 'request_fail_message ' => esc_html__ ( 'Request failed: ' , 'knowledgebase ' ),
361362 ),
362363 )
363364 );
@@ -385,6 +386,7 @@ public function admin_enqueue_scripts() {
385386 }
386387
387388 if ( $ should_enqueue ) {
389+ wp_enqueue_script ( 'wzkb-admin ' );
388390 wp_enqueue_style ( 'wzkb-admin-ui ' );
389391 }
390392 }
@@ -440,6 +442,21 @@ public function admin_notices() {
440442 );
441443 }
442444 }
445+
446+ // Show notice if sidebar is enabled and using a block theme.
447+ if ( wzkb_get_option ( 'show_sidebar ' ) && function_exists ( 'wp_is_block_theme ' ) && wp_is_block_theme () ) {
448+ $ settings_link = sprintf ( '<a href="%s">%s</a> ' , esc_url ( admin_url ( 'site-editor.php?postType=wp_template&postId=knowledgebase-pro//single-wz_knowledgebase-with-sidebar ' ) ), esc_html__ ( 'Site Editor ' , 'knowledgebase ' ) );
449+ $ message = sprintf (
450+ /* translators: 1: "Include Sidebar" setting name, 2: HTML link to Site Editor */
451+ esc_html__ ( 'The "Include Sidebar" setting only works with classic themes. For block themes, please use the sidebar templates available in the %2$s instead. ' , 'knowledgebase ' ),
452+ '<strong> ' . esc_html__ ( 'Include Sidebar ' , 'knowledgebase ' ) . '</strong> ' ,
453+ $ settings_link
454+ );
455+ printf (
456+ '<div class="notice notice-info"><p>%s</p></div> ' ,
457+ wp_kses_post ( $ message )
458+ );
459+ }
443460 }
444461
445462 /**
0 commit comments