Skip to content

Commit 61d5fac

Browse files
committed
Add customizer settings
1 parent 5fbd2ee commit 61d5fac

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

plugin/assets/css/src/customize-controls.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
content: "\f460" !important;
5151
}
5252

53-
& .customize-section-description-container {
53+
& .customize-section-description-container .customize-section-title {
5454
display: none;
5555
}
5656
}

theme/functions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ function material_is_plugin_active() {
220220
require get_template_directory() . '/inc/customizer/header-footer.php';
221221
require get_template_directory() . '/inc/customizer/layout.php';
222222
require get_template_directory() . '/inc/customizer/menu.php';
223+
require get_template_directory() . '/inc/customizer/global-style.php';
223224

224225
/**
225226
* Custom menu walker
@@ -259,4 +260,5 @@ function material_is_plugin_active() {
259260
MaterialDesign\Theme\Customizer\Header_Footer\setup();
260261
MaterialDesign\Theme\Customizer\Layout\setup();
261262
MaterialDesign\Theme\Customizer\Menu\setup();
263+
MaterialDesign\Theme\Customizer\Global_Style\setup();
262264
MaterialDesign\Theme\Widgets\setup();
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* @package MaterialDesign
18+
*/
19+
20+
/**
21+
* Material design customizer global styles.
22+
*
23+
* @package MaterialDesign
24+
*/
25+
26+
namespace MaterialDesign\Theme\Customizer\Global_Style;
27+
28+
use MaterialDesign\Theme\Customizer;
29+
30+
/**
31+
* Attach hooks.
32+
*
33+
* @return void
34+
*/
35+
function setup() {
36+
if ( material_is_plugin_active() ) {
37+
add_action( 'customize_register', __NAMESPACE__ . '\register' );
38+
}
39+
}
40+
41+
/**
42+
* Add and initialize colors section
43+
*
44+
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
45+
*/
46+
function register( $wp_customize ) {
47+
// Add color palettes section.
48+
$args = [
49+
'priority' => 300,
50+
'title' => esc_html__( 'Global styles', 'material-design-google' ),
51+
'description' => esc_html__( 'Global style change will affect all the blocks used in your pages. This may override styles applied to blocks locally.', 'material-design-google' ),
52+
];
53+
54+
Customizer\add_section( $wp_customize, 'global-setting', $args );
55+
add_settings( $wp_customize );
56+
}
57+
58+
/**
59+
* Create settings based on controls
60+
*
61+
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
62+
*
63+
* @return void
64+
*/
65+
function add_settings( $wp_customize ) {
66+
$settings = [];
67+
$controls = [];
68+
69+
foreach ( get_controls() as $control ) {
70+
$settings[ $control['id'] ] = [
71+
'transport' => 'refresh',
72+
'sanitize_callback' => Customizer\get_sanitize_callback( $control['type'] ),
73+
];
74+
75+
$controls[ $control['id'] ] = array_merge(
76+
[
77+
'section' => Customizer\prepend_slug( 'global-setting' ),
78+
],
79+
$control
80+
);
81+
}
82+
83+
Customizer\add_settings( $wp_customize, $settings );
84+
Customizer\add_controls( $wp_customize, $controls );
85+
}
86+
87+
/**
88+
* Define color controls to use
89+
*
90+
* @return array
91+
*/
92+
function get_controls() {
93+
return [
94+
[
95+
'id' => 'card_style',
96+
'label' => esc_html__( 'Cards', 'material-design-google' ),
97+
'type' => 'radio',
98+
'default' => 'elevated',
99+
'choices' => [
100+
'elevated' => esc_html__( 'Elevated', 'material-design-google' ),
101+
'outlined' => esc_html__( 'Outlined', 'material-design-google' ),
102+
],
103+
],
104+
[
105+
'id' => 'text_style',
106+
'label' => esc_html__( 'Text field', 'material-design-google' ),
107+
'type' => 'radio',
108+
'default' => 'elevated',
109+
'choices' => [
110+
'elevated' => esc_html__( 'Elevated', 'material-design-google' ),
111+
'outlined' => esc_html__( 'Outlined', 'material-design-google' ),
112+
],
113+
],
114+
];
115+
}

0 commit comments

Comments
 (0)