Merge pull request #1057 from IanDelMar/theme-settings

Add filter hooks
This commit is contained in:
UnderstrapFramework 2019-12-13 11:14:15 +00:00 committed by GitHub
commit 00cf4043d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 24 deletions

View File

@ -42,7 +42,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
'title' => __( 'Theme Layout Settings', 'understrap' ),
'capability' => 'edit_theme_options',
'description' => __( 'Container width and sidebar defaults', 'understrap' ),
'priority' => 160,
'priority' => apply_filters( 'understrap_theme_layout_options_priority', 160 ),
)
);
@ -61,8 +61,8 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
// Get the list of possible select options.
$choices = $setting->manager->get_control( $setting->id )->choices;
// If the input is a valid key, return it; otherwise, return the default.
return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
// If the input is a valid key, return it; otherwise, return the default.
return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
}
@ -90,7 +90,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
'container' => __( 'Fixed width container', 'understrap' ),
'container-fluid' => __( 'Full width container', 'understrap' ),
),
'priority' => '10',
'priority' => apply_filters( 'understrap_container_type_priority', 10 ),
)
)
);
@ -125,7 +125,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
'both' => __( 'Left & Right sidebars', 'understrap' ),
'none' => __( 'No sidebar', 'understrap' ),
),
'priority' => '20',
'priority' => apply_filters( 'understrap_sidebar_position_priority', 20 ),
)
)
);

View File

@ -9,26 +9,39 @@
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'understrap_setup_theme_default_settings' ) ) {
/**
* Store default theme settings in database.
*/
function understrap_setup_theme_default_settings() {
// check if settings are set, if not set defaults.
// Caution: DO NOT check existence using === always check with == .
// Latest blog posts style.
$understrap_posts_index_style = get_theme_mod( 'understrap_posts_index_style' );
if ( '' == $understrap_posts_index_style ) {
set_theme_mod( 'understrap_posts_index_style', 'default' );
}
// Sidebar position.
$understrap_sidebar_position = get_theme_mod( 'understrap_sidebar_position' );
if ( '' == $understrap_sidebar_position ) {
set_theme_mod( 'understrap_sidebar_position', 'right' );
}
// Container width.
$understrap_container_type = get_theme_mod( 'understrap_container_type' );
if ( '' == $understrap_container_type ) {
set_theme_mod( 'understrap_container_type', 'container' );
$defaults = understrap_get_theme_default_settings();
$settings = get_theme_mods();
foreach ( $defaults as $setting_id => $default_value ) {
// Check if setting is set, if not set it to its default value.
if ( ! isset( $settings[ $setting_id ] ) ) {
set_theme_mod( $setting_id, $default_value );
}
}
}
}
if ( ! function_exists( 'understrap_get_theme_default_settings' ) ) {
/**
* Retrieve default theme settings.
*
* @return array
*/
function understrap_get_theme_default_settings() {
$defaults = array(
'understrap_posts_index_style' => 'default', // Latest blog posts style.
'understrap_sidebar_position' => 'right', // Sidebar position.
'understrap_container_type' => 'container', // Container width.
);
/**
* Filters the default theme settings.
*
* @param array $defaults Array of default theme settings.
*/
return apply_filters( 'understrap_theme_default_settings', $defaults );
}
}