Changeset 3830587
- Timestamp:
- 11/27/2026 11:03:18 PM (less than one hour ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
novelience-redirects/assets/blueprints/blueprint.json
r3828500 r3830587 28 28 "step": "writeFile", 29 29 "path": "/wordpress/wp-content/mu-plugins/novelience-redirects-preview.php", 30 "data": "<?php\n/**\n * Plugin Name: Novelience Redirects preview\n * Description: Links to the two sample CSV files on the Novelience Redirects screen of this preview, in the language of the current user.\n */\ndefined('ABSPATH') || exit;\n\nadd_action('admin_notices', static function (): void {\n $screen = function_exists('get_current_screen') ? get_current_screen() : null;\n if (!$screen || $screen->id !== 'tools_page_novelience-redirects') {\n return;\n }\n // The file names, CSV columns and sample rows are data and stay identical in every language.\n $texts = [\n 'en' => [\n 'Preview: the map below was imported from',\n '(the old-catalogue chain is collapsed to its final target). Download',\n 'and import it to see a loop refused while the active map stays unchanged.',\n ],\n 'fr' => [\n 'Aperçu : la cartographie ci-dessous a été importée depuis',\n '(la chaîne de l’ancien catalogue est ramenée à sa cible finale). Téléchargez',\n 'puis importez-le pour voir une boucle de redirection refusée, la cartographie active restant inchangée.',\n ],\n 'de' => [\n 'Vorschau: Die Tabelle unten wurde aus',\n 'importiert (die Kette des alten Katalogs ist auf ihr endgültiges Ziel zusammengefasst). Lade',\n 'herunter und importiere die Datei: Die Weiterleitungsschleife wird abgelehnt und die aktive Tabelle bleibt unverändert.',\n ],\n 'es' => [\n 'Vista previa: el mapa de abajo se importó desde',\n '(la cadena del catálogo antiguo se simplifica en su destino final). Descarga',\n 'e impórtalo para ver cómo se rechaza un bucle de redirección mientras el mapa activo no cambia.',\n ],\n 'it' => [\n 'Anteprima: la mappa qui sotto è stata importata da',\n '(la catena del vecchio catalogo è compressa nella sua destinazione finale). Scarica',\n 'e importalo per vedere un loop di reindirizzamento rifiutato mentre la mappa attiva resta invariata.',\n ],\n ];\n $language = strtolower(substr((string) get_user_locale(), 0, 2));\n $text = $texts[$language] ?? $texts['en'];\n $base = content_url('uploads/novelience-redirects-demo/');\n printf(\n '<div class=\"notice notice-info\"><p>%s <a href=\"%s\" download>example-map.csv</a> %s <a href=\"%s\" download>refused-loop.csv</a> %s</p></div>',\n esc_html($text[0]),\n esc_url($base . 'example-map.csv'),\n esc_html($text[1]),\n esc_url($base . 'refused-loop.csv'),\n esc_html($text[2])\n );\n});\n "30 "data": "<?php\n/**\n * Plugin Name: Novelience Redirects preview\n * Description: Links to the two sample CSV files on the Novelience Redirects screen of this preview, in the language of the current user.\n */\ndefined('ABSPATH') || exit;\n\nadd_action('admin_notices', static function (): void {\n $screen = function_exists('get_current_screen') ? get_current_screen() : null;\n if (!$screen || $screen->id !== 'tools_page_novelience-redirects') {\n return;\n }\n // The file names, CSV columns and sample rows are data and stay identical in every language.\n $texts = [\n 'en' => [\n 'Preview: the map below was imported from',\n '(the old-catalogue chain is collapsed to its final target). Download',\n 'and import it to see a loop refused while the active map stays unchanged.',\n ],\n 'fr' => [\n 'Aperçu : la cartographie ci-dessous a été importée depuis',\n '(la chaîne de l’ancien catalogue est ramenée à sa cible finale). Téléchargez',\n 'puis importez-le pour voir une boucle de redirection refusée, la cartographie active restant inchangée.',\n ],\n 'de' => [\n 'Vorschau: Die Tabelle unten wurde aus',\n 'importiert (die Kette des alten Katalogs ist auf ihr endgültiges Ziel zusammengefasst). Lade',\n 'herunter und importiere die Datei: Die Weiterleitungsschleife wird abgelehnt und die aktive Tabelle bleibt unverändert.',\n ],\n 'es' => [\n 'Vista previa: el mapa de abajo se importó desde',\n '(la cadena del catálogo antiguo se simplifica en su destino final). Descarga',\n 'e impórtalo para ver cómo se rechaza un bucle de redirección mientras el mapa activo no cambia.',\n ],\n 'it' => [\n 'Anteprima: la mappa qui sotto è stata importata da',\n '(la catena del vecchio catalogo è compressa nella sua destinazione finale). Scarica',\n 'e importalo per vedere un loop di reindirizzamento rifiutato mentre la mappa attiva resta invariata.',\n ],\n ];\n $language = strtolower(substr((string) get_user_locale(), 0, 2));\n $text = $texts[$language] ?? $texts['en'];\n $base = content_url('uploads/novelience-redirects-demo/');\n printf(\n '<div class=\"notice notice-info\"><p>%s <a href=\"%s\" download>example-map.csv</a> %s <a href=\"%s\" download>refused-loop.csv</a> %s</p></div>',\n esc_html($text[0]),\n esc_url($base . 'example-map.csv'),\n esc_html($text[1]),\n esc_url($base . 'refused-loop.csv'),\n esc_html($text[2])\n );\n});\n\n// Sample destination pages of the map: their title and text follow the site language of the preview.\n$novelience_redirects_preview_pages = static function (): array {\n return [\n 'new-page' => [\n 'en' => ['New page', 'This page replaces the old page of the site. The redirect map sends visitors of the old address here.'],\n 'fr' => ['Nouvelle page', 'Cette page remplace l’ancienne page du site. La cartographie de redirections y conduit les visiteurs de l’ancienne adresse.'],\n 'de' => ['Neue Seite', 'Diese Seite ersetzt die alte Seite der Website. Die Weiterleitungstabelle führt Besucher der alten Adresse hierher.'],\n 'es' => ['Página nueva', 'Esta página sustituye a la antigua página del sitio. El mapa de redirecciones lleva aquí a quienes visitan la dirección antigua.'],\n 'it' => ['Nuova pagina', 'Questa pagina sostituisce la vecchia pagina del sito. La mappa dei reindirizzamenti porta qui chi visita il vecchio indirizzo.'],\n ],\n 'catalogue' => [\n 'en' => ['Catalogue', 'Current address of the catalogue. Both former addresses of the catalogue lead here in a single redirect.'],\n 'fr' => ['Catalogue', 'Adresse actuelle du catalogue. Les deux anciennes adresses du catalogue y mènent en une seule redirection.'],\n 'de' => ['Katalog', 'Aktuelle Adresse des Katalogs. Beide früheren Adressen des Katalogs führen mit einer einzigen Weiterleitung hierher.'],\n 'es' => ['Catálogo', 'Dirección actual del catálogo. Las dos direcciones anteriores del catálogo llevan aquí con una sola redirección.'],\n 'it' => ['Catalogo', 'Indirizzo attuale del catalogo. Entrambi i vecchi indirizzi del catalogo portano qui con un solo reindirizzamento.'],\n ],\n 'contact' => [\n 'en' => ['Contact', 'Renamed contact page. The former contact-us address leads here.'],\n 'fr' => ['Contact', 'Page de contact renommée. L’ancienne adresse contact-us y conduit.'],\n 'de' => ['Kontakt', 'Umbenannte Kontaktseite. Die frühere Adresse contact-us führt hierher.'],\n 'es' => ['Contacto', 'Página de contacto renombrada. La antigua dirección contact-us lleva aquí.'],\n 'it' => ['Contatti', 'Pagina dei contatti rinominata. Il vecchio indirizzo contact-us porta qui.'],\n ],\n ];\n};\n$novelience_redirects_preview_text = static function (int $post_id, int $index) use ($novelience_redirects_preview_pages): ?string {\n $slug = (string) get_post_meta($post_id, '_novelience_redirects_preview_page', true);\n $pages = $novelience_redirects_preview_pages();\n if ($slug === '' || !isset($pages[$slug])) {\n return null;\n }\n $language = strtolower(substr((string) get_locale(), 0, 2));\n return ($pages[$slug][$language] ?? $pages[$slug]['en'])[$index];\n};\nadd_filter('the_title', static function ($title, $post_id = 0) use ($novelience_redirects_preview_text) {\n $text = $post_id ? $novelience_redirects_preview_text((int) $post_id, 0) : null;\n return $text ?? $title;\n}, 10, 2);\nadd_filter('the_content', static function ($content) use ($novelience_redirects_preview_text) {\n $text = in_the_loop() ? $novelience_redirects_preview_text((int) get_the_ID(), 1) : null;\n return $text !== null ? '<p>' . esc_html($text) . '</p>' : $content;\n});\n" 31 31 }, 32 32 { 33 33 "step": "runPHP", 34 "code": "<?php\nrequire_once '/wordpress/wp-load.php';\n$fail = static function (string $message): void {\n echo 'Novelience Redirects preview: ' . $message . \"\\n\";\n exit(1);\n};\nif (!function_exists('novelience_redirects_parse_csv') || !function_exists('novelience_redirects_import')) {\n $fail('Novelience Redirects is not active.');\n}\n $dir = WP_CONTENT_DIR . '/uploads/novelience-redirects-demo';\nwp_mkdir_p($dir);\n$u = static fn (string $path): string => home_url($path);\n$csv = static function (array $rows): string {\n $out = \"source_url,target_url,decision,reason\\n\";\n foreach ($rows as $row) {\n $out .= implode(',', $row) . \"\\n\";\n }\n return $out;\n};\n$valid = $csv([\n [$u('/old-page'), $u('/new-page/'), 'redirect_301', 'Site restructuring'],\n [$u('/old-catalogue'), $u('/catalogue-2024'), 'redirect_301', 'First move of the catalogue'],\n [$u('/catalogue-2024'), $u('/catalogue/'), 'redirect_301', 'Second move of the catalogue'],\n [$u('/contact-us'), $u('/contact/'), 'redirect_301', 'Renamed page'],\n [$u('/draft-offer'), $u('/offer/'), 'ignore', 'Kept for review and not imported'],\n]);\n$loop = $csv([\n [$u('/offer-a'), $u('/offer-b'), 'redirect_301', 'Points to offer-b'],\n [$u('/offer-b'), $u('/offer-a'), 'redirect_301', 'Points back to offer-a'],\n]);\nfile_put_contents($dir . '/example-map.csv', $valid);\nfile_put_contents($dir . '/refused-loop.csv', $loop);\n$rows = novelience_redirects_parse_csv($dir . '/example-map.csv');\nif (is_wp_error($rows)) {\n $fail('Example map rejected: ' . $rows->get_error_message());\n}\n$result = novelience_redirects_import($rows, 'example-map.csv');\nif (is_wp_error($result)) {\n $fail('Example map import failed: ' . $result->get_error_message());\n}\necho wp_json_encode($result);\n"34 "code": "<?php\nrequire_once '/wordpress/wp-load.php';\n$fail = static function (string $message): void {\n echo 'Novelience Redirects preview: ' . $message . \"\\n\";\n exit(1);\n};\nif (!function_exists('novelience_redirects_parse_csv') || !function_exists('novelience_redirects_import')) {\n $fail('Novelience Redirects is not active.');\n}\n// The map targets real pages of the preview site, so that every redirect ends on an existing page.\nforeach (['new-page' => 'New page', 'catalogue' => 'Catalogue', 'contact' => 'Contact'] as $slug => $title) {\n $existing = get_page_by_path($slug, OBJECT, 'page');\n $id = $existing ? (int) $existing->ID : (int) wp_insert_post([\n 'post_type' => 'page',\n 'post_status' => 'publish',\n 'post_name' => $slug,\n 'post_title' => $title,\n 'post_content' => '',\n ], true);\n if ($id <= 0 || get_post_field('post_name', $id) !== $slug) {\n $fail('Sample page ' . $slug . ' could not be created.');\n }\n update_post_meta($id, '_novelience_redirects_preview_page', $slug);\n}\nif ((string) get_option('permalink_structure') === '') {\n update_option('permalink_structure', '/%postname%/');\n}\nflush_rewrite_rules(false);\n$dir = WP_CONTENT_DIR . '/uploads/novelience-redirects-demo';\nwp_mkdir_p($dir);\n$u = static fn (string $path): string => home_url($path);\n$csv = static function (array $rows): string {\n $out = \"source_url,target_url,decision,reason\\n\";\n foreach ($rows as $row) {\n $out .= implode(',', $row) . \"\\n\";\n }\n return $out;\n};\n$valid = $csv([\n [$u('/old-page'), $u('/new-page/'), 'redirect_301', 'Site restructuring'],\n [$u('/old-catalogue'), $u('/catalogue-2024'), 'redirect_301', 'First move of the catalogue'],\n [$u('/catalogue-2024'), $u('/catalogue/'), 'redirect_301', 'Second move of the catalogue'],\n [$u('/contact-us'), $u('/contact/'), 'redirect_301', 'Renamed page'],\n [$u('/draft-offer'), $u('/offer/'), 'ignore', 'Kept for review and not imported'],\n]);\n$loop = $csv([\n [$u('/offer-a'), $u('/offer-b'), 'redirect_301', 'Points to offer-b'],\n [$u('/offer-b'), $u('/offer-a'), 'redirect_301', 'Points back to offer-a'],\n]);\nfile_put_contents($dir . '/example-map.csv', $valid);\nfile_put_contents($dir . '/refused-loop.csv', $loop);\n$rows = novelience_redirects_parse_csv($dir . '/example-map.csv');\nif (is_wp_error($rows)) {\n $fail('Example map rejected: ' . $rows->get_error_message());\n}\n$result = novelience_redirects_import($rows, 'example-map.csv');\nif (is_wp_error($result)) {\n $fail('Example map import failed: ' . $result->get_error_message());\n}\necho wp_json_encode($result);\n" 35 35 } 36 36 ]
Note:
See TracChangeset
for help on using the changeset viewer.