-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan.php
More file actions
138 lines (106 loc) · 2.76 KB
/
Copy pathplan.php
File metadata and controls
138 lines (106 loc) · 2.76 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* Plugin Name: Plan
* Plugin URI: https://wordpress.org/
* Description: Create table Plans
* Version: 1.0
* Author: lobov
* Author URI: https://wordpress.org/
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: plan
* PHP version: 7.4
*/
namespace Plan;
use Plan\Core\Core;
use Plan\CPT\CPT;
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'Plan' ) ) :
final class Plan {
// Plugin Shortcode
public const SHORTCODE = 'plans';
public const CACHEKEY = 'plans_query_cache';
public const CACHE_TTL = 0;
private static $instance;
private Autoloader $autoloader;
public static function instance(): Plan {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
self::$instance = new self;
self::$instance->includes();
self::$instance->autoloader = new Autoloader( 'Plan' );
add_action( 'plugins_loaded', [ self::$instance, 'loaded' ] );
}
return self::$instance;
}
// Plugin Root File.
public static function file(): string {
return __FILE__;
}
// Plugin Base Name.
public static function basename(): string {
return plugin_basename( __FILE__ );
}
// Plugin Folder Path.
public static function dir(): string {
return plugin_dir_path( __FILE__ );
}
// Plugin Folder URL.
public static function url(): string {
return plugin_dir_url( __FILE__ );
}
// Get Plugin Info
public static function info( $show = '' ): string {
$data = [
'name' => 'Plugin Name',
'version' => 'Version',
];
$plugin_data = get_file_data( __FILE__, $data, false );
return $plugin_data[ $show ] ?? '';
}
/**
* Include required files.
*
* @access private
* @since 1.0
*/
private function includes(): void {
require_once self::dir() . 'classes/Autoloader.php';
}
/**
* Throw error on object clone.
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @return void
* @access protected
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'plan' ), '1.0' );
}
/**
* Disable unserializing of the class.
*
* @return void
* @access protected
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'plan' ), '1.0' );
}
/**
* Download the folder with languages.
*
* @access Publisher
* @return void
*/
public function loaded(): void {
new Core();
new CPT();
}
}
endif;
function wp_plugin_run(): Plan {
return Plan::instance();
}
wp_plugin_run();