Skip to content

Instantly share code, notes, and snippets.

@adam-laita
Last active January 5, 2026 13:26
Show Gist options
  • Select an option

  • Save adam-laita/01c088b986dac578ec0839d52bdbb8a5 to your computer and use it in GitHub Desktop.

Select an option

Save adam-laita/01c088b986dac578ec0839d52bdbb8a5 to your computer and use it in GitHub Desktop.
Adds support for Czech typography plugins for Bricks builder.
<?php
/**
* Plugin Name: Bricks Typography
* Description: Adds support for Czech/Polish typography plugins for Bricks builder.
* Plugin URI: https://gist.github.com/adam-laita/01c088b986dac578ec0839d52bdbb8a5
* Author: Adam Laita
* Author URI: https://www.laita.cz
* Version: 2.0.0
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Configuration: Text keys to process in Bricks element settings.
*
* @var array
*/
$bt_text_keys = array(
'text',
'title',
'subtitle',
'content',
'description',
'meta',
'prefix',
'suffix',
'label',
'placeholder',
'heading',
'subheading',
'name',
'position',
'company',
'quote',
'feature',
'price',
'currency',
'period',
'button_text',
);
/**
* Check if Bricks theme is active.
*/
$bt_theme = wp_get_theme();
if ( 'Bricks' === $bt_theme->name || 'Bricks' === $bt_theme->parent_theme ) {
/**
* Filter Bricks element settings and apply typography replacements.
*
* @param array $settings Element settings.
* @param object $element Bricks element object.
* @return array Modified settings.
*/
add_filter( 'bricks/element/settings', function ( $settings, $element ) {
global $bt_text_keys;
return bt_process_settings_recursive( $settings, $bt_text_keys );
}, 10, 2 );
}
/**
* Recursively process settings array and apply typography replacements.
*
* @param mixed $data Settings data (array or string).
* @param array $text_keys Keys to process.
* @return mixed Processed data.
*/
function bt_process_settings_recursive( $data, $text_keys ) {
if ( ! is_array( $data ) ) {
return $data;
}
foreach ( $data as $key => &$value ) {
if ( is_array( $value ) ) {
// Recursively process nested arrays.
$value = bt_process_settings_recursive( $value, $text_keys );
} elseif ( is_string( $value ) && in_array( $key, $text_keys, true ) ) {
// Apply typography replacement to matching keys.
$value = bt_apply_typography( $value );
}
}
unset( $value );
return $data;
}
/**
* Apply typography plugins to given text.
*
* Supports:
* - Čeština – Pro typografii (Bozimediazalomeni)
* - Zalomení
* - Sierotki (Polish orphans)
*
* @param string $text Text to process.
* @return string Processed text.
*/
function bt_apply_typography( $text ) {
if ( empty( $text ) ) {
return $text;
}
// Plugin: Čeština – Pro typografii (cestina-zalomeni-radku).
if ( class_exists( 'Bozimediazalomeni_Public' ) && method_exists( 'Bozimediazalomeni_Public', 'add_hard_spaces' ) ) {
$text = Bozimediazalomeni_Public::add_hard_spaces( $text );
}
// Plugin: Zalomení.
if ( class_exists( 'Zalomeni' ) && method_exists( 'Zalomeni', 'texturize' ) ) {
$text = Zalomeni::texturize( $text );
}
// Plugin: Sierotki (Polish orphans).
if ( class_exists( 'iworks_orphan' ) ) {
global $bt_sierotki_instance;
if ( ! isset( $bt_sierotki_instance ) ) {
$bt_sierotki_instance = new iworks_orphan();
}
if ( method_exists( $bt_sierotki_instance, 'replace' ) ) {
$text = $bt_sierotki_instance->replace( $text );
}
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment