Complex classes like Kirki_Control_Typography often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Kirki_Control_Typography, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 20 | class Kirki_Control_Typography extends WP_Customize_Control { | 
            ||
| 21 | |||
| 22 | /**  | 
            ||
| 23 | * The control type.  | 
            ||
| 24 | *  | 
            ||
| 25 | * @access public  | 
            ||
| 26 | * @var string  | 
            ||
| 27 | */  | 
            ||
| 28 | public $type = 'kirki-typography';  | 
            ||
| 29 | |||
| 30 | /**  | 
            ||
| 31 | * Used to automatically generate all CSS output.  | 
            ||
| 32 | *  | 
            ||
| 33 | * @access public  | 
            ||
| 34 | * @var array  | 
            ||
| 35 | */  | 
            ||
| 36 | public $output = array();  | 
            ||
| 37 | |||
| 38 | /**  | 
            ||
| 39 | * Data type  | 
            ||
| 40 | *  | 
            ||
| 41 | * @access public  | 
            ||
| 42 | * @var string  | 
            ||
| 43 | */  | 
            ||
| 44 | public $option_type = 'theme_mod';  | 
            ||
| 45 | |||
| 46 | /**  | 
            ||
| 47 | * The kirki_config we're using for this control  | 
            ||
| 48 | *  | 
            ||
| 49 | * @access public  | 
            ||
| 50 | * @var string  | 
            ||
| 51 | */  | 
            ||
| 52 | public $kirki_config = 'global';  | 
            ||
| 53 | |||
| 54 | /**  | 
            ||
| 55 | * Constructor.  | 
            ||
| 56 | *  | 
            ||
| 57 | * Supplied `$args` override class property defaults.  | 
            ||
| 58 | *  | 
            ||
| 59 | * If `$args['settings']` is not defined, use the $id as the setting ID.  | 
            ||
| 60 | *  | 
            ||
| 61 | * @since 3.0.0  | 
            ||
| 62 | *  | 
            ||
| 63 | * @param WP_Customize_Manager $manager Customizer bootstrap instance.  | 
            ||
| 64 | * @param string $id Control ID.  | 
            ||
| 65 | 	 * @param array                $args    { | 
            ||
| 66 | * Optional. Arguments to override class property defaults.  | 
            ||
| 67 | *  | 
            ||
| 68 | * @type int $instance_number Order in which this instance was created in relation  | 
            ||
| 69 | * to other instances.  | 
            ||
| 70 | * @type WP_Customize_Manager $manager Customizer bootstrap instance.  | 
            ||
| 71 | * @type string $id Control ID.  | 
            ||
| 72 | * @type array $settings All settings tied to the control. If undefined, `$id` will  | 
            ||
| 73 | * be used.  | 
            ||
| 74 | * @type string $setting The primary setting for the control (if there is one).  | 
            ||
| 75 | * Default 'default'.  | 
            ||
| 76 | * @type int $priority Order priority to load the control. Default 10.  | 
            ||
| 77 | * @type string $section Section the control belongs to. Default empty.  | 
            ||
| 78 | * @type string $label Label for the control. Default empty.  | 
            ||
| 79 | * @type string $description Description for the control. Default empty.  | 
            ||
| 80 | * @type array $choices List of choices for 'radio' or 'select' type controls, where  | 
            ||
| 81 | * values are the keys, and labels are the values.  | 
            ||
| 82 | * Default empty array.  | 
            ||
| 83 | * @type array $input_attrs List of custom input attributes for control output, where  | 
            ||
| 84 | * attribute names are the keys and values are the values. Not  | 
            ||
| 85 | * used for 'checkbox', 'radio', 'select', 'textarea', or  | 
            ||
| 86 | * 'dropdown-pages' control types. Default empty array.  | 
            ||
| 87 | * @type array $json Deprecated. Use WP_Customize_Control::json() instead.  | 
            ||
| 88 | * @type string $type Control type. Core controls include 'text', 'checkbox',  | 
            ||
| 89 | * 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional  | 
            ||
| 90 | * input types such as 'email', 'url', 'number', 'hidden', and  | 
            ||
| 91 | * 'date' are supported implicitly. Default 'text'.  | 
            ||
| 92 | * }  | 
            ||
| 93 | */  | 
            ||
| 94 | 	public function __construct( $manager, $id, $args = array() ) { | 
            ||
| 100 | |||
| 101 | /**  | 
            ||
| 102 | * Enqueue control related scripts/styles.  | 
            ||
| 103 | *  | 
            ||
| 104 | * @access public  | 
            ||
| 105 | */  | 
            ||
| 106 | 	public function enqueue_scripts() { | 
            ||
| 125 | |||
| 126 | /**  | 
            ||
| 127 | * Refresh the parameters passed to the JavaScript via JSON.  | 
            ||
| 128 | *  | 
            ||
| 129 | * @see WP_Customize_Control::to_json()  | 
            ||
| 130 | */  | 
            ||
| 131 | 	public function to_json() { | 
            ||
| 132 | parent::to_json();  | 
            ||
| 133 | |||
| 134 | $this->json['default'] = $this->setting->default;  | 
            ||
| 135 | 		if ( isset( $this->default ) ) { | 
            ||
| 136 | $this->json['default'] = $this->default;  | 
            ||
| 137 | }  | 
            ||
| 138 | $this->json['output'] = $this->output;  | 
            ||
| 139 | $this->json['value'] = Kirki_Field_Typography::sanitize( $this->value() );  | 
            ||
| 140 | $this->json['choices'] = $this->choices;  | 
            ||
| 141 | $this->json['link'] = $this->get_link();  | 
            ||
| 142 | $this->json['id'] = $this->id;  | 
            ||
| 143 | |||
| 144 | $this->json['inputAttrs'] = '';  | 
            ||
| 145 | 		foreach ( $this->input_attrs as $attr => $value ) { | 
            ||
| 146 | $this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';  | 
            ||
| 147 | }  | 
            ||
| 148 | |||
| 149 | 		foreach ( array_keys( $this->json['value'] ) as $key ) { | 
            ||
| 150 | 			if ( ! in_array( $key, array( 'variant', 'font-weight', 'font-style' ) ) && ! isset( $this->json['default'][ $key ] ) ) { | 
            ||
| 151 | unset( $this->json['value'][ $key ] );  | 
            ||
| 152 | }  | 
            ||
| 153 | }  | 
            ||
| 154 | |||
| 155 | // Fix for https://github.com/aristath/kirki/issues/1405.  | 
            ||
| 156 | 		foreach ( array_keys( $this->json['value'] ) as $key ) { | 
            ||
| 157 | 			if ( isset( $this->json['default'][ $key ] ) && false === $this->json['default'][ $key ] ) { | 
            ||
| 158 | unset( $this->json['value'][ $key ] );  | 
            ||
| 159 | }  | 
            ||
| 160 | }  | 
            ||
| 161 | $this->json['show_variants'] = ( true === Kirki_Fonts_Google::$force_load_all_variants ) ? false : true;  | 
            ||
| 162 | $this->json['show_subsets'] = ( true === Kirki_Fonts_Google::$force_load_all_subsets ) ? false : true;  | 
            ||
| 163 | $this->json['languages'] = Kirki_Fonts::get_google_font_subsets();  | 
            ||
| 164 | }  | 
            ||
| 165 | |||
| 166 | /**  | 
            ||
| 167 | * An Underscore (JS) template for this control's content (but not its container).  | 
            ||
| 168 | *  | 
            ||
| 169 | * Class variables for this control class are available in the `data` JS object;  | 
            ||
| 170 | 	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}. | 
            ||
| 171 | *  | 
            ||
| 172 | * @see WP_Customize_Control::print_template()  | 
            ||
| 173 | *  | 
            ||
| 174 | * @access protected  | 
            ||
| 175 | */  | 
            ||
| 176 | 	protected function content_template() { | 
            ||
| 177 | ?>  | 
            ||
| 178 | <label class="customizer-text">  | 
            ||
| 179 | 			<# if ( data.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #> | 
            ||
| 180 | 			<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #> | 
            ||
| 181 | </label>  | 
            ||
| 182 | |||
| 183 | <div class="wrapper">  | 
            ||
| 184 | |||
| 185 | 			<# if ( data.default['font-family'] ) { #> | 
            ||
| 186 | 				<# if ( '' == data.value['font-family'] ) { data.value['font-family'] = data.default['font-family']; } #> | 
            ||
| 187 | 				<# if ( data.choices['fonts'] ) { data.fonts = data.choices['fonts']; } #> | 
            ||
| 188 | <div class="font-family">  | 
            ||
| 189 | <h5><?php esc_attr_e( 'Font Family', 'kirki' ); ?></h5>  | 
            ||
| 190 | 					<select {{{ data.inputAttrs }}} id="kirki-typography-font-family-{{{ data.id }}}" placeholder="<?php esc_attr_e( 'Select Font Family', 'kirki' ); ?>"></select> | 
            ||
| 191 | </div>  | 
            ||
| 192 | 				<# if ( ! _.isUndefined( data.choices['font-backup'] ) && true === data.choices['font-backup'] ) { #> | 
            ||
| 193 | <div class="font-backup hide-on-standard-fonts kirki-font-backup-wrapper">  | 
            ||
| 194 | <h5><?php esc_attr_e( 'Backup Font', 'kirki' ); ?></h5>  | 
            ||
| 195 | 						<select {{{ data.inputAttrs }}} id="kirki-typography-font-backup-{{{ data.id }}}" placeholder="<?php esc_attr_e( 'Select Font Family', 'kirki' ); ?>"></select> | 
            ||
| 196 | </div>  | 
            ||
| 197 | <# } #>  | 
            ||
| 198 | 				<# if ( true === data.show_variants || false !== data.default.variant ) { #> | 
            ||
| 199 | <div class="variant kirki-variant-wrapper">  | 
            ||
| 200 | <h5><?php esc_attr_e( 'Variant', 'kirki' ); ?></h5>  | 
            ||
| 201 | 						<select {{{ data.inputAttrs }}} class="variant" id="kirki-typography-variant-{{{ data.id }}}"></select> | 
            ||
| 202 | </div>  | 
            ||
| 203 | <# } #>  | 
            ||
| 204 | 				<# if ( true === data.show_subsets ) { #> | 
            ||
| 205 | <div class="subsets hide-on-standard-fonts kirki-subsets-wrapper">  | 
            ||
| 206 | <h5><?php esc_attr_e( 'Subset(s)', 'kirki' ); ?></h5>  | 
            ||
| 207 | 						<select {{{ data.inputAttrs }}} class="subset" id="kirki-typography-subsets-{{{ data.id }}}"<# if ( _.isUndefined( data.choices['disable-multiple-variants'] ) || false === data.choices['disable-multiple-variants'] ) { #> multiple<# } #>> | 
            ||
| 208 | 							<# _.each( data.value.subsets, function( subset ) { #> | 
            ||
| 209 | 								<option value="{{ subset }}" selected="selected">{{ data.languages[ subset ] }}</option> | 
            ||
| 210 | <# } ); #>  | 
            ||
| 211 | </select>  | 
            ||
| 212 | </div>  | 
            ||
| 213 | <# } #>  | 
            ||
| 214 | <# } #>  | 
            ||
| 215 | |||
| 216 | 			<# if ( data.default['font-size'] ) { #> | 
            ||
| 217 | <div class="font-size">  | 
            ||
| 218 | <h5><?php esc_attr_e( 'Font Size', 'kirki' ); ?></h5>  | 
            ||
| 219 | 					<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['font-size'] }}"/> | 
            ||
| 220 | </div>  | 
            ||
| 221 | <# } #>  | 
            ||
| 222 | |||
| 223 | 			<# if ( data.default['line-height'] ) { #> | 
            ||
| 224 | <div class="line-height">  | 
            ||
| 225 | <h5><?php esc_attr_e( 'Line Height', 'kirki' ); ?></h5>  | 
            ||
| 226 | 					<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['line-height'] }}"/> | 
            ||
| 227 | </div>  | 
            ||
| 228 | <# } #>  | 
            ||
| 229 | |||
| 230 | 			<# if ( data.default['letter-spacing'] ) { #> | 
            ||
| 231 | <div class="letter-spacing">  | 
            ||
| 232 | <h5><?php esc_attr_e( 'Letter Spacing', 'kirki' ); ?></h5>  | 
            ||
| 233 | 					<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['letter-spacing'] }}"/> | 
            ||
| 234 | </div>  | 
            ||
| 235 | <# } #>  | 
            ||
| 236 | |||
| 237 | 			<# if ( data.default['word-spacing'] ) { #> | 
            ||
| 238 | <div class="word-spacing">  | 
            ||
| 239 | <h5><?php esc_attr_e( 'Word Spacing', 'kirki' ); ?></h5>  | 
            ||
| 240 | 					<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['word-spacing'] }}"/> | 
            ||
| 241 | </div>  | 
            ||
| 242 | <# } #>  | 
            ||
| 243 | |||
| 244 | 			<# if ( data.default['text-align'] ) { #> | 
            ||
| 245 | <div class="text-align">  | 
            ||
| 246 | <h5><?php esc_attr_e( 'Text Align', 'kirki' ); ?></h5>  | 
            ||
| 247 | 					<input {{{ data.inputAttrs }}} type="radio" value="inherit" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-inherit" <# if ( data.value['text-align'] === 'inherit' ) { #> checked="checked"<# } #>> | 
            ||
| 248 | 						<label for="{{ data.id }}-text-align-inherit"> | 
            ||
| 249 | <span class="dashicons dashicons-editor-removeformatting"></span>  | 
            ||
| 250 | <span class="screen-reader-text"><?php esc_attr_e( 'Inherit', 'kirki' ); ?></span>  | 
            ||
| 251 | </label>  | 
            ||
| 252 | </input>  | 
            ||
| 253 | 					<input {{{ data.inputAttrs }}} type="radio" value="left" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-left" <# if ( data.value['text-align'] === 'left' ) { #> checked="checked"<# } #>> | 
            ||
| 254 | 						<label for="{{ data.id }}-text-align-left"> | 
            ||
| 255 | <span class="dashicons dashicons-editor-alignleft"></span>  | 
            ||
| 256 | <span class="screen-reader-text"><?php esc_attr_e( 'Left', 'kirki' ); ?></span>  | 
            ||
| 257 | </label>  | 
            ||
| 258 | </input>  | 
            ||
| 259 | 					<input {{{ data.inputAttrs }}} type="radio" value="center" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-center" <# if ( data.value['text-align'] === 'center' ) { #> checked="checked"<# } #>> | 
            ||
| 260 | 						<label for="{{ data.id }}-text-align-center"> | 
            ||
| 261 | <span class="dashicons dashicons-editor-aligncenter"></span>  | 
            ||
| 262 | <span class="screen-reader-text"><?php esc_attr_e( 'Center', 'kirki' ); ?></span>  | 
            ||
| 263 | </label>  | 
            ||
| 264 | </input>  | 
            ||
| 265 | 					<input {{{ data.inputAttrs }}} type="radio" value="right" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-right" <# if ( data.value['text-align'] === 'right' ) { #> checked="checked"<# } #>> | 
            ||
| 266 | 						<label for="{{ data.id }}-text-align-right"> | 
            ||
| 267 | <span class="dashicons dashicons-editor-alignright"></span>  | 
            ||
| 268 | <span class="screen-reader-text"><?php esc_attr_e( 'Right', 'kirki' ); ?></span>  | 
            ||
| 269 | </label>  | 
            ||
| 270 | </input>  | 
            ||
| 271 | 					<input {{{ data.inputAttrs }}} type="radio" value="justify" name="_customize-typography-text-align-radio-{{ data.id }}" id="{{ data.id }}-text-align-justify" <# if ( data.value['text-align'] === 'justify' ) { #> checked="checked"<# } #>> | 
            ||
| 272 | 						<label for="{{ data.id }}-text-align-justify"> | 
            ||
