The Kirki_Helper class
A collection of helper methods
A collection of helper methods
Kirki includes some helper methods that allow you to make a few tasks easier.
To get the attachment ID of an image from its URL, you can use the following:
$image_id = Kirki_Helper::get_image_id( $url );
$image = Kirki_Helper::get_image_from_url( $url );
The above will return an array formatted like this:
array(
'url' // string, the URL of the image
'width' // integer, the width of the image
'height' // integer, the height of the image
'thumbnail' // string, URL of the image's thumbnail.
);
$posts = Kirki_Helper::get_posts( $args );
as $args
you will have to use an array formatted as documented in WordPress’s get_posts
function.
The difference between WordPress’s get_posts
function and the Kirki_Helper::get_posts
method is that the method included in Kirki will return an array of posts formatted in a way that can be easily used in a control in the choices
argument.
Example:
Kirki::add_field( 'my_config', array(
'type' => 'select',
'settings' => 'my_setting',
'label' => esc_html__( 'This is the label', 'kirki' ),
'section' => 'my_section',
'default' => '',
'priority' => 10,
'multiple' => 1,
'choices' => Kirki_Helper::get_posts(
array(
'posts_per_page' => 10,
'post_type' => 'page'
) ,
),
) );
$taxonomies = Kirki_Helper::get_taxonomies();
This will return an array of all the available taxonomies so you can use it directly in a control’s choices
argument.
Example:
Kirki::add_field( 'my_config', array(
'type' => 'select',
'settings' => 'my_setting',
'label' => esc_html__( 'This is the label', 'kirki' ),
'section' => 'my_section',
'default' => 'option-1',
'priority' => 10,
'multiple' => 1,
'choices' => Kirki_Helper::get_taxonomies(),
) );
$post_types = Kirki_Helper::get_post_types();
This will return an array of all the publicly-available post-types so you can use it directly in a control’s choices
argument.
Example:
Kirki::add_field( 'my_config', array(
'type' => 'select',
'settings' => 'my_setting',
'label' => esc_html__( 'This is the label', 'kirki' ),
'section' => 'my_section',
'default' => 'option-1',
'priority' => 10,
'multiple' => 1,
'choices' => Kirki_Helper::get_post_types(),
) );
$terms = Kirki_Helper::get_terms( $taxonomies );
as $taxonomies
you will have to use an array formatted as documented in WordPress’s get_terms
function.
The difference between WordPress’s get_terms
function and the Kirki_Helper::get_terms
method is that the method included in Kirki will return an array of posts formatted in a way that can be easily used in a control in the choices
argument.
Example:
Kirki::add_field( 'my_config', array(
'type' => 'select',
'settings' => 'my_setting',
'label' => esc_html__( 'This is the label', 'kirki' ),
'section' => 'my_section',
'default' => 'option-1',
'priority' => 10,
'multiple' => 1,
'choices' => Kirki_Helper::get_terms( array('taxonomy' => 'category') )),
) );
For full list of choices https://developer.wordpress.org/reference/functions/get_terms/#source
Please note that to make the custom post types and taxonomies work you must add the fields and sections in ‘init’ action.
Example:
add_action( 'init', function() {
Kirki::add_field( 'my_settings', array(
'type' => 'select',
'settings' => 'my_setting',
'label' => __( 'This is the label', 'kirki' ),
'section' => 'title_tagline',
'default' => '',
'priority' => 10,
'choices' => Kirki_Helper::get_terms( 'product_cat' ),
) );
} );
Can't find what you're looking for? Check the github issues or edit this page to add what's missing.