if (is_admin()) { add_action('admin_menu', static function () { if (!function_exists('bt_sw_theme_child_slugs')) return; add_submenu_page('woocommerce', 'BT Themenwelt-Wörter', 'Themenwelt-Wörter', 'manage_woocommerce', 'bt-sw-theme-words', 'bt_sw_theme_words_admin_page'); }); add_action('admin_post_bt_sw_theme_words_save', static function () { if (!current_user_can('manage_woocommerce')) wp_die('Keine Berechtigung.'); check_admin_referer('bt_sw_theme_words_save'); $theme = isset($_POST['theme']) ? sanitize_title(wp_unslash($_POST['theme'])) : ''; if (!function_exists('bt_sw_theme_child_slugs') || !in_array($theme, bt_sw_theme_child_slugs(), true)) wp_die('Ungültiges Thema.'); $new = []; foreach (['buchstaben', 'zahlen'] as $pool) { $text = isset($_POST[$pool]) ? (string) wp_unslash($_POST[$pool]) : ''; $lines = preg_split('/\r\n|\r|\n/', trim($text)); $output = []; foreach ($lines as $line) { if (trim($line) === '') continue; if (!preg_match('/^\s*\d+(?:\s*[,; ]\s*\d+)*\s*$/', $line)) wp_die('Nur Produkt-IDs (durch Komma oder Leerzeichen getrennt) verwenden.'); $ids = array_values(array_filter(array_map('absint', preg_split('/[,;\s]+/', trim($line))))); if (count($ids) > 30) wp_die('Maximal 30 Zeichen pro Wortzeile.'); foreach ($ids as $id) { if (!bt_sw_theme_words_product_allowed($id, $pool)) { wp_die('Produkt-ID ' . esc_html((string) $id) . ' ist kein veröffentlichter ' . esc_html($pool) . '-Artikel mit Produktbild.'); } } $output[] = $ids; } if (count($output) > 8) wp_die('Maximal acht Wortzeilen pro Pool.'); $new[$pool] = $output; } $all = get_option('bt_sw_theme_word_sequences', []); if (!is_array($all)) $all = []; $all[$theme] = $new; update_option('bt_sw_theme_word_sequences', $all, false); if (function_exists('bt_swatches_bump_cache_version')) bt_swatches_bump_cache_version(); wp_safe_redirect(add_query_arg(['page'=>'bt-sw-theme-words', 'theme'=>$theme, 'updated'=>'1'], admin_url('admin.php'))); exit; }); } if (!function_exists('bt_sw_theme_words_admin_page')) { function bt_sw_theme_words_admin_page(): void { if (!current_user_can('manage_woocommerce')) return; $slugs = function_exists('bt_sw_theme_child_slugs') ? bt_sw_theme_child_slugs() : []; $theme = isset($_GET['theme']) ? sanitize_title(wp_unslash($_GET['theme'])) : ($slugs[0] ?? ''); if (!in_array($theme, $slugs, true)) $theme = $slugs[0] ?? ''; echo '
Nur gezielte Produktbilder in den vorhandenen Pools Buchstaben und Zahlen. Jede Zeile bildet ein zusammenhängendes Wort. Doppelte Produkt-IDs sind erlaubt; die globale Produktreihenfolge bleibt unverändert.
'; if (isset($_GET['updated']) && $_GET['updated'] === '1') echo 'Wortfolgen gespeichert.