Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Last active January 16, 2020 20:01
Show Gist options
  • Save everaldomatias/eca3b38bb629cdc0a3c044703b9d88eb to your computer and use it in GitHub Desktop.
Save everaldomatias/eca3b38bb629cdc0a3c044703b9d88eb to your computer and use it in GitHub Desktop.
Example for the Kirki WordPress Plugin configuration
<?php
/**
*
* Config, Panels, Sections and Fields by Kirki
*
* @link https://kirki.org/
* @author Everaldo Matias <https://everaldo.dev>
* @since 16/01/2020
* @version 1.0
*
*/
if ( class_exists( 'Kirki' ) ) {
/**
*
* Config for this project
*
* @link https://kirki.org/docs/config
*
*/
Kirki::add_config( 'your_theme_config', [
'capability' => 'update_core',
'option_type' => 'theme_mod'
] );
/**
*
* Example of the panel 1 for this project
*
* @link https://kirki.org/docs/adding-panels-and-sections
*
*/
Kirki::add_panel( 'panel_1', [
'title' => esc_attr__( 'Painel 1', 'textdomain' ),
'description' => esc_attr__( 'Modelo Painel 1.', 'textdomain' ),
'priority' => 10,
] );
/**
*
* Example of the section to panel 1 for this project
*
* @link https://kirki.org/docs/adding-panels-and-sections
*
*/
Kirki::add_section( 'section_1', [
'title' => __( 'Section 1', 'textdomain' ),
'panel' => 'panel_1',
'priority' => 10,
] );
/**
*
* Example of the fields to section 1 for this project
*
* @link https://kirki.org/docs/adding-panels-and-sections
*
*/
/**
*
* Fields 1 to Section 1
* ==============================================================================
*
* For all controls/fields see https://kirki.org/docs/controls/
*
*/
/**
* Text Field
* @link https://kirki.org/docs/controls/text
*/
Kirki::add_field( 'your_theme_config', [
'type' => 'text',
'settings' => 'text_field_id',
'label' => esc_html__( 'Text Control', 'textdomain' ),
'section' => 'section_1',
'default' => esc_html__( 'This is a default value', 'textdomain' ),
'priority' => 10,
] );
/**
*
* Image field
* @link https://kirki.org/docs/controls/image
*
*/
Kirki::add_field( 'your_theme_config', [
'type' => 'image',
'settings' => 'image_field_url',
'label' => esc_html__( 'Image Control (URL)', 'textdomain' ),
'description' => esc_html__( 'Description Here.', 'textdomain' ),
'section' => 'section_1',
'default' => '',
] );
/**
*
* Switch field
* @link https://kirki.org/docs/controls/switch
*
*/
Kirki::add_field( 'your_theme_config', [
'type' => 'switch',
'settings' => 'switch_field_id',
'label' => esc_html__( 'This is the label', 'textdomain' ),
'section' => 'section_1',
'default' => '1',
'priority' => 10,
'choices' => [
'on' => esc_html__( 'Enable', 'textdomain' ),
'off' => esc_html__( 'Disable', 'textdomain' ),
],
] );
} else {
add_action( 'admin_notices', 'kirki_not_installed_notice', 99 );
}
/**
*
* Function to print on admin panel a warning when plugin is not installed/active
*
* @author Everaldo Matias <https://everaldo.dev>
* @since 16/01/2020
* @version 1.0
*
*/
function kirki_not_installed_notice() {
?>
<div class="notice error kirki-not-installed-notice" >
<p><?php _e( 'The <strong>Kirki plugin</strong> is not installed! It is necessary for your site to have all the features provided. <a href="' . esc_url( admin_url() ) . 'plugin-install.php?s=kirki&tab=search&type=term">Click here to install</a>!', 'textdomain' ); ?></p>
</div><!-- /.kirki-not-installed-notice -->
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment