Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Bootswatch to StrapPress
if ( class_exists('Kirki') ) {
Kirki::add_config( 'strappress_theme', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod',
) );
/* Add Bootswatch to Colors Section */
Kirki::add_field( 'strappress_theme', array(
'type' => 'radio-image',
'settings' => 'bootswatch_css',
'label' => __( 'Bootswatch Themes', 'strappress' ),
'section' => 'colors',
'default' => 'style',
'priority' => 1,
'multiple' => 1,
'choices' => strappress_get_bootswatch()
) );
}
/* Bootswatch API - Return different themes */
function strappress_get_bootswatch() {
$request = wp_remote_get( 'https://bootswatch.com/api/4.json' );
if( is_wp_error( $request ) ) {
return false; // Bail early
}
$body = wp_remote_retrieve_body( $request );
$data = json_decode( $body );
if( ! empty( $data ) ) {
$items = array();
foreach( $data->themes as $theme ) {
$theme_name = strtolower($theme->name);
$items[$theme_name] = $theme->thumbnail;
}
return $items;
}
}
$bootswatch = get_theme_mod( 'bootswatch_css', 'style' );
if ($bootswatch != '') {
wp_enqueue_style( 'strappress-style', '//maxcdn.bootstrapcdn.com/bootswatch/4.0.0-beta.2/'. $bootswatch .'/bootstrap.min.css', array(), '1.0.0' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment