fix(header): make Asterion logo link to home
One-shot mu-plugin patches the Bricks heading 'hdrlgo' in template #25 to add link.type='external' + link.url='/'. Idempotent — re-runs are safe. Patches both _bricks_page_content_2 (JSON, source) and _bricks_page_header_2 (serialized PHP, mirrored by the REST bridge), so the change takes effect immediately without re-running av-fix-template-meta. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
65
tools/av-fix-header-logo-link.php
Normal file
65
tools/av-fix-header-logo-link.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: Asterion — Make Header logo link to home (one-shot)
|
||||||
|
* /?av_fix_header_logo=1 → patch element 'hdrlgo' in Bricks template #25
|
||||||
|
* to add link.type=external, link.url=/ so clicking the logo reloads home.
|
||||||
|
*
|
||||||
|
* Stored in _bricks_page_header_2 (serialized PHP array), and also in
|
||||||
|
* _bricks_page_content_2 (JSON) thanks to the dual-format read filter in
|
||||||
|
* av-bricks-rest-bridge.php.
|
||||||
|
*/
|
||||||
|
defined('ABSPATH') || exit;
|
||||||
|
|
||||||
|
add_action('template_redirect', function () {
|
||||||
|
if (! in_array($_SERVER['SERVER_NAME'] ?? '', ['localhost', '127.0.0.1'], true)) return;
|
||||||
|
if (empty($_GET['av_fix_header_logo'])) return;
|
||||||
|
|
||||||
|
header('Content-Type: text/plain; charset=utf-8');
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$patched = 0;
|
||||||
|
foreach (['_bricks_page_content_2', '_bricks_page_header_2'] as $key) {
|
||||||
|
$val = $wpdb->get_var($wpdb->prepare(
|
||||||
|
"SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id=%d AND meta_key=%s LIMIT 1",
|
||||||
|
25, $key
|
||||||
|
));
|
||||||
|
if (! is_string($val) || $val === '') {
|
||||||
|
echo " $key : (empty, skip)\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$is_json = ($val[0] === '[');
|
||||||
|
$elements = $is_json ? json_decode($val, true) : @unserialize($val);
|
||||||
|
if (! is_array($elements)) {
|
||||||
|
echo " $key : (not parseable, skip)\n";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$modified = false;
|
||||||
|
foreach ($elements as $i => $el) {
|
||||||
|
if (($el['id'] ?? '') === 'hdrlgo') {
|
||||||
|
$elements[$i]['settings']['link'] = [
|
||||||
|
'type' => 'external',
|
||||||
|
'url' => '/',
|
||||||
|
];
|
||||||
|
$modified = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($modified) {
|
||||||
|
$new = $is_json ? wp_json_encode($elements) : maybe_serialize($elements);
|
||||||
|
$wpdb->update($wpdb->postmeta, ['meta_value' => $new],
|
||||||
|
['post_id' => 25, 'meta_key' => $key], ['%s'], ['%d', '%s']);
|
||||||
|
wp_cache_delete(25, 'post_meta');
|
||||||
|
$patched++;
|
||||||
|
echo " $key : hdrlgo patched (link.url=/)\n";
|
||||||
|
} else {
|
||||||
|
echo " $key : hdrlgo not found\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\nDONE. $patched meta key(s) patched.\n";
|
||||||
|
echo "Reload any page → click 'ASTERION VR' in header → should go to /.\n";
|
||||||
|
exit;
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user