-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.php
More file actions
90 lines (79 loc) · 1.97 KB
/
Copy pathload.php
File metadata and controls
90 lines (79 loc) · 1.97 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Utility library for WordPress plugins and themes.
* @package ReallySpecific\Utils
* @since 0.1.0
*/
namespace ReallySpecific\Utils;
function setup() {
static $setup = false;
if ( $setup ) {
return;
}
autoload_directory( __DIR__ . '/functions' );
spl_autoload_register( function( $class_name ) {
class_loader( $class_name );
} );
$setup = true;
}
/**
* Requires all php files in a given directory
*
* @param mixed $abs_path
* @return void
*/
function autoload_directory( $abs_path, $recursive = false ) {
$abs_path = rtrim( $abs_path, '/' );
if ( ! is_dir( $abs_path ) ) {
throw new Exception( 'Not a directory: ' . $abs_path );
}
$dir = opendir( $abs_path );
while ( false !== ( $file = readdir( $dir ) ) ) {
if ( str_starts_with( $file, '.' ) ) {
continue;
}
if ( is_dir( $abs_path . '/' . $file ) && $recursive ) {
autoload_directory( $abs_path . '/' . $file, $recursive );
continue;
}
if ( ! str_ends_with( $file, '.php' ) ) {
continue;
}
include_once $abs_path . '/' . $file;
}
}
/**
* Loads a utility class file if the class does not already exist.
*
* @param string $class_name The name of the class to load.
* @return void
*/
function class_loader( string $class_name, ?string $class_folder = null, ?string $root_namespace = null )
{
if ( class_exists( $class_name ) ) {
return;
}
if ( is_null( $class_folder ) ) {
$class_folder = __DIR__ . '/classes/';
}
if ( is_null( $root_namespace ) ) {
$root_namespace = __NAMESPACE__;
}
$class_name = str_replace( $root_namespace . '\\', '', $class_name );
$class_path = rtrim( $class_folder, '/' ) . '/' . str_replace( '\\', '/', $class_name ) . '.php';
if ( file_exists( $class_path ) ) {
include_once $class_path;
}
}
function utils_dir() {
return __DIR__;
}
function is_debug_mode() {
return defined( 'WP_DEBUG' ) && WP_DEBUG;
}
function debug( $return_value, $log_message, $status = 'warning' ) {
return $return_value;
}
if ( defined( 'ABSPATH' ) ) {
setup();
}