Files
AsterionWP2026/wp-content/themes/asterion-bricks/functions.php
j.foucher 026be81373 chore: session 2 snapshot — archive before Bricks-first restart
Snapshots the project at the end of session 2, just before resetting to a
Bricks-first orthodox architecture. RESTART-PLAN.md at the root explains
why this approach is being abandoned and what the next session will look like.

Why we restart
- Three architectures got stacked: Custom PHP Templates → Gutenberg blocks
  in post_content → Bricks data in post meta. Each layer fights the next.
- Bricks Builder UI does not load because our header.php / footer.php /
  page.php emit chrome that conflicts with Bricks' own template-parts.
- CSS overrides multiplied (Gutenberg + Bricks variants) and still don't
  pixel-match the original PHP-rendered visual.
- 8+ one-shot mu-plugins live in LocalWP to patch over inconsistencies.

What survives the restart (preserved here on main)
- BRIEF, both PDFs, .txt extracts (sources of truth)
- assets/css/tokens.css (full design system, untouched)
- assets/fonts/Inter-Variable*.woff2 (RGPD self-hosted)
- inc/<section>-data.php files (text copy from PDF strategie, will become
  /content-source/ on next session for reuse as translation dictionary
  and as input to programmatic page generation)
- The Git repo, remote, branch main
- LocalWP site, Bricks v2.3.4, WPML 4.9.3 with active licenses
- WPML EN + FR setup with directory URL strategy

What gets wiped at the start of next session
- wp-content/themes/asterion-bricks/header.php / footer.php / page.php /
  index.php / front-page.php / template-parts/ / templates/
- inc/render-blocks.php, inc/render-blocks-native.php, inc/render-bricks.php
- inc/shortcodes.php, inc/i18n.php, inc/form-handler.php
- 35+ WP pages created over the session
- All one-shot mu-plugins in LocalWP/wp-content/mu-plugins/

Restart approach (detailed in RESTART-PLAN.md)
- Minimalist child theme: style.css, functions.php, theme.json, tokens.css,
  trimmed utilities.css, fonts, inc/cpt.php — that's it.
- No header.php / footer.php / page.php in child theme — Bricks Templates
  (Header / Footer / Single — Page) take over via Bricks' Conditions.
