PHP code example of parisek / timber-kit
1. Go to this page and download the library: Download parisek/timber-kit library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
parisek / timber-kit example snippets
function timber_block_render_callback( ...$args ): void {
\Parisek\TimberKit\BlockRenderer::render( ...$args );
}
protected bool $site_health = true;
protected function health_checks( array $checks ): array {
unset( $checks['rest_users_restricted'] ); // host blocks loopbacks — verified at the edge instead
$checks['my_check'] = new MyCheck(); // implements Parisek\TimberKit\Health\HealthCheck
return $checks;
}
class Base extends StarterBase {
public function __construct() {
$this->wpml_block_override = true;
parent::__construct();
}
}
add_action( 'init', static function (): void {
if ( class_exists( \Parisek\TimberKit\WpmlBlockOverride::class ) ) {
\Parisek\TimberKit\WpmlBlockOverride::register();
}
} );
add_filter( 'timber_kit/wpml_block_override/should_override', '__return_false' );
add_filter( 'timber_kit/wpml_block_override/should_override', function ( $enabled, $block ) {
$off = [ 'acf/hero-text', 'acf/booking-form' ];
return in_array( $block['blockName'] ?? '', $off, true ) ? false : $enabled;
}, 10, 2 );
add_filter( 'timber_kit/wpml_block_override/copy_fields', function ( $copy_fields, $block_name ) {
if ( $block_name !== 'jumbotron-video' ) {
return $copy_fields;
}
return array_values( array_filter(
$copy_fields,
fn ( $entry ) => $entry['field']['name'] !== 'background_image'
) );
}, 10, 2 );
use Parisek\TimberKit\StarterBase;
use Parisek\TimberKit\Helpers;
class Base extends StarterBase {
public function __construct() {
$this->menus = [
'main-menu' => 'Main Menu',
'footer-menu' => 'Footer Menu',
];
$this->font_stylesheets = [
'poppins' => 'fonts/poppins/stylesheet.css',
];
$this->disable_search = false;
parent::__construct();
}
}
public function setup_breadcrumb_labels() {
$this->breadcrumb_labels = [
'home' => _x( 'Home', 'breadcrumb', 'my-theme' ),
// …
];
}
// wp-config.php — alternative / override (the constant always wins)
define( 'TIMBERKIT_MEDIA_ORIGIN', 'https://example.com' );
define( 'WPFORMS_CAPTCHA_PROVIDER', 'turnstile' );
define( 'WPFORMS_TURNSTILE_SITE_KEY', '1x00000000000000000000AA' );
define( 'WPFORMS_TURNSTILE_SECRET_KEY', '1x0000000000000000000000000000000AA' );
// one top-level page with an admin-bar shortcut + two sub-pages under it
$this->options_pages = [
[ 'menu_slug' => 'settings', 'page_title' => 'Theme Settings', 'admin_bar' => true ],
[ 'menu_slug' => 'footer', 'page_title' => 'Footer', 'parent_slug' => 'settings' ],
[ 'menu_slug' => 'social', 'page_title' => 'Social', 'parent_slug' => 'settings' ],
[ 'menu_slug' => 'dev', 'page_title' => 'Dev Settings', 'capability' => 'manage_options' ],
];
// disable completely
$this->options_pages = [];
class Base extends \Parisek\TimberKit\StarterBase {
public function setup_breadcrumb_labels() {
$this->breadcrumb_labels = array(
'home' => _x( 'Home', $this->theme_name, $this->theme_name ),
'404' => _x( 'Page not found', $this->theme_name, $this->theme_name ),
'search' => _x( 'Search: %s', $this->theme_name, $this->theme_name ),
'pagination' => _x( 'Page %d', $this->theme_name, $this->theme_name ),
'author' => _x( 'Author: %s', $this->theme_name, $this->theme_name ),
);
}
}
// Override mode/eagerness in your Base.php (extends StarterBase)
class Base extends \Parisek\TimberKit\StarterBase {
protected ?array $speculation_rules = [
'mode' => 'prefetch', // safer when Consent Mode v2 fires on pageview
'eagerness' => 'moderate',
'authentication' => 'logged_out',
];
}
function timber_block_render_callback( ...$args ): void {
\Parisek\TimberKit\BlockRenderer::render( ...$args );
}
add_filter(
'timber_kit/block_renderer/empty_alert_html',
static function (string $default, string $block_name, array $attributes): string {
$block_label = $attributes['title'] ?? $attributes['name'];
return Timber::compile('@component/alert/alert.twig', [
'content' => [
'message' => '<strong>' . esc_html($block_label) . ':</strong> ' .
esc_html(__('Pro zobrazení vyplňte požadované údaje v pravém panelu.', 'starter_theme')),
'type' => 'warning',
'container' => 'container',
],
]);
},
10,
3
);