Merge pull request #1057 from IanDelMar/theme-settings
Add filter hooks
This commit is contained in:
commit
00cf4043d3
|
@ -42,7 +42,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
|
||||||
'title' => __( 'Theme Layout Settings', 'understrap' ),
|
'title' => __( 'Theme Layout Settings', 'understrap' ),
|
||||||
'capability' => 'edit_theme_options',
|
'capability' => 'edit_theme_options',
|
||||||
'description' => __( 'Container width and sidebar defaults', 'understrap' ),
|
'description' => __( 'Container width and sidebar defaults', 'understrap' ),
|
||||||
'priority' => 160,
|
'priority' => apply_filters( 'understrap_theme_layout_options_priority', 160 ),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
|
||||||
'container' => __( 'Fixed width container', 'understrap' ),
|
'container' => __( 'Fixed width container', 'understrap' ),
|
||||||
'container-fluid' => __( 'Full 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' ),
|
'both' => __( 'Left & Right sidebars', 'understrap' ),
|
||||||
'none' => __( 'No sidebar', 'understrap' ),
|
'none' => __( 'No sidebar', 'understrap' ),
|
||||||
),
|
),
|
||||||
'priority' => '20',
|
'priority' => apply_filters( 'understrap_sidebar_position_priority', 20 ),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -9,26 +9,39 @@
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
if ( ! function_exists( 'understrap_setup_theme_default_settings' ) ) {
|
if ( ! function_exists( 'understrap_setup_theme_default_settings' ) ) {
|
||||||
|
/**
|
||||||
|
* Store default theme settings in database.
|
||||||
|
*/
|
||||||
function understrap_setup_theme_default_settings() {
|
function understrap_setup_theme_default_settings() {
|
||||||
|
$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.
|
||||||
|
);
|
||||||
|
|
||||||
// check if settings are set, if not set defaults.
|
/**
|
||||||
// Caution: DO NOT check existence using === always check with == .
|
* Filters the default theme settings.
|
||||||
// Latest blog posts style.
|
*
|
||||||
$understrap_posts_index_style = get_theme_mod( 'understrap_posts_index_style' );
|
* @param array $defaults Array of default theme settings.
|
||||||
if ( '' == $understrap_posts_index_style ) {
|
*/
|
||||||
set_theme_mod( 'understrap_posts_index_style', 'default' );
|
return apply_filters( 'understrap_theme_default_settings', $defaults );
|
||||||
}
|
|
||||||
|
|
||||||
// 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' );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue