Files
AsterionWP2026/tools/fresh-setup-mu-plugin.php
j.foucher 7765d0fab2 chore: add tools/fresh-setup-mu-plugin for clean LocalWP recreation
Helper for resetting the dev environment by deleting the LocalWP site and
creating a fresh one (cleaner than wiping pages/options/transients in place).

tools/fresh-setup-mu-plugin.php
  Drop into wp-content/mu-plugins/ of a brand-new LocalWP install named
  "Asterion 2026". On first hit it:
    - sets siteurl/home to http://localhost:10004 (override AV_TARGET_HOME
      if LocalWP allocates a different port)
    - sets pretty permalinks (/%postname%/)
    - timezone Europe/Paris
    - activates the Bricks parent + asterion-bricks child theme (assumes
      the Junction has been re-made and the Bricks ZIP unpacked)
    - activates WPML core
    - sets Bricks Builder Access postTypes to page/post/case_study/scenario
    - flushes rewrite rules
    - self-deletes

tools/README.md
  Step-by-step procedure for the LocalWP delete → recreate → junction →
  unpack ZIPs → drop mu-plugin → first-hit flow. Plus the manual follow-up
  for Bricks license, WPML wizard, Bricks Theme Styles.

This file path (tools/) is a deliberate sibling of content-source/ and
ThirdParty/, all of them used during setup or migration but never loaded
by the site at runtime.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 14:38:33 +02:00

126 lines
5.1 KiB
PHP

<?php
/**
* Plugin Name: Asterion Fresh Setup (one-shot)
* Description: Configures a brand-new LocalWP install for the Asterion VR project — sets siteurl/home, permalinks, activates Bricks child theme + WPML, configures Bricks postTypes. Self-deletes after success.
* Version: 0.1.0
*
* USAGE
* -----
* After deleting the old LocalWP site and creating a new "Asterion 2026":
* 1. Note the new site's HTTP port from LocalWP (likely 10004 again).
* 2. Re-create the Junction so the child theme lives in the LocalWP install:
* (run as admin from PowerShell)
* New-Item -ItemType Junction `
* -Path "<NEW_SITE_PATH>\app\public\wp-content\themes\asterion-bricks" `
* -Target "C:\ASTERION\GIT\WP2026\wp-content\themes\asterion-bricks"
* 3. Extract ThirdParty/bricks.X.Y.Z.zip into the LocalWP themes/ folder.
* 4. Extract ThirdParty/sitepress-multilingual-cms.X.Y.Z.zip into plugins/.
* 5. If the new port is NOT 10004, edit the AV_TARGET_HOME constant below.
* 6. Copy this file to <NEW_SITE_PATH>\app\public\wp-content\mu-plugins\.
* 7. Visit http://localhost:<port>/ once — the plugin runs and self-deletes.
*
* What it sets up
* ---------------
* - WP_HOME / WP_SITEURL options pointing at localhost:<port>
* - Permalinks /%postname%/
* - Activates Bricks parent + Asterion Bricks child theme (bricks-bricks-child)
* - Activates WPML core
* - Configures Bricks postTypes = ['page', 'post', 'case_study', 'scenario']
* - Sets the WP timezone to Europe/Paris and locale to en_US (default)
*
* What it does NOT do (do these manually in WP admin)
* ---------------------------------------------------
* - Bricks license activation (Bricks → License → paste your key)
* - WPML license + setup wizard (WPML → Setup → EN default + FR + directories)
* - Bricks Theme Styles (Bricks → Theme Styles → align with tokens.css)
* - Build of the Header / Footer / archive Bricks Templates
*
* @package AsterionBricks
* @since 0.2.0
*/
defined('ABSPATH') || exit;
// Hardcode the target site URL. Adjust if LocalWP allocated a different port.
define('AV_TARGET_HOME', 'http://localhost:10004');
add_action('init', function () {
if (get_option('av_fresh_setup_done') === '1') {
$self = __FILE__;
add_action('shutdown', function () use ($self) {
if (file_exists($self)) {
@unlink($self);
}
});
return;
}
$log = [];
// 1. Site URL + home (avoids the localhost:port → / 301 cache trap)
update_option('siteurl', AV_TARGET_HOME);
update_option('home', AV_TARGET_HOME);
$log[] = "Set siteurl/home to " . AV_TARGET_HOME;
// 2. Pretty permalinks (required for /customers/ /scenarios/ slugs and WPML)
if (get_option('permalink_structure') !== '/%postname%/') {
update_option('permalink_structure', '/%postname%/');
$log[] = "Set permalink_structure to /%postname%/";
}
// 3. Timezone + WP locale defaults
update_option('timezone_string', 'Europe/Paris');
if (get_locale() !== 'en_US') {
update_option('WPLANG', 'en_US');
}
// 4. Activate Bricks child theme (its parent Bricks must be present)
$themes = wp_get_themes();
if (isset($themes['bricks']) && isset($themes['asterion-bricks'])) {
if (get_option('stylesheet') !== 'asterion-bricks') {
switch_theme('asterion-bricks');
$log[] = "Switched theme to asterion-bricks (parent: bricks)";
}
} else {
$missing = [];
if (! isset($themes['bricks'])) $missing[] = 'bricks (parent)';
if (! isset($themes['asterion-bricks'])) $missing[] = 'asterion-bricks (child junction)';
$log[] = "Theme NOT switched. Missing: " . implode(', ', $missing);
}
// 5. Activate WPML core
if (! function_exists('is_plugin_active')) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$wpml_main = 'sitepress-multilingual-cms/sitepress.php';
if (file_exists(WP_PLUGIN_DIR . '/' . $wpml_main)) {
if (! is_plugin_active($wpml_main)) {
$result = activate_plugin($wpml_main, '', false, true);
$log[] = is_wp_error($result)
? 'WPML activation FAILED: ' . $result->get_error_message()
: 'WPML activated';
} else {
$log[] = 'WPML already active';
}
} else {
$log[] = "WPML not found at plugins/{$wpml_main}";
}
// 6. Bricks: enable Page/Post/CPT in Builder access > postTypes
if (defined('BRICKS_DB_GLOBAL_SETTINGS')) {
$settings = get_option(BRICKS_DB_GLOBAL_SETTINGS, []);
$settings['postTypes'] = ['page', 'post', 'case_study', 'scenario'];
update_option(BRICKS_DB_GLOBAL_SETTINGS, $settings);
$log[] = "Bricks postTypes set to page/post/case_study/scenario";
} else {
$log[] = "Bricks not loaded yet — re-run by visiting the site once Bricks is active";
}
// 7. Flush rewrite rules so the new permalink structure takes effect
flush_rewrite_rules();
update_option('av_fresh_setup_done', '1', false);
update_option('av_fresh_setup_log', $log, false);
}, 50);