deprecated
1 month ago
Aliases.php
2 months ago
Config.php
5 months ago
Control.php
5 months ago
Deprecated.php
5 months ago
Field.php
2 months ago
Framework.php
5 months ago
Init.php
2 months ago
Kirki.php
2 months ago
Modules.php
2 months ago
Pro_Namespace_Compatibility.php
5 months ago
Sanitize_Values.php
5 months ago
Scripts.php
2 months ago
Settings.php
5 months ago
Values.php
5 months ago
Modules.php
165 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Handles modules loading. |
| 4 | * |
| 5 | * @package Kirki |
| 6 | * @category Modules |
| 7 | * @author Themeum |
| 8 | * @copyright Copyright (c) 2023, Themeum |
| 9 | * @license https://opensource.org/licenses/MIT |
| 10 | * @since 3.0.0 |
| 11 | */ |
| 12 | |
| 13 | namespace Kirki\Compatibility; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * The Modules class. |
| 21 | */ |
| 22 | class Modules { |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * An array of available modules. |
| 27 | * |
| 28 | * @static |
| 29 | * @access private |
| 30 | * @since 3.0.0 |
| 31 | * @var array |
| 32 | */ |
| 33 | private static $modules = []; |
| 34 | |
| 35 | /** |
| 36 | * An array of active modules (objects). |
| 37 | * |
| 38 | * @static |
| 39 | * @access private |
| 40 | * @since 3.0.0 |
| 41 | * @var array |
| 42 | */ |
| 43 | private static $active_modules = []; |
| 44 | |
| 45 | /** |
| 46 | * Constructor. |
| 47 | * |
| 48 | * @access public |
| 49 | * @since 3.0.0 |
| 50 | */ |
| 51 | public function __construct() { |
| 52 | |
| 53 | add_action( 'after_setup_theme', [ $this, 'setup_default_modules' ], 10 ); |
| 54 | add_action( 'after_setup_theme', [ $this, 'init' ], 11 ); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Set the default modules and apply the 'kirki_modules' filter. |
| 60 | * In v3.0.35 this method was renamed from default_modules to setup_default_modules, |
| 61 | * and its visibility changed from private to public to fix https://github.com/aristath/kirki/issues/2023 |
| 62 | * |
| 63 | * @access public |
| 64 | * @since 3.0.0 |
| 65 | */ |
| 66 | public function setup_default_modules() { |
| 67 | |
| 68 | self::$modules = apply_filters( |
| 69 | 'kirki_modules', |
| 70 | [ |
| 71 | 'css' => '\Kirki\Module\CSS', |
| 72 | 'tooltips' => '\Kirki\Module\Tooltips', |
| 73 | 'postMessage' => '\Kirki\Module\Postmessage', |
| 74 | 'selective-refresh' => '\Kirki\Module\Selective_Refresh', |
| 75 | 'field-dependencies' => '\Kirki\Module\Field_Dependencies', |
| 76 | 'webfonts' => '\Kirki\Module\Webfonts', |
| 77 | 'preset' => '\Kirki\Module\Preset', |
| 78 | 'gutenberg' => '\Kirki\Module\Editor_Styles', |
| 79 | 'section-icons' => '\Kirki\Module\Section_Icons', |
| 80 | ] |
| 81 | ); |
| 82 | |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Instantiates the modules. |
| 87 | * In v3.0.35 the visibility for this method was changed |
| 88 | * from private to public to fix https://github.com/aristath/kirki/issues/2023 |
| 89 | * |
| 90 | * @access public |
| 91 | * @since 3.0.0 |
| 92 | */ |
| 93 | public function init() { |
| 94 | |
| 95 | foreach ( self::$modules as $module_class ) { |
| 96 | if ( class_exists( $module_class ) ) { |
| 97 | new $module_class(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Add a module. |
| 105 | * |
| 106 | * @static |
| 107 | * @access public |
| 108 | * @param string $module The classname of the module to add. |
| 109 | * @since 3.0.0 |
| 110 | */ |
| 111 | public static function add_module( $module ) { |
| 112 | |
| 113 | if ( ! in_array( $module, self::$modules, true ) ) { |
| 114 | self::$modules[] = $module; |
| 115 | } |
| 116 | |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Remove a module. |
| 121 | * |
| 122 | * @static |
| 123 | * @access public |
| 124 | * @param string $module The classname of the module to add. |
| 125 | * @since 3.0.0 |
| 126 | */ |
| 127 | public static function remove_module( $module ) { |
| 128 | |
| 129 | $key = array_search( $module, self::$modules, true ); |
| 130 | |
| 131 | if ( false !== $key ) { |
| 132 | unset( self::$modules[ $key ] ); |
| 133 | } |
| 134 | |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Get the modules array. |
| 139 | * |
| 140 | * @static |
| 141 | * @access public |
| 142 | * @since 3.0.0 |
| 143 | * @return array |
| 144 | */ |
| 145 | public static function get_modules() { |
| 146 | |
| 147 | return self::$modules; |
| 148 | |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Get the array of active modules (objects). |
| 153 | * |
| 154 | * @static |
| 155 | * @access public |
| 156 | * @since 3.0.0 |
| 157 | * @return array |
| 158 | */ |
| 159 | public static function get_active_modules() { |
| 160 | |
| 161 | return self::$active_modules; |
| 162 | |
| 163 | } |
| 164 | |
| 165 | } |