Professional Documents
Culture Documents
Kirki toolkit
@APredic
O meni
Aleksandar Predic
● Twitter: @Apredic
● Shindiri Studio
● PHP / WordPress developer
● Jedan od osnivača #WPNis zajednice
Izvinjavam se unapred
● Postoji 4 tipa Customizer objekata: Paneli, Sekcije, Podešavanja i kontrole (Panels, Sections,
Settings and Controls).
Tipovi Customizer objekata
1. Controls - Kontrole su UI koji koristimo za kreiranje opcija teme ili plugin-a:
Input, textarea, radio buttons…
Dva načina:
theme_supports
The Kirki::add_section() method is Optional. This can be used to hide a
nothing more than a wrapper for the
setting if the theme lacks support for a
WordPress customizer API and
specific feature (using
therefore follows the exact same
add_theme_support).
syntax.
Customizer
Dodati kontrole
function my_custom_text_settings( $wp_customize )
{
Kirki
// Register the settings
endif;
add_action( 'init', 'twentyseventeen_child_kirki' );
Kreiranje Kirki konfiguracije
Arguments:
,
));
$wp_customize->selective_refresh->add_partial( 'document_title', array(
'selector' => 'head > title',
'settings' => array(
'blogname'
),
'render_callback' => 'wp_get_document_title',
));
}
add_action( 'customize_register', 'my_register_blogname_partials' );
Kirki - partial_refresh
Kirki::add_field( 'my_config', array(
'type' => 'text',
'settings' => 'my_setting',
'label' => esc_attr__( 'Text Control', 'my_textdomain' ) ,
'section' => 'my_section',
'default' => esc_attr__( 'This is a defualt value', 'my_textdomain' ) ,
'priority' => 10,
'partial_refresh' => array(
'header_site_title' => array(
'selector' => '.site-title a',
'render_callback' =>
function () {
return get_bloginfo( 'name', 'display' );
}
,
),
'document_title' => array(
'selector' => 'head > title',
'render_callback' => 'wp_get_document_title',
),
),
));
Twenty seventeen footer copyright via child theme
- footer.php
get_template_part('template-parts/footer/site', 'info');
- template-parts/footer/site-info.php
<div class="site-info">
<?php echo twentyseventeen_child_footer_copyright(); ?>
</div><!-- .site-info -->
- functions.php
if (!function_exists('twentyseventeen_child_footer_copyright')) :
/**
* Enable to control copyright text in footer
*/
function twentyseventeen_child_footer_copyright() {
return wp_kses_post(get_theme_mod('twentyseventeen_child_footer_text', __('This is a defualt copyright text',
'my_textdomain')));
}
endif;
Footer copyright kontrole
// Add our footer section
Kirki::add_section( 'twentyseventeen_child_footer_id', array(
'title' => esc_html__( 'My Footer Section', 'twentyseventeen_child' ) ,
- functions.php 'description' => esc_html__( 'My Footer Section Description',
'twentyseventeen_child' ) ,
'panel' => 'twentyseventeen_child_panel_id', // Not typically needed.
- Funkcija: 'priority' => 10,
'capability' => 'edit_theme_options'
twentyseventeen_child_kirki ));
));
Rezultat
Preuzimanje vrednosti dodatin polja
- Theme Mods
$value = get_theme_mod( 'option_name', 'default_value' );
- Options
$value = get_option( 'option_name', 'default_value' );
- Serialized Options
function my_theme_get_option( $setting, $default ) {
return $value;
}
Bugs
- active_callback ne funkcioniše u kombinaciji sa:
● partial_refresh
● 'transport' => 'postMessage'
https://github.com/aristath/kirki/issues/1118
● partial_refresh
https://aristath.github.io/kirki/docs/controls/repeater.html
Primer iz prezentacije
GitHub - https://github.com/AleksandarPredic/twentyseventeen_child
Resursi
Customize API - https://developer.wordpress.org/themes/customize-api
Tutorial - https://wpserbia.rs/blog/kirki-toolkit/
Dokumentacija - https://aristath.github.io/kirki/