Created
December 13, 2017 19:43
-
-
Save braginteractive/006e4da6ad7123ff1823e56e5ba18fde to your computer and use it in GitHub Desktop.
Add Bootswatch to StrapPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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