It would be nice if we could force bricks to always use bricks instead of Gutenberg Content for certain Post-Types.
I had the usecase where a I had a certain post-type (stores) where i setup a single Template for that CPT with optional Bricks Content if that perticular store wanted to display indivual content.
If the content was empty, the single template rendered just fine, but if i once added bricks content and removed it (by saving an empty page), it would fallback to rendering the Gutenberg content and didn’t display my single Template anymore. I fixed it by forcing the editor mode with this filter and an options page, where I could set post-types where i wanted the behaviour to change:
namespace Userfreunde;
if (! defined('ABSPATH')) exit;
class Bricks
{
public function __construct()
add_filter('get_post_metadata', [$this, 'force_bricks_editor_mode'], 10, 4);
}
// MARK: Force Bricks Editor Mode
/**
* Posts of the post types selected in the bricksForceEditorModePostTypes
* setting always render through the Bricks single template — the editor
* mode meta must read 'bricks' for that. Bricks however resets the meta to
* 'wordpress' when a post is saved with an empty canvas (ajax.php: editor
* mode reset on empty content) — render_with_bricks() then bails before the
* template lookup and single.php renders the default fallback. The filter
* also overrules already affected posts without touching the database.
*/
public function force_bricks_editor_mode(mixed $value, mixed $object_id, mixed $meta_key, mixed $single): mixed
{
if (!defined('BRICKS_DB_EDITOR_MODE') || $meta_key !== BRICKS_DB_EDITOR_MODE) return $value;
$post_types = Settings::get('bricksForceEditorModePostTypes', []);
if (!is_array($post_types) || $post_types === []) return $value;
if (!in_array(get_post_type((int) $object_id), $post_types, true)) return $value;
return $single ? 'bricks' : ['bricks'];
}
}
This works great for me, but I think this could be a feature that bricks should ship inherently, since the inconsistency can be confusing to developers.
Best Regards
Suat