diff --git a/gdpr-content-blocker/assets/admin.js b/gdpr-content-blocker/assets/admin.js index f940db6..c19b9ff 100644 --- a/gdpr-content-blocker/assets/admin.js +++ b/gdpr-content-blocker/assets/admin.js @@ -11,15 +11,13 @@ $( '.cb-color-picker', ctx ).wpColorPicker(); } - /* ── Live header update: "interner-name — Anbietername" ── */ + /* ── Live header update: provider name ── */ function syncTitle( box ) { - const id = ( $( '.cb-input-id', box ).val() || '' ).trim(); const name = ( $( '.cb-input-name', box ).val() || '' ).trim(); - const head = ( id || ( cbAdmin.newServiceLbl || 'neu' ) ) + ( name ? ' — ' + name : '' ); - $( '.cb-service-title', box ).first().text( head ); + $( '.cb-service-title', box ).first().text( name || ( cbAdmin.newServiceLbl || 'Neuer Dienst' ) ); } function bindNameSync( box ) { - $( '.cb-input-name, .cb-input-id', box ).on( 'input', function () { + $( '.cb-input-name', box ).on( 'input', function () { syncTitle( box ); } ); } @@ -239,7 +237,7 @@ const $box = addServiceRow( data ); if ( $box && $box.length ) { $box[ 0 ].scrollIntoView( { behavior: 'smooth', block: 'center' } ); - $box.find( '.cb-input-id' ).trigger( 'focus' ); + $box.find( '.cb-input-name' ).trigger( 'focus' ); } } ) .appendTo( $act ); diff --git a/gdpr-content-blocker/includes/class-settings.php b/gdpr-content-blocker/includes/class-settings.php index 45ab11c..cedae13 100644 --- a/gdpr-content-blocker/includes/class-settings.php +++ b/gdpr-content-blocker/includes/class-settings.php @@ -104,17 +104,36 @@ class CB_Settings { : []; $services = []; + $used_ids = []; foreach ( $raw_services as $item ) { if ( ! is_array( $item ) ) { continue; } + $name = sanitize_text_field( $item['name'] ?? '' ); + if ( $name === '' ) { + continue; // a service needs at least a provider name + } + + // Keep the existing id stable (hidden field); derive from the name + // for new services. Ensure uniqueness. $id = sanitize_key( $item['id'] ?? '' ); if ( $id === '' ) { - continue; + $id = sanitize_title( $name ); } + if ( $id === '' ) { + $id = 'dienst'; + } + $base_id = $id; + $n = 2; + while ( in_array( $id, $used_ids, true ) ) { + $id = $base_id . '-' . $n; + $n++; + } + $used_ids[] = $id; + $services[] = [ 'id' => $id, - 'name' => sanitize_text_field( $item['name'] ?? '' ), + 'name' => $name, 'enabled' => ! empty( $item['enabled'] ), 'match_pattern' => sanitize_text_field( $item['match_pattern'] ?? '' ), 'recipient' => sanitize_text_field( $item['recipient'] ?? '' ), @@ -530,8 +549,8 @@ class CB_Settings { $name = $svc['name'] ?? ''; $id = $svc['id'] ?? ''; $enabled = $svc['enabled'] ?? true; // default ON (new + legacy services) - // Header label: "interner-name — Anbietername" - $headname = trim( ( $id !== '' ? $id : __( 'neu', 'gdpr-content-blocker' ) ) . ( $name !== '' ? ' — ' . $name : '' ) ); + // Header shows just the provider name (internal id is auto-derived). + $headname = $name !== '' ? $name : __( 'Neuer Dienst', 'gdpr-content-blocker' ); ?>