Passed
Push — develop ( d44a36...35a5e4 )
by Aristeides
03:17
created

Kirki_Modules::remove_module()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Handles modules loading.
4
 *
5
 * @package     Kirki
6
 * @category    Core
7
 * @author      Aristeides Stathopoulos
8
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
9
 * @license    https://opensource.org/licenses/MIT
10
 * @since       3.0.0
11
 */
12
13
/**
14
 * The Kirki_Modules class.
15
 */
16
class Kirki_Modules {
17
18
	/**
19
	 * An array of available modules.
20
	 *
21
	 * @static
22
	 * @access private
23
	 * @since 3.0.0
24
	 * @var array
25
	 */
26
	private static $modules = array();
27
28
	/**
29
	 * An array of active modules (objects).
30
	 *
31
	 * @static
32
	 * @access private
33
	 * @since 3.0.0
34
	 * @var array
35
	 */
36
	private static $active_modules = array();
37
38
	/**
39
	 * Constructor.
40
	 *
41
	 * @access public
42
	 * @since 3.0.0
43
	 */
44
	public function __construct() {
45
		add_action( 'after_setup_theme', array( $this, 'setup_default_modules' ), 10 );
46
		add_action( 'after_setup_theme', array( $this, 'init' ), 11 );
47
	}
48
49
	/**
50
	 * Set the default modules and apply the 'kirki_modules' filter.
51
	 * In v3.0.35 this method was renamed from default_modules to setup_default_modules,
52
	 * and its visibility changed from private to public to fix https://github.com/aristath/kirki/issues/2023
53
	 *
54
	 * @access public
55
	 * @since 3.0.0
56
	 */
57
	public function setup_default_modules() {
58
		self::$modules = apply_filters(
59
			'kirki_modules', array(
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
60
				'css'                => 'Kirki_Modules_CSS',
61
				'css-vars'           => 'Kirki_Modules_CSS_Vars',
62
				'customizer-styling' => 'Kirki_Modules_Customizer_Styling',
63
				'icons'              => 'Kirki_Modules_Icons',
64
				'loading'            => 'Kirki_Modules_Loading',
65
				'tooltips'           => 'Kirki_Modules_Tooltips',
66
				'branding'           => 'Kirki_Modules_Customizer_Branding',
67
				'postMessage'        => 'Kirki_Modules_PostMessage',
68
				'selective-refresh'  => 'Kirki_Modules_Selective_Refresh',
69
				'field-dependencies' => 'Kirki_Modules_Field_Dependencies',
70
				'custom-sections'    => 'Kirki_Modules_Custom_Sections',
71
				'webfonts'           => 'Kirki_Modules_Webfonts',
72
				'webfont-loader'     => 'Kirki_Modules_Webfont_Loader',
73
				'preset'             => 'Kirki_Modules_Preset',
74
				'gutenberg'          => 'Kirki_Modules_Gutenberg',
75
			)
76
		);
77
	}
78
79
	/**
80
	 * Instantiates the modules.
81
	 * In v3.0.35 the visibility for this method was changed
82
	 * from private to public to fix https://github.com/aristath/kirki/issues/2023
83
	 *
84
	 * @access public
85
	 * @since 3.0.0
86
	 */
87
	public function init() {
88
		foreach ( self::$modules as $key => $module_class ) {
89
			if ( class_exists( $module_class ) ) {
90
				// Use this syntax instead of $module_class::get_instance()
91
				// for PHP 5.2 compatibility.
92
				self::$active_modules[ $key ] = call_user_func( array( $module_class, 'get_instance' ) );
93
			}
94
		}
95
	}
96
97
	/**
98
	 * Add a module.
99
	 *
100
	 * @static
101
	 * @access public
102
	 * @param string $module The classname of the module to add.
103
	 * @since 3.0.0
104
	 */
105
	public static function add_module( $module ) {
106
		if ( ! in_array( $module, self::$modules, true ) ) {
107
			self::$modules[] = $module;
108
		}
109
	}
110
111
	/**
112
	 * Remove a module.
113
	 *
114
	 * @static
115
	 * @access public
116
	 * @param string $module The classname of the module to add.
117
	 * @since 3.0.0
118
	 */
119
	public static function remove_module( $module ) {
120
		$key = array_search( $module, self::$modules, true );
121
		if ( false !== $key ) {
122
			unset( self::$modules[ $key ] );
123
		}
124
	}
125
126
	/**
127
	 * Get the modules array.
128
	 *
129
	 * @static
130
	 * @access public
131
	 * @since 3.0.0
132
	 * @return array
133
	 */
134
	public static function get_modules() {
135
		return self::$modules;
136
	}
137
138
	/**
139
	 * Get the array of active modules (objects).
140
	 *
141
	 * @static
142
	 * @access public
143
	 * @since 3.0.0
144
	 * @return array
145
	 */
146
	public static function get_active_modules() {
147
		return self::$active_modules;
148
	}
149
}
150