Skip to content

Commit 2b421a9

Browse files
committed
Show notice in Namer page if API key is not set
1 parent 001e1e2 commit 2b421a9

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

includes/Admin/Namer_Page.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function add_hooks() {
6262
add_action( 'admin_menu', array( $this, 'add_page' ) );
6363
add_action( 'admin_post_' . self::ACTION_ANALYZE, array( $this, 'handle_analyze' ) );
6464
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
65+
add_action( 'admin_notices', array( $this, 'render_api_key_notice' ) );
6566
add_action( 'wp_ajax_plugin_check_namer_analyze', array( $this, 'ajax_analyze' ) );
6667
}
6768

@@ -273,6 +274,44 @@ protected function get_ai_config() {
273274
);
274275
}
275276

277+
/**
278+
* Renders admin notice when API key settings are not configured (Namer page only).
279+
*
280+
* @since 1.8.0
281+
*/
282+
public function render_api_key_notice() {
283+
$screen = get_current_screen();
284+
if ( ! $screen || $screen->id !== $this->hook_suffix ) {
285+
return;
286+
}
287+
288+
if ( ! current_user_can( 'manage_options' ) ) {
289+
return;
290+
}
291+
292+
$ai_config = $this->get_ai_config();
293+
if ( ! is_wp_error( $ai_config ) ) {
294+
return;
295+
}
296+
297+
$settings_url = add_query_arg( array( 'page' => Settings_Page::PAGE_SLUG ), admin_url( 'options-general.php' ) );
298+
?>
299+
<div class="notice notice-warning is-dismissible">
300+
<p>
301+
<?php
302+
printf(
303+
/* translators: %s: Link to Plugin Check settings page. */
304+
wp_kses_post(
305+
__( 'To use the Namer tool, <a href="%s">set a valid API key in Plugin Check settings</a>.', 'plugin-check' )
306+
),
307+
esc_url( $settings_url )
308+
);
309+
?>
310+
</p>
311+
</div>
312+
<?php
313+
}
314+
276315
/**
277316
* Renders the page.
278317
*
@@ -329,7 +368,7 @@ class="regular-text"
329368
</table>
330369

331370
<p class="description">
332-
<strong><?php echo esc_html__( 'Note:', 'plugin-check' ); ?></strong>
371+
<strong><?php echo esc_html__( 'Note:', 'plugin-check' ); ?></strong>
333372
<br/>
334373
<?php echo esc_html__( 'This tool provides guidance only and is not definitive. It contains a prompt that is used to evaluate the similarity of a plugin name to other plugin names and ensure compliance with trademark regulations.', 'plugin-check' ); ?>
335374
<br/>

0 commit comments

Comments
 (0)