| 273 | <span class="dashicons dashicons-editor-justify"></span>  | 
            ||
| 274 | <span class="screen-reader-text"><?php esc_attr_e( 'Justify', 'kirki' ); ?></span>  | 
            ||
| 275 | </label>  | 
            ||
| 276 | </input>  | 
            ||
| 277 | </div>  | 
            ||
| 278 | <# } #>  | 
            ||
| 279 | |||
| 280 | 			<# if ( data.default['text-transform'] ) { #> | 
            ||
| 281 | <div class="text-transform">  | 
            ||
| 282 | <h5><?php esc_attr_e( 'Text Transform', 'kirki' ); ?></h5>  | 
            ||
| 283 | 					<select {{{ data.inputAttrs }}} id="kirki-typography-text-transform-{{{ data.id }}}"> | 
            ||
| 284 | 						<option value="none"<# if ( 'none' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_attr_e( 'None', 'kirki' ); ?></option> | 
            ||
| 285 | 						<option value="capitalize"<# if ( 'capitalize' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_attr_e( 'Capitalize', 'kirki' ); ?></option> | 
            ||
| 286 | 						<option value="uppercase"<# if ( 'uppercase' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_attr_e( 'Uppercase', 'kirki' ); ?></option> | 
            ||
| 287 | 						<option value="lowercase"<# if ( 'lowercase' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_attr_e( 'Lowercase', 'kirki' ); ?></option> | 
            ||
| 288 | 						<option value="initial"<# if ( 'initial' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_attr_e( 'Initial', 'kirki' ); ?></option> | 
            ||
| 289 | 						<option value="inherit"<# if ( 'inherit' === data.value['text-transform'] ) { #>selected<# } #>><?php esc_attr_e( 'Inherit', 'kirki' ); ?></option> | 
            ||
| 290 | </select>  | 
            ||
| 291 | </div>  | 
            ||
| 292 | <# } #>  | 
            ||
| 293 | |||
| 294 | 			<# if ( false !== data.default['color'] && data.default['color'] ) { #> | 
            ||
| 295 | <div class="color">  | 
            ||
| 296 | <h5><?php esc_attr_e( 'Color', 'kirki' ); ?></h5>  | 
            ||
| 297 | 					<input {{{ data.inputAttrs }}} type="text" data-palette="{{ data.palette }}" data-default-color="{{ data.default['color'] }}" value="{{ data.value['color'] }}" class="kirki-color-control" {{{ data.link }}} /> | 
            ||
| 298 | </div>  | 
            ||
| 299 | <# } #>  | 
            ||
| 300 | |||
| 301 | 			<# if ( data.default['margin-top'] ) { #> | 
            ||
| 302 | <div class="margin-top">  | 
            ||
| 303 | <h5><?php esc_attr_e( 'Margin Top', 'kirki' ); ?></h5>  | 
            ||
| 304 | 					<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['margin-top'] }}"/> | 
            ||
| 305 | </div>  | 
            ||
| 306 | <# } #>  | 
            ||
| 307 | |||
| 308 | 			<# if ( data.default['margin-bottom'] ) { #> | 
            ||
| 309 | <div class="margin-bottom">  | 
            ||
| 310 | <h5><?php esc_attr_e( 'Margin Bottom', 'kirki' ); ?></h5>  | 
            ||
| 311 | 					<input {{{ data.inputAttrs }}} type="text" value="{{ data.value['margin-bottom'] }}"/> | 
            ||
| 312 | </div>  | 
            ||
| 313 | <# } #>  | 
            ||
| 314 | </div>  | 
            ||
| 315 | <#  | 
            ||
| 316 | 		if ( ! _.isUndefined( data.value['font-family'] ) ) { | 
            ||
| 317 | data.value['font-family'] = data.value['font-family'].replace( /"/g, ''' );  | 
            ||
| 318 | }  | 
            ||
| 319 | valueJSON = JSON.stringify( data.value ).replace( /'/g, ''' );  | 
            ||
| 320 | #>  | 
            ||
| 321 | 		<input class="typography-hidden-value" type="hidden" value='{{{ valueJSON }}}' {{{ data.link }}}> | 
            ||
| 322 | <?php  | 
            ||
| 323 | }  | 
            ||
