Bricks's frontend.php template_redirect() permanently redirects any /template/* URL to the homepage (site_url(), 301) when : - is_singular(bricks_template) - !current_user_can_use_builder() - !isset(bricks_global_settings.publicTemplates) - !maintenance mode This kicks in BEFORE the Bricks builder check can run, so clicking "Edit with Bricks" on a template ends up redirected to home → admin URL → Bricks's own builder.php sees current_post_type as empty (because the post wasn't actually queried before the redirect) → final redirect to wp-admin/edit.php?post_type=&bricks_notice=error_post_type with the "Invalid post type" notice. Setting bricks_global_settings.publicTemplates = '1' disables this preemptive redirect. Templates stay excluded from search but their permalinks resolve normally → builder can attach. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
35 lines
1.4 KiB
PHP
35 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: Asterion — Enable Bricks publicTemplates setting
|
|
* /?av_enable_public_templates=1
|
|
*
|
|
* Bricks redirects /template/* URLs to the homepage when the user can't use
|
|
* the builder AND publicTemplates is unset. This causes "Edit with Bricks"
|
|
* to fail with "Invalid post type" because the builder URL (?bricks=run on
|
|
* the template permalink) gets redirected before reaching the builder.
|
|
*
|
|
* The fix : set publicTemplates=1 in Bricks global settings. Templates are
|
|
* still excluded from search results, but their permalinks resolve normally
|
|
* → the builder can load them.
|
|
*/
|
|
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_enable_public_templates'])) return;
|
|
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
|
|
$opts = get_option('bricks_global_settings', []);
|
|
if (! is_array($opts)) $opts = [];
|
|
|
|
$before = $opts['publicTemplates'] ?? '(unset)';
|
|
$opts['publicTemplates'] = '1';
|
|
update_option('bricks_global_settings', $opts);
|
|
|
|
echo "bricks_global_settings.publicTemplates : " . var_export($before, true) . " → '1'\n";
|
|
echo "\nTemplate URLs (/template/...) should now resolve directly without redirecting to home.\n";
|
|
echo "Edit with Bricks on Header / Footer / Single Post should work.\n";
|
|
exit;
|
|
});
|