- User builds 5-7 archetype Bricks templates visually (~1-2h each) then
  programmatic generation fills the variants from inc/*-data.php sources.
- WPML duplication after EN is validated.

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

174 lines
5.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Asterion Bricks — child theme bootstrap
*
* Loads design tokens, utilities, components, and main JS in a deterministic
* order. Registers theme support, image sizes, and includes modular pieces
* (custom post types, SEO schemas).
*
* @package AsterionBricks
* @since 0.1.0
*/
defined('ABSPATH') || exit;
define('AV_THEME_VERSION', '0.1.0');
define('AV_THEME_DIR', get_stylesheet_directory());
define('AV_THEME_URI', get_stylesheet_directory_uri());
/**
* Enqueue child theme styles and scripts.
*
* Bricks parent stylesheet is loaded by the parent theme itself — no need to
* re-enqueue. We layer our tokens → utilities → components on top.
*
* Cache busting via `filemtime()` so dev changes are picked up without manual
* version bumps. In production, swap to AV_THEME_VERSION + a build step.
*/
add_action('wp_enqueue_scripts', function () {
$css_dir = AV_THEME_DIR . '/assets/css';
$css_uri = AV_THEME_URI . '/assets/css';
$js_dir = AV_THEME_DIR . '/assets/js';
$js_uri = AV_THEME_URI . '/assets/js';
if (file_exists($css_dir . '/tokens.css')) {
wp_enqueue_style(
'av-tokens',
$css_uri . '/tokens.css',
[],
filemtime($css_dir . '/tokens.css')
);
}
if (file_exists($css_dir . '/utilities.css')) {
wp_enqueue_style(
'av-utilities',
$css_uri . '/utilities.css',
['av-tokens'],
filemtime($css_dir . '/utilities.css')
);
}
if (file_exists($css_dir . '/components.css')) {
wp_enqueue_style(
'av-components',
$css_uri . '/components.css',
['av-tokens', 'av-utilities'],
filemtime($css_dir . '/components.css')
);
}
if (file_exists($js_dir . '/main.js')) {
wp_enqueue_script(
'av-main',
$js_uri . '/main.js',
[],
filemtime($js_dir . '/main.js'),
['strategy' => 'defer', 'in_footer' => true]
);
}
}, 20);
/**
* Preload self-hosted Inter fonts to reduce LCP.
*
* Only emits <link rel="preload"> for fonts that actually exist on disk —
* silent during early dev when the WOFF2 files have not been dropped yet.
*/
add_action('wp_head', function () {
$fonts = [
'Inter-Variable.woff2',
// 'InterDisplay-Variable.woff2',
];
foreach ($fonts as $font) {
$path = AV_THEME_DIR . '/assets/fonts/' . $font;
if (file_exists($path)) {
printf(
'<link rel="preload" href="%s/assets/fonts/%s" as="font" type="font/woff2" crossorigin>' . "\n",
esc_url(AV_THEME_URI),
esc_attr($font)
);
}
}
}, 1);
/**
* Modular includes.
*
* Each file is opt-in via file_exists() so partial scaffolds don't fatal.
*/
$av_includes = [
'inc/i18n.php', // av_lang(), av_t() — load FIRST.
'inc/cpt.php', // Custom post types: case_study, scenario.
'inc/seo.php', // Schema.org JSON-LD overrides.
'inc/form-handler.php', // Conversion form POST handler.
'inc/render-blocks.php', // Data array → core/html migrator (legacy, kept for fallback).
'inc/render-blocks-native.php', // Data array → native Gutenberg blocks (legacy POC).
'inc/render-bricks.php', // Data array → Bricks Builder native elements (current target).
'inc/shortcodes.php', // [av_form slug="..."] etc.
];
foreach ($av_includes as $av_include) {
$path = AV_THEME_DIR . '/' . $av_include;
if (file_exists($path)) {
require_once $path;
}
}
unset($av_include, $path);
/**
* Theme support and custom image sizes.
*
* Image sizes per Design Handoff section 8.3:
* - hero 2400×1350 (16:9)
* - card 800×600 (4:3)
* - thumb 400×300 (4:3)
*/
add_action('after_setup_theme', function () {
add_theme_support('post-thumbnails');
add_theme_support('html5', [
'search-form', 'comment-form', 'comment-list',
'gallery', 'caption', 'style', 'script',
]);
add_theme_support('responsive-embeds');
add_theme_support('align-wide');
add_theme_support('editor-styles');
add_image_size('av-hero', 2400, 1350, true);
add_image_size('av-card', 800, 600, true);
add_image_size('av-thumb', 400, 300, true);
load_child_theme_textdomain('asterion-bricks', AV_THEME_DIR . '/languages');
});
/**
* Hide the WP admin bar on frontend for non-admins (cleaner preview screenshots).
*/
add_action('after_setup_theme', function () {
if (! current_user_can('administrator')) {
show_admin_bar(false);
}
});
/**
* Disable Gutenberg block library default styles on the public frontend only —
* we own typography end-to-end through tokens.css.
*
* Skipped when:
* - inside the Bricks Builder canvas (?bricks=run, ?brickspreview=1) — those
* screens rely on the WP-core stylesheets for their own UI / preview.
* - in the WP admin itself.
*/
add_action('wp_enqueue_scripts', function () {
if (is_admin()) return;
if (function_exists('bricks_is_builder') && bricks_is_builder()) return;
if (function_exists('bricks_is_frontend_builder_iframe') && bricks_is_frontend_builder_iframe()) return;
if (! empty($_GET['bricks']) || ! empty($_GET['brickspreview'])) return;
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('global-styles');
wp_dequeue_style('classic-theme-styles');
}, 100);