Passed
Pull Request — master (#1889)
by Aristeides
04:14
created

Kirki_Modules_Webfonts_Local::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
c 1
b 0
f 1
nc 1
nop 4
dl 0
loc 7
rs 9.4285
1
<?php
2
/**
3
 * Handles adding to the footer the @font-face CSS for locally-hosted google-fonts.
4
 * Solves privacy concerns with Google's CDN and their sometimes less-than-transparent policies.
5
 *
6
 * @package     Kirki
7
 * @category    Core
8
 * @author      Aristeides Stathopoulos
9
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
10
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
11
 * @since       3.0.28
12
 */
13
14
/**
15
 * Manages the way Google Fonts are enqueued.
16
 */
17
final class Kirki_Modules_Webfonts_Local {
18
19
	/**
20
	 * The config ID.
21
	 *
22
	 * @access protected
23
	 * @since 3.0.28
24
	 * @var string
25
	 */
26
	protected $config_id;
27
28
	/**
29
	 * The Kirki_Modules_Webfonts object.
30
	 *
31
	 * @access protected
32
	 * @since 3.0.28
33
	 * @var object
34
	 */
35
	protected $webfonts;
36
37
	/**
38
	 * The Kirki_Fonts_Google object.
39
	 *
40
	 * @access protected
41
	 * @since 3.0.28
42
	 * @var object
43
	 */
44
	protected $googlefonts;
45
46
	/**
47
	 * Fonts to load.
48
	 *
49
	 * @access protected
50
	 * @since 3.0.28
51
	 * @var array
52
	 */
53
	protected $fonts_to_load = array();
54
55
	/**
56
	 * Constructor.
57
	 *
58
	 * @access public
59
	 * @since 3..28
60
	 * @param string $config_id   The config-ID.
61
	 * @param object $webfonts    The Kirki_Modules_Webfonts object.
62
	 * @param object $googlefonts The Kirki_Fonts_Google object.
63
	 * @param array  $args        Extra args we want to pass.
64
	 */
65
	public function __construct( $config_id, $webfonts, $googlefonts, $args = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

65
	public function __construct( $config_id, $webfonts, $googlefonts, /** @scrutinizer ignore-unused */ $args = array() ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
67
		$this->config_id   = $config_id;
68
		$this->webfonts    = $webfonts;
69
		$this->googlefonts = $googlefonts;
70
71
		add_action( 'wp_footer', array( $this, 'webfont_loader' ) );
72
	}
73
74
	/**
75
	 * Webfont Loader for Google Fonts.
76
	 *
77
	 * @access public
78
	 * @since 3.0.28
79
	 */
80
	public function webfont_loader() {
81
82
		// Go through our fields and populate $this->fonts.
83
		$this->webfonts->loop_fields( $this->config_id );
84
85
		$this->googlefonts->fonts = apply_filters( 'kirki_enqueue_google_fonts', $this->googlefonts->fonts );
86
87
		// Goes through $this->fonts and adds or removes things as needed.
88
		$this->googlefonts->process_fonts();
89
90
		$css = '';
91
		$fonts = array_keys( $this->googlefonts->fonts );
92
		$fonts = array_unique( $fonts );
93
		foreach ( $fonts as $family ) {
94
			$css .= Kirki_Fonts_Google_Local::do( $family )->get_css();
95
		}
96
		if ( $css ) {
97
			echo '<style id="kirki-local-webfonts-' . esc_attr( sanitize_key( $this->config_id ) ) . '">' . $css . '</style>'; // WPCS: XSS ok.
98
		}
99
	}
100
}
101