Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions integrations/bricks/includes/class-fonts-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,60 @@ 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.
//
// 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',
);
}
}
} catch ( \Throwable $e ) {
// Bricks API unavailable or incompatible — fall through to WP_Query.
}
}

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,
'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();
Expand Down