'; if ( current_user_can( 'view_site_health_checks' ) ) { $html .= '

' . esc_html__( 'AI Product Tools could not finish its database update, so some features may not work until it does. It tries again automatically. For details, open Tools > Site Health > Info and look for "AI Product Tools: diagnostics".', 'ai-product-tools' ) . '

'; $html .= '

' . esc_html__( 'Open Site Health', 'ai-product-tools' ) . '

'; } else { $html .= '

' . esc_html__( 'AI Product Tools could not finish its database update, so some features may not work until it does. It tries again automatically. A site administrator can find the details in Site Health.', 'ai-product-tools' ) . '

'; } $html .= ''; $html .= self::get_dismiss_script(); return $html; } /** * AJAX handler persisting the dismissal of the upgrade named in the request. * * The request names the upgrade its notice was rendered for. Only the * upgrade the site has still to finish is stored: a notice that stayed * open while the plugin was updated belongs to an earlier upgrade, and * closing it must not hide the notice of the one that fails after it. A * finished upgrade has nothing to dismiss. * * @return void */ public static function handle_dismiss(): void { check_ajax_referer( self::DISMISS_ACTION, 'nonce' ); if ( ! current_user_can( 'manage_aipt_settings' ) ) { wp_die( -1 ); } // phpcs:ignore WordPress.Security.NonceVerification.Missing -- check_ajax_referer() above verified the nonce. $upgrade = isset( $_POST['upgrade'] ) ? sanitize_text_field( wp_unslash( $_POST['upgrade'] ) ) : ''; $status = Migration::schema_status(); if ( '' === $upgrade || 'current' === $status['state'] || self::upgrade_id( $status ) !== $upgrade ) { wp_die( '0' ); } else { update_user_meta( get_current_user_id(), self::dismiss_meta_key(), $upgrade ); wp_die( '1' ); } } /** * Meta key of the dismissal on the current site. User meta is shared by * every site of a network, and each site runs its own upgrade. * * @return string */ public static function dismiss_meta_key(): string { return self::DISMISS_META_PREFIX . get_current_blog_id(); } /** * Names one upgrade by the versions it is heading for. A later plugin * version has another name, so a dismissal does not carry over to it. * * @param array $status Result of Migration::schema_status(). * @return string */ private static function upgrade_id( array $status ): string { return $status['schema_target'] . '|' . $status['version_target']; } /** * Whether the current admin screen belongs to this plugin. Mirrors * {@see ContentModeUpdateNotice::is_plugin_page()}. * * @return bool */ private static function is_plugin_page(): bool { if ( ! is_admin() ) { return false; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Page slug read only, no state change. $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; if ( '' === $page ) { return false; } if ( 'ai-product-tools' === $page ) { return true; } return 0 === strpos( $page, 'aipt-' ); } /** * Inline script wiring the core dismiss button to the AJAX handler. * Mirrors {@see ContentModeUpdateNotice::get_dismiss_script()}. * * @return string */ private static function get_dismiss_script(): string { return ''; } }