| 324 | |||
| 325 | /**  | 
            ||
| 326 | * Formats variants.  | 
            ||
| 327 | *  | 
            ||
| 328 | * @access protected  | 
            ||
| 329 | * @since 3.0.0  | 
            ||
| 330 | * @param array $variants The variants.  | 
            ||
| 331 | * @return array  | 
            ||
| 332 | */  | 
            ||
| 333 | 	protected function format_variants_array( $variants ) { | 
            ||
| 334 | |||
| 335 | $all_variants = Kirki_Fonts::get_all_variants();  | 
            ||
| 336 | $final_variants = array();  | 
            ||
| 337 | 		foreach ( $variants as $variant ) { | 
            ||
| 338 | 			if ( is_string( $variant ) ) { | 
            ||
| 339 | $final_variants[] = array(  | 
            ||
| 340 | 'id' => $variant,  | 
            ||
| 341 | 'label' => isset( $all_variants[ $variant ] ) ? $all_variants[ $variant ] : $variant,  | 
            ||
| 342 | );  | 
            ||
| 343 | 			} elseif ( is_array( $variant ) && isset( $variant['id'] ) && isset( $variant['label'] ) ) { | 
            ||
| 344 | $final_variants[] = $variant;  | 
            ||
| 345 | }  | 
            ||
| 346 | }  | 
            ||
| 347 | return $final_variants;  | 
            ||
| 348 | }  | 
            ||
| 349 | |||
| 350 | /**  | 
            ||
| 351 | * Gets standard fonts properly formatted for our control.  | 
            ||
| 352 | *  | 
            ||
| 353 | * @access protected  | 
            ||
| 354 | * @since 3.0.0  | 
            ||
| 355 | * @return array  | 
            ||
| 356 | */  | 
            ||
| 357 | 	protected function get_standard_fonts() { | 
            ||
| 358 | // Add fonts to our JS objects.  | 
            ||
| 359 | $standard_fonts = Kirki_Fonts::get_standard_fonts();  | 
            ||
| 360 | |||
| 361 | $std_user_keys = array();  | 
            ||
| 362 | 		if ( isset( $this->choices['fonts'] ) && isset( $this->choices['fonts']['standard'] ) ) { | 
            ||
| 363 | $std_user_keys = $this->choices['fonts']['standard'];  | 
            ||
| 364 | }  | 
            ||
| 365 | |||
| 366 | $standard_fonts_final = array();  | 
            ||
| 367 | $default_variants = $this->format_variants_array( array(  | 
            ||
| 368 | 'regular',  | 
            ||
| 369 | 'italic',  | 
            ||
| 370 | '700',  | 
            ||
| 371 | '700italic',  | 
            ||
| 372 | ) );  | 
            ||
| 373 | 		foreach ( $standard_fonts as $key => $font ) { | 
            ||
| 374 | 			if ( ( ! empty( $std_user_keys ) && ! in_array( $key, $std_user_keys, true ) ) || ! isset( $font['stack'] ) || ! isset( $font['label'] ) ) { | 
            ||
| 375 | continue;  | 
            ||
| 376 | }  | 
            ||
| 377 | $standard_fonts_final[] = array(  | 
            ||
| 378 | 'family' => $font['stack'],  | 
            ||
| 379 | 'label' => $font['label'],  | 
            ||
| 380 | 'subsets' => array(),  | 
            ||
| 381 | 'is_standard' => true,  | 
            ||
| 382 | 'variants' => ( isset( $font['variants'] ) ) ? $this->format_variants_array( $font['variants'] ) : $default_variants,  | 
            ||
| 383 | );  | 
            ||
| 384 | }  | 
            ||
| 385 | return $standard_fonts_final;  | 
            ||
| 386 | }  | 
            ||
