From b0d5483744eb7909346365451c349f699ec1e7c7 Mon Sep 17 00:00:00 2001
From: kagg-design <info@kagg.eu>
Date: Mon, 25 Nov 2024 22:27:31 +0200
Subject: [PATCH] Add 'theme' badge to themes on the Integrations page.

---
 assets/css/integrations.css       |  9 +++++++++
 readme.txt                        |  1 +
 src/php/Settings/Integrations.php | 17 ++++++++++++++++-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/assets/css/integrations.css b/assets/css/integrations.css
index 9ca73d04..a33fa827 100644
--- a/assets/css/integrations.css
+++ b/assets/css/integrations.css
@@ -76,6 +76,15 @@
 	width: unset;
 }
 
+.hcaptcha-integrations table tr .hcaptcha-integrations-entity {
+	color: #ffffff;
+	background: #4de1d2;
+	border: 1px #00a3bf solid;
+	font-size: 14px;
+	line-height: 18px;
+	padding: 4px 6px;
+}
+
 .hcaptcha-integrations-logo {
 	position: relative;
 }
diff --git a/readme.txt b/readme.txt
index dcd490e1..7620de70 100644
--- a/readme.txt
+++ b/readme.txt
@@ -603,6 +603,7 @@ Instructions for popular native integrations are below:
 * Added Maintenance Login Form integration.
 * Added Extra theme integration.
 * Added theme argument to the [hcaptcha] shortcode.
+* Added 'theme' badge to themes on the Integrations page.
 * Fixed deactivating of all themes by Ctrl+Click on the Integrations page.
 * Fixed theme name display upon activation.
 * Fixed display of the hCaptcha shortcode with individual parameters.
diff --git a/src/php/Settings/Integrations.php b/src/php/Settings/Integrations.php
index 7f8330d8..a4970406 100644
--- a/src/php/Settings/Integrations.php
+++ b/src/php/Settings/Integrations.php
@@ -670,7 +670,7 @@ private function logo( array $form_field ): string {
 		$logo_file = sanitize_file_name( strtolower( $label ) . '.' . $logo_type );
 		$entity    = $form_field['entity'] ?? 'plugin';
 
-		return sprintf(
+		$logo = sprintf(
 			'<div class="hcaptcha-integrations-logo" data-installed="%1$s">' .
 			'<img src="%2$s" alt="%3$s Logo" data-label="%3$s" data-entity="%4$s">' .
 			'</div>',
@@ -679,6 +679,15 @@ private function logo( array $form_field ): string {
 			$label,
 			$entity
 		);
+
+		if ( 'theme' === $entity ) {
+			$logo .= sprintf(
+				'<div class="hcaptcha-integrations-entity">%1$s</div>',
+				$entity
+			);
+		}
+
+		return $logo;
 	}
 
 	/**
@@ -701,6 +710,8 @@ public function setup_fields(): void {
 
 		$this->form_fields = $this->sort_fields( $this->form_fields );
 
+		$prefix = self::PREFIX . '-' . $this->section_title() . '-';
+
 		foreach ( $this->form_fields as $status => &$form_field ) {
 			$form_field['installed'] = in_array( $status, $installed, true );
 			$form_field['section']   = ( ! $form_field['installed'] ) || $form_field['disabled']
@@ -710,6 +721,10 @@ public function setup_fields(): void {
 			if ( isset( $form_field['label'] ) ) {
 				$form_field['label'] = $this->logo( $form_field );
 			}
+
+			$entity              = $form_field['entity'] ?? '';
+			$theme               = 'theme' === $entity ? ' ' . $prefix . 'theme' : '';
+			$form_field['class'] = str_replace( '_', '-', $prefix . $status . $theme );
 		}
 
 		unset( $form_field );