PluginProbe
SureCookie – GDPR Cookie Consent Banner, Cookie Scanner & Script Blocking / trunk
SureCookie – GDPR Cookie Consent Banner, Cookie Scanner & Script Blocking vtrunk
1.5.0 1.4.0 1.3.0 1.3.1 trunk 0.0.0-alpha.1 0.0.0-alpha.2 0.0.0-alpha.3 0.0.1-beta.1 0.0.1-beta.2 0.0.1-beta.3 0.0.1-beta.4 1.0.0 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4
surecookie / inc / modules / init.php

init.php in SureCookie – GDPR Cookie Consent Banner, Cookie Scanner & Script Blocking trunk, at inc/modules/init.php

60 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Modules Init class.
4 *
5 * @package SureCookie\Inc\Modules
6 * @since 0.0.1
7 */
8
9 namespace SureCookie\Inc\Modules;
10
11 use SureCookie\Inc\Traits\GetInstance;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Init class.
19 *
20 * @since 0.0.1
21 */
22 class Init {
23 use GetInstance;
24
25 /**
26 * Constructor.
27 *
28 * @since 0.0.1
29 */
30 public function __construct() {
31 $modules_dir = __DIR__;
32 $init_files = glob( "{$modules_dir}/*/init.php" );
33
34 if ( ! $init_files ) {
35 return;
36 }
37
38 foreach ( $init_files as $file ) {
39 $module_name = basename( dirname( $file ) );
40 $namespace_name = $this->convert_to_namespace( $module_name );
41 $class_name = "\\SureCookie\\Inc\\Modules\\{$namespace_name}\\Init";
42
43 if ( class_exists( $class_name ) && method_exists( $class_name, 'get_instance' ) ) {
44 $class_name::get_instance();
45 }
46 }
47 }
48
49 /**
50 * Convert folder name to proper namespace format.
51 *
52 * @param string $folder_name Module folder name.
53 * @return string
54 * @since 0.0.1
55 */
56 private function convert_to_namespace( string $folder_name ): string {
57 return str_replace( ' ', '', ucwords( str_replace( '-', ' ', $folder_name ) ) );
58 }
59 }
60