From c11d07f53083ba4c996f5830139726ff3bd9dca6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 31 May 2026 10:20:19 +0000 Subject: [PATCH 1/2] Fix: include Bricks Font Manager CPT fonts in typography dropdown Bricks stores custom uploaded fonts as a CPT (not in the bricks_custom_fonts option). The fonts REST endpoint now calls Bricks\Custom_Fonts::get_custom_fonts() when the class is available, with a WP_Query fallback on BRICKS_DB_CUSTOM_FONTS for edge cases where the class hasn't loaded yet. Both paths feed into the existing deduplication step, so no duplicates appear if a font exists in both storage locations. https://claude.ai/code/session_01DU3r3kT7GqH7w7jeadV2DT --- .../bricks/includes/class-fonts-rest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/integrations/bricks/includes/class-fonts-rest.php b/integrations/bricks/includes/class-fonts-rest.php index b7317654..023b3273 100644 --- a/integrations/bricks/includes/class-fonts-rest.php +++ b/integrations/bricks/includes/class-fonts-rest.php @@ -124,6 +124,48 @@ public function get_fonts( WP_REST_Request $request ) { } } + // ── Custom fonts uploaded via Bricks Font Manager (CPT) ──────── + // Bricks stores fonts added through Settings > Custom Fonts as a + // custom post type. The option-based 'bricks_custom_fonts' above + // covers an older/alternative storage path; this block covers the + // CPT path used by current Bricks versions. + if ( class_exists( 'Bricks\Custom_Fonts' ) ) { + $cpt_fonts = \Bricks\Custom_Fonts::get_custom_fonts(); + if ( is_array( $cpt_fonts ) ) { + foreach ( $cpt_fonts as $font_data ) { + if ( empty( $font_data['family'] ) || ! is_string( $font_data['family'] ) ) { + continue; + } + $fonts[] = array( + 'family' => sanitize_text_field( $font_data['family'] ), + 'label' => sanitize_text_field( $font_data['family'] ), + 'source' => 'custom', + ); + } + } + } elseif ( defined( 'BRICKS_DB_CUSTOM_FONTS' ) ) { + // Bricks class not yet loaded — query the CPT directly. + $cpt_posts = get_posts( + array( + 'post_type' => BRICKS_DB_CUSTOM_FONTS, + 'posts_per_page' => -1, + 'post_status' => 'publish', + 'fields' => 'ids', + ) + ); + foreach ( $cpt_posts as $post_id ) { + $family = get_the_title( $post_id ); + if ( ! $family ) { + continue; + } + $fonts[] = array( + 'family' => sanitize_text_field( $family ), + 'label' => sanitize_text_field( $family ), + 'source' => 'custom', + ); + } + } + // Deduplicate by family name (case-insensitive) keeping first entry. $seen = array(); $unique = array(); From d8bfd30be6cc474146d546a643c7ecbdc5ce21d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 31 May 2026 10:43:03 +0000 Subject: [PATCH 2/2] fix: guard Bricks\Custom_Fonts::get_custom_fonts() against API mismatch get_custom_fonts() is undocumented/internal in Bricks. Added method_exists() check alongside class_exists() so a missing method doesn't fatal. Wrapped the call in try/catch(\Throwable) so runtime errors from an incompatible Bricks version fall through to the existing WP_Query CPT path instead. https://claude.ai/code/session_01DU3r3kT7GqH7w7jeadV2DT --- .../bricks/includes/class-fonts-rest.php | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/integrations/bricks/includes/class-fonts-rest.php b/integrations/bricks/includes/class-fonts-rest.php index 023b3273..9c0f6c55 100644 --- a/integrations/bricks/includes/class-fonts-rest.php +++ b/integrations/bricks/includes/class-fonts-rest.php @@ -129,22 +129,34 @@ public function get_fonts( WP_REST_Request $request ) { // custom post type. The option-based 'bricks_custom_fonts' above // covers an older/alternative storage path; this block covers the // CPT path used by current Bricks versions. - if ( class_exists( 'Bricks\Custom_Fonts' ) ) { - $cpt_fonts = \Bricks\Custom_Fonts::get_custom_fonts(); - if ( is_array( $cpt_fonts ) ) { - foreach ( $cpt_fonts as $font_data ) { - if ( empty( $font_data['family'] ) || ! is_string( $font_data['family'] ) ) { - continue; + // + // get_custom_fonts() is an internal Bricks method with no public API + // contract, so we guard against missing/incompatible versions and fall + // back to a direct WP_Query when the API is unavailable. + $cpt_via_api = false; + if ( class_exists( 'Bricks\Custom_Fonts' ) && method_exists( '\Bricks\Custom_Fonts', 'get_custom_fonts' ) ) { + try { + $cpt_fonts = \Bricks\Custom_Fonts::get_custom_fonts(); + if ( is_array( $cpt_fonts ) ) { + $cpt_via_api = true; + foreach ( $cpt_fonts as $font_data ) { + if ( empty( $font_data['family'] ) || ! is_string( $font_data['family'] ) ) { + continue; + } + $fonts[] = array( + 'family' => sanitize_text_field( $font_data['family'] ), + 'label' => sanitize_text_field( $font_data['family'] ), + 'source' => 'custom', + ); } - $fonts[] = array( - 'family' => sanitize_text_field( $font_data['family'] ), - 'label' => sanitize_text_field( $font_data['family'] ), - 'source' => 'custom', - ); } + } catch ( \Throwable $e ) { + // Bricks API unavailable or incompatible — fall through to WP_Query. } - } elseif ( defined( 'BRICKS_DB_CUSTOM_FONTS' ) ) { - // Bricks class not yet loaded — query the CPT directly. + } + + if ( ! $cpt_via_api && defined( 'BRICKS_DB_CUSTOM_FONTS' ) ) { + // Bricks class/method not available — query the CPT directly. $cpt_posts = get_posts( array( 'post_type' => BRICKS_DB_CUSTOM_FONTS,