| 387 | |||
| 388 | /**  | 
            ||
| 389 | * Gets google fonts properly formatted for our control.  | 
            ||
| 390 | *  | 
            ||
| 391 | * @access protected  | 
            ||
| 392 | * @since 3.0.0  | 
            ||
| 393 | * @return array  | 
            ||
| 394 | */  | 
            ||
| 395 | 	protected function get_google_fonts() { | 
            ||
| 396 | // Add fonts to our JS objects.  | 
            ||
| 397 | $google_fonts = Kirki_Fonts::get_google_fonts();  | 
            ||
| 398 | $all_variants = Kirki_Fonts::get_all_variants();  | 
            ||
| 399 | $all_subsets = Kirki_Fonts::get_google_font_subsets();  | 
            ||
| 400 | |||
| 401 | $gf_user_keys = array();  | 
            ||
| 402 | 		if ( isset( $this->choices['fonts'] ) && isset( $this->choices['fonts']['google'] ) ) { | 
            ||
| 403 | $gf_user_keys = $this->choices['fonts']['google'];  | 
            ||
| 404 | }  | 
            ||
| 405 | |||
| 406 | $google_fonts_final = array();  | 
            ||
| 407 | 		foreach ( $google_fonts as $family => $args ) { | 
            ||
| 408 | 			if ( ! empty( $gf_user_keys ) && ! in_array( $family, $gf_user_keys, true ) ) { | 
            ||
| 409 | continue;  | 
            ||
| 410 | }  | 
            ||
| 411 | |||
| 412 | $label = ( isset( $args['label'] ) ) ? $args['label'] : $family;  | 
            ||
| 413 | $variants = ( isset( $args['variants'] ) ) ? $args['variants'] : array( 'regular', '700' );  | 
            ||
| 414 | $subsets = ( isset( $args['subsets'] ) ) ? $args['subsets'] : array();  | 
            ||
| 415 | |||
| 416 | $available_variants = array();  | 
            ||
| 417 | 			if ( is_array( $variants ) ) { | 
            ||
| 418 | 				foreach ( $variants as $variant ) { | 
            ||
| 419 | 					if ( array_key_exists( $variant, $all_variants ) ) { | 
            ||
| 420 | $available_variants[] = array(  | 
            ||
| 421 | 'id' => $variant,  | 
            ||
| 422 | 'label' => $all_variants[ $variant ],  | 
            ||
| 423 | );  | 
            ||
| 424 | }  | 
            ||
| 425 | }  | 
            ||
| 426 | }  | 
            ||
| 427 | |||
| 428 | $available_subsets = array();  | 
            ||
| 429 | 			if ( is_array( $subsets ) ) { | 
            ||
| 430 | 				foreach ( $subsets as $subset ) { | 
            ||
| 431 | 					if ( array_key_exists( $subset, $all_subsets ) ) { | 
            ||
| 432 | $available_subsets[] = array(  | 
            ||
| 433 | 'id' => $subset,  | 
            ||
| 434 | 'label' => $all_subsets[ $subset ],  | 
            ||
| 435 | );  | 
            ||
| 436 | }  | 
            ||
| 437 | }  | 
            ||
| 438 | }  | 
            ||
| 439 | |||
| 440 | $google_fonts_final[] = array(  | 
            ||
| 441 | 'family' => $family,  | 
            ||
| 442 | 'label' => $label,  | 
            ||
| 443 | 'variants' => $available_variants,  | 
            ||
| 444 | 'subsets' => $available_subsets,  | 
            ||
| 445 | );  | 
            ||
| 446 | } // End foreach().  | 
            ||
| 447 | return $google_fonts_final;  | 
            ||
| 448 | }  | 
            ||
| 449 | |||
| 450 | /**  | 
            ||
| 451 | * Render the control's content.  | 
            ||
| 452 | *  | 
            ||
| 453 | * @see WP_Customize_Control::render_content()  | 
            ||
| 454 | */  | 
            ||
| 455 | 	protected function render_content() {} | 
            ||
| 456 | }  | 
            ||
| 457 |