Repository navigation
Expand file tree
/
Copy pathinit.php
More file actions
63 lines (49 loc) · 1.45 KB
/
Copy pathinit.php
File metadata and controls
63 lines (49 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*
* Plugin Name: Pockets Core Development Tools
* Description: A powerful site development framework for wordpress.
* Version: 0.99
* Author: Hybrid Web Dev
* Author URI: https://hybridwebdev.com
* License: GPLv2 or later
* Requires PHP: 8.0
* Requires at least: 6.0
*/
namespace pockets;
defined('ABSPATH') || exit;
#[\AllowDynamicProperties]
class base {
function __construct(){
$this->pluginFile = __FILE__;
$this->dir = plugin_dir_path( $this->pluginFile );
$this->url = plugin_dir_url( $this->pluginFile );
}
static function init(...$args){
return new static(...$args);
}
}
class autoloader {
private function __construct(
public string $dir,
public string $namespace
){}
static function register(...$args){
spl_autoload_register( [ new static(...$args), 'loader'] );
}
private function loader($filename){
$class_target = explode('\\', str_ireplace('_', '-', untrailingslashit( $filename ) ) );
if( str_replace("-", "_", $class_target[0]) != $this->namespace ) return;
array_shift($class_target); // pops off
$chunks = implode('/', $class_target);
$file = "{$this->dir}/{$chunks}.php";
if ( is_file($file) ) require_once($file);
}
}
autoloader::register( plugin_dir_path( __FILE__ ), __NAMESPACE__ );
/**
Binds at earliest priorty so that other plugins can register to load
after it.
*/
add_action("plugins_loaded", function(){
plugin\module::init();
}, 1 );