admin->admin_notices_api ?? null; if ( ! $admin_notices_api ) { return; } // Result notice after running the create-missing-tables action. if ( isset( $_GET['tptn_tables_created'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $status = sanitize_key( wp_unslash( $_GET['tptn_tables_created'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( 'created' === $status ) { $admin_notices_api->register_notice( array( 'id' => 'tptn_tables_created', 'message' => '
' . esc_html__( 'Top 10: Missing database tables were created successfully.', 'top-10' ) . '
', 'type' => 'success', 'dismissible' => true, 'capability' => 'manage_options', ) ); } elseif ( 'failed' === $status ) { $admin_notices_api->register_notice( array( 'id' => 'tptn_tables_create_failed', 'message' => '' . esc_html__( 'Top 10: One or more database tables could not be created. Please check your database permissions or try the Recreate tables option on the Tools page.', 'top-10' ) . '
', 'type' => 'error', 'dismissible' => true, 'capability' => 'manage_options', ) ); } } $missing = $this->get_missing_tables(); if ( empty( $missing ) ) { return; } $admin_notices_api->register_notice( array( 'id' => 'tptn_missing_tables', 'message' => $this->build_missing_table_message( $missing ), 'type' => 'warning', 'dismissible' => false, 'capability' => 'manage_options', ) ); } /** * Get the list of missing Top 10 tables. * * @since 4.3.0 * * @return array Array of HTML-formatted missing table descriptions. */ private function get_missing_tables(): array { $all_tables = array( Database::get_table( false ) => __( 'Top 10 (total counts)', 'top-10' ), Database::get_table( true ) => __( 'Top 10 Daily (daily counts)', 'top-10' ), Database::get_log_table() => __( 'Visits Log', 'top-10' ), Database::get_funnel_table() => __( 'Visits Funnel', 'top-10' ), ); $missing = array(); $statuses = Database::get_table_installation_status(); foreach ( $all_tables as $table => $label ) { if ( empty( $statuses[ $table ] ) ) { $missing[] = sprintf( '%s (%s)', esc_html( $table ), esc_html( $label ) );
}
}
return $missing;
}
/**
* Build the missing-tables notice message HTML.
*
* @since 4.3.0
*
* @param array $missing Array of HTML-formatted missing table descriptions.
* @return string Notice HTML.
*/
private function build_missing_table_message( array $missing ): string {
$create_url = wp_nonce_url(
admin_url( 'admin.php?action=tptn_create_missing_tables' ),
'tptn-create-missing-tables'
);
$items = '';
foreach ( $missing as $item ) {
$items .= '